|
@@ -8,7 +8,6 @@ namespace MafiaTelegramBot.Game.GameRooms
|
|
{
|
|
{
|
|
public partial class GameRoom
|
|
public partial class GameRoom
|
|
{
|
|
{
|
|
-
|
|
|
|
public abstract class Channel
|
|
public abstract class Channel
|
|
{
|
|
{
|
|
protected readonly GameRoom Room;
|
|
protected readonly GameRoom Room;
|
|
@@ -18,46 +17,62 @@ namespace MafiaTelegramBot.Game.GameRooms
|
|
Room = room;
|
|
Room = room;
|
|
}
|
|
}
|
|
|
|
|
|
- public abstract Task Send(string message, IReplyMarkup replyMarkup = null);
|
|
|
|
- public abstract Task SendExcept(long playerId, string message, IReplyMarkup replyMarkup = null);
|
|
|
|
|
|
+ public abstract Task Send(string message, IReplyMarkup replyMarkup = null,
|
|
|
|
+ bool exceptDied = false);
|
|
|
|
+
|
|
|
|
+ public abstract Task SendExcept(long playerId, string message, IReplyMarkup replyMarkup = null,
|
|
|
|
+ bool exceptDied = false);
|
|
}
|
|
}
|
|
|
|
+
|
|
public class PlayersChannel : Channel
|
|
public class PlayersChannel : Channel
|
|
{
|
|
{
|
|
- public override async Task Send(string message, IReplyMarkup replyMarkup = null)
|
|
|
|
|
|
+ public override async Task Send(string message, IReplyMarkup replyMarkup = null,
|
|
|
|
+ bool exceptDied = false)
|
|
{
|
|
{
|
|
- var receivers = Room.Players.Values;
|
|
|
|
|
|
+ var receivers = exceptDied
|
|
|
|
+ ? Room.Players.Values
|
|
|
|
+ : Room.Players.Values.Where(p => p.IsAlive);
|
|
foreach (var player in receivers)
|
|
foreach (var player in receivers)
|
|
await Bot.SendWithMarkdown2(player.ChatId, message, replyMarkup);
|
|
await Bot.SendWithMarkdown2(player.ChatId, message, replyMarkup);
|
|
}
|
|
}
|
|
|
|
|
|
- public override async Task SendExcept(long playerId, string message, IReplyMarkup replyMarkup = null)
|
|
|
|
|
|
+ public override async Task SendExcept(long playerId, string message, IReplyMarkup replyMarkup = null,
|
|
|
|
+ bool exceptDied = false)
|
|
{
|
|
{
|
|
- var receivers = Room.Players.Values.Where(p => p.Id != playerId);
|
|
|
|
|
|
+ var receivers = exceptDied ? Room.Players.Values
|
|
|
|
+ : Room.Players.Values.Where(p => p.IsAlive && p.Id != playerId);
|
|
foreach (var player in receivers)
|
|
foreach (var player in receivers)
|
|
await Bot.SendWithMarkdown2(player.ChatId, message, replyMarkup);
|
|
await Bot.SendWithMarkdown2(player.ChatId, message, replyMarkup);
|
|
}
|
|
}
|
|
|
|
|
|
- public PlayersChannel(GameRoom room) : base(room) { }
|
|
|
|
|
|
+ public PlayersChannel(GameRoom room) : base(room)
|
|
|
|
+ {
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public class MafiaChannel : Channel
|
|
public class MafiaChannel : Channel
|
|
{
|
|
{
|
|
- public override async Task Send(string message, IReplyMarkup replyMarkup = null)
|
|
|
|
|
|
+ public override async Task Send(string message, IReplyMarkup replyMarkup = null, bool exceptDied = false)
|
|
{
|
|
{
|
|
- var receivers = Room.Players.Values.Where(p=> p.CurrentRole.RoleKey is Roles.Don or Roles.Mafia);
|
|
|
|
|
|
+ var mafia = Room.Players.Values.Where(p => p.CurrentRole.RoleKey is Roles.Don or Roles.Mafia);
|
|
|
|
+ var receivers = exceptDied ? mafia : mafia.Where(p => p.IsAlive);
|
|
foreach (var player in receivers)
|
|
foreach (var player in receivers)
|
|
await Bot.SendWithMarkdown2(player.ChatId, message, replyMarkup);
|
|
await Bot.SendWithMarkdown2(player.ChatId, message, replyMarkup);
|
|
}
|
|
}
|
|
|
|
|
|
- public override async Task SendExcept(long playerId, string message, IReplyMarkup replyMarkup = null)
|
|
|
|
|
|
+ public override async Task SendExcept(long playerId, string message, IReplyMarkup replyMarkup = null,
|
|
|
|
+ bool exceptDied = false)
|
|
{
|
|
{
|
|
var except = Room.Players.Values.Where(p => p.Id != playerId);
|
|
var except = Room.Players.Values.Where(p => p.Id != playerId);
|
|
- var receivers = except.Where(p=> p.CurrentRole.RoleKey is Roles.Don or Roles.Mafia);
|
|
|
|
|
|
+ var mafia = except.Where(p => p.CurrentRole.RoleKey is Roles.Don or Roles.Mafia);
|
|
|
|
+ var receivers = exceptDied ? mafia : mafia.Where(p => p.IsAlive);
|
|
foreach (var player in receivers)
|
|
foreach (var player in receivers)
|
|
await Bot.SendWithMarkdown2(player.ChatId, message, replyMarkup);
|
|
await Bot.SendWithMarkdown2(player.ChatId, message, replyMarkup);
|
|
}
|
|
}
|
|
|
|
|
|
- public MafiaChannel(GameRoom room) : base(room) { }
|
|
|
|
|
|
+ public MafiaChannel(GameRoom room) : base(room)
|
|
|
|
+ {
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|