|
@@ -2,7 +2,6 @@ using System.Linq;
|
|
|
using System.Threading.Tasks;
|
|
|
using MafiaTelegramBot.Game.GameRooms;
|
|
|
using MafiaTelegramBot.Resources;
|
|
|
-using Telegram.Bot.Types;
|
|
|
|
|
|
namespace MafiaTelegramBot.Game.GameRoles
|
|
|
{
|
|
@@ -10,13 +9,14 @@ namespace MafiaTelegramBot.Game.GameRoles
|
|
|
{
|
|
|
public override Roles RoleKey => Roles.Parasite;
|
|
|
|
|
|
- private bool _haveTarget = false;
|
|
|
+ private bool _actionApplied;
|
|
|
+ public long ParentId;
|
|
|
public override async Task NightAction()
|
|
|
{
|
|
|
- if (NightTargetId == -1)
|
|
|
+ if (!_actionApplied)
|
|
|
{
|
|
|
- NightTargetList = Room.Players.Values.Except(KnownRoles).Where(p => p.IsAlive).ToList();
|
|
|
- var message = await Room.PlayersCh.SendTo(Player.ChatId, strings.choose_player_to_check_role,
|
|
|
+ NightTargetList = Room.Players.Values.Where(p => p.IsAlive && p.Id != Player.Id).ToList();
|
|
|
+ var message = await Room.PlayersCh.SendTo(Player.ChatId, strings.choose_your_container,
|
|
|
Keyboard.NightChooseTargetKeyboard(NightTargetList, Player.Id));
|
|
|
MessageId = message.MessageId;
|
|
|
}
|
|
@@ -24,65 +24,38 @@ namespace MafiaTelegramBot.Game.GameRoles
|
|
|
|
|
|
public override async Task CancelNightActionResult(string message)
|
|
|
{
|
|
|
- if (!_haveTarget) await base.CancelNightActionResult(message);
|
|
|
+ if (!_actionApplied) await base.CancelNightActionResult(message);
|
|
|
}
|
|
|
|
|
|
public override async Task ApplyNightActionResult()
|
|
|
{
|
|
|
- if (!_haveTarget && NightTargetId != -2)
|
|
|
+ if (!_actionApplied && NightTargetId != -2)
|
|
|
{
|
|
|
- if (NightTargetId == -1)
|
|
|
- {
|
|
|
- NightTargetId = NightTargetList[Utilities.Rnd.Next(NightTargetList.Count)].Id;
|
|
|
- await Room.PlayersCh.EditTo(Player.Id, MessageId,
|
|
|
- $"{strings.automatically_choosed_target} {Room.Players[NightTargetId].NickName}");
|
|
|
- }
|
|
|
-
|
|
|
- if (Room.Players.ContainsKey(NightTargetId))
|
|
|
- {
|
|
|
- if (!_haveTarget && NightTargetId != -1)
|
|
|
- {
|
|
|
- _haveTarget = true;
|
|
|
- await Room.PlayersCh.SendTo(NightTargetId,
|
|
|
- $"{strings.you_have_been_chosen_by_the_parasite} {Player.NickName}");
|
|
|
- }
|
|
|
- }
|
|
|
+ _actionApplied = true;
|
|
|
+ if (NightTargetId == -1) await SetRandomNightTarget();
|
|
|
+ ParentId = NightTargetId;
|
|
|
+ if (NightTargetId != -1)
|
|
|
+ await Room.PlayersCh.SendTo(NightTargetId, $"{strings.you_have_been_chosen_by_the_parasite} {Player.NickName}");
|
|
|
else Player.IsAlive = false;
|
|
|
}
|
|
|
-
|
|
|
- if (Room.Players.ContainsKey(NightTargetId) && NightTargetId != -2)
|
|
|
- {
|
|
|
- if (_haveTarget)
|
|
|
- {
|
|
|
- if (!Room.Players[NightTargetId].IsAlive && Player.IsAlive)
|
|
|
- {
|
|
|
- Player.IsAlive = false;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else Player.IsAlive = false;
|
|
|
}
|
|
|
|
|
|
public override async Task<string> IsWon()
|
|
|
{
|
|
|
return await Task.Run(() =>
|
|
|
{
|
|
|
- if (Room.Players.ContainsKey(NightTargetId))
|
|
|
- if (Room.Players[NightTargetId].IsAlive) return strings.the_parasite_won;
|
|
|
- return "";
|
|
|
+ if (!Room.Players.ContainsKey(ParentId)) return "";
|
|
|
+ return Room.Players[ParentId].IsAlive ? strings.the_parasite_won : "";
|
|
|
});
|
|
|
}
|
|
|
|
|
|
public override async Task SetNightTarget(long userId)
|
|
|
{
|
|
|
- if (!_haveTarget)
|
|
|
+ if (!Room.Players.ContainsKey(userId)) await Room.PlayersCh.SendTo(Player.Id, strings.this_player_left_from_game);
|
|
|
+ else
|
|
|
{
|
|
|
- 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}");
|
|
|
- }
|
|
|
+ NightTargetId = userId;
|
|
|
+ await Room.PlayersCh.EditTo(Player.Id, MessageId, $"{strings.you_choose_target} {Room.Players[userId].NickName}");
|
|
|
}
|
|
|
}
|
|
|
public ParasiteRole(GameRoom room, Player player) : base(room, player) { }
|