Jelajahi Sumber

bug fix, change Don role message, change Defence time to 30 sec

Tigran 4 tahun lalu
induk
melakukan
65b23dea7d

+ 1 - 1
MafiaTelegramBot/Game/GameRoles/DonRole.cs

@@ -51,7 +51,7 @@ namespace MafiaTelegramBot.Game.GameRoles
                 {
                     var role = Room.Players[NightTargetId].GetRole() is Roles.Cop or Roles.Detective or Roles.Journalist
                         ? Room.Players[NightTargetId].GetRoleName()
-                        : roles.Villager;
+                        : strings.not_cop;
                     if (KnownRoles.ContainsKey(NightTargetId)) KnownRoles[NightTargetId] = role;
                     else KnownRoles.Add(Room.Players[NightTargetId].Id, role);
                     await Room.PlayersMessageChannel.EditTo(Player.Id, MessageId,

+ 21 - 22
MafiaTelegramBot/Game/GameRooms/GameRoom.GameProcess.cs

@@ -9,7 +9,6 @@ using MafiaTelegramBot.DataBase.EntityDao;
 using MafiaTelegramBot.Game.GameRoles;
 using MafiaTelegramBot.Models;
 using MafiaTelegramBot.Resources;
-using Microsoft.EntityFrameworkCore;
 using Timer = System.Timers.Timer;
 
 namespace MafiaTelegramBot.Game.GameRooms
@@ -43,7 +42,7 @@ namespace MafiaTelegramBot.Game.GameRooms
                     if (!player.IsPlaying) continue;
                     await PlayersMessageChannel.Send($"{strings.now_turn} ({player.TurnOrder}) {player.NickName}");
                     if (TimerEnabled) await Bot.SendWithMarkdown2(player.ChatId, strings.you_turn_say);
-                    await player.CurrentRole.SpeakAction();
+                    await player.CurrentRole.SpeakAction(Constants.DAY_SPEAK_INTERVAL);
                     if (firstPlayer != null && player.IsPlaying) _turnOrder.Enqueue(player);
                     else firstPlayer = player;
                 }
@@ -168,8 +167,8 @@ namespace MafiaTelegramBot.Game.GameRooms
                 {
                     await PlayersMessageChannel.Send($"{strings.now_turn} ({player.TurnOrder}) {player.NickName}");
                     if (TimerEnabled) await Bot.SendWithMarkdown2(player.ChatId, strings.you_turn_say);
-                    await player.CurrentRole.SpeakAction();
-                    if (Players.ContainsKey(player.Id)) await player.CurrentRole.VotingAction(_voteUpList.Count == 0);
+                    await player.CurrentRole.SpeakAction(Constants.DAY_SPEAK_INTERVAL);
+                    if (Players.ContainsKey(player.Id)) await player.CurrentRole.VotingAction(VoteUpList.Count == 0);
                 }
 
                 if (toEndQueue != null) _turnOrder.Enqueue(player);
@@ -304,47 +303,47 @@ namespace MafiaTelegramBot.Game.GameRooms
         {
             await Task.Run(async () =>
             {
-                switch (_voteUpList.Count)
+                switch (VoteUpList.Count)
                 {
                     case 0:
                         await PlayersMessageChannel.Send(strings.nothing_up_to_vote);
                         break;
                     case 1:
                     {
-                        await _voteUpList[0].CurrentRole.Dispatch();
+                        await VoteUpList[0].CurrentRole.Dispatch();
                         break;
                     }
                     default:
                     {
-                        await DefencePhase(_voteUpList);
-                        _voteUpList = await CalculateCandidates();
-                        switch (_voteUpList.Count)
+                        await DefencePhase(VoteUpList);
+                        VoteUpList = await CalculateCandidates();
+                        switch (VoteUpList.Count)
                         {
                             case 0:
                                 await PlayersMessageChannel.Send(strings.nothing_up_to_dispatch);
                                 break;
                             case 1:
-                                await _voteUpList[0].CurrentRole.Dispatch();
+                                await VoteUpList[0].CurrentRole.Dispatch();
                                 break;
                             case > 1:
-                                var copyVoteUpList = _voteUpList.ToList();
-                                await DefencePhase(_voteUpList);
-                                _voteUpList = await CalculateCandidates();
-                                var alivers = copyVoteUpList.Except(_voteUpList).ToList();
+                                var copyVoteUpList = VoteUpList.ToList();
+                                await DefencePhase(VoteUpList);
+                                VoteUpList = await CalculateCandidates();
+                                var alivers = copyVoteUpList.Except(VoteUpList).ToList();
                                 foreach (var alive in alivers)
                                     alive.ElderRoleAchievementEvent();
 
-                                switch (_voteUpList.Count)
+                                switch (VoteUpList.Count)
                                 {
                                     case 0:
                                         await PlayersMessageChannel.Send(strings.nothing_up_to_dispatch);
                                         break;
                                     case 1:
-                                        await _voteUpList[0].CurrentRole.Dispatch();
+                                        await VoteUpList[0].CurrentRole.Dispatch();
                                         break;
                                     default:
                                         await PlayersMessageChannel.Send(strings.villagers_could_not_decide);
-                                        foreach (var alive in _voteUpList)
+                                        foreach (var alive in VoteUpList)
                                             alive.ElderRoleAchievementEvent();
                                         break;
                                 }
@@ -356,7 +355,7 @@ namespace MafiaTelegramBot.Game.GameRooms
                     }
                 }
 
-                _voteUpList.Clear();
+                VoteUpList.Clear();
                 _voteKillList.Clear();
             });
         }
@@ -375,7 +374,7 @@ namespace MafiaTelegramBot.Game.GameRooms
             if (message == strings.results_of_voting) message = strings.no_one_voted;
             await PlayersMessageChannel.Send(message);
 
-            var votes = _voteUpList.Where(p => Players.ContainsKey(p.Id))
+            var votes = VoteUpList.Where(p => Players.ContainsKey(p.Id))
                 .GroupBy(p => p.Id)
                 .Select(item => new { id = item.Key, count = item.Count() })
                 .ToList();
@@ -385,7 +384,7 @@ namespace MafiaTelegramBot.Game.GameRooms
             var maxObjects = votes.Where(item => item.count == max);
             result.AddRange(from obj in maxObjects select Players[obj.id]);
             _voteKillList.Clear();
-            _voteUpList.Clear();
+            VoteUpList.Clear();
             return result;
         }
 
@@ -406,7 +405,7 @@ namespace MafiaTelegramBot.Game.GameRooms
                     {
                         if (!toKill)
                         {
-                            if (_voteUpList.AddUnique(Players[targetId]))
+                            if (VoteUpList.AddUnique(Players[targetId]))
                             {
                                 if (playerId != targetId)
                                 {
@@ -425,7 +424,7 @@ namespace MafiaTelegramBot.Game.GameRooms
                         }
                         else if (_voteKillList.AddUniqueByKey(playerId, targetId))
                         {
-                            _voteUpList.Add(Players[targetId]);
+                            VoteUpList.Add(Players[targetId]);
                             if (messageId != -1)
                             {
                                 if (playerId != targetId)

+ 4 - 4
MafiaTelegramBot/Game/GameRooms/GameRoom.Role.cs

@@ -71,7 +71,7 @@ namespace MafiaTelegramBot.Game.GameRooms
                     {
                         await Room.PlayersMessageChannel.SendExcept(Player.Id, $"{strings.to_player} {Player.NickName} {strings.issued_posthumous_minute}");
                         await Room.PlayersMessageChannel.SendTo(Player.ChatId, strings.you_will_be_dispatched);
-                        await SpeakAction(enableTimer: true);
+                        await SpeakAction(Constants.DISPATCH_SPEAK_INTERVAL, true);
                     }
                     await Kill();
                     await Room.PlayersMessageChannel.Send($"({Player.TurnOrder}) {Player.NickName} {strings.dispatched}");
@@ -115,7 +115,7 @@ namespace MafiaTelegramBot.Game.GameRooms
                 Player = player;
             }
 
-            public async Task SpeakAction(int interval = Constants.SPEAK_INTERVAL, bool enableTimer = false)
+            public async Task SpeakAction(int interval, bool enableTimer = false)
             {
                 await Room.PlayersMessageChannel.SendTo(Player.ChatId, $"{strings.your_turn}", Keyboard.InGamePlayerMenuWithEndTurn);
                 Player.IsSpeaker = true;
@@ -132,7 +132,7 @@ namespace MafiaTelegramBot.Game.GameRooms
             public async Task VotingAction(bool isFirst = false)
             {
                 var voteTimer = new Timer(Constants.PUT_UP_VOTE_INTERVAL) {AutoReset = false};
-                var alivePlayers = Room.Players.Values.Where(p => p.IsAlive).Except(Room._voteUpList).ToList();
+                var alivePlayers = Room.Players.Values.Where(p => p.IsAlive).Except(Room.VoteUpList).ToList();
                 var message = await Room.PlayersMessageChannel.SendTo(Player.ChatId,
                     $"{strings.put_up_vote}\n{strings.you_have_twenty_seconds}{(isFirst ? "\n" + strings.user_not_choose : "")}",  
                     Keyboard.VoteKeyboard(alivePlayers, Player.Id, !isFirst));
@@ -172,7 +172,7 @@ namespace MafiaTelegramBot.Game.GameRooms
             public async Task DefenceAction()
             {
                 await Room.PlayersMessageChannel.SendExcept(Player.Id, $"{strings.now_defence} ({Player.TurnOrder}) {Player.NickName}");
-                await Room.PlayersMessageChannel.SendTo(Player.ChatId, strings.you_have_eigty_seconds_to_defence);
+                await Room.PlayersMessageChannel.SendTo(Player.ChatId, strings.you_have_thirty_seconds_to_defence);
                 await SpeakAction(Constants.DEFENCE_INTERVAL);
             }
             public static Role GetNewRoleInstance(Roles roleKey, GameRoom room, Player player)

+ 2 - 2
MafiaTelegramBot/Game/GameRooms/GameRoom.Structure.cs

@@ -24,7 +24,7 @@ namespace MafiaTelegramBot.Game.GameRooms
 
         private Timer _waitingPlayers;
 
-        private List<Player> _voteUpList = new();
+        public List<Player> VoteUpList = new();
         private readonly Dictionary<long, long> _voteKillList = new();
 
         public readonly MessageHandler MHandler;
@@ -77,7 +77,7 @@ namespace MafiaTelegramBot.Game.GameRooms
                 if (IsDay && player.IsSpeaker) player.CurrentRole.TalkingActionComplete.Set();
                 if (IsDay && !player.IsSpeaker) player.CurrentRole.VoteActionComplete.Set();
                 if (!IsDay) await player.CurrentRole.SetNightTarget(-1);
-                _voteUpList.RemoveAll(p=> p.Id == player.Id);
+                VoteUpList.RemoveAll(p=> p.Id == player.Id);
                 _voteKillList.Remove(player.Id);
                 var voteKillCopy = _voteKillList.ToList();
                 foreach (var (k, v) in voteKillCopy)

+ 1 - 1
MafiaTelegramBot/Game/Player.cs

@@ -99,7 +99,7 @@ namespace MafiaTelegramBot.Game
 
         public override bool Equals(object? obj)
         {
-            return obj is UserEntity user && user.Id == Id;
+            return obj is Player player && player.Id == Id;
         }
 
         public override int GetHashCode()

+ 13 - 11
MafiaTelegramBot/Resources/Constants.cs

@@ -6,13 +6,14 @@ namespace MafiaTelegramBot.Resources
 {
     public static class Constants
     {
-        public const int PLAYER_LIMITS_MIN = 6;
+        private const bool DEBUG = false;
+        
+        public const int PLAYER_LIMITS_MIN = DEBUG ? 1 : 6;
         public const int MEMORY_CLEANER_INTERVAL = 60 * 60 * 1000;
-        public const int MEMORY_CLEANER_PLAYERS_COUNT = 3;
+        public const int MEMORY_CLEANER_PLAYERS_COUNT = DEBUG ? 1 : 6;
         // ReSharper disable once InconsistentNaming
         public static readonly TimeSpan PLAYER_INACTIVE_INTERVAL = new(0, 40, 0);
         public const int MINUTES_UNTIL_DISSOLVE = 10;
-        public const int PLAYER_LIMITS_MAX = 16;
         public const int MAX_SHOWING_ROOMS = 10;
         
         public const string SHOP_CURRENCY = "RUB";
@@ -22,15 +23,16 @@ namespace MafiaTelegramBot.Resources
             new LabeledPrice {Label = "100 рублей", Amount = 10000}
         };
 
-        public const bool ENABLE_AUTO_VOTING = true;
+        public const bool ENABLE_AUTO_VOTING = !DEBUG;
 
-        public const int FIRST_NIGHT_INTERVAL = 10 * 1000;
-        public const int PUT_UP_VOTE_INTERVAL = 20 * 1000;
-        public const int VOTE_KILL_INTERVAL = 20 * 1000;
-        public const int NIGHT_ACTION_INTERVAL = 60 * 1000;
-        public const int DEFENCE_INTERVAL = 90 * 1000;
-        public const int SPEAK_INTERVAL = 60 * 1000;
-        public const int DISCUSSION_INTERVAL = 60 * 1000;
+        public const int FIRST_NIGHT_INTERVAL = DEBUG ? 1*1000 : 10 * 1000;
+        public const int PUT_UP_VOTE_INTERVAL = DEBUG ? 1*1000 : 20 * 1000;
+        public const int VOTE_KILL_INTERVAL = DEBUG ? 1*1000 : 20 * 1000;
+        public const int NIGHT_ACTION_INTERVAL = DEBUG ? 1*1000 : 60 * 1000;
+        public const int DEFENCE_INTERVAL = DEBUG ? 1*1000 : 30 * 1000;
+        public const int DAY_SPEAK_INTERVAL = DEBUG ? 1*1000 : 60 * 1000;
+        public const int DISPATCH_SPEAK_INTERVAL = DEBUG ? 1*1000 : 60 * 1000;
+        public const int DISCUSSION_INTERVAL = DEBUG ? 1*1000 : 60 * 1000;
 
         public const int ROOM_CODE_LENGTH = 6;
         

+ 14 - 2
MafiaTelegramBot/Resources/strings.Designer.cs

@@ -759,9 +759,9 @@ namespace MafiaTelegramBot {
             }
         }
         
-        internal static string you_have_eigty_seconds_to_defence {
+        internal static string you_have_thirty_seconds_to_defence {
             get {
-                return ResourceManager.GetString("you_have_eigty_seconds_to_defence", resourceCulture);
+                return ResourceManager.GetString("you_have_thirty_seconds_to_defence", resourceCulture);
             }
         }
         
@@ -1382,5 +1382,17 @@ namespace MafiaTelegramBot {
                 return ResourceManager.GetString("game_ended_with_draw", resourceCulture);
             }
         }
+        
+        internal static string you_have_thirty_seconds {
+            get {
+                return ResourceManager.GetString("you_have_thirty_seconds", resourceCulture);
+            }
+        }
+        
+        internal static string not_cop {
+            get {
+                return ResourceManager.GetString("not_cop", resourceCulture);
+            }
+        }
     }
 }

+ 8 - 2
MafiaTelegramBot/Resources/strings.resx

@@ -375,8 +375,8 @@
     <data name="players_not_equal_roles" xml:space="preserve">
         <value>Количество игроков не равно количеству ролей</value> 
     </data>
-    <data name="you_have_eigty_seconds_to_defence" xml:space="preserve">
-        <value>У вас есть 90 секунд на оправдание</value>
+    <data name="you_have_thirty_seconds_to_defence" xml:space="preserve">
+        <value>У вас есть 30 секунд на оправдание</value>
     </data>
     <data name="player_not_died_he_has_alibi" xml:space="preserve">
         <value>но у него есть алиби</value>
@@ -687,4 +687,10 @@
     <data name="game_ended_with_draw" xml:space="preserve">
         <value>Весь город погиб при загадочных обстоятельствах. Игра закончилась ничьей... Рейтинг изменен не будет</value>
     </data>
+    <data name="you_have_thirty_seconds" xml:space="preserve">
+        <value>У вас есть 30 секунд, чтобы что-то сказать</value>
+    </data>
+    <data name="not_cop" xml:space="preserve">
+        <value>Не комиссар</value>
+    </data>
 </root>