Notifying clients when the round ends
This commit is contained in:
@@ -557,6 +557,15 @@ namespace Barotrauma.Networking
|
|||||||
case ServerPacketHeader.STARTGAME:
|
case ServerPacketHeader.STARTGAME:
|
||||||
startGameCoroutine = GameMain.ShowLoading(StartGame(inc), false);
|
startGameCoroutine = GameMain.ShowLoading(StartGame(inc), false);
|
||||||
break;
|
break;
|
||||||
|
case ServerPacketHeader.ENDGAME:
|
||||||
|
string endMessage = inc.ReadString();
|
||||||
|
bool missionSuccessful = inc.ReadBoolean();
|
||||||
|
if (missionSuccessful && GameMain.GameSession.Mission != null)
|
||||||
|
{
|
||||||
|
GameMain.GameSession.Mission.Completed = true;
|
||||||
|
}
|
||||||
|
CoroutineManager.StartCoroutine(EndGame(endMessage));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -634,6 +643,41 @@ namespace Barotrauma.Networking
|
|||||||
yield return CoroutineStatus.Success;
|
yield return CoroutineStatus.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<object> EndGame(string endMessage)
|
||||||
|
{
|
||||||
|
if (!gameStarted) yield return CoroutineStatus.Success;
|
||||||
|
|
||||||
|
if (GameMain.GameSession != null) GameMain.GameSession.gameMode.End(endMessage);
|
||||||
|
|
||||||
|
gameStarted = false;
|
||||||
|
Character.Controlled = null;
|
||||||
|
GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
|
||||||
|
GameMain.LightManager.LosEnabled = false;
|
||||||
|
respawnManager = null;
|
||||||
|
|
||||||
|
float endPreviewLength = 10.0f;
|
||||||
|
if (Screen.Selected == GameMain.GameScreen)
|
||||||
|
{
|
||||||
|
new TransitionCinematic(Submarine.MainSub, GameMain.GameScreen.Cam, endPreviewLength);
|
||||||
|
float secondsLeft = endPreviewLength;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
secondsLeft -= CoroutineManager.UnscaledDeltaTime;
|
||||||
|
yield return CoroutineStatus.Running;
|
||||||
|
} while (secondsLeft > 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
Submarine.Unload();
|
||||||
|
GameMain.NetLobbyScreen.Select();
|
||||||
|
myCharacter = null;
|
||||||
|
foreach (Client c in otherClients)
|
||||||
|
{
|
||||||
|
c.inGame = false;
|
||||||
|
c.Character = null;
|
||||||
|
}
|
||||||
|
yield return CoroutineStatus.Success;
|
||||||
|
}
|
||||||
|
|
||||||
private void ReadLobbyUpdate(NetIncomingMessage inc)
|
private void ReadLobbyUpdate(NetIncomingMessage inc)
|
||||||
{
|
{
|
||||||
ServerNetObject objHeader;
|
ServerNetObject objHeader;
|
||||||
|
|||||||
@@ -1065,6 +1065,15 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
if (connectedClients.Count > 0)
|
if (connectedClients.Count > 0)
|
||||||
{
|
{
|
||||||
|
NetOutgoingMessage msg = server.CreateMessage();
|
||||||
|
msg.Write((byte)ServerPacketHeader.ENDGAME);
|
||||||
|
msg.Write(endMessage);
|
||||||
|
msg.Write(mission != null && mission.Completed);
|
||||||
|
if (server.ConnectionsCount > 0)
|
||||||
|
{
|
||||||
|
server.SendMessage(msg, server.Connections, NetDeliveryMethod.ReliableOrdered, 0);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (Client client in connectedClients)
|
foreach (Client client in connectedClients)
|
||||||
{
|
{
|
||||||
client.Character = null;
|
client.Character = null;
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ namespace Barotrauma.Networking
|
|||||||
UPDATE_INGAME, //update state ingame (character input and chat messages)
|
UPDATE_INGAME, //update state ingame (character input and chat messages)
|
||||||
|
|
||||||
QUERY_STARTGAME, //ask the clients whether they're ready to start
|
QUERY_STARTGAME, //ask the clients whether they're ready to start
|
||||||
STARTGAME //start a new round
|
STARTGAME, //start a new round
|
||||||
|
ENDGAME
|
||||||
}
|
}
|
||||||
enum ServerNetObject
|
enum ServerNetObject
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user