NecromancerRole.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 NecromancerRole : GameRoom.Role
  8. {
  9. public override Roles RoleKey => Roles.Necromancer;
  10. public override int RankingCost { get; } = 25;
  11. private int _color = 1;
  12. public override int ColorRole
  13. {
  14. get => _color;
  15. set => _color = (int) value;
  16. }
  17. private bool _actionApplied;
  18. public override async Task NightAction()
  19. {
  20. NightTargetId = -1;
  21. if (Player.IsAlive)
  22. {
  23. if (!_actionApplied)
  24. {
  25. NightTargetList = Room.Players.Values.Where(p => !p.IsAlive).ToList();
  26. var message = NightTargetList.Count > 0
  27. ? await Room.PlayersMessageChannel.SendTo(Player.Info, strings.choose_player_to_ressurect,
  28. Keyboard.NightChooseTargetKeyboard(NightTargetList, true))
  29. : await Room.PlayersMessageChannel.SendTo(Player.Info, strings.nothing_to_ressurect);
  30. MessageId = message.MessageId;
  31. }
  32. }
  33. else NightTargetId = -3;
  34. }
  35. public override async Task ApplyNightActionResult()
  36. {
  37. if (_actionApplied || NightTargetId == -2) { }
  38. else if (NightTargetId == -1) await Room.PlayersMessageChannel.EditTo(Player.Info, MessageId, strings.you_have_not_choosen_target);
  39. else if (NightTargetId != -3)
  40. {
  41. _actionApplied = true;
  42. if(Room.Players.ContainsKey(NightTargetId))
  43. if (Room.Players[NightTargetId].CurrentRole.RoleKey == Roles.Parasite)
  44. {
  45. var parasiteTarget = ((ParasiteRole) Room.PlayersRole[Roles.Parasite][0].CurrentRole).ParentId;
  46. if (Room.Players[parasiteTarget].IsAlive) Room.Players[NightTargetId].IsAlive = true;
  47. else
  48. await Room.PlayersMessageChannel.EditTo(Player.Info, MessageId, strings.player_parasit_with_dead_owner);
  49. }
  50. else Room.Players[NightTargetId].IsAlive = true;
  51. }
  52. }
  53. public override async Task SetNightTarget(long userId)
  54. {
  55. if (!Room.Players.ContainsKey(userId)) await Room.PlayersMessageChannel.SendTo(Player.Info, strings.this_player_left_from_game);
  56. else if (userId != -1)
  57. {
  58. NightTargetId = userId;
  59. if(userId == Player.Info.Id) await Room.PlayersMessageChannel.EditTo(Player.Info, MessageId,strings.you_heal_yourself);
  60. else await Room.PlayersMessageChannel.EditTo(Player.Info, MessageId, $"{strings.you_choose_target} {Room.Players[NightTargetId].Info.NickName}");
  61. }
  62. else await Room.PlayersMessageChannel.EditTo(Player.Info, MessageId, strings.you_skip_vote);
  63. }
  64. public NecromancerRole(GameRoom room, Player player) : base(room, player) { }
  65. }
  66. }