Explorar o código

Leave from game bug fix

Tigran %!s(int64=4) %!d(string=hai) anos
pai
achega
8b18f35e40

+ 8 - 8
MafiaTelegramBot.sln.DotSettings.user

@@ -1,13 +1,13 @@
 <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
-	<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=0ea868fa_002D7cf8_002D466b_002Dbf25_002Dc540fc960a6b/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="Killing_Player_In_Summing_Up_Phase #2" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
-  &lt;TestAncestor&gt;&#xD;
-    &lt;TestId&gt;xUnit::BB1857E4-418E-4AE5-8437-43EBD1D903FB::net5.0::MafiaTelegramBotTests.Game.Tests.GameRooms.Tests.GameRoomTests&lt;/TestId&gt;&#xD;
-  &lt;/TestAncestor&gt;&#xD;
+	<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=0ea868fa_002D7cf8_002D466b_002Dbf25_002Dc540fc960a6b/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="Killing_Player_In_Summing_Up_Phase #2" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
+  &lt;TestAncestor&gt;
+    &lt;TestId&gt;xUnit::BB1857E4-418E-4AE5-8437-43EBD1D903FB::net5.0::MafiaTelegramBotTests.Game.Tests.GameRooms.Tests.GameRoomTests&lt;/TestId&gt;
+  &lt;/TestAncestor&gt;
 &lt;/SessionState&gt;</s:String>
-	<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=fbf9be8e_002Dabe2_002D485d_002Dbae0_002D5fd4fbd8c901/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="Killing_Player_In_Summing_Up_Phase" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
-  &lt;TestAncestor&gt;&#xD;
-    &lt;TestId&gt;xUnit::BB1857E4-418E-4AE5-8437-43EBD1D903FB::net5.0::MafiaTelegramBotTests.Game.Tests.GameRooms.Tests.GameRoomTests.Killing_Player_In_Summing_Up_Phase&lt;/TestId&gt;&#xD;
-  &lt;/TestAncestor&gt;&#xD;
+	<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=fbf9be8e_002Dabe2_002D485d_002Dbae0_002D5fd4fbd8c901/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="Killing_Player_In_Summing_Up_Phase" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
+  &lt;TestAncestor&gt;
+    &lt;TestId&gt;xUnit::BB1857E4-418E-4AE5-8437-43EBD1D903FB::net5.0::MafiaTelegramBotTests.Game.Tests.GameRooms.Tests.GameRoomTests.Killing_Player_In_Summing_Up_Phase&lt;/TestId&gt;
+  &lt;/TestAncestor&gt;
 &lt;/SessionState&gt;</s:String>
 	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=MafiaTelegramBot_002Fappsettings/@EntryIndexedValue">True</s:Boolean>
 	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=MafiaTelegramBot_002FResources_002Fkeyboard/@EntryIndexedValue">False</s:Boolean>

+ 9 - 7
MafiaTelegramBot/Game/GameRooms/GameRoom.MessageHandler.cs

@@ -2,6 +2,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 using MafiaTelegramBot.Controllers;
+using MafiaTelegramBot.Models;
 using MafiaTelegramBot.Resources;
 using Telegram.Bot.Types;
 
@@ -11,7 +12,7 @@ namespace MafiaTelegramBot.Game.GameRooms
     {
         public class MessageHandler
         {
-            private List<long> LeavingPlayers = new();
+            private readonly List<long> _exitingPlayers = new();
             
             private readonly GameRoom _room;
 
@@ -25,7 +26,7 @@ namespace MafiaTelegramBot.Game.GameRooms
                 var text = update.Message.Text;
                 var userId = update.Message.From.Id;
                 if (!_room.Players.ContainsKey(userId)) return new Message();
-                if(LeavingPlayers.Contains(userId)) await Leave(_room.Players[userId], update.Message.Text);
+                if(_exitingPlayers.Contains(userId)) await Leave(_room.Players[userId], update.Message.Text);
                 else if (text == keyboard.look_players_list) await LookPlayers(_room.Players[userId]);
                 else if (text == keyboard.leave) await Leave(_room.Players[userId]);
                 else if (text == keyboard.end_turn)
@@ -59,14 +60,15 @@ namespace MafiaTelegramBot.Game.GameRooms
                 var stopIndex = -1;
                 for (var i = 0; i <= players.Length && i != stopIndex; ++i)
                 {
+                    i %= players.Length;
                     if (stopIndex == -1 && players[i].Id == nextPlayer.Id) stopIndex = i;
                     if (stopIndex == -1) continue;
-                    i %= players.Length;
                     var role =  knownRoles.ContainsKey(players[i].Id)
                         ? knownRoles[players[i].Id]
                         : "";
                     message +=
-                        $"\n{(message == strings.players_list ? strings.next + " - " : "")}({players[i].TurnOrder}) " +
+                        $"\n{(message == strings.players_list ? strings.next + " - " : "")}" +
+                        $"({players[i].TurnOrder}) " +
                         $"{(players[i].Id == player.Id ? strings.you : players[i].NickName)} " +
                         $"({(players[i].IsAlive ? strings.alive : strings.died)}) " +
                         $"{role}";
@@ -79,19 +81,19 @@ namespace MafiaTelegramBot.Game.GameRooms
                 var roomName = player.GetRoomName();
                 if (_room.IsRunning)
                 {
-                    if (LeavingPlayers.Remove(player.Id))
+                    if (_exitingPlayers.Remove(player.Id))
                     {
                         if (text == strings.exit)
                         {
                             var resultCode = await RoomController.LeaveFromGame(player);
                             if (resultCode == ResultCode.CodeOk)
-                                await _room.PlayersCh.SendTo(player.ChatId, $"{strings.you_leave_from_game} _*{roomName}*_", Keyboard.MainMenu);
+                                await Bot.SendWithMarkdown2(player.ChatId, $"{strings.you_leave_from_game} _*{roomName}*_", Keyboard.MainMenu);
                             else await Utilities.GetResultCodeMessage(resultCode, player.ChatId);
                         }
                     }
                     else
                     {
-                        LeavingPlayers.Add(player.Id);
+                        _exitingPlayers.Add(player.Id);
                         await _room.PlayersCh.SendTo(player.ChatId, $"{strings.confirm_exit} ```{strings.exit}``` {strings.to_confirm_exit}");
                     }
                 }