LawyerRole.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 LawyerRole : GameRoom.Role
  8. {
  9. public override Roles RoleKey => Roles.Lawyer;
  10. private int _color = 1;
  11. public override int ColorRole
  12. {
  13. get => _color;
  14. set => _color = (int) value;
  15. }
  16. public override async Task NightAction()
  17. {
  18. NightTargetId = -1;
  19. NightTargetList = Room.Players.Values.Where(p => p.IsAlive).ToList();
  20. var message = await Room.PlayersCh.SendTo(Player.ChatId, strings.choose_player_to_check_role,
  21. Keyboard.NightChooseTargetKeyboard(NightTargetList, Player.Id));
  22. MessageId = message.MessageId;
  23. }
  24. public override async Task ApplyNightActionResult()
  25. {
  26. if (NightTargetId != -2)
  27. {
  28. if (NightTargetId == -1) await SetRandomNightTarget();
  29. if (Room.Players.ContainsKey(NightTargetId))
  30. {
  31. var role = Room.Players[NightTargetId].GetRole() is Roles.Don or Roles.Mafia or Roles.Dame
  32. ? roles.Mafia
  33. : Room.Players[NightTargetId].GetRole() is Roles.Werewolf && ((WerewolfRole) Room.Players[NightTargetId].CurrentRole).IsMafia
  34. ? roles.Mafia
  35. : roles.Villager;
  36. if (KnownRoles.ContainsKey(NightTargetId)) KnownRoles[NightTargetId] = role;
  37. else KnownRoles.Add(Room.Players[NightTargetId].Id, role);
  38. await Room.PlayersCh.EditTo(Player.Id, MessageId,
  39. $"{strings.role_of_your_target} {Room.Players[NightTargetId].NickName} - {role}");
  40. }
  41. else await Room.PlayersCh.EditTo(Player.Id, MessageId, strings.this_player_left_from_game);
  42. }
  43. }
  44. public override async Task SetNightTarget(long userId)
  45. {
  46. if (!Room.Players.ContainsKey(userId)) await Room.PlayersCh.SendTo(Player.Id, strings.this_player_left_from_game);
  47. else
  48. {
  49. NightTargetId = userId;
  50. await Room.PlayersCh.EditTo(Player.Id, MessageId, $"{strings.you_choose_target} {Room.Players[userId].NickName}");
  51. }
  52. }
  53. public LawyerRole(GameRoom room, Player player) : base(room, player) { }
  54. }
  55. }