Passed
Push — master ( bf860f...1dd8f7 )
by Nico
57:55 queued 29:36
created

UpdatePirateWrath::handleShipDestruction()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 36
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 6
eloc 19
c 2
b 0
f 0
nc 6
nop 4
dl 0
loc 36
ccs 0
cts 21
cp 0
crap 42
rs 9.0111
1
<?php
2
3
namespace Stu\Module\Ship\Lib\Destruction\Handler;
4
5
use Stu\Lib\Information\InformationInterface;
6
use Stu\Lib\Pirate\Component\PirateWrathManagerInterface;
7
use Stu\Module\Logging\LoggerUtilFactoryInterface;
8
use Stu\Module\Logging\PirateLoggerInterface;
9
use Stu\Module\PlayerSetting\Lib\UserEnum;
10
use Stu\Module\Ship\Lib\Destruction\ShipDestroyerInterface;
11
use Stu\Module\Ship\Lib\Destruction\ShipDestructionCauseEnum;
12
use Stu\Module\Ship\Lib\ShipWrapperInterface;
13
14
class UpdatePirateWrath implements ShipDestructionHandlerInterface
15
{
16
    private PirateLoggerInterface $logger;
17
18 1
    public function __construct(
19
        private PirateWrathManagerInterface $pirateWrathManager,
20
        LoggerUtilFactoryInterface $loggerUtilFactory
21
    ) {
22 1
        $this->logger = $loggerUtilFactory->getPirateLogger();
23
    }
24
25
    public function handleShipDestruction(
26
        ?ShipDestroyerInterface $destroyer,
27
        ShipWrapperInterface $destroyedShipWrapper,
28
        ShipDestructionCauseEnum $cause,
29
        InformationInterface $informations
30
    ): void {
31
32
        if ($destroyer === null) {
33
            return;
34
        }
35
36
        $ship = $destroyedShipWrapper->get();
37
        $targetPrestige = $ship->getRump()->getPrestige();
38
        if ($targetPrestige < 1) {
39
            return;
40
        }
41
42
        $destroyerUser = $destroyer->getUser();
43
        $userOfDestroyed = $destroyedShipWrapper->get()->getUser();
44
45
        if ($destroyerUser->getId() === UserEnum::USER_NPC_KAZON) {
46
            $this->pirateWrathManager->decreaseWrath($userOfDestroyed, $targetPrestige);
47
        }
48
49
        if ($userOfDestroyed->getId() === UserEnum::USER_NPC_KAZON) {
50
51
            $fleet = $ship->getFleet();
52
            $this->logger->log(sprintf(
53
                '    %s (%s) of fleet %d got destroyed by %s',
54
                $ship->getName(),
55
                $ship->getRump()->getName(),
56
                $fleet === null ? 0 : $fleet->getId(),
57
                $destroyer->getName()
58
            ));
59
60
            $this->pirateWrathManager->increaseWrath($userOfDestroyed, $targetPrestige);
61
        }
62
    }
63
}
64