123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using System;
- using System.Linq;
- using System.Threading.Tasks;
- using MafiaTelegramBot.Game.GameRooms;
- using MafiaTelegramBot.Resources;
- namespace MafiaTelegramBot.Game.GameRoles
- {
- public class CopRole : GameRoom.Role
- {
- public override Roles RoleKey => Roles.Cop;
- private int _color = 1;
- public int CountBlack = 0;
- public int CountRed = 0;
- public override int ColorRole
- {
- get => _color;
- set => _color = (int) value;
- }
- public override async Task NightAction()
- {
- NightTargetId = -1;
- if (Player.IsAlive)
- {
- NightTargetList = Room.Players.Values
- .Where(p => p.IsAlive && (!KnownRoles.ContainsKey(p.Id) || Room.IsExtended) && p.Id != Player.Id).ToList();
- var message = await Room.PlayersMessageChannel.SendTo(Player.ChatId, strings.choose_player_to_check_role,
- Keyboard.NightChooseTargetKeyboard(NightTargetList, Player.Id));
- MessageId = message.MessageId;
- }
- else NightTargetId = -3;
- }
- public override async Task ApplyNightActionResult()
- {
- if (NightTargetId != -2 && NightTargetId != -3)
- {
- if (NightTargetId == -1) await SetRandomNightTarget();
- if (Room.Players.ContainsKey(NightTargetId))
- {
- 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 (Room.Players[NightTargetId].CurrentRole.ColorRole == 1) CountRed++;
- if (Room.Players[NightTargetId].CurrentRole.ColorRole == 2) CountBlack++;
- if (KnownRoles.ContainsKey(NightTargetId)) KnownRoles[NightTargetId] = role;
- else KnownRoles.Add(Room.Players[NightTargetId].Id, role);
- await Room.PlayersMessageChannel.EditTo(Player.Id, MessageId,
- $"{strings.role_of_your_target} {Room.Players[NightTargetId].NickName} - {role}");
- }
- else await Room.PlayersMessageChannel.EditTo(Player.Id, MessageId, strings.this_player_left_from_game);
- }
- }
- public override async Task SetNightTarget(long userId)
- {
- if (!Room.Players.ContainsKey(userId)) await Room.PlayersMessageChannel.SendTo(Player.Id, strings.this_player_left_from_game);
- else
- {
- NightTargetId = userId;
- await Room.PlayersMessageChannel.EditTo(Player.Id, MessageId, $"{strings.you_choose_target} {Room.Players[userId].NickName}");
- }
- }
- public CopRole(GameRoom room, Player player) : base(room, player) { }
- }
- }
|