|
@@ -1,4 +1,5 @@
|
|
using System;
|
|
using System;
|
|
|
|
+using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
@@ -14,42 +15,50 @@ namespace MafiaTelegramBot.Game.GameRooms
|
|
{
|
|
{
|
|
public abstract class Role
|
|
public abstract class Role
|
|
{
|
|
{
|
|
- private readonly GameRoom _room;
|
|
|
|
|
|
+ protected readonly GameRoom Room;
|
|
|
|
+ protected readonly Player Player;
|
|
|
|
+ public readonly List<Player> KnownRoles = new();
|
|
|
|
+ protected long NightTargetId = -1;
|
|
|
|
+ public readonly ManualResetEvent DayActionComplete = new(false);
|
|
|
|
+ protected int MessageId = -1;
|
|
|
|
+ public abstract Task NightAction();
|
|
|
|
+ public abstract Task ApplyNightActionResult();
|
|
|
|
+ public abstract Task<Message> SetNightTarget(long userId);
|
|
|
|
+ public abstract Roles RoleKey { get; }
|
|
|
|
|
|
- protected Role(GameRoom room)
|
|
|
|
|
|
+ protected Role(GameRoom room, Player player)
|
|
{
|
|
{
|
|
- _room = room;
|
|
|
|
|
|
+ Room = room;
|
|
|
|
+ Player = player;
|
|
}
|
|
}
|
|
- public abstract Roles RoleKey { get; }
|
|
|
|
|
|
|
|
- public readonly ManualResetEvent DayActionComplete = new(false);
|
|
|
|
- public async Task DayAction(Player player)
|
|
|
|
|
|
+ public async Task DayAction()
|
|
{
|
|
{
|
|
- await _room.PlayersCh.SendExcept(player.Id, $"{strings.now_turn} {player.NickName}");
|
|
|
|
- await Bot.SendWithMarkdown2(player.ChatId, strings.your_turn);
|
|
|
|
- player.IsSpeaker = true;
|
|
|
|
|
|
+ await Room.PlayersCh.SendExcept(Player.Id, $"{strings.now_turn} {Player.NickName}");
|
|
|
|
+ await Bot.SendWithMarkdown2(Player.ChatId, strings.your_turn);
|
|
|
|
+ Player.IsSpeaker = true;
|
|
var timer = new Timer(60 * 1000);
|
|
var timer = new Timer(60 * 1000);
|
|
- var voteTimer = new Timer(60 * 1000);
|
|
|
|
|
|
+ var voteTimer = new Timer(10 * 1000);
|
|
Message message = null;
|
|
Message message = null;
|
|
- timer.Elapsed += async (sender, args) =>
|
|
|
|
|
|
+ timer.Elapsed += async (_, _) =>
|
|
{
|
|
{
|
|
- player.IsSpeaker = false;
|
|
|
|
- await Bot.SendWithMarkdown2(player.ChatId, strings.your_turn_ended);
|
|
|
|
- if (!_room.IsFirstCycle)
|
|
|
|
|
|
+ Player.IsSpeaker = false;
|
|
|
|
+ await Bot.SendWithMarkdown2(Player.ChatId, strings.your_turn_ended);
|
|
|
|
+ if (!Room.IsFirstCycle)
|
|
{
|
|
{
|
|
- var alivePlayers = _room.Players.Values.Where(p => p.IsAlive).ToList();
|
|
|
|
- message = await Bot.SendWithMarkdown2(player.ChatId, strings.put_up_vote, Keyboards.VoteKeyboard(alivePlayers, player.Id, !player.IsFirst));
|
|
|
|
- voteTimer.Elapsed += async (o, eventArgs) =>
|
|
|
|
|
|
+ var alivePlayers = Room.Players.Values.Where(p => p.IsAlive).ToList();
|
|
|
|
+ message = await Bot.SendWithMarkdown2(Player.ChatId, strings.put_up_vote, Keyboards.VoteKeyboard(alivePlayers, Player.Id, !Player.IsFirst));
|
|
|
|
+ voteTimer.Elapsed += async (_, _) =>
|
|
{
|
|
{
|
|
- await Bot.Get().EditMessageReplyMarkupAsync(player.ChatId, message.MessageId);
|
|
|
|
- if (player.IsFirst)
|
|
|
|
- await _room.PutUpVote(player.Id, player.Id);
|
|
|
|
|
|
+ await Bot.Get().EditMessageReplyMarkupAsync(Player.ChatId, message.MessageId);
|
|
|
|
+ if (Player.IsFirst)
|
|
|
|
+ await Room.PutUpVote(Player.Id, Player.Id);
|
|
else
|
|
else
|
|
- await _room.PlayersCh.SendExcept(player.Id, $"{player.NickName} {strings.didnt_put_anyone}");
|
|
|
|
|
|
+ await Room.PlayersCh.SendExcept(Player.Id, $"{Player.NickName} {strings.didnt_put_anyone}");
|
|
DayActionComplete.Set();
|
|
DayActionComplete.Set();
|
|
};
|
|
};
|
|
- await Bot.SendWithMarkdown2(player.Id, strings.you_have_one_minute);
|
|
|
|
- if(player.IsFirst) await Bot.SendWithMarkdown2(player.Id, strings.user_not_choose);
|
|
|
|
|
|
+ await Bot.SendWithMarkdown2(Player.Id, strings.you_have_one_minute);
|
|
|
|
+ if(Player.IsFirst) await Bot.SendWithMarkdown2(Player.Id, strings.user_not_choose);
|
|
voteTimer.Start();
|
|
voteTimer.Start();
|
|
}
|
|
}
|
|
if(!voteTimer.Enabled) DayActionComplete.Set();
|
|
if(!voteTimer.Enabled) DayActionComplete.Set();
|
|
@@ -60,23 +69,21 @@ namespace MafiaTelegramBot.Game.GameRooms
|
|
DayActionComplete.Reset();
|
|
DayActionComplete.Reset();
|
|
timer.Stop();
|
|
timer.Stop();
|
|
voteTimer.Stop();
|
|
voteTimer.Stop();
|
|
- if(message!=null) await Bot.Get().DeleteMessageAsync(player.ChatId, message.MessageId);
|
|
|
|
|
|
+ if(message!=null) await Bot.Get().DeleteMessageAsync(Player.ChatId, message.MessageId);
|
|
}
|
|
}
|
|
|
|
|
|
- protected abstract Task<Message> NightAction(Player player);
|
|
|
|
-
|
|
|
|
- public static Role GetNewRoleInstance(Roles roleKey, GameRoom room)
|
|
|
|
|
|
+ public static Role GetNewRoleInstance(Roles roleKey, GameRoom room, Player player)
|
|
{
|
|
{
|
|
return roleKey switch
|
|
return roleKey switch
|
|
{
|
|
{
|
|
- Roles.All => new NoneRole(room),
|
|
|
|
- Roles.Doctor => new DoctorRole(room),
|
|
|
|
- Roles.Mafia => new MafiaRole(room),
|
|
|
|
- Roles.Don => new DonRole(room),
|
|
|
|
- Roles.Cop => new CopRole(room),
|
|
|
|
- Roles.Villager => new VillagerRole(room),
|
|
|
|
- Roles.Hooker => new HookerRole(room),
|
|
|
|
- Roles.None => new NoneRole(room),
|
|
|
|
|
|
+ Roles.All => new NoneRole(),
|
|
|
|
+ Roles.Doctor => new DoctorRole(room, player),
|
|
|
|
+ Roles.Mafia => new MafiaRole(room, player),
|
|
|
|
+ Roles.Don => new DonRole(room, player),
|
|
|
|
+ Roles.Cop => new CopRole(room, player),
|
|
|
|
+ Roles.Villager => new VillagerRole(room, player),
|
|
|
|
+ Roles.Hooker => new HookerRole(room, player),
|
|
|
|
+ Roles.None => new NoneRole(room, player),
|
|
_ => throw new ArgumentOutOfRangeException(nameof(roleKey), roleKey, null)
|
|
_ => throw new ArgumentOutOfRangeException(nameof(roleKey), roleKey, null)
|
|
};
|
|
};
|
|
}
|
|
}
|