HookerRole.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System.Linq;
  2. using System.Threading.Tasks;
  3. using MafiaTelegramBot.Game.GameRooms;
  4. using MafiaTelegramBot.Models;
  5. using MafiaTelegramBot.Resources;
  6. using User = MafiaTelegramBot.DataBase.Entity.UserEntity;
  7. namespace MafiaTelegramBot.Game.GameRoles
  8. {
  9. public class HookerRole : GameRoom.Role
  10. {
  11. public override Roles RoleKey => Roles.Hooker;
  12. private int _color = 1;
  13. public override double ColorRole
  14. {
  15. get => _color;
  16. set => _color = (int) value;
  17. }
  18. public override async Task NightAction()
  19. {
  20. NightTargetId = -1;
  21. NightTargetList = Room.Players.Values.Where(p => p.IsAlive && p.Id != Player.Id && p.CanBeBlockedNight).ToList();
  22. var message = await Bot.SendWithMarkdown2(Player.ChatId, strings.choose_player_to_block,
  23. Keyboard.NightChooseTargetKeyboard(NightTargetList, Player.Id));
  24. MessageId = message.MessageId;
  25. }
  26. public override async Task ApplyNightActionResult()
  27. {
  28. if (NightTargetId == -1)
  29. {
  30. await SetRandomNightTarget();
  31. if (Room.Players.ContainsKey(NightTargetId))
  32. await Room.Players[NightTargetId].CurrentRole.CancelNightActionResult(strings.hooker_block_you);
  33. }
  34. if (Room.Players.ContainsKey(NightTargetId))
  35. Room.Players[NightTargetId].CanBeBlockedNight = false;
  36. }
  37. public override async Task SetNightTarget(long userId)
  38. {
  39. if(Room.Players.ContainsKey(userId))
  40. {
  41. NightTargetId = userId;
  42. Room.Players[NightTargetId].CanBeBlockedNight = false;
  43. await Room.Players[NightTargetId].CurrentRole.CancelNightActionResult(strings.hooker_block_you);
  44. await Room.PlayersCh.EditTo(Player.ChatId, MessageId, $"{strings.you_choose_target} {Room.Players[userId].NickName}");
  45. }
  46. else await Room.PlayersCh.SendTo(Player.Id, strings.this_player_left_from_game);
  47. }
  48. public override Task Kill()
  49. {
  50. if (!Room.IsDay)
  51. {
  52. var target = Room.Players[NightTargetId];
  53. if (target.CurrentRole.RoleKey != Roles.Mafia) target.IsAlive = false;
  54. }
  55. Player.IsAlive = false;
  56. return Task.CompletedTask;
  57. }
  58. public HookerRole(GameRoom room, Player player) : base(room, player) { }
  59. }
  60. }