Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Commit

Permalink
fix: fix kill leader
Browse files Browse the repository at this point in the history
  • Loading branch information
leia-uwu committed Oct 1, 2024
1 parent 0e3b53d commit 8e2511d
Showing 1 changed file with 38 additions and 24 deletions.
62 changes: 38 additions & 24 deletions server/src/game/objects/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,12 @@ export class PlayerBarn {
const currentTeamIndex = aliveTeams.indexOf(currentTeam);
return aliveTeams.at(currentTeamIndex - 1) ?? currentTeam;
}

getPlayerWithHighestKills(): Player | undefined {
return this.game.playerBarn.livingPlayers
.filter((p) => p.kills >= GameConfig.player.killLeaderMinKills)
.sort((a, b) => b.kills - a.kills)[0];
}
}

export class Player extends BaseGameObject {
Expand Down Expand Up @@ -2059,26 +2065,14 @@ export class Player extends BaseGameObject {
if (source !== this) {
source.kills++;

if (this.game.map.mapDef.gameMode.killLeaderEnabled) {
const killLeader = this.game.playerBarn.killLeader;
if (
source.kills >= GameConfig.player.killLeaderMinKills &&
source.kills > (killLeader?.kills ?? 0)
) {
if (killLeader) {
killLeader.role = "";
}
source.promoteToRole("kill_leader");
}
if (source.isKillLeader) {
this.game.playerBarn.killLeaderDirty = true;
}
if (source.isKillLeader) {
this.game.playerBarn.killLeaderDirty = true;
}

if (source.hasPerk("takedown")) {
source.health += 25;
source.boost += 25;
source.giveHaste(GameConfig.HasteType.Takedown, 20);
source.giveHaste(GameConfig.HasteType.Takedown, 3);
}
}

Expand Down Expand Up @@ -2137,27 +2131,47 @@ export class Player extends BaseGameObject {
roleMsg.killerId = params.source?.__id ?? 0;
this.game.broadcastMsg(net.MsgType.RoleAnnouncement, roleMsg);
}
if (this.isKillLeader) {
this.game.playerBarn.killLeader = undefined;
this.game.playerBarn.killLeaderDirty = true;
this.isKillLeader = false;

if (this.isKillLeader) {
const roleMsg = new net.RoleAnnouncementMsg();
roleMsg.role = "kill_leader";
roleMsg.assigned = false;
roleMsg.killed = true;
roleMsg.playerId = this.__id;
roleMsg.killerId = params.source?.__id ?? 0;
this.game.broadcastMsg(net.MsgType.RoleAnnouncement, roleMsg);
}

if (this.game.map.mapDef.gameMode.killLeaderEnabled) {
const killLeader = this.game.playerBarn.killLeader;

const newKillLeader = this.game.playerBarn.livingPlayers
.filter((p) => p.kills >= GameConfig.player.killLeaderMinKills)
.sort((a, b) => a.kills - b.kills)[0];
if (newKillLeader) {
newKillLeader.promoteToRole("kill_leader");
let killLeaderKills = 0;

if (killLeader && !killLeader.dead) {
killLeaderKills = killLeader.kills;
}

const newKillLeader = this.game.playerBarn.getPlayerWithHighestKills();
if (
killLeader !== newKillLeader &&
params.source &&
newKillLeader === params.source &&
newKillLeader.kills > killLeaderKills
) {
if (killLeader) {
killLeader.role = "";
}

params.source.promoteToRole("kill_leader");
}
}

if (this.isKillLeader) {
this.game.playerBarn.killLeader = undefined;
this.game.playerBarn.killLeaderDirty = true;
this.isKillLeader = false;
}

this.game.pluginManager.emit("playerKill", { ...params, player: this });

//
Expand Down

0 comments on commit 8e2511d

Please sign in to comment.