Add ProjectZomboidPvpLog (pvp.txt)
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.
This commit is contained in:
47
src/Log/ProjectZomboid/ProjectZomboidPvpLog.php
Normal file
47
src/Log/ProjectZomboid/ProjectZomboidPvpLog.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace IndifferentKetchup\Codex\Log\ProjectZomboid;
|
||||
|
||||
use IndifferentKetchup\Codex\Analyser\AnalyserInterface;
|
||||
use IndifferentKetchup\Codex\Analyser\PatternAnalyser;
|
||||
use IndifferentKetchup\Codex\Detective\FilenameDetector;
|
||||
use IndifferentKetchup\Codex\Detective\WeightedSinglePatternDetector;
|
||||
use IndifferentKetchup\Codex\Parser\ParserInterface;
|
||||
use IndifferentKetchup\Codex\Parser\PatternParser;
|
||||
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\PvpPattern;
|
||||
|
||||
class ProjectZomboidPvpLog extends ProjectZomboidEventLog
|
||||
{
|
||||
public static function getDefaultParser(): ParserInterface
|
||||
{
|
||||
return static::makePatternParser(
|
||||
PvpPattern::LINE,
|
||||
[PatternParser::TIME, PatternParser::LEVEL, PatternParser::PREFIX]
|
||||
);
|
||||
}
|
||||
|
||||
public static function getDefaultAnalyser(): AnalyserInterface
|
||||
{
|
||||
return new PatternAnalyser();
|
||||
}
|
||||
|
||||
public static function getDetectors(): array
|
||||
{
|
||||
return [
|
||||
(new FilenameDetector())
|
||||
->setPattern('/_pvp\.txt$/')
|
||||
->setWeight(0.95),
|
||||
(new WeightedSinglePatternDetector())
|
||||
->setPattern('/^\[[^\]]+\]\[\w+\] Combat: "[^"]+" \(/m')
|
||||
->setWeight(0.95),
|
||||
(new WeightedSinglePatternDetector())
|
||||
->setPattern('/^\[[^\]]+\]\[\w+\] Safety: "/m')
|
||||
->setWeight(0.85),
|
||||
];
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return "Project Zomboid PvP Log";
|
||||
}
|
||||
}
|
||||
27
src/Pattern/ProjectZomboid/PvpPattern.php
Normal file
27
src/Pattern/ProjectZomboid/PvpPattern.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace IndifferentKetchup\Codex\Pattern\ProjectZomboid;
|
||||
|
||||
/**
|
||||
* Regex constants for the Project Zomboid pvp.txt format.
|
||||
*
|
||||
* Two row variants share the file: Safe House toggles
|
||||
* [time][LOG] Safety: "player" (x,y,z) restore true.
|
||||
* and Combat events
|
||||
* [time][INFO] Combat: "attacker" (x,y,z) hit "victim" (x,y,z) weapon="W" damage=N.NN.
|
||||
*
|
||||
* Z coordinates can be negative (basement levels: -1, -2).
|
||||
*
|
||||
* LINE captures, in order:
|
||||
* 1. time
|
||||
* 2. level (LOG | INFO | WARN | ERROR)
|
||||
* 3. subsystem (Safety | Combat)
|
||||
*/
|
||||
class PvpPattern
|
||||
{
|
||||
public const string LINE = '/^\[(\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3})\]\[(LOG|INFO|WARN|ERROR)\] (\w+): .+\.$/';
|
||||
|
||||
public const string COMBAT = '/^Combat: "(?<attacker>[^"]+)" \((?<ax>\d+),(?<ay>\d+),(?<az>-?\d+)\) hit "(?<victim>[^"]+)" \((?<vx>\d+),(?<vy>\d+),(?<vz>-?\d+)\) weapon="(?<weapon>[^"]+)" damage=(?<damage>-?\d+\.\d+)\.$/';
|
||||
|
||||
public const string SAFETY = '/^Safety: "(?<player>[^"]+)" \((?<x>\d+),(?<y>\d+),(?<z>-?\d+)\) (?<verb>\w+) (?<state>true|false)\.$/';
|
||||
}
|
||||
10
test/src/Games/ProjectZomboid/fixtures/pvp-minimal.txt
Normal file
10
test/src/Games/ProjectZomboid/fixtures/pvp-minimal.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
[16-04-26 16:17:49.731][LOG] Safety: "Player1" (1000,2000,0) restore true.
|
||||
[16-04-26 16:18:12.078][LOG] Safety: "Player2" (1010,2010,0) restore true.
|
||||
[16-04-26 16:20:34.144][LOG] Safety: "Player1" (1000,2000,0) store true.
|
||||
[16-04-26 16:25:41.402][LOG] Safety: "AdminUser" (1020,2020,0) restore true.
|
||||
[16-04-26 16:36:07.978][LOG] Safety: "Player2" (1011,2011,0) store true.
|
||||
[16-04-26 17:14:28.814][INFO] Combat: "Player1" (1005,2005,0) hit "Player2" (1005,2005,0) weapon="Bare Hands" damage=0.026675.
|
||||
[16-04-26 17:14:35.128][INFO] Combat: "Player1" (1005,2005,0) hit "Player2" (1006,2005,0) weapon="Tire Iron (Worn)" damage=0.112317.
|
||||
[16-04-26 17:42:49.022][INFO] Combat: "Player2" (1005,2005,0) hit "Player2" (1005,2005,0) weapon="zombie" damage=-1.000000.
|
||||
[16-04-26 17:45:14.028][INFO] Combat: "Player1" (1100,2200,0) hit "Player2" (1100,2201,0) weapon="vehicle" damage=0.000000.
|
||||
[16-04-26 18:00:01.515][INFO] Combat: "AdminUser" (1020,2020,-1) hit "Player1" (1020,2020,-1) weapon="Hunting Knife" damage=0.350000.
|
||||
@@ -0,0 +1,69 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user