HookerRole.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. NightTargetList = 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(NightTargetList, Player.Id));
  19. MessageId = message.MessageId;
  20. }
  21. public override async Task ApplyNightActionResult()
  22. {
  23. if (NightTargetId == -1)
  24. {
  25. NightTargetId = NightTargetList[Utilities.Rnd.Next(NightTargetList.Count)].Id;
  26. var target = Room.Players[NightTargetId];
  27. target.CanBeBlockedNight = false;
  28. await target.CurrentRole.CancelNightActionResult(strings.hooker_block_you);
  29. await Room.PlayersCh.EditTo(Player.Id, MessageId, $"{strings.automatically_choosed_target} {Room.Players[NightTargetId].NickName}");
  30. }
  31. else Room.Players[NightTargetId].IsBlocked = false;
  32. }
  33. public override async Task SetNightTarget(long userId)
  34. {
  35. NightTargetId = userId;
  36. var target = Room.Players[userId];
  37. target.CanBeBlockedNight = false;
  38. target.IsBlocked = true;
  39. await target.CurrentRole.CancelNightActionResult(strings.hooker_block_you);
  40. await Bot.EditMessageAsync(Player.ChatId, MessageId, $"{strings.you_choose_target} {Room.Players[userId].NickName}");
  41. }
  42. public override Task Kill()
  43. {
  44. if (!Room.IsDay)
  45. {
  46. var target = Room.Players[NightTargetId];
  47. if (target.CurrentRole.RoleKey != Roles.Mafia) target.IsAlive = false;
  48. }
  49. Player.IsAlive = false;
  50. return Task.CompletedTask;
  51. }
  52. public HookerRole(GameRoom room, Player player) : base(room, player) { }
  53. }
  54. }