(clgg) help server add the map message when a spectator joins a started gametags/0.1.0
| @@ -493,6 +493,9 @@ namespace Client | |||||
| case MessageOfObj.MessageOfObjOneofCase.HiddenGateMessage: | case MessageOfObj.MessageOfObjOneofCase.HiddenGateMessage: | ||||
| listOfHiddenGate.Add(obj.HiddenGateMessage); | listOfHiddenGate.Add(obj.HiddenGateMessage); | ||||
| break; | break; | ||||
| case MessageOfObj.MessageOfObjOneofCase.MapMessage: | |||||
| GetMap(obj.MapMessage); | |||||
| break; | |||||
| } | } | ||||
| } | } | ||||
| listOfAll.Add(content.AllMessage); | listOfAll.Add(content.AllMessage); | ||||
| @@ -2,7 +2,7 @@ | |||||
| "profiles": { | "profiles": { | ||||
| "Client": { | "Client": { | ||||
| "commandName": "Project", | "commandName": "Project", | ||||
| "commandLineArgs": "--cl --playbackFile D:\\2_autumn\\thuai6\\THUAI6\\logic\\cmd\\test.thuaipb --playbackSpeed 2 " | |||||
| "commandLineArgs": "--cl --port 8888 --characterID 2031" | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -61,7 +61,7 @@ namespace Client | |||||
| { | { | ||||
| name.Text = "🚀 Tricker's"; | name.Text = "🚀 Tricker's"; | ||||
| } | } | ||||
| else if(playerId< GameData.numOfStudent) | |||||
| else if (playerId < GameData.numOfStudent) | |||||
| { | { | ||||
| name.Text = "🚀 Student" + Convert.ToString(playerId) + "'s"; | name.Text = "🚀 Student" + Convert.ToString(playerId) + "'s"; | ||||
| } | } | ||||
| @@ -215,15 +215,16 @@ namespace Gaming | |||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| public void Attack(long playerID, double angle) | |||||
| public bool Attack(long playerID, double angle) | |||||
| { | { | ||||
| if (!gameMap.Timer.IsGaming) | if (!gameMap.Timer.IsGaming) | ||||
| return; | |||||
| return false; | |||||
| Character? player = gameMap.FindPlayerToAction(playerID); | Character? player = gameMap.FindPlayerToAction(playerID); | ||||
| if (player != null) | if (player != null) | ||||
| { | { | ||||
| _ = attackManager.Attack(player, angle); | |||||
| return attackManager.Attack(player, angle); | |||||
| } | } | ||||
| return false; | |||||
| } | } | ||||
| public void UseProp(long playerID, PropType propType = PropType.Null) | public void UseProp(long playerID, PropType propType = PropType.Null) | ||||
| { | { | ||||
| @@ -130,7 +130,11 @@ namespace Server | |||||
| case GameState.GameRunning: | case GameState.GameRunning: | ||||
| case GameState.GameEnd: | case GameState.GameEnd: | ||||
| case GameState.GameStart: | 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) | foreach (GameObj gameObj in gameObjList) | ||||
| { | { | ||||
| MessageOfObj? msg = CopyInfo.Auto(gameObj); | MessageOfObj? msg = CopyInfo.Auto(gameObj); | ||||
| @@ -16,6 +16,22 @@ namespace Server | |||||
| { | { | ||||
| public partial class GameServer : AvailableService.AvailableServiceBase | 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<BoolRes> TryConnection(IDMsg request, ServerCallContext context) | public override Task<BoolRes> TryConnection(IDMsg request, ServerCallContext context) | ||||
| { | { | ||||
| #if DEBUG | #if DEBUG | ||||
| @@ -53,6 +69,7 @@ namespace Server | |||||
| { | { | ||||
| semaDict.Add(request.PlayerId, temp); | semaDict.Add(request.PlayerId, temp); | ||||
| } | } | ||||
| IsSpectatorJoin = true; | |||||
| } | } | ||||
| do | do | ||||
| { | { | ||||
| @@ -147,8 +164,7 @@ namespace Server | |||||
| return Task.FromResult(boolRes); | return Task.FromResult(boolRes); | ||||
| } | } | ||||
| var gameID = communicationToGameID[request.PlayerId]; | var gameID = communicationToGameID[request.PlayerId]; | ||||
| game.Attack(gameID, request.Angle); | |||||
| boolRes.ActSuccess = true; | |||||
| boolRes.ActSuccess = game.Attack(gameID, request.Angle); | |||||
| return Task.FromResult(boolRes); | return Task.FromResult(boolRes); | ||||
| } | } | ||||
| @@ -170,8 +186,7 @@ namespace Server | |||||
| return Task.FromResult(moveRes); | return Task.FromResult(moveRes); | ||||
| } | } | ||||
| var gameID = communicationToGameID[request.PlayerId]; | 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; | if (!game.GameMap.Timer.IsGaming) moveRes.ActSuccess = false; | ||||
| return Task.FromResult(moveRes); | return Task.FromResult(moveRes); | ||||
| } | } | ||||