diff --git a/dependency/proto/Message2Server.proto b/dependency/proto/Message2Server.proto index 0c32e16f..90c1d45b 100755 --- a/dependency/proto/Message2Server.proto +++ b/dependency/proto/Message2Server.proto @@ -70,6 +70,5 @@ message BuildShipMsg { ShipType ship_type = 1; int64 team_id = 2; - int64 player_id = 3; - int32 birthpoint_index = 4; + int32 birthpoint_index = 3; } \ No newline at end of file diff --git a/logic/Gaming/Game.cs b/logic/Gaming/Game.cs index 02c9cc0d..12fb7167 100755 --- a/logic/Gaming/Game.cs +++ b/logic/Gaming/Game.cs @@ -22,15 +22,42 @@ public struct PlayerInitInfo(long teamID, long playerID, ShipType shipType) public List TeamList => teamList; private readonly Map gameMap; public Map GameMap => gameMap; + private Random random = new(); public long AddPlayer(PlayerInitInfo playerInitInfo) { if (!gameMap.TeamExists(playerInitInfo.teamID)) { return GameObj.invalidID; } - if (playerInitInfo.shipType != ShipType.Null) + if (playerInitInfo.playerID != 0) { // Add a ship + var shipType = playerInitInfo.shipType; + switch (shipType) + { + case ShipType.Null: + return GameObj.invalidID; + case ShipType.CivilShip: + if (teamList[(int)playerInitInfo.teamID].ShipPool.GetNum(ShipType.CivilShip) >= GameData.MaxCivilShipNum) + { + return GameObj.invalidID; + } + break; + case ShipType.WarShip: + if (teamList[(int)playerInitInfo.teamID].ShipPool.GetNum(ShipType.WarShip) >= GameData.MaxWarShipNum) + { + return GameObj.invalidID; + } + break; + case ShipType.FlagShip: + if (teamList[(int)playerInitInfo.teamID].ShipPool.GetNum(ShipType.FlagShip) >= GameData.MaxFlagShipNum) + { + return GameObj.invalidID; + } + break; + default: + return GameObj.invalidID; + } Ship? newShip = shipManager.AddShip(playerInitInfo.teamID, playerInitInfo.playerID, playerInitInfo.shipType, teamList[(int)playerInitInfo.teamID].MoneyPool); if (newShip == null) @@ -46,21 +73,22 @@ public long AddPlayer(PlayerInitInfo playerInitInfo) return playerInitInfo.playerID; } } - public bool ActivateShip(long teamID, long playerID, ShipType shipType, int birthPointIndex = 0) + public long ActivateShip(long teamID, ShipType shipType, int birthPointIndex = 0) { Ship? ship = teamList[(int)teamID].ShipPool.GetObj(shipType); if (ship == null) - return false; - else if (ship.IsRemoved == false) - return false; + return GameObj.invalidID; if (birthPointIndex < 0) birthPointIndex = 0; if (birthPointIndex >= teamList[(int)teamID].BirthPointList.Count) birthPointIndex = teamList[(int)teamID].BirthPointList.Count - 1; XY pos = teamList[(int)teamID].BirthPointList[birthPointIndex]; - Random random = new(); pos += new XY(((random.Next() & 2) - 1) * 1000, ((random.Next() & 2) - 1) * 1000); - return shipManager.ActivateShip(ship, pos); + if (shipManager.ActivateShip(ship, pos)) + { + return ship.PlayerID; + } + return GameObj.invalidID; } public bool StartGame(int milliSeconds) { diff --git a/logic/Server/RpcServices.cs b/logic/Server/RpcServices.cs index 917bb74d..1fff2abb 100755 --- a/logic/Server/RpcServices.cs +++ b/logic/Server/RpcServices.cs @@ -519,7 +519,7 @@ public override Task BuildShip(BuildShipMsg request, ServerCallContext boolRes.ActSuccess = false; return Task.FromResult(boolRes); } - boolRes.ActSuccess = game.ActivateShip(request.TeamId, request.PlayerId, Transformation.ShipTypeFromProto(request.ShipType), request.BirthpointIndex); + boolRes.ActSuccess = game.ActivateShip(request.TeamId, Transformation.ShipTypeFromProto(request.ShipType), request.BirthpointIndex) != GameObj.invalidID; #if DEBUG Console.WriteLine("END BuildShip"); #endif