12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using System.Linq;
- using System.Threading.Tasks;
- using MafiaTelegramBot.Game.GameRooms;
- using MafiaTelegramBot.Resources;
- namespace MafiaTelegramBot.Game.GameRoles
- {
- public class WerewolfRole : GameRoom.Role
- {
- public override Roles RoleKey => Roles.Werewolf;
- public bool IsMafia = false;
-
- private int _color = 1;
- public override double ColorRole
- {
- get => _color;
- set => _color = (int) value;
- }
- public override async Task NightAction()
- {
- if (IsMafia)
- {
- Player.IsSpeaker = true;
- var targets = Room.Players.Values.Where(p => p.IsAlive).ToList();
- var message = await Room.PlayersCh.SendTo(Player.ChatId, strings.choose_player_to_kill,
- Keyboard.NightMafiaTargetKeyboard(targets, Player.Id));
- MafiaMessageId = message.MessageId;
- }
- }
- public override async Task ApplyNightActionResult()
- {
- if (IsMafia)
- {
- Player.IsSpeaker = false;
- if (MafiaTargetId != -2)
- {
- if (MafiaTargetId == -1)
- await Room.PlayersCh.EditTo(Player.Id, MafiaMessageId, strings.you_have_not_choosen_target);
- else MafiaTargetId = -1;
- }
- }
- }
- public void TransformToMafia()
- {
- if (IsMafia) return;
- ColorRole = 2;
- IsMafia = true;
- var mafiaList = Room.Players.Values.Where(p => p.GetRole() is Roles.Don or Roles.Mafia or Roles.Dame).ToDictionary(p=>p.Id, p => p.GetRoleName());
- foreach (var mafia in mafiaList)
- Room.Players[mafia.Key].CurrentRole.KnownRoles.Add(Player.Id, Player.GetRoleName());
- }
- public override async Task SetMafiaTarget(long userId)
- {
- if (IsMafia)
- {
- if (userId == -1) await Room.PlayersCh.EditTo(Player.Id, MafiaMessageId, strings.you_skip_vote);
- else
- {
- if (!Room.Players.ContainsKey(userId))
- await Room.PlayersCh.SendTo(Player.Id, strings.this_player_left_from_game);
- else
- {
- MafiaTargetId = userId;
- await Room.PlayersCh.EditTo(Player.Id, MafiaMessageId,
- $"{strings.you_choose_target} {Room.Players[userId].NickName}");
- }
- }
- }
- }
- public WerewolfRole(GameRoom room, Player player) : base(room, player) { }
- }
- }
|