diff --git a/server/src/Core/World.php b/server/src/Core/World.php index b9bd7b8..8da738e 100644 --- a/server/src/Core/World.php +++ b/server/src/Core/World.php @@ -501,10 +501,14 @@ public function bulletHit(Hittable $hit, Bullet $bullet, bool $wasHeadshot): voi if ($hit instanceof SolidSurface) { $soundEvent->setSurface($hit); } + $damage = $hit->getDamage(); + $attacker = $bullet->getOriginPlayerId(); $soundEvent->addExtra('origin', $bullet->getOrigin()->toArray()); + $soundEvent->addExtra('damage', min(100, $damage)); + $soundEvent->addExtra('shooter', $attacker); $this->makeSound($soundEvent); - $this->game->getScore()->getPlayerStat($bullet->getOriginPlayerId())->addDamage($hit->getDamage()); + $this->game->getScore()->getPlayerStat($attacker)->addDamage($damage); } public function tryPlantBomb(Player $player): void diff --git a/www/assets/css/hud.css b/www/assets/css/hud.css index d71582b..1080164 100644 --- a/www/assets/css/hud.css +++ b/www/assets/css/hud.css @@ -157,10 +157,6 @@ pointer-events: initial; } -#hud #game-menu div[data-setting] > div.row { - clear: both; -} - #hud #game-menu div[data-setting] > div.row > div { float: left; width: 50%; @@ -334,6 +330,42 @@ height: 100%; } +#hud #round-damage-stat { + font-size: 80%; + color: #ffffff; + margin: 0.9rem 0; +} + +#hud #round-damage-stat table { + width: auto; + background: rgba(0, 0, 0, 0.6); + text-align: right; + border-collapse: collapse; +} + +#hud #round-damage-stat table td, +#hud #round-damage-stat table th { + padding: 2px 8px; + border: 1px dotted #ffffff47; +} + +#hud #round-damage-stat tr > *:nth-child(1) { + text-align: left; +} + +#hud #round-damage-stat tr td:nth-child(2).highlight { + text-shadow: 0 0 2px green; +} + +#hud #round-damage-stat tr td:nth-child(3).highlight { + text-shadow: 0 0 2px red; +} + +#hud #fps-stats > div { + float: left; + margin-right: 4px; +} + #hud .bg { background: rgba(0, 0, 0, 0.6); } diff --git a/www/assets/js/Game.js b/www/assets/js/Game.js index 2b516e0..1ddfef0 100644 --- a/www/assets/js/Game.js +++ b/www/assets/js/Game.js @@ -26,6 +26,7 @@ export class Game { #dropItems = {}; #throwables = {}; #roundIntervalIds = []; + #roundDamage = {did: {},got: {}} #playerSlotsVisibleModels = [ InventorySlot.SLOT_KNIFE, InventorySlot.SLOT_PRIMARY, InventorySlot.SLOT_SECONDARY, InventorySlot.SLOT_BOMB, InventorySlot.SLOT_GRENADE_DECOY, InventorySlot.SLOT_GRENADE_MOLOTOV, @@ -93,6 +94,8 @@ export class Game { unpause() { this.#paused = false this.#hud.clearTopMessage() + this.#hud.updateRoundDamage(null) + this.#roundDamage = {did: {},got: {}} console.log("Game unpause") } @@ -119,6 +122,7 @@ export class Game { this.#round = newRoundNumber this.#hud.displayTopMessage(winner + ' wins') this.#hud.requestFullScoreBoardUpdate(this.score) + this.#hud.updateRoundDamage(this.#roundDamage, this.getEnemyPlayers()) } halfTime() { @@ -130,7 +134,8 @@ export class Game { } playerHit(data, wasHeadshot) { - if (data.player === this.playerSpectate.getId()) { + const playerHitId = data.player + if (playerHitId === this.playerSpectate.getId()) { const anglePlayer = Math.round(this.getPlayerSpectateRotation()[0]) const camera = this.#world.getCamera() @@ -155,6 +160,21 @@ export class Game { } else { this.#world.bulletPlayerHit(data.position, wasHeadshot) } + + const damage = data.extra.damage + const myId = this.playerMe.getId() + const attackerId = data.extra.shooter + if (playerHitId === myId) { + if (!this.#roundDamage.got[attackerId]) { + this.#roundDamage.got[attackerId] = [] + } + this.#roundDamage.got[attackerId].push(damage) + } else if (attackerId === myId) { + if (!this.#roundDamage.did[playerHitId]) { + this.#roundDamage.did[playerHitId] = [] + } + this.#roundDamage.did[playerHitId].push(damage) + } } processSound(data) { @@ -573,6 +593,11 @@ export class Game { return this.players.filter((player) => player.isAttacker() === meIsAttacker) } + getEnemyPlayers() { + let meIsAttacker = this.playerMe.isAttacker() + return this.players.filter((player) => player.isAttacker() !== meIsAttacker) + } + meIsAlive() { return this.playerMe.isAlive() } diff --git a/www/assets/js/Hud.js b/www/assets/js/Hud.js index 6d59b04..33d9fcc 100644 --- a/www/assets/js/Hud.js +++ b/www/assets/js/Hud.js @@ -5,6 +5,7 @@ import {KillFeed} from "./hud/KillFeed.js"; import {Radar} from "./hud/Radar.js"; import {HitFeedback} from "./hud/HitFeedback.js"; import {GameMenu} from "./hud/GameMenu.js"; +import {RoundDamageStat} from "./hud/RoundDamageStat.js"; export class HUD { #game @@ -13,6 +14,7 @@ export class HUD { #gameMenu = null; #killFeed = null; #hitFeedback = null; + #roundDamageStat = null; #radar = null; #showAble = { showScore: false, @@ -90,6 +92,10 @@ export class HUD { this.#scoreBoardData = scoreBoardData } + updateRoundDamage(roundDamage, enemyPlayers) { + this.#roundDamageStat.update(roundDamage, enemyPlayers) + } + updateMyTeamPlayerMoney(playerData, money) { const moneyElement = this.#scoreBoard.getPlayerStatRowElement(playerData).querySelector('[data-money]') moneyElement.innerText = `${money}` @@ -295,7 +301,8 @@ export class HUD {
Enemy Name | +Harm did | +Harm got | +
---|