WerewolfRole.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Linq;
  2. using System.Threading.Tasks;
  3. using MafiaTelegramBot.Game.GameRooms;
  4. using MafiaTelegramBot.Resources;
  5. namespace MafiaTelegramBot.Game.GameRoles
  6. {
  7. public class WerewolfRole : GameRoom.Role
  8. {
  9. public override Roles RoleKey => Roles.Werewolf;
  10. public bool IsMafia = false;
  11. private int _color = 1;
  12. public override double ColorRole
  13. {
  14. get => _color;
  15. set => _color = (int) value;
  16. }
  17. public override async Task NightAction()
  18. {
  19. if (IsMafia)
  20. {
  21. Player.IsSpeaker = true;
  22. var targets = Room.Players.Values.Where(p => p.IsAlive).ToList();
  23. var message = await Room.PlayersCh.SendTo(Player.ChatId, strings.choose_player_to_kill,
  24. Keyboard.NightMafiaTargetKeyboard(targets, Player.Id));
  25. MafiaMessageId = message.MessageId;
  26. }
  27. }
  28. public override async Task ApplyNightActionResult()
  29. {
  30. if (IsMafia)
  31. {
  32. Player.IsSpeaker = false;
  33. if (MafiaTargetId != -2)
  34. {
  35. if (MafiaTargetId == -1)
  36. await Room.PlayersCh.EditTo(Player.Id, MafiaMessageId, strings.you_have_not_choosen_target);
  37. else MafiaTargetId = -1;
  38. }
  39. }
  40. }
  41. public void TransformToMafia()
  42. {
  43. if (IsMafia) return;
  44. ColorRole = 2;
  45. IsMafia = true;
  46. 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());
  47. foreach (var mafia in mafiaList)
  48. Room.Players[mafia.Key].CurrentRole.KnownRoles.Add(Player.Id, Player.GetRoleName());
  49. }
  50. public override async Task SetMafiaTarget(long userId)
  51. {
  52. if (IsMafia)
  53. {
  54. if (userId == -1) await Room.PlayersCh.EditTo(Player.Id, MafiaMessageId, strings.you_skip_vote);
  55. else
  56. {
  57. if (!Room.Players.ContainsKey(userId))
  58. await Room.PlayersCh.SendTo(Player.Id, strings.this_player_left_from_game);
  59. else
  60. {
  61. MafiaTargetId = userId;
  62. await Room.PlayersCh.EditTo(Player.Id, MafiaMessageId,
  63. $"{strings.you_choose_target} {Room.Players[userId].NickName}");
  64. }
  65. }
  66. }
  67. }
  68. public WerewolfRole(GameRoom room, Player player) : base(room, player) { }
  69. }
  70. }