Skip to content

Commit 19363d6

Browse files
committed
Round end damage stats for each enemy
1 parent c466ad4 commit 19363d6

5 files changed

Lines changed: 140 additions & 7 deletions

File tree

server/src/Core/World.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,14 @@ public function bulletHit(Hittable $hit, Bullet $bullet, bool $wasHeadshot): voi
501501
if ($hit instanceof SolidSurface) {
502502
$soundEvent->setSurface($hit);
503503
}
504+
$damage = $hit->getDamage();
505+
$attacker = $bullet->getOriginPlayerId();
504506
$soundEvent->addExtra('origin', $bullet->getOrigin()->toArray());
507+
$soundEvent->addExtra('damage', min(100, $damage));
508+
$soundEvent->addExtra('shooter', $attacker);
505509

506510
$this->makeSound($soundEvent);
507-
$this->game->getScore()->getPlayerStat($bullet->getOriginPlayerId())->addDamage($hit->getDamage());
511+
$this->game->getScore()->getPlayerStat($attacker)->addDamage($damage);
508512
}
509513

510514
public function tryPlantBomb(Player $player): void

www/assets/css/hud.css

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,6 @@
157157
pointer-events: initial;
158158
}
159159

160-
#hud #game-menu div[data-setting] > div.row {
161-
clear: both;
162-
}
163-
164160
#hud #game-menu div[data-setting] > div.row > div {
165161
float: left;
166162
width: 50%;
@@ -334,6 +330,42 @@
334330
height: 100%;
335331
}
336332

333+
#hud #round-damage-stat {
334+
font-size: 80%;
335+
color: #ffffff;
336+
margin: 0.9rem 0;
337+
}
338+
339+
#hud #round-damage-stat table {
340+
width: auto;
341+
background: rgba(0, 0, 0, 0.6);
342+
text-align: right;
343+
border-collapse: collapse;
344+
}
345+
346+
#hud #round-damage-stat table td,
347+
#hud #round-damage-stat table th {
348+
padding: 2px 8px;
349+
border: 1px dotted #ffffff47;
350+
}
351+
352+
#hud #round-damage-stat tr > *:nth-child(1) {
353+
text-align: left;
354+
}
355+
356+
#hud #round-damage-stat tr td:nth-child(2).highlight {
357+
text-shadow: 0 0 2px green;
358+
}
359+
360+
#hud #round-damage-stat tr td:nth-child(3).highlight {
361+
text-shadow: 0 0 2px red;
362+
}
363+
364+
#hud #fps-stats > div {
365+
float: left;
366+
margin-right: 4px;
367+
}
368+
337369
#hud .bg {
338370
background: rgba(0, 0, 0, 0.6);
339371
}

