Browse Source

feat: (clgg) help server add the map message when a spectator joins a started game

(clgg) help server add the map message when a spectator joins a started game
tags/0.1.0
Shawqeem 2 years ago
parent
commit
c670fda87e
6 changed files with 33 additions and 10 deletions
  1. +3
    -0
      logic/Client/MainWindow.xaml.cs
  2. +1
    -1
      logic/Client/Properties/launchSettings.json
  3. +1
    -1
      logic/Client/StatusBarOfCircumstance.xaml.cs
  4. +4
    -3
      logic/Gaming/Game.cs
  5. +5
    -1
      logic/Server/GameServer.cs
  6. +19
    -4
      logic/Server/RpcServices.cs

+ 3
- 0
logic/Client/MainWindow.xaml.cs View File

@@ -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);


+ 1
- 1
logic/Client/Properties/launchSettings.json View File

@@ -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"
}
}
}

+ 1
- 1
logic/Client/StatusBarOfCircumstance.xaml.cs View File

@@ -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";
}


+ 4
- 3
logic/Gaming/Game.cs View File

@@ -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)
{


+ 5
- 1
logic/Server/GameServer.cs View File

@@ -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);


+ 19
- 4
logic/Server/RpcServices.cs View File

@@ -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<BoolRes> 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);
}


Loading…
Cancel
Save