Skip to content

Commit

Permalink
remove capture flag when player leaves
Browse files Browse the repository at this point in the history
  • Loading branch information
keshav2010 committed Jul 24, 2024
1 parent f64b485 commit 9bae1af
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 0 additions & 1 deletion gameserver/commands/OnLeaveCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ export class OnLeaveCommand extends Command<SessionRoom, CommandPayload> {
execute({ client, message, gameManager }: CommandPayload) {
const sessionId = client.sessionId;
this.state.removePlayer(sessionId, gameManager!);
this.state.tilemap.updateOwnershipMap(this.state.getPlayers());
}
}
6 changes: 3 additions & 3 deletions public/scenes/GameScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,9 +703,9 @@ export class GameScene extends BaseScene {
`obj_captureFlag_${player.id}_${newFlag.id}`
);
if (!flag) return;
this.DestroyObjectById(`obj_captureFlag_${player.id}_${newFlag.id}`);
this.DestroyObjectById(`obj_captureFlag_${player.id}_${flag.id}`);
this.DestroyStateChangeListener(
`statechange_captureFlag_${player.id}_${newFlag.id}`
`statechange_captureFlag_${player.id}_${flag.id}`
);
})
);
Expand All @@ -714,10 +714,10 @@ export class GameScene extends BaseScene {
this.AddStateChangeListener(
state.players.onRemove((player) => {
const kingdomId = `obj_playerCastle_${player.id}`;
this.DestroyObjectById(kingdomId);
this.events.emit(PacketType.ByServer.PLAYER_LEFT, {
playerState: player,
});
this.DestroyObjectById(kingdomId);
})
);

Expand Down
6 changes: 6 additions & 0 deletions public/scenes/PlayerStatisticHUD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { NetworkManager } from "../NetworkManager";
import { PlayerState } from "../../gameserver/schema/PlayerState";
import { Spearman } from "../soldiers/Spearman";
import CONSTANTS from "../constant";
import { CaptureFlag } from "../gameObjects/CaptureFlag";

const textStyle: Phaser.Types.GameObjects.Text.TextStyle = {
color: "#fff",
Expand Down Expand Up @@ -198,6 +199,11 @@ export class PlayerStatisticHUD extends BaseScene {
gameScene.onSoldierRemoved(soldier.id, playerObject.id);
});

const captureFlags = gameScene.GetObjectsWithKeyPrefix<CaptureFlag>(
`obj_captureFlag_${playerObject.id}`
);
captureFlags.forEach((flag) => flag.destroy(true));

soldierCount.setText(
`Total Soldiers: ${[...state.players.values()].reduce((acc, curr) => {
acc = acc + curr.soldiers.size;
Expand Down

0 comments on commit 9bae1af

Please sign in to comment.