From 5b74548cf4e8d73de182db515b8e1dcf5ff09abf Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Tue, 30 Apr 2024 14:47:47 +0530 Subject: [PATCH] few more fixes --- src/MarbleWorld.hx | 2 ++ src/gui/PlayGui.hx | 26 +++++++++++++++----------- src/modes/HuntMode.hx | 2 +- src/net/Net.hx | 3 +++ src/net/NetCommands.hx | 19 +++++++++++++++---- 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index 34650dd7..c304712e 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -709,6 +709,7 @@ class MarbleWorld extends Scheduler { marble.megaMarbleUseTick = 0; marble.helicopterUseTick = 0; marble.collider.radius = marble._radius = 0.3; + @:privateAccess marble.netFlags |= MarbleNetFlags.DoHelicopter | MarbleNetFlags.DoMega | MarbleNetFlags.GravityChange; } else { @:privateAccess marble.helicopterEnableTime = -1e8; @:privateAccess marble.megaMarbleEnableTime = -1e8; @@ -1398,6 +1399,7 @@ class MarbleWorld extends Scheduler { public function removePlayer(cc:GameConnection) { var otherMarble = this.clientMarbles[cc]; if (otherMarble != null) { + cancel(otherMarble.oobSchedule); this.predictions.removeMarbleFromPrediction(otherMarble); this.scene.removeChild(otherMarble); this.collisionWorld.removeMarbleEntity(otherMarble.collider); diff --git a/src/gui/PlayGui.hx b/src/gui/PlayGui.hx index 05f111f2..5beea19a 100644 --- a/src/gui/PlayGui.hx +++ b/src/gui/PlayGui.hx @@ -775,20 +775,24 @@ class PlayGui { } public function addPlayer(id:Int, name:String, us:Bool) { - playerList.push({ - id: id, - name: name, - us: us, - score: 0 - }); - redrawPlayerList(); + if (playerListCtrl != null) { + playerList.push({ + id: id, + name: name, + us: us, + score: 0 + }); + redrawPlayerList(); + } } public function removePlayer(id:Int) { - var f = playerList.filter(x -> x.id == id); - if (f.length != 0) - playerList.remove(f[0]); - redrawPlayerList(); + if (playerListCtrl != null) { + var f = playerList.filter(x -> x.id == id); + if (f.length != 0) + playerList.remove(f[0]); + redrawPlayerList(); + } } public function incrementPlayerScore(id:Int, score:Int) { diff --git a/src/modes/HuntMode.hx b/src/modes/HuntMode.hx index 705d910d..6e9dc198 100644 --- a/src/modes/HuntMode.hx +++ b/src/modes/HuntMode.hx @@ -258,7 +258,7 @@ class HuntMode extends NullMode { } override function onRespawn(marble:Marble) { - if (activeGemSpawnGroup.length != 0) { + if (marble.controllable && activeGemSpawnGroup.length != 0) { var gemAvg = new Vector(); for (gi in activeGemSpawnGroup) { var g = gemSpawnPoints[gi]; diff --git a/src/net/Net.hx b/src/net/Net.hx index 2299b509..b48fb28d 100644 --- a/src/net/Net.hx +++ b/src/net/Net.hx @@ -201,7 +201,9 @@ class Net { if (Net.client != null) Net.client.close(); Net.client = null; + Net.clientDatachannel = null; Net.clientId = 0; + Net.clients.clear(); Net.clientIdMap.clear(); Net.clientConnection = null; Net.serverInfo = null; @@ -217,6 +219,7 @@ class Net { Net.isMP = false; Net.isClient = false; Net.isHost = false; + Net.clientId = 0; Net.clients.clear(); Net.clientIdMap.clear(); MasterServerClient.disconnectFromMasterServer(); diff --git a/src/net/NetCommands.hx b/src/net/NetCommands.hx index fd3d1b91..250b4fe8 100644 --- a/src/net/NetCommands.hx +++ b/src/net/NetCommands.hx @@ -156,6 +156,17 @@ class NetCommands { var conn = Net.clientIdMap.get(clientId); if (MarbleGame.instance.world != null) { MarbleGame.instance.world.removePlayer(conn); + + var allReady = true; + for (id => client in Net.clientIdMap) { + if (client.state != GameplayState.GAME) { + allReady = false; + break; + } + } + if (allReady && MarbleGame.instance.world.serverStartTicks == 0) { + MarbleGame.instance.world.allClientsReady(); + } } Net.clientIdMap.remove(clientId); if (MarbleGame.canvas.content is MultiplayerLevelSelectGui) { @@ -202,16 +213,16 @@ class NetCommands { } @:rpc(server) public static function endGame() { + for (c => v in Net.clientIdMap) { + v.state = LOBBY; + v.lobbyReady = false; + } if (Net.isClient) { if (MarbleGame.instance.world != null) { MarbleGame.instance.quitMission(); } } if (Net.isHost) { - for (c => v in Net.clientIdMap) { - v.state = LOBBY; - v.lobbyReady = false; - } Net.lobbyHostReady = false; if (Net.isHost) {