diff --git a/logic/Client/MainWindow.xaml.cs b/logic/Client/MainWindow.xaml.cs index e870848..c115e6e 100644 --- a/logic/Client/MainWindow.xaml.cs +++ b/logic/Client/MainWindow.xaml.cs @@ -493,6 +493,9 @@ namespace Client case MessageOfObj.MessageOfObjOneofCase.HiddenGateMessage: listOfHiddenGate.Add(obj.HiddenGateMessage); break; + case MessageOfObj.MessageOfObjOneofCase.MapMessage: + GetMap(obj.MapMessage); + break; } } listOfAll.Add(content.AllMessage); diff --git a/logic/Client/Properties/launchSettings.json b/logic/Client/Properties/launchSettings.json index fb94197..a671030 100644 --- a/logic/Client/Properties/launchSettings.json +++ b/logic/Client/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Client": { "commandName": "Project", - "commandLineArgs": "--cl --playbackFile D:\\2_autumn\\thuai6\\THUAI6\\logic\\cmd\\test.thuaipb --playbackSpeed 2 " + "commandLineArgs": "--cl --port 8888 --characterID 2031" } } } \ No newline at end of file diff --git a/logic/Client/StatusBarOfCircumstance.xaml.cs b/logic/Client/StatusBarOfCircumstance.xaml.cs index 47d95b0..1e3b863 100644 --- a/logic/Client/StatusBarOfCircumstance.xaml.cs +++ b/logic/Client/StatusBarOfCircumstance.xaml.cs @@ -61,7 +61,7 @@ namespace Client { name.Text = "🚀 Tricker's"; } - else if(playerId< GameData.numOfStudent) + else if (playerId < GameData.numOfStudent) { name.Text = "🚀 Student" + Convert.ToString(playerId) + "'s"; } diff --git a/logic/Gaming/Game.cs b/logic/Gaming/Game.cs index edbdb3c..65d0d6d 100644 --- a/logic/Gaming/Game.cs +++ b/logic/Gaming/Game.cs @@ -215,15 +215,16 @@ namespace Gaming } return false; } - public void Attack(long playerID, double angle) + public bool Attack(long playerID, double angle) { if (!gameMap.Timer.IsGaming) - return; + return false; Character? player = gameMap.FindPlayerToAction(playerID); if (player != null) { - _ = attackManager.Attack(player, angle); + return attackManager.Attack(player, angle); } + return false; } public void UseProp(long playerID, PropType propType = PropType.Null) { diff --git a/logic/Server/GameServer.cs b/logic/Server/GameServer.cs index 2a80249..c0a1abf 100644 --- a/logic/Server/GameServer.cs +++ b/logic/Server/GameServer.cs @@ -130,7 +130,11 @@ namespace Server case GameState.GameRunning: case GameState.GameEnd: case GameState.GameStart: - if (gameState == GameState.GameStart) currentGameInfo.ObjMessage.Add(currentMapMsg); + if (gameState == GameState.GameStart || IsSpectatorJoin) + { + currentGameInfo.ObjMessage.Add(currentMapMsg); + IsSpectatorJoin = false; + } foreach (GameObj gameObj in gameObjList) { MessageOfObj? msg = CopyInfo.Auto(gameObj); diff --git a/logic/Server/RpcServices.cs b/logic/Server/RpcServices.cs index d775697..fccb653 100644 --- a/logic/Server/RpcServices.cs +++ b/logic/Server/RpcServices.cs @@ -16,6 +16,22 @@ namespace Server { public partial class GameServer : AvailableService.AvailableServiceBase { + protected object spectatorLock = new object(); + protected bool isSpectatorJoin = false; + protected bool IsSpectatorJoin + { + get + { + lock (spectatorLock) + return isSpectatorJoin; + } + + set + { + lock (spectatorLock) + isSpectatorJoin = value; + } + } public override Task TryConnection(IDMsg request, ServerCallContext context) { #if DEBUG @@ -53,6 +69,7 @@ namespace Server { semaDict.Add(request.PlayerId, temp); } + IsSpectatorJoin = true; } do { @@ -147,8 +164,7 @@ namespace Server return Task.FromResult(boolRes); } var gameID = communicationToGameID[request.PlayerId]; - game.Attack(gameID, request.Angle); - boolRes.ActSuccess = true; + boolRes.ActSuccess = game.Attack(gameID, request.Angle); return Task.FromResult(boolRes); } @@ -170,8 +186,7 @@ namespace Server return Task.FromResult(moveRes); } var gameID = communicationToGameID[request.PlayerId]; - game.MovePlayer(gameID, (int)request.TimeInMilliseconds, request.Angle); - moveRes.ActSuccess = true; + moveRes.ActSuccess = game.MovePlayer(gameID, (int)request.TimeInMilliseconds, request.Angle); if (!game.GameMap.Timer.IsGaming) moveRes.ActSuccess = false; return Task.FromResult(moveRes); }