DetectiveRole.cs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 DetectiveRole : GameRoom.Role
  8. {
  9. public override Roles RoleKey => Roles.Detective;
  10. private int _color = 1;
  11. private string _action = "";
  12. public override double ColorRole
  13. {
  14. get => _color;
  15. set => _color = (int) value;
  16. }
  17. public override async Task NightAction()
  18. {
  19. NightTargetId = -1;
  20. _action = "";
  21. NightTargetList = Room.Players.Values.Where(p => p.IsAlive).ToList();
  22. var message = await Room.PlayersCh.SendTo(Player.ChatId, strings.choose_player_to_check_or_kill,
  23. Keyboard.DetectiveTargetKeyboard(NightTargetList, Player.Id));
  24. MessageId = message.MessageId;
  25. }
  26. public override async Task ApplyNightActionResult()
  27. {
  28. if (NightTargetId != -2)
  29. {
  30. if (NightTargetId == -1)
  31. {
  32. await SetRandomNightTarget();
  33. var randomAction = Utilities.Rnd.Next(2);
  34. _action = randomAction == 0 ? "kill" : "check";
  35. }
  36. if (Room.Players.ContainsKey(NightTargetId))
  37. {
  38. if (_action == "check")
  39. {
  40. var role = Room.Players[NightTargetId].GetRole() is Roles.Don or Roles.Mafia or Roles.Dame
  41. ? roles.Mafia
  42. : Room.Players[NightTargetId].GetRole() is Roles.Werewolf && ((WerewolfRole) Room.Players[NightTargetId].CurrentRole).IsMafia
  43. ? roles.Mafia
  44. : roles.Villager;
  45. if (KnownRoles.ContainsKey(NightTargetId)) KnownRoles[NightTargetId] = role;
  46. else KnownRoles.Add(Room.Players[NightTargetId].Id, role);
  47. await Room.PlayersCh.EditTo(Player.Id, MessageId,
  48. $"{strings.role_of_your_target} {Room.Players[NightTargetId].NickName} - {role}");
  49. }
  50. else
  51. {
  52. await Room.Players[NightTargetId].CurrentRole.Kill();
  53. }
  54. }
  55. else await Room.PlayersCh.EditTo(Player.Id, MessageId, strings.this_player_left_from_game);
  56. }
  57. }
  58. public override async Task SetNightTarget(long userId)
  59. {
  60. if (!Room.Players.ContainsKey(userId)) await Room.PlayersCh.SendTo(Player.Id, strings.this_player_left_from_game);
  61. else
  62. {
  63. NightTargetId = userId;
  64. await Room.PlayersCh.EditTo(Player.Id, MessageId, $"{strings.you_choose_target} {Room.Players[userId].NickName}");
  65. }
  66. }
  67. public async Task SetNightTarget(long userId, string action)
  68. {
  69. if (!Room.Players.ContainsKey(userId)) await Room.PlayersCh.SendTo(Player.Id, strings.this_player_left_from_game);
  70. else
  71. {
  72. _action = action;
  73. NightTargetId = userId;
  74. await Room.PlayersCh.EditTo(Player.Id, MessageId, $"{strings.you_choose_target} {Room.Players[userId].NickName}");
  75. }
  76. }
  77. public DetectiveRole(GameRoom room, Player player) : base(room, player) { }
  78. }
  79. }