Skip to content

Commit

Permalink
Fix M4 rifle chest damage and provide test
Browse files Browse the repository at this point in the history
  • Loading branch information
solcloud committed Nov 1, 2023
1 parent c5b892a commit 7c6934b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/src/Weapon/RifleM4A4.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getDamageValue(HitBoxType $hitBox, ArmorType $armor): int
{
return match ($hitBox) {
HitBoxType::HEAD => $armor->hasArmorHead() ? 92 : 131,
HitBoxType::CHEST, HitBoxType::BACK => $armor->hasArmor() ? 92 : 131,
HitBoxType::CHEST, HitBoxType::BACK => $armor->hasArmor() ? 23 : 32,
HitBoxType::STOMACH => $armor->hasArmor() ? 28 : 41,
HitBoxType::LEG => 24,
};
Expand Down
44 changes: 44 additions & 0 deletions test/og/Shooting/PlayerKillTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,50 @@ public function testBulletHitOnePlayerOnlyOneHitBox(): void
$this->assertTrue($player1->isAlive());
}

public function testM4KillPlayerInFourBulletsInChestWithNoKevlar(): void
{
$game = $this->createTestGame();
$p2 = new Player(2, Color::BLUE, false);
$game->addPlayer($p2);
$p2->setPosition(new Point(500, 0, 500));
$game->getPlayer(1)->setPosition($p2->getPositionClone()->addZ(-200));

$finished = false;
$attackCallback = function (Player $p) use ($game) {
$this->assertSame(1, $game->getRoundNumber());
$res = $p->attack();
$this->assertNotNull($res);
$this->assertTrue($res->somePlayersWasHit());
$hits = $res->getHits();
$this->assertCount(2, $hits);
$hit = $hits[0];
$this->assertInstanceOf(HitBox::class, $hit);
$this->assertSame(HitBoxType::CHEST, $hit->getType());
};


$this->playPlayer($game, [
fn(Player $p) => $p->getInventory()->earnMoney(5000),
fn(Player $p) => $this->assertTrue($p->buyItem(BuyMenuItem::RIFLE_M4A4)),
fn(Player $p) => $p->getSight()->look(180, -10),
$this->waitNTicks(RifleM4A4::equipReadyTimeMs),
$attackCallback,
$this->waitNTicks(RifleM4A4::recoilResetMs),
$attackCallback,
$this->waitNTicks(RifleM4A4::recoilResetMs),
$attackCallback,
$this->waitNTicks(RifleM4A4::recoilResetMs),
$attackCallback,
$this->waitNTicks(RifleM4A4::recoilResetMs),
fn() => $this->assertSame(2, $game->getRoundNumber()),
function () use (&$finished) {
$finished = true;
},
$this->endGame(),
], $p2->getId());
$this->assertTrue($finished);
}

public function testUspKillPlayerInThreeBulletsInChestWithNoKevlar(): void
{
$player2Commands = [
Expand Down

0 comments on commit 7c6934b

Please sign in to comment.