From c67e98634b1b90802f2a937c1a780a26ba0fda17 Mon Sep 17 00:00:00 2001 From: keshav2010 Date: Tue, 9 Apr 2024 19:57:02 +0530 Subject: [PATCH] remove player if tower destroyed --- gameserver/schema/SoldierState.ts | 5 ++++- .../server-state-machine/SessionStateBehaviour.ts | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/gameserver/schema/SoldierState.ts b/gameserver/schema/SoldierState.ts index 5449524..0004c12 100644 --- a/gameserver/schema/SoldierState.ts +++ b/gameserver/schema/SoldierState.ts @@ -346,7 +346,10 @@ export class SoldierState extends Schema implements ISceneItem, IBoidAgent { enemyTowers .map((d) => stateManager.getPlayer(d.id)) .forEach((playerBase) => { - if (playerBase) playerBase.spawnFlagHealth -= 0.5 * delta; + if (playerBase) { + const flagHealth = playerBase.spawnFlagHealth - 0.5 * delta; + playerBase.spawnFlagHealth = Math.max(0, flagHealth); + } }); this.stateMachine.tick({ delta, stateManager, soldier: this }); } diff --git a/gameserver/stateMachines/server-state-machine/SessionStateBehaviour.ts b/gameserver/stateMachines/server-state-machine/SessionStateBehaviour.ts index 383143b..9524fdc 100644 --- a/gameserver/stateMachines/server-state-machine/SessionStateBehaviour.ts +++ b/gameserver/stateMachines/server-state-machine/SessionStateBehaviour.ts @@ -92,12 +92,15 @@ export default { ); if (!isAlreadyInScene) gameStateManager.addSceneItem(player); }); - + sessionState.sessionState = "BATTLE_STATE"; } var deltaTime = delta / 1000; playersConnected.forEach((player) => { player.tick(deltaTime, gameStateManager); + if (player.spawnFlagHealth === 0) { + sessionState.removePlayer(player.id, gameStateManager); + } }); } catch (err) { console.log(err); @@ -113,5 +116,10 @@ export default { delta: number; sessionState: SessionState; tick: Room; - }) => {}, + }) => { + try { + } catch (error) { + console.log(error); + } + }, };