www/assets/js/Game.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export class Game {
2626
#dropItems = {};
2727
#throwables = {};
2828
#roundIntervalIds = [];
29+
#roundDamage = {did: {},got: {}}
2930
#playerSlotsVisibleModels = [
3031
InventorySlot.SLOT_KNIFE, InventorySlot.SLOT_PRIMARY, InventorySlot.SLOT_SECONDARY,
3132
InventorySlot.SLOT_BOMB, InventorySlot.SLOT_GRENADE_DECOY, InventorySlot.SLOT_GRENADE_MOLOTOV,
@@ -93,6 +94,8 @@ export class Game {
9394
unpause() {
9495
this.#paused = false
9596
this.#hud.clearTopMessage()
97+
this.#hud.updateRoundDamage(null)
98+
this.#roundDamage = {did: {},got: {}}
9699
console.log("Game unpause")
97100
}
98101

@@ -119,6 +122,7 @@ export class Game {
119122
this.#round = newRoundNumber
120123
this.#hud.displayTopMessage(winner + ' wins')
121124
this.#hud.requestFullScoreBoardUpdate(this.score)
125+
this.#hud.updateRoundDamage(this.#roundDamage, this.getEnemyPlayers())
122126
}
123127

124128
halfTime() {
@@ -130,7 +134,8 @@ export class Game {
130134
}
131135

132136
playerHit(data, wasHeadshot) {
133-
if (data.player === this.playerSpectate.getId()) {
137+
const playerHitId = data.player
138+
if (playerHitId === this.playerSpectate.getId()) {
134139
const anglePlayer = Math.round(this.getPlayerSpectateRotation()[0])
135140
const camera = this.#world.getCamera()
136141

@@ -155,6 +160,21 @@ export class Game {
155160
} else {
156161
this.#world.bulletPlayerHit(data.position, wasHeadshot)
157162
}
163+
164+
const damage = data.extra.damage
165+
const myId = this.playerMe.getId()
166+
const attackerId = data.extra.shooter
167+
if (playerHitId === myId) {
168+
if (!this.#roundDamage.got[attackerId]) {
169+
this.#roundDamage.got[attackerId] = []
170+
}
171+
this.#roundDamage.got[attackerId].push(damage)
172+
} else if (attackerId === myId) {
173+
if (!this.#roundDamage.did[playerHitId]) {
174+
this.#roundDamage.did[playerHitId] = []
175+
}
176+
this.#roundDamage.did[playerHitId].push(damage)
177+
}
158178
}
159179

160180
processSound(data) {
@@ -573,6 +593,11 @@ export class Game {
573593
return this.players.filter((player) => player.isAttacker() === meIsAttacker)
574594
}
575595

596+
getEnemyPlayers() {
597+
let meIsAttacker = this.playerMe.isAttacker()
598+
return this.players.filter((player) => player.isAttacker() !== meIsAttacker)
599+
}
600+
576601
meIsAlive() {
577602
return this.playerMe.isAlive()
578603
}

www/assets/js/Hud.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {KillFeed} from "./hud/KillFeed.js";
55
import {Radar} from "./hud/Radar.js";
66
import {HitFeedback} from "./hud/HitFeedback.js";
77
import {GameMenu} from "./hud/GameMenu.js";
8+
import {RoundDamageStat} from "./hud/RoundDamageStat.js";
89

910
export class HUD {
1011
#game
@@ -13,6 +14,7 @@ export class HUD {
1314
#gameMenu = null;
1415
#killFeed = null;
1516
#hitFeedback = null;
17+
#roundDamageStat = null;
1618
#radar = null;
1719
#showAble = {
1820
showScore: false,
@@ -90,6 +92,10 @@ export class HUD {
9092
this.#scoreBoardData = scoreBoardData
9193
}
9294

95+
updateRoundDamage(roundDamage, enemyPlayers) {
96+
this.#roundDamageStat.update(roundDamage, enemyPlayers)
97+
}
98+
9399
updateMyTeamPlayerMoney(playerData, money) {
94100
const moneyElement = this.#scoreBoard.getPlayerStatRowElement(playerData).querySelector('[data-money]')
95101
moneyElement.innerText = `${money}`
@@ -295,7 +301,8 @@ export class HUD {
295301
<div data-have-defuse-kit class="hidden icons" style="margin:22px 4px;font-size:200%;color:#5d8dea">\uE066</div>
296302
</div>
297303
<div class="bottom">
298-
<div id="fps-stats"></div>
304+
<div id="round-damage-stat"></div>
305+
<div id="fps-stats" class="row"></div>
299306
<div class="health row bg icons">
300307
<div class="hp">
301308
+ <span data-health>100</span>
@@ -381,6 +388,7 @@ export class HUD {
381388
this.#gameMenu = new GameMenu(this.#elements.gameMenu, setting, this)
382389
this.#killFeed = new KillFeed(this.#scoreBoard, this.#elements.killFeed)
383390
this.#hitFeedback = new HitFeedback(elementHud.querySelector('#hit-feedback'))
391+
this.#roundDamageStat = new RoundDamageStat(elementHud.querySelector('#round-damage-stat'))
384392

385393
const self = this
386394
const radarImage = new Image()
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import {ColorNames} from "../Enums.js";
2+
3+
export class RoundDamageStat {
4+
#element
5+
6+
constructor(element) {
7+
this.#element = element
8+
}
9+
10+
update(damage, enemyPlayers) {
11+
if (damage === null) {
12+
this.#element.innerHTML = ''
13+
return
14+
}
15+
16+
let id, count, sum, deadPlayers = [], alivePlayers = []
17+
enemyPlayers.forEach((player) => {
18+
id = player.getId()
19+
let data = {
20+
name: ColorNames[player.getColorIndex()],
21+
health: player.data.health,
22+
damageDid: 0,
23+
damageGot: 0,
24+
}
25+
if (damage.did[id]) {
26+
count = damage.did[id].length
27+
sum = damage.did[id].reduce((acc, val) => acc += val)
28+
data.damageDid = `${sum} in ${count}`
29+
}
30+
if (damage.got[id]) {
31+
count = damage.got[id].length
32+
sum = damage.got[id].reduce((acc, val) => acc += val)
33+
data.damageGot = `${sum} in ${count}`
34+
}
35+
36+
if (player.isAlive()) {
37+
alivePlayers.push(data)
38+
} else {
39+
deadPlayers.push(data)
40+
}
41+
})
42+
43+
let html = ''
44+
;[...alivePlayers, ...deadPlayers].forEach((row) => {
45+
html += `<tr>
46+
<td>${row.name} (${row.health} hp)</td>
47+
<td${row.damageDid === 0 ? '' : ' class="highlight"'}>${row.damageDid}</td>
48+
<td${row.damageGot === 0 ? '' : ' class="highlight"'}>${row.damageGot}</td>
49+
</tr>
50+
`
51+
})
52+
53+
this.#element.innerHTML = `<table>
54+
<tr>
55+
<th>Enemy Name</th>
56+
<th>Harm did</th>
57+
<th>Harm got</th>
58+
</tr>
59+
${html}
60+
</table>
61+
`
62+
}
63+
64+
}

0 commit comments

Comments
 (0)