Skip to content

Commit d4c0693

Browse files
coopryansolcloud
authored andcommitted
Show in HUD if player has 2 flashbangs
1 parent c738e0d commit d4c0693

File tree

6 files changed

+24
-2
lines changed

6 files changed

+24
-2
lines changed

infection.json5

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"Minus": false,
3333
"Modulus": false,
3434
"Multiplication": false,
35+
"NullSafeMethodCall": false,
3536
"Plus": false,
3637
"RoundingFamily": false,
3738
"TrueValue": false,

server/src/Core/Inventory.php

+5
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ public function getEquipped(): Item
8787
return $this->items[$this->equippedSlot];
8888
}
8989

90+
public function getItemSlot(InventorySlot $slot): ?Item
91+
{
92+
return ($this->items[$slot->value] ?? null);
93+
}
94+
9095
private function tryRemoveLastEquippedGrenade(Item $item): void
9196
{
9297
$index = array_search($item->getSlot()->value, $this->lastEquippedGrenadeSlots, true);

server/src/Core/Player.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ public function serialize(): array
329329
$ammoReserve = $equippedItem->getAmmoReserve();
330330
$reloading = $equippedItem->isReloading();
331331
}
332+
$filledSlots = $this->inventory->getFilledSlots();
333+
if (isset($filledSlots[InventorySlot::SLOT_GRENADE_FLASH->value])) {
334+
$filledSlots[InventorySlot::SLOT_GRENADE_FLASH->value]['pcs'] = $this->inventory->getItemSlot(InventorySlot::SLOT_GRENADE_FLASH)?->getQuantity();
335+
}
332336

333337
return [
334338
'id' => $this->id,
@@ -338,7 +342,7 @@ public function serialize(): array
338342
'canAttack' => $canAttack,
339343
'canBuy' => $this->world->canBuy($this),
340344
'canPlant' => $this->world->canPlant($this),
341-
'slots' => $this->inventory->getFilledSlots(),
345+
'slots' => $filledSlots,
342346
'health' => $this->health,
343347
'position' => $this->position->toArray(),
344348
'look' => $this->sight->toArray(),

test/og/Inventory/InventoryTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -588,15 +588,18 @@ public function testPlayerBuyTwoFlashes(): void
588588
$this->assertSame($itemPrice, $item->getPrice());
589589
$this->assertFalse($game->getPlayer(1)->getInventory()->canBuy($item));
590590
$this->assertSame(2, $item->getQuantity());
591+
$this->assertSame(2, $game->getPlayer(1)->serialize()['slots'][InventorySlot::SLOT_GRENADE_FLASH->value]['pcs'] ?? false); // @phpstan-ignore-line
591592

592593
$flashBang1 = $game->getPlayer(1)->dropEquippedItem();
594+
$this->assertSame(1, $game->getPlayer(1)->serialize()['slots'][InventorySlot::SLOT_GRENADE_FLASH->value]['pcs'] ?? false); // @phpstan-ignore-line
593595
$this->assertInstanceOf(Flashbang::class, $flashBang1);
594596
$flashBang2 = $game->getPlayer(1)->dropEquippedItem();
595597
$this->assertInstanceOf(Flashbang::class, $flashBang2);
596598
$this->assertFalse($flashBang1 === $flashBang2);
597599
$this->assertTrue($item === $flashBang2);
598600
$this->assertSame(1, $flashBang1->getQuantity());
599601
$this->assertSame(1, $flashBang2->getQuantity());
602+
$this->assertNull($game->getPlayer(1)->serialize()['slots'][InventorySlot::SLOT_GRENADE_FLASH->value]['pcs'] ?? null); // @phpstan-ignore-line
600603
}
601604

602605
public function testPlayerBuyMaxFourGrenades(): void

www/assets/css/hud.css

+8
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,14 @@
496496
padding: 8px;
497497
}
498498

499+
#hud .inventory .grenades span > span.count {
500+
padding: 0;
501+
font-size: 12px;
502+
color: #ffebc5;
503+
position: relative;
504+
left: -6px;
505+
}
506+
499507
#hud .inventory .highlight {
500508
font-weight: bold;
501509
color: #ffebc5;

www/assets/js/Hud.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ export class HUD {
208208
return
209209
}
210210

211-
grenade += `<span${slotId === slot ? ' class="highlight"' : ''}>${Enum.ItemIdToIcon[item.id]}</span>`
211+
let grenadeCount = (item.pcs > 1) ? `<span class="count">x${item.pcs}</span>` : ''
212+
grenade += `<span${slotId === slot ? ' class="highlight"' : ''}>${Enum.ItemIdToIcon[item.id]}${grenadeCount}</span>`
212213
})
213214
this.#elements.inventory.innerHTML = html + `<div class="grenades">${grenade}</div>`
214215
}

0 commit comments

Comments
 (0)