DoctorRole.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System.Linq;
  2. using System.Threading.Tasks;
  3. using MafiaTelegramBot.Game.GameRooms;
  4. using MafiaTelegramBot.Models;
  5. using MafiaTelegramBot.Resources;
  6. using Telegram.Bot.Types;
  7. namespace MafiaTelegramBot.Game.GameRoles
  8. {
  9. public class DoctorRole : GameRoom.Role
  10. {
  11. public override Roles RoleKey => Roles.Doctor;
  12. private bool _haveTargets = true;
  13. public override async Task NightAction()
  14. {
  15. var targets = Room.Players.Values.Where(p => p.IsAlive && p.CanBeHealed).ToList();
  16. Message message = null;
  17. if (targets.Count == 0)
  18. {
  19. message = await Bot.SendWithMarkdown2(Player.ChatId, strings.nothing_to_heal);
  20. _haveTargets = false;
  21. }
  22. else message = await Bot.SendWithMarkdown2(Player.ChatId, strings.choose_player_to_heal,
  23. Keyboard.NightChooseTargetKeyboard(targets, Player.Id));
  24. MessageId = message.MessageId;
  25. }
  26. public override async Task ApplyNightActionResult()
  27. {
  28. if (NightTargetId == -1 && _haveTargets)
  29. await Bot.EditMessageAsync(Player.ChatId, MessageId, strings.you_have_not_choosen_target);
  30. else
  31. {
  32. var target = Room.Players[NightTargetId];
  33. NightTargetId = -1;
  34. if (!target.IsAlive)
  35. {
  36. target.IsAlive = true;
  37. target.CanBeHealed = false;
  38. await Bot.SendWithMarkdown2(Player.ChatId, $"{strings.you_save_player} {target.NickName}");
  39. await Bot.SendWithMarkdown2(target.ChatId, strings.doctor_save_you);
  40. }
  41. }
  42. }
  43. public override Task CancelNightActionResult(string message)
  44. {
  45. return Task.CompletedTask;
  46. }
  47. public override async Task<Message> SetNightTarget(long userId)
  48. {
  49. NightTargetId = userId;
  50. var target = Room.Players[userId];
  51. await Bot.SendWithMarkdown2(target.ChatId, strings.doctor_heals_you);
  52. return await Bot.EditMessageAsync(Player.ChatId, MessageId, $"{strings.you_choose_target} {Room.Players[userId].NickName}");
  53. }
  54. public DoctorRole(GameRoom room, Player player) : base(room, player) { }
  55. }
  56. }