BodyguardRole.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.Linq;
  2. using System.Threading.Tasks;
  3. using MafiaTelegramBot.Game.GameRooms;
  4. using MafiaTelegramBot.Models;
  5. using MafiaTelegramBot.Resources;
  6. namespace MafiaTelegramBot.Game.GameRoles
  7. {
  8. public class BodyguardRole : GameRoom.Role
  9. {
  10. public override Roles RoleKey => Roles.Bodyguard;
  11. public override async Task NightAction()
  12. {
  13. NightTargetId = -1;
  14. NightTargetList = Room.Players.Values.Where(p => p.IsAlive && p.Id != Player.Id).ToList();
  15. var message = await Bot.SendWithMarkdown2(Player.ChatId, strings.choose_target_to_protect,
  16. Keyboard.NightChooseTargetKeyboard(NightTargetList, Player.Id));
  17. MessageId = message.MessageId;
  18. }
  19. public override async Task ApplyNightActionResult()
  20. {
  21. if (NightTargetId != -2)
  22. {
  23. if (NightTargetId == -1) await SetRandomNightTarget();
  24. if(Room.Players.ContainsKey(NightTargetId))
  25. {
  26. if (!Room.Players[NightTargetId].IsAlive)
  27. {
  28. Room.Players[NightTargetId].IsAlive = true;
  29. Player.IsAlive = false;
  30. }
  31. }
  32. }
  33. }
  34. public override async Task SetNightTarget(long userId)
  35. {
  36. if (!Room.Players.ContainsKey(userId)) await Room.PlayersCh.SendTo(Player.Id, strings.this_player_left_from_game);
  37. else
  38. {
  39. NightTargetId = userId;
  40. await Room.PlayersCh.EditTo(Player.Id, MessageId, $"{strings.you_choose_target} {Room.Players[userId].NickName}");
  41. }
  42. }
  43. public BodyguardRole(GameRoom room, Player player) : base(room, player) { }
  44. }
  45. }