From 668841fcde22f255c73f55b69c29e68e4fcbb5ae Mon Sep 17 00:00:00 2001 From: gsy1519 <614054460@qq.com> Date: Tue, 14 Mar 2023 23:15:53 +0800 Subject: [PATCH] fix: :bug: fix StartLearning fuction --- logic/Server/GameServer.cs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/logic/Server/GameServer.cs b/logic/Server/GameServer.cs index ab19a2c..d309141 100644 --- a/logic/Server/GameServer.cs +++ b/logic/Server/GameServer.cs @@ -34,7 +34,7 @@ namespace Server private uint spectatorMinPlayerID = 2022; private List spectatorList = new List(); public int TeamCount => options.TeamCount; - protected long[,] communicationToGameID; // 通信用的ID映射到游戏内的ID,[i,j]表示team:i,player:j的id。 + protected long[] communicationToGameID; // 通信用的ID映射到游戏内的ID private readonly object messageToAllClientsLock = new(); public static readonly long SendMessageToClientIntervalInMilliseconds = 50; private readonly Semaphore endGameInfoSema = new(0, 1); @@ -257,7 +257,7 @@ namespace Server long newPlayerID = game.AddPlayer(playerInitInfo); if (newPlayerID == GameObj.invalidID) return; - communicationToGameID[PlayerIDToTeamID(request.PlayerId), request.PlayerId] = newPlayerID; + communicationToGameID[request.PlayerId] = newPlayerID; // 内容待修改 var temp = (new SemaphoreSlim(0, 1), new SemaphoreSlim(0, 1)); bool start = false; @@ -305,7 +305,7 @@ namespace Server #if DEBUG Console.WriteLine($"Move ID: {request.PlayerId}, TimeInMilliseconds: {request.TimeInMilliseconds}"); #endif - var gameID = communicationToGameID[PlayerIDToTeamID(request.PlayerId), request.PlayerId]; + var gameID = communicationToGameID[request.PlayerId]; game.MovePlayer(gameID, (int)request.TimeInMilliseconds, request.Angle); // 之后game.MovePlayer可能改为bool类型 MoveRes moveRes = new(); @@ -352,7 +352,8 @@ namespace Server Console.WriteLine($"StartLearning ID: {request.PlayerId}"); #endif BoolRes boolRes = new(); - boolRes.ActSuccess = game.Fix(request.PlayerId); + var gameID = communicationToGameID[request.PlayerId]; + boolRes.ActSuccess = game.Fix(gameID); return Task.FromResult(boolRes); } @@ -404,15 +405,9 @@ namespace Server } finally { this.game = new Game(map, options.TeamCount); } } - communicationToGameID = new long[options.TeamCount, options.PlayerCountPerTeam]; + communicationToGameID = new long[options.PlayerCountPerTeam + 1]; //创建server时先设定待加入人物都是invalid - for (int i = 0; i < communicationToGameID.GetLength(0); i++) - { - for (int j = 0; j < communicationToGameID.GetLength(1); j++) - { - communicationToGameID[i, j] = GameObj.invalidID; - } - } + for (int i = 0; i < communicationToGameID.GetLength(0); i++) communicationToGameID[i] = GameObj.invalidID; if (options.FileName != DefaultArgumentOptions.FileName) {