Skip to content

Commit

Permalink
Added team kill counter
Browse files Browse the repository at this point in the history
The gameover packet now shows how much kills your team got.
  • Loading branch information
hotDuckWhatsUp committed Jun 28, 2024
1 parent 84691c4 commit f4b536d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,10 @@ <h1 id="game-over-player-name" class="modal-item">Player</h1>
<span class="stat-name">Kills:</span>
<span class="stat-value" id="game-over-kills"></span>
</div>
<div class="stat" id="teamKills">
<span class="stat-name">Team kills:</span>
<span class="stat-value" id="game-over-team-kills"></span>
</div>
<div class="stat">
<span class="stat-name">Damage done:</span>
<span class="stat-value" id="game-over-damage-done"></span>
Expand Down
8 changes: 8 additions & 0 deletions client/src/scripts/managers/uiManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ export class UIManager {
gameOverText: $<HTMLHeadingElement>("#game-over-text"),
gameOverPlayerName: $<HTMLHeadingElement>("#game-over-player-name"),
gameOverKills: $<HTMLSpanElement>("#game-over-kills"),
gameOverTeamKills: $<HTMLSpanElement>("#game-over-team-kills"),
teamKillsDisplay: $<HTMLSpanElement>("#teamKills"),
gameOverDamageDone: $<HTMLSpanElement>("#game-over-damage-done"),
gameOverDamageTaken: $<HTMLSpanElement>("#game-over-damage-taken"),
gameOverTime: $<HTMLSpanElement>("#game-over-time"),
Expand Down Expand Up @@ -369,6 +371,7 @@ export class UIManager {
gameOverRank,
gameOverPlayerName,
gameOverKills,
gameOverTeamKills,
gameOverDamageDone,
gameOverDamageTaken,
gameOverTime
Expand Down Expand Up @@ -400,6 +403,7 @@ export class UIManager {
gameOverPlayerName.html(playerName + playerBadgeText);

gameOverKills.text(packet.kills);
gameOverTeamKills.text(packet.teamKills);
gameOverDamageDone.text(packet.damageDone);
gameOverDamageTaken.text(packet.damageTaken);
gameOverTime.text(formatDate(packet.timeAlive));
Expand All @@ -410,6 +414,10 @@ export class UIManager {

// Player rank
gameOverRank.text(`#${packet.rank}`).toggleClass("won", packet.won);

if (game.teamID === undefined) {
this.ui.teamKillsDisplay.hide();
}
}

// I'd rewrite this as MapPings.filter(…), but it's not really clear how
Expand Down
3 changes: 3 additions & 0 deletions common/src/packets/gameOverPacket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export class GameOverPacket implements Packet {
won!: boolean;
playerID!: number;
kills!: number;
teamKills!: number;
damageDone!: number;
damageTaken!: number;
timeAlive!: number;
Expand All @@ -14,6 +15,7 @@ export class GameOverPacket implements Packet {
stream.writeBoolean(this.won);
stream.writeObjectID(this.playerID);
stream.writeUint8(this.kills);
stream.writeUint8(this.teamKills);
stream.writeUint16(this.damageDone);
stream.writeUint16(this.damageTaken);
stream.writeUint16(this.timeAlive);
Expand All @@ -24,6 +26,7 @@ export class GameOverPacket implements Packet {
this.won = stream.readBoolean();
this.playerID = stream.readObjectID();
this.kills = stream.readUint8();
this.teamKills = stream.readUint8();
this.damageDone = stream.readUint16();
this.damageTaken = stream.readUint16();
this.timeAlive = stream.readUint16();
Expand Down
9 changes: 9 additions & 0 deletions server/src/objects/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export class Player extends BaseGameObject<ObjectCategory.Player> {
readonly ip?: string;

teamID?: number;
teamKills = 0;

readonly loadout: {
badge?: BadgeDefinition
Expand Down Expand Up @@ -1367,6 +1368,13 @@ export class Player extends BaseGameObject<ObjectCategory.Player> {
if (item.definition.killstreak) {
killFeedPacket.killstreak = item.stats.kills;
}

++player.teamKills;
for (const p of this.game.livingPlayers) {
if (p.teamID == player.teamID) {
p.teamKills = player.teamKills;
}
}
};

const attributeToDowner = (): boolean => {
Expand Down Expand Up @@ -1612,6 +1620,7 @@ export class Player extends BaseGameObject<ObjectCategory.Player> {
packet.won = won;
packet.playerID = this.id;
packet.kills = this.kills;
packet.teamKills = this.teamKills;
packet.damageDone = this.damageDone;
packet.damageTaken = this.damageTaken;
packet.timeAlive = (this.game.now - this.joinTime) / 1000;
Expand Down

0 comments on commit f4b536d

Please sign in to comment.