HookerRole.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. public override async Task NightAction()
  13. {
  14. var targets = Room.Players.Values.Where(p => p.IsAlive && p.Id != Player.Id && p.CanBeBlockedNight).ToList();
  15. if (NightTargetId != -1) Room.Players[NightTargetId].CanBeBlockedNight = true;
  16. NightTargetId = -1;
  17. var message = await Bot.SendWithMarkdown2(Player.ChatId, strings.choose_player_to_block_night,
  18. Keyboard.NightChooseTargetKeyboard(targets, Player.Id));
  19. MessageId = message.MessageId;
  20. }
  21. public override async Task ApplyNightActionResult()
  22. {
  23. if(NightTargetId == -1) await Room.PlayersCh.EditTo(Player.Id, MafiaMessageId, strings.you_have_not_choosen_target);
  24. else Room.Players[NightTargetId].IsBlocked = false;
  25. }
  26. public override async Task SetNightTarget(long userId)
  27. {
  28. if(userId == -1) await Room.PlayersCh.EditTo(Player.Id, MafiaMessageId, strings.you_skip_vote);
  29. else
  30. {
  31. NightTargetId = userId;
  32. var target = Room.Players[userId];
  33. target.CanBeBlockedNight = false;
  34. target.IsBlocked = true;
  35. await target.CurrentRole.CancelNightActionResult(strings.hooker_block_you);
  36. await Bot.EditMessageAsync(Player.ChatId, MessageId, $"{strings.you_choose_target} {Room.Players[userId].NickName}");
  37. }
  38. }
  39. public override Task Kill()
  40. {
  41. if (NightTargetId != -1 && !Room.IsDay)
  42. {
  43. var target = Room.Players[NightTargetId];
  44. if (target.CurrentRole.RoleKey != Roles.Mafia) target.IsAlive = false;
  45. }
  46. Player.IsAlive = false;
  47. return Task.CompletedTask;
  48. }
  49. public HookerRole(GameRoom room, Player player) : base(room, player) { }
  50. }
  51. }