Skip to content

Commit

Permalink
fix: grenade last equipped slots
Browse files Browse the repository at this point in the history
  • Loading branch information
starswaitforus authored and solcloud committed Oct 14, 2024
1 parent 51d97ab commit 7dab153
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 3 additions & 2 deletions server/src/Core/Inventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ private function tryRemoveLastEquippedGrenade(Item $item): void
{
if ($item instanceof Grenade) {
$index = array_search($item->getSlot()->value, $this->lastEquippedGrenadeSlots, true);
assert(is_int($index));
unset($this->lastEquippedGrenadeSlots[$index]);
if (is_int($index)) {
unset($this->lastEquippedGrenadeSlots[$index]);
}
}
}

Expand Down
24 changes: 24 additions & 0 deletions test/og/Shooting/GrenadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use cs\Core\Setting;
use cs\Core\Wall;
use cs\Enum\BuyMenuItem;
use cs\Enum\Color;
use cs\Enum\InventorySlot;
use cs\Enum\SoundType;
use cs\Equipment\Decoy;
Expand Down Expand Up @@ -464,4 +465,27 @@ public function testSmokeCanBounceOnFloorBeforePopping(): void
$this->assertGreaterThan(1, $bounceCount);
}

public function testBuyGrenadeMultipleSurvivedRounds(): void
{
$game = $this->createNoPauseGame(6);
$p2 = new Player(2, Color::GREEN, false);
$game->addPlayer($p2);

$this->playPlayer($game, [
fn(Player $p) => $this->assertTrue($p->buyItem(BuyMenuItem::GRENADE_DECOY)),
$this->waitNTicks(Decoy::equipReadyTimeMs),
fn(Player $p) => $this->assertNotNull($p->attack()),
$this->waitNTicks(100),
fn() => $p2->suicide(),
fn(Player $p) => $this->assertFalse($p->getInventory()->has(InventorySlot::SLOT_GRENADE_DECOY->value)),
fn(Player $p) => $this->assertTrue($p->buyItem(BuyMenuItem::GRENADE_DECOY)),
$this->waitNTicks(Decoy::equipReadyTimeMs),
fn(Player $p) => $this->assertNotNull($p->attack()),
$this->waitNTicks(100),
$this->endGame(),
]);

$this->assertSame(2, $game->getRoundNumber());
}

}

0 comments on commit 7dab153

Please sign in to comment.