CopRole.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using MafiaTelegramBot.Game.GameRooms;
  5. using MafiaTelegramBot.Resources;
  6. namespace MafiaTelegramBot.Game.GameRoles
  7. {
  8. public class CopRole : GameRoom.Role
  9. {
  10. public override Roles RoleKey => Roles.Cop;
  11. private int _color = 1;
  12. public int CountBlack = 0;
  13. public int CountRed = 0;
  14. public override int ColorRole
  15. {
  16. get => _color;
  17. set => _color = (int) value;
  18. }
  19. public override async Task NightAction()
  20. {
  21. NightTargetId = -1;
  22. if (Player.IsAlive)
  23. {
  24. NightTargetList = Room.Players.Values
  25. .Where(p => p.IsAlive && (!KnownRoles.ContainsKey(p.Id) || Room.IsExtended) && p.Id != Player.Id).ToList();
  26. var message = await Room.PlayersMessageChannel.SendTo(Player.ChatId, strings.choose_player_to_check_role,
  27. Keyboard.NightChooseTargetKeyboard(NightTargetList, Player.Id));
  28. MessageId = message.MessageId;
  29. }
  30. else NightTargetId = -3;
  31. }
  32. public override async Task ApplyNightActionResult()
  33. {
  34. if (NightTargetId != -2 && NightTargetId != -3)
  35. {
  36. if (NightTargetId == -1) await SetRandomNightTarget();
  37. if (Room.Players.ContainsKey(NightTargetId))
  38. {
  39. var role = Room.Players[NightTargetId].GetRole() is Roles.Don or Roles.Mafia or Roles.Dame
  40. ? roles.Mafia
  41. : Room.Players[NightTargetId].GetRole() is Roles.Werewolf && ((WerewolfRole) Room.Players[NightTargetId].CurrentRole).IsMafia
  42. ? roles.Mafia
  43. : roles.Villager;
  44. if (Room.Players[NightTargetId].CurrentRole.ColorRole == 1) CountRed++;
  45. if (Room.Players[NightTargetId].CurrentRole.ColorRole == 2) CountBlack++;
  46. if (KnownRoles.ContainsKey(NightTargetId)) KnownRoles[NightTargetId] = role;
  47. else KnownRoles.Add(Room.Players[NightTargetId].Id, role);
  48. await Room.PlayersMessageChannel.EditTo(Player.Id, MessageId,
  49. $"{strings.role_of_your_target} {Room.Players[NightTargetId].NickName} - {role}");
  50. }
  51. else await Room.PlayersMessageChannel.EditTo(Player.Id, MessageId, strings.this_player_left_from_game);
  52. }
  53. }
  54. public override async Task SetNightTarget(long userId)
  55. {
  56. if (!Room.Players.ContainsKey(userId)) await Room.PlayersMessageChannel.SendTo(Player.Id, strings.this_player_left_from_game);
  57. else
  58. {
  59. NightTargetId = userId;
  60. await Room.PlayersMessageChannel.EditTo(Player.Id, MessageId, $"{strings.you_choose_target} {Room.Players[userId].NickName}");
  61. }
  62. }
  63. public CopRole(GameRoom room, Player player) : base(room, player) { }
  64. }
  65. }