|
|
@@ -20,14 +20,14 @@ namespace Server |
|
|
protected readonly ArgumentOptions options; |
|
|
protected readonly ArgumentOptions options; |
|
|
private HttpSender? httpSender; |
|
|
private HttpSender? httpSender; |
|
|
private object gameLock = new(); |
|
|
private object gameLock = new(); |
|
|
private const int playerNum = 1; // 注意修改 |
|
|
|
|
|
|
|
|
private int playerNum => options.playerNum; // 注意修改 |
|
|
private MessageToClient currentGameInfo = new(); |
|
|
private MessageToClient currentGameInfo = new(); |
|
|
private MessageOfObj currentMapMsg = new(); |
|
|
private MessageOfObj currentMapMsg = new(); |
|
|
private object newsLock = new(); |
|
|
private object newsLock = new(); |
|
|
private List<MessageOfNews> currentNews = new(); |
|
|
private List<MessageOfNews> currentNews = new(); |
|
|
private SemaphoreSlim endGameSem = new(0); |
|
|
private SemaphoreSlim endGameSem = new(0); |
|
|
protected readonly Game game; |
|
|
protected readonly Game game; |
|
|
private uint spectatorMinPlayerID = 2022; |
|
|
|
|
|
|
|
|
private uint spectatorMinPlayerID = 2023; |
|
|
private List<uint> spectatorList = new List<uint>(); |
|
|
private List<uint> spectatorList = new List<uint>(); |
|
|
public int TeamCount => options.TeamCount; |
|
|
public int TeamCount => options.TeamCount; |
|
|
protected long[] communicationToGameID; // 通信用的ID映射到游戏内的ID,通信中0-3为Student,4为Tricker |
|
|
protected long[] communicationToGameID; // 通信用的ID映射到游戏内的ID,通信中0-3为Student,4为Tricker |
|
|
@@ -115,7 +115,7 @@ namespace Server |
|
|
mwr?.Flush(); |
|
|
mwr?.Flush(); |
|
|
if (options.ResultFileName != DefaultArgumentOptions.FileName) |
|
|
if (options.ResultFileName != DefaultArgumentOptions.FileName) |
|
|
SaveGameResult(options.ResultFileName + ".json"); |
|
|
SaveGameResult(options.ResultFileName + ".json"); |
|
|
//SendGameResult(); |
|
|
|
|
|
|
|
|
SendGameResult(); |
|
|
this.endGameSem.Release(); |
|
|
this.endGameSem.Release(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@@ -142,7 +142,7 @@ namespace Server |
|
|
currentNews.Clear(); |
|
|
currentNews.Clear(); |
|
|
} |
|
|
} |
|
|
currentGameInfo.GameState = gameState; |
|
|
currentGameInfo.GameState = gameState; |
|
|
currentGameInfo.AllMessage = new(); // 还没写 |
|
|
|
|
|
|
|
|
currentGameInfo.AllMessage = GetMessageOfAll(); |
|
|
mwr?.WriteOne(currentGameInfo); |
|
|
mwr?.WriteOne(currentGameInfo); |
|
|
break; |
|
|
break; |
|
|
case GameState.GameStart: |
|
|
case GameState.GameStart: |
|
|
@@ -160,7 +160,7 @@ namespace Server |
|
|
currentNews.Clear(); |
|
|
currentNews.Clear(); |
|
|
} |
|
|
} |
|
|
currentGameInfo.GameState = gameState; |
|
|
currentGameInfo.GameState = gameState; |
|
|
currentGameInfo.AllMessage = new(); // 还没写 |
|
|
|
|
|
|
|
|
currentGameInfo.AllMessage = GetMessageOfAll(); // 还没写 |
|
|
mwr?.WriteOne(currentGameInfo); |
|
|
mwr?.WriteOne(currentGameInfo); |
|
|
break; |
|
|
break; |
|
|
default: |
|
|
default: |
|
|
@@ -186,7 +186,14 @@ namespace Server |
|
|
private int PlayerIDToTeamID(long playerID) |
|
|
private int PlayerIDToTeamID(long playerID) |
|
|
{ |
|
|
{ |
|
|
if (0 <= playerID && playerID < options.PlayerCountPerTeam) return 0; |
|
|
if (0 <= playerID && playerID < options.PlayerCountPerTeam) return 0; |
|
|
if (playerID == options.PlayerCountPerTeam) return 1; |
|
|
|
|
|
|
|
|
if (playerID == 4) return 1; |
|
|
|
|
|
return -1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private int PlayerTypeToTeamID(Protobuf.PlayerType playerType) |
|
|
|
|
|
{ |
|
|
|
|
|
if (playerType == PlayerType.StudentPlayer) return 0; |
|
|
|
|
|
if (playerType == PlayerType.TrickerPlayer) return 1; |
|
|
return -1; |
|
|
return -1; |
|
|
} |
|
|
} |
|
|
private uint GetBirthPointIdx(long playerID) // 获取出生点位置 |
|
|
private uint GetBirthPointIdx(long playerID) // 获取出生点位置 |
|
|
@@ -200,6 +207,35 @@ namespace Server |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private MessageOfAll GetMessageOfAll() |
|
|
|
|
|
{ |
|
|
|
|
|
MessageOfAll msg = new MessageOfAll(); |
|
|
|
|
|
//msg.GameTime |
|
|
|
|
|
msg.SubjectLeft = GameData.numOfGeneratorRequiredForRepair - (int)game.GameMap.NumOfRepairedGenerators; |
|
|
|
|
|
//msg.StudentGraduated |
|
|
|
|
|
//msg.StudentQuited |
|
|
|
|
|
msg.StudentScore = 0; |
|
|
|
|
|
msg.TrickerScore = 0; |
|
|
|
|
|
game.GameMap.GameObjLockDict[GameObjType.Character].EnterReadLock(); |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
foreach (Character character in game.GameMap.GameObjDict[GameObjType.Character]) |
|
|
|
|
|
{ |
|
|
|
|
|
if (!character.IsGhost()) msg.StudentScore += character.Score; |
|
|
|
|
|
else msg.TrickerScore += character.Score; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
finally |
|
|
|
|
|
{ |
|
|
|
|
|
game.GameMap.GameObjLockDict[GameObjType.Character].ExitReadLock(); |
|
|
|
|
|
} |
|
|
|
|
|
//msg.GateOpened = |
|
|
|
|
|
//msg.HiddenGateRefreshed = |
|
|
|
|
|
//msg.HiddenGateOpened |
|
|
|
|
|
return msg; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private Protobuf.PlaceType IntToPlaceType(uint n) |
|
|
private Protobuf.PlaceType IntToPlaceType(uint n) |
|
|
{ |
|
|
{ |
|
|
switch (n) |
|
|
switch (n) |
|
|
@@ -234,7 +270,9 @@ namespace Server |
|
|
} |
|
|
} |
|
|
public override Task<BoolRes> TryConnection(IDMsg request, ServerCallContext context) |
|
|
public override Task<BoolRes> TryConnection(IDMsg request, ServerCallContext context) |
|
|
{ |
|
|
{ |
|
|
|
|
|
#if DEBUG |
|
|
Console.WriteLine($"TryConnection ID: {request.PlayerId}"); |
|
|
Console.WriteLine($"TryConnection ID: {request.PlayerId}"); |
|
|
|
|
|
#endif |
|
|
var onConnection = new BoolRes(); |
|
|
var onConnection = new BoolRes(); |
|
|
lock (gameLock) |
|
|
lock (gameLock) |
|
|
{ |
|
|
{ |
|
|
@@ -273,29 +311,15 @@ namespace Server |
|
|
if (communicationToGameID[request.PlayerId] != GameObj.invalidID) //是否已经添加了该玩家 |
|
|
if (communicationToGameID[request.PlayerId] != GameObj.invalidID) //是否已经添加了该玩家 |
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
|
Preparation.Utility.CharacterType characterType = Preparation.Utility.CharacterType.Null; // 待修改 |
|
|
|
|
|
|
|
|
Preparation.Utility.CharacterType characterType = Preparation.Utility.CharacterType.Null; |
|
|
if (request.PlayerType == PlayerType.StudentPlayer) |
|
|
if (request.PlayerType == PlayerType.StudentPlayer) |
|
|
{ |
|
|
|
|
|
switch (request.StudentType) |
|
|
|
|
|
{ |
|
|
|
|
|
default: |
|
|
|
|
|
characterType = Preparation.Utility.CharacterType.Athlete; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
characterType = CopyInfo.ToStudentType(request.StudentType); |
|
|
else if (request.PlayerType == PlayerType.TrickerPlayer) |
|
|
else if (request.PlayerType == PlayerType.TrickerPlayer) |
|
|
{ |
|
|
|
|
|
switch (request.TrickerType) |
|
|
|
|
|
{ |
|
|
|
|
|
default: |
|
|
|
|
|
characterType = Preparation.Utility.CharacterType.Assassin; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
characterType = CopyInfo.ToTrickerType(request.TrickerType); |
|
|
|
|
|
|
|
|
lock (addPlayerLock) |
|
|
lock (addPlayerLock) |
|
|
{ |
|
|
{ |
|
|
Game.PlayerInitInfo playerInitInfo = new(GetBirthPointIdx(request.PlayerId), PlayerIDToTeamID(request.PlayerId), request.PlayerId, characterType); |
|
|
|
|
|
|
|
|
Game.PlayerInitInfo playerInitInfo = new(GetBirthPointIdx(request.PlayerId), PlayerTypeToTeamID(request.PlayerType), request.PlayerId, characterType); |
|
|
long newPlayerID = game.AddPlayer(playerInitInfo); |
|
|
long newPlayerID = game.AddPlayer(playerInitInfo); |
|
|
if (newPlayerID == GameObj.invalidID) |
|
|
if (newPlayerID == GameObj.invalidID) |
|
|
return; |
|
|
return; |
|
|
@@ -326,6 +350,9 @@ namespace Server |
|
|
|
|
|
|
|
|
public override Task<BoolRes> Attack(AttackMsg request, ServerCallContext context) |
|
|
public override Task<BoolRes> Attack(AttackMsg request, ServerCallContext context) |
|
|
{ |
|
|
{ |
|
|
|
|
|
#if DEBUG |
|
|
|
|
|
Console.WriteLine($"Attack ID: {request.PlayerId}"); |
|
|
|
|
|
#endif |
|
|
var gameID = communicationToGameID[request.PlayerId]; |
|
|
var gameID = communicationToGameID[request.PlayerId]; |
|
|
game.Attack(gameID, request.Angle); |
|
|
game.Attack(gameID, request.Angle); |
|
|
BoolRes boolRes = new(); |
|
|
BoolRes boolRes = new(); |
|
|
@@ -348,16 +375,6 @@ namespace Server |
|
|
return Task.FromResult(moveRes); |
|
|
return Task.FromResult(moveRes); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public override Task<BoolRes> PickProp(PropMsg request, ServerCallContext context) |
|
|
|
|
|
{ |
|
|
|
|
|
BoolRes boolRes = new(); |
|
|
|
|
|
var gameID = communicationToGameID[request.PlayerId]; |
|
|
|
|
|
if (request.PropType == Protobuf.PropType.NullPropType) |
|
|
|
|
|
boolRes.ActSuccess = game.PickProp(gameID, Preparation.Utility.PropType.Null); |
|
|
|
|
|
// 待修改 |
|
|
|
|
|
return Task.FromResult(boolRes); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override Task<BoolRes> SendMessage(SendMsg request, ServerCallContext context) |
|
|
public override Task<BoolRes> SendMessage(SendMsg request, ServerCallContext context) |
|
|
{ |
|
|
{ |
|
|
var boolRes = new BoolRes(); |
|
|
var boolRes = new BoolRes(); |
|
|
@@ -388,31 +405,81 @@ namespace Server |
|
|
#if DEBUG |
|
|
#if DEBUG |
|
|
Console.WriteLine(news.News); |
|
|
Console.WriteLine(news.News); |
|
|
#endif |
|
|
#endif |
|
|
//teamCommunicatonMsg[request.ToPlayerId].Enqueue(msg); |
|
|
|
|
|
} |
|
|
} |
|
|
boolRes.ActSuccess = true; |
|
|
boolRes.ActSuccess = true; |
|
|
return Task.FromResult(boolRes); |
|
|
return Task.FromResult(boolRes); |
|
|
} |
|
|
} |
|
|
|
|
|
public override Task<BoolRes> PickProp(PropMsg request, ServerCallContext context) |
|
|
|
|
|
{ |
|
|
|
|
|
#if DEBUG |
|
|
|
|
|
Console.WriteLine($"PickProp ID: {request.PlayerId}"); |
|
|
|
|
|
#endif |
|
|
|
|
|
BoolRes boolRes = new(); |
|
|
|
|
|
var gameID = communicationToGameID[request.PlayerId]; |
|
|
|
|
|
boolRes.ActSuccess = game.PickProp(gameID, CopyInfo.ToPropType(request.PropType)); |
|
|
|
|
|
return Task.FromResult(boolRes); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public override Task<BoolRes> UseProp(PropMsg request, ServerCallContext context) |
|
|
public override Task<BoolRes> UseProp(PropMsg request, ServerCallContext context) |
|
|
{ |
|
|
{ |
|
|
return base.UseProp(request, context); |
|
|
|
|
|
|
|
|
#if DEBUG |
|
|
|
|
|
Console.WriteLine($"UseProp ID: {request.PlayerId}"); |
|
|
|
|
|
#endif |
|
|
|
|
|
BoolRes boolRes = new(); |
|
|
|
|
|
var gameID = communicationToGameID[request.PlayerId]; |
|
|
|
|
|
//boolRes.ActSuccess = game.UseProp(gameID, CopyInfo.ToPropType(request.PropType)); |
|
|
|
|
|
return Task.FromResult(boolRes); |
|
|
|
|
|
} |
|
|
|
|
|
public override Task<BoolRes> ThrowProp(PropMsg request, ServerCallContext context) |
|
|
|
|
|
{ |
|
|
|
|
|
#if DEBUG |
|
|
|
|
|
Console.WriteLine($"ThrowProp ID: {request.PlayerId}"); |
|
|
|
|
|
#endif |
|
|
|
|
|
BoolRes boolRes = new(); |
|
|
|
|
|
var gameID = communicationToGameID[request.PlayerId]; |
|
|
|
|
|
//boolRes.ActSuccess = game.ThrowProp(gameID, CopyInfo.ToPropType(request.PropType)); |
|
|
|
|
|
return Task.FromResult(boolRes); |
|
|
} |
|
|
} |
|
|
public override Task<BoolRes> UseSkill(SkillMsg request, ServerCallContext context) |
|
|
public override Task<BoolRes> UseSkill(SkillMsg request, ServerCallContext context) |
|
|
{ |
|
|
{ |
|
|
return base.UseSkill(request, context); |
|
|
|
|
|
|
|
|
#if DEBUG |
|
|
|
|
|
Console.WriteLine($"UseSkill ID: {request.PlayerId}"); |
|
|
|
|
|
#endif |
|
|
|
|
|
BoolRes boolRes = new(); |
|
|
|
|
|
var gameID = communicationToGameID[request.PlayerId]; |
|
|
|
|
|
//boolRes.ActSuccess = game.UseActiveSkill(gameID, CopyInfo.ToPropType(request.PropType)); |
|
|
|
|
|
return Task.FromResult(boolRes); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public override Task<BoolRes> Graduate(IDMsg request, ServerCallContext context) |
|
|
public override Task<BoolRes> Graduate(IDMsg request, ServerCallContext context) |
|
|
{ |
|
|
{ |
|
|
return base.Graduate(request, context); |
|
|
|
|
|
|
|
|
#if DEBUG |
|
|
|
|
|
Console.WriteLine($"Graduate ID: {request.PlayerId}"); |
|
|
|
|
|
#endif |
|
|
|
|
|
BoolRes boolRes = new(); |
|
|
|
|
|
var gameID = communicationToGameID[request.PlayerId]; |
|
|
|
|
|
boolRes.ActSuccess = game.Escape(gameID); |
|
|
|
|
|
return Task.FromResult(boolRes); |
|
|
} |
|
|
} |
|
|
public override Task<BoolRes> StartRescueMate(IDMsg request, ServerCallContext context) |
|
|
public override Task<BoolRes> StartRescueMate(IDMsg request, ServerCallContext context) |
|
|
{ |
|
|
{ |
|
|
return base.StartRescueMate(request, context); |
|
|
|
|
|
|
|
|
#if DEBUG |
|
|
|
|
|
Console.WriteLine($"StartRescueMate ID: {request.PlayerId}"); |
|
|
|
|
|
#endif |
|
|
|
|
|
BoolRes boolRes = new(); |
|
|
|
|
|
var gameID = communicationToGameID[request.PlayerId]; |
|
|
|
|
|
//boolRes.ActSuccess = game.Rescue(gameID); |
|
|
|
|
|
return Task.FromResult(boolRes); |
|
|
} |
|
|
} |
|
|
public override Task<BoolRes> StartTreatMate(IDMsg request, ServerCallContext context) |
|
|
public override Task<BoolRes> StartTreatMate(IDMsg request, ServerCallContext context) |
|
|
{ |
|
|
{ |
|
|
return base.StartTreatMate(request, context); |
|
|
|
|
|
|
|
|
#if DEBUG |
|
|
|
|
|
Console.WriteLine($"StartTreatMate ID: {request.PlayerId}"); |
|
|
|
|
|
#endif |
|
|
|
|
|
BoolRes boolRes = new(); |
|
|
|
|
|
var gameID = communicationToGameID[request.PlayerId]; |
|
|
|
|
|
//boolRes.ActSuccess = game.Treat(gameID); |
|
|
|
|
|
return Task.FromResult(boolRes); |
|
|
} |
|
|
} |
|
|
public override Task<BoolRes> StartLearning(IDMsg request, ServerCallContext context) |
|
|
public override Task<BoolRes> StartLearning(IDMsg request, ServerCallContext context) |
|
|
{ |
|
|
{ |
|
|
@@ -424,6 +491,71 @@ namespace Server |
|
|
boolRes.ActSuccess = game.Fix(gameID); |
|
|
boolRes.ActSuccess = game.Fix(gameID); |
|
|
return Task.FromResult(boolRes); |
|
|
return Task.FromResult(boolRes); |
|
|
} |
|
|
} |
|
|
|
|
|
public override Task<BoolRes> StartOpenChest(IDMsg request, ServerCallContext context) |
|
|
|
|
|
{ |
|
|
|
|
|
#if DEBUG |
|
|
|
|
|
Console.WriteLine($"StartOpenChest ID: {request.PlayerId}"); |
|
|
|
|
|
#endif |
|
|
|
|
|
BoolRes boolRes = new(); |
|
|
|
|
|
var gameID = communicationToGameID[request.PlayerId]; |
|
|
|
|
|
boolRes.ActSuccess = game.OpenChest(gameID); |
|
|
|
|
|
return Task.FromResult(boolRes); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override Task<BoolRes> StartOpenGate(IDMsg request, ServerCallContext context) |
|
|
|
|
|
{ |
|
|
|
|
|
#if DEBUG |
|
|
|
|
|
Console.WriteLine($"StartOpenGate ID: {request.PlayerId}"); |
|
|
|
|
|
#endif |
|
|
|
|
|
BoolRes boolRes = new(); |
|
|
|
|
|
var gameID = communicationToGameID[request.PlayerId]; |
|
|
|
|
|
boolRes.ActSuccess = game.OpenDoorway(gameID); |
|
|
|
|
|
return Task.FromResult(boolRes); |
|
|
|
|
|
} |
|
|
|
|
|
public override Task<BoolRes> OpenDoor(IDMsg request, ServerCallContext context) |
|
|
|
|
|
{ |
|
|
|
|
|
#if DEBUG |
|
|
|
|
|
Console.WriteLine($"OpenDoor ID: {request.PlayerId}"); |
|
|
|
|
|
#endif |
|
|
|
|
|
BoolRes boolRes = new(); |
|
|
|
|
|
var gameID = communicationToGameID[request.PlayerId]; |
|
|
|
|
|
boolRes.ActSuccess = game.LockOrOpenDoor(gameID); |
|
|
|
|
|
return Task.FromResult(boolRes); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override Task<BoolRes> CloseDoor(IDMsg request, ServerCallContext context) |
|
|
|
|
|
{ |
|
|
|
|
|
#if DEBUG |
|
|
|
|
|
Console.WriteLine($"CloseDoor ID: {request.PlayerId}"); |
|
|
|
|
|
#endif |
|
|
|
|
|
BoolRes boolRes = new(); |
|
|
|
|
|
var gameID = communicationToGameID[request.PlayerId]; |
|
|
|
|
|
boolRes.ActSuccess = game.LockOrOpenDoor(gameID); |
|
|
|
|
|
return Task.FromResult(boolRes); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override Task<BoolRes> EndAllAction(IDMsg request, ServerCallContext context) |
|
|
|
|
|
{ |
|
|
|
|
|
#if DEBUG |
|
|
|
|
|
Console.WriteLine($"EndAllAction ID: {request.PlayerId}"); |
|
|
|
|
|
#endif |
|
|
|
|
|
BoolRes boolRes = new(); |
|
|
|
|
|
var gameID = communicationToGameID[request.PlayerId]; |
|
|
|
|
|
boolRes.ActSuccess = game.Stop(gameID); |
|
|
|
|
|
return Task.FromResult(boolRes); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override Task<BoolRes> SkipWindow(IDMsg request, ServerCallContext context) |
|
|
|
|
|
{ |
|
|
|
|
|
#if DEBUG |
|
|
|
|
|
Console.WriteLine($"SkipWindow ID: {request.PlayerId}"); |
|
|
|
|
|
#endif |
|
|
|
|
|
BoolRes boolRes = new(); |
|
|
|
|
|
var gameID = communicationToGameID[request.PlayerId]; |
|
|
|
|
|
boolRes.ActSuccess = game.ClimbingThroughWindow(gameID); |
|
|
|
|
|
return Task.FromResult(boolRes); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public GameServer(ArgumentOptions options) |
|
|
public GameServer(ArgumentOptions options) |
|
|
{ |
|
|
{ |
|
|
|