1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using System.Linq;
- using System.Threading.Tasks;
- using MafiaTelegramBot.Game.GameRooms;
- using MafiaTelegramBot.Resources;
- namespace MafiaTelegramBot.Game.GameRoles
- {
- public class DetectiveRole : GameRoom.Role
- {
- public override Roles RoleKey => Roles.Detective;
- private int _color = 1;
- private string _action = "";
- public override double ColorRole
- {
- get => _color;
- set => _color = (int) value;
- }
- public override async Task NightAction()
- {
- NightTargetId = -1;
- _action = "";
- NightTargetList = Room.Players.Values.Where(p => p.IsAlive).ToList();
- var message = await Room.PlayersCh.SendTo(Player.ChatId, strings.choose_player_to_check_or_kill,
- Keyboard.DetectiveTargetKeyboard(NightTargetList, Player.Id));
- MessageId = message.MessageId;
- }
- public override async Task ApplyNightActionResult()
- {
- if (NightTargetId != -2)
- {
- if (NightTargetId == -1)
- {
- await SetRandomNightTarget();
- var randomAction = Utilities.Rnd.Next(2);
- _action = randomAction == 0 ? "kill" : "check";
- }
- if (Room.Players.ContainsKey(NightTargetId))
- {
- if (_action == "check")
- {
- var role = Room.Players[NightTargetId].GetRole() is Roles.Don or Roles.Mafia or Roles.Dame
- ? roles.Mafia
- : Room.Players[NightTargetId].GetRole() is Roles.Werewolf && ((WerewolfRole) Room.Players[NightTargetId].CurrentRole).IsMafia
- ? roles.Mafia
- : roles.Villager;
- if (KnownRoles.ContainsKey(NightTargetId)) KnownRoles[NightTargetId] = role;
- else KnownRoles.Add(Room.Players[NightTargetId].Id, role);
- await Room.PlayersCh.EditTo(Player.Id, MessageId,
- $"{strings.role_of_your_target} {Room.Players[NightTargetId].NickName} - {role}");
- }
- else
- {
- await Room.Players[NightTargetId].CurrentRole.Kill();
- }
- }
- else await Room.PlayersCh.EditTo(Player.Id, MessageId, strings.this_player_left_from_game);
- }
- }
- public override async Task SetNightTarget(long userId)
- {
- if (!Room.Players.ContainsKey(userId)) await Room.PlayersCh.SendTo(Player.Id, strings.this_player_left_from_game);
- else
- {
- NightTargetId = userId;
- await Room.PlayersCh.EditTo(Player.Id, MessageId, $"{strings.you_choose_target} {Room.Players[userId].NickName}");
- }
- }
- public async Task SetNightTarget(long userId, string action)
- {
- if (!Room.Players.ContainsKey(userId)) await Room.PlayersCh.SendTo(Player.Id, strings.this_player_left_from_game);
- else
- {
- _action = action;
- NightTargetId = userId;
- await Room.PlayersCh.EditTo(Player.Id, MessageId, $"{strings.you_choose_target} {Room.Players[userId].NickName}");
- }
- }
- public DetectiveRole(GameRoom room, Player player) : base(room, player) { }
- }
- }
|