/
CombatLogDungeonRouteFilter.php
90 lines (74 loc) · 2.73 KB
/
CombatLogDungeonRouteFilter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
namespace App\Service\CombatLog\Filters;
use App\Logic\CombatLog\BaseEvent;
use App\Logic\CombatLog\CombatEvents\AdvancedCombatLogEvent;
use App\Logic\CombatLog\Guid\Creature;
use App\Models\DungeonRoute;
use App\Service\CombatLog\Interfaces\CombatLogParserInterface;
use App\Service\CombatLog\ResultEvents\BaseResultEvent;
use Illuminate\Support\Collection;
class CombatLogDungeonRouteFilter implements CombatLogParserInterface
{
/** @var Collection|BaseResultEvent[] */
private Collection $resultEvents;
/** @var Collection|CombatLogParserInterface[] */
private Collection $filters;
private SpecialEventsFilter $specialEventsFilter;
private CombatFilter $combatFilter;
private SpellFilter $spellFilter;
public function __construct()
{
$this->resultEvents = collect();
$this->specialEventsFilter = new SpecialEventsFilter($this->resultEvents);
$this->combatFilter = new CombatFilter($this->resultEvents);
$this->spellFilter = new SpellFilter($this->resultEvents);
$this->filters = collect([
$this->specialEventsFilter,
$this->combatFilter,
$this->spellFilter,
]);
}
/**
* @param DungeonRoute $dungeonRoute
*
* @return void
*/
public function setDungeonRoute(DungeonRoute $dungeonRoute): self
{
$this->combatFilter->setValidNpcIds($dungeonRoute->dungeon->getInUseNpcIds());
return $this;
}
/**
* @param BaseEvent $combatLogEvent
* @param int $lineNr
*
* @return bool
*/
public function parse(BaseEvent $combatLogEvent, int $lineNr): bool
{
$result = false;
foreach ($this->filters as $filter) {
$result = $filter->parse($combatLogEvent, $lineNr) || $result;
}
return $result;
}
/**
* @return Collection|BaseResultEvent[]
*/
public function getResultEvents(): Collection
{
return $this->resultEvents->sortBy(function (BaseResultEvent $baseResultEvent) {
// Add some CONSISTENT (not necessarily accurate) numbers so that events with
$addition = 0;
$baseEvent = $baseResultEvent->getBaseEvent();
if ($baseEvent instanceof AdvancedCombatLogEvent) {
$guid = $baseEvent->getAdvancedData()->getInfoGuid();
if ($guid instanceof Creature) {
// Ensure that the addition doesn't go higher than 1
$addition = min(0.99999, ($guid->getId() + hexdec($guid->getSpawnUID())) / 10000000000000);
}
}
return $baseResultEvent->getBaseEvent()->getTimestamp()->getTimestampMs() + $addition;
});
}
}