Two row variants share the file: Safe House toggles ([LOG] Safety:) and Combat events ([INFO] Combat: ... weapon=... damage=...). Parser captures time, level, and the subsystem token (Safety|Combat) as the entry prefix. COMBAT and SAFETY regexes extract structured fields, including support for negative Z coordinates from basement levels. Synthetic fixture covers both variants and represents zombie/vehicle/ real-PvP weapon types so analysers can later filter on damage>0 and weapon!=zombie.
70 lines
2.5 KiB
PHP
70 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace IndifferentKetchup\Codex\Test\Tests\Games\ProjectZomboid\Log;
|
|
|
|
use IndifferentKetchup\Codex\Detective\Detective;
|
|
use IndifferentKetchup\Codex\Log\File\PathLogFile;
|
|
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidPvpLog;
|
|
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\PvpPattern;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class ProjectZomboidPvpLogTest extends TestCase
|
|
{
|
|
private function fixturePath(): string
|
|
{
|
|
return __DIR__ . '/../../../../src/Games/ProjectZomboid/fixtures/pvp-minimal.txt';
|
|
}
|
|
|
|
public function testParsesEachLineAsAnEntry(): void
|
|
{
|
|
$log = (new ProjectZomboidPvpLog())->setLogFile(new PathLogFile($this->fixturePath()));
|
|
$log->parse();
|
|
|
|
$this->assertCount(10, $log->getEntries());
|
|
}
|
|
|
|
public function testSubsystemIsCapturedAsPrefix(): void
|
|
{
|
|
$log = (new ProjectZomboidPvpLog())->setLogFile(new PathLogFile($this->fixturePath()));
|
|
$log->parse();
|
|
|
|
$entries = $log->getEntries();
|
|
$this->assertSame('Safety', $entries[0]->getPrefix());
|
|
$this->assertSame('Combat', $entries[5]->getPrefix());
|
|
}
|
|
|
|
public function testCombatRegexExtractsRealPvpDamage(): void
|
|
{
|
|
$line = 'Combat: "Player1" (1005,2005,0) hit "Player2" (1006,2005,0) weapon="Tire Iron (Worn)" damage=0.112317.';
|
|
$this->assertSame(1, preg_match(PvpPattern::COMBAT, $line, $m));
|
|
$this->assertSame('Player1', $m['attacker']);
|
|
$this->assertSame('Player2', $m['victim']);
|
|
$this->assertSame('Tire Iron (Worn)', $m['weapon']);
|
|
$this->assertSame('0.112317', $m['damage']);
|
|
}
|
|
|
|
public function testCombatRegexHandlesNegativeZ(): void
|
|
{
|
|
$line = 'Combat: "AdminUser" (1020,2020,-1) hit "Player1" (1020,2020,-1) weapon="Hunting Knife" damage=0.350000.';
|
|
$this->assertSame(1, preg_match(PvpPattern::COMBAT, $line, $m));
|
|
$this->assertSame('-1', $m['az']);
|
|
}
|
|
|
|
public function testSafetyRegexExtracts(): void
|
|
{
|
|
$line = 'Safety: "Player1" (1000,2000,0) restore true.';
|
|
$this->assertSame(1, preg_match(PvpPattern::SAFETY, $line, $m));
|
|
$this->assertSame('Player1', $m['player']);
|
|
$this->assertSame('restore', $m['verb']);
|
|
}
|
|
|
|
public function testDetectiveDispatchesByContent(): void
|
|
{
|
|
$detective = (new Detective())
|
|
->setLogFile(new PathLogFile($this->fixturePath()))
|
|
->addPossibleLogClass(ProjectZomboidPvpLog::class);
|
|
|
|
$this->assertInstanceOf(ProjectZomboidPvpLog::class, $detective->detect());
|
|
}
|
|
}
|