Passed
Pull Request — master (#1833)
by Nico
34:40
created

ProjectilePhalanx::isShieldPenetration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\Lib\Battle\Provider;
6
7
use Stu\Component\Colony\Storage\ColonyStorageManagerInterface;
8
use Stu\Orm\Entity\ColonyInterface;
9
use Stu\Orm\Entity\TorpedoTypeInterface;
10
use Stu\Orm\Entity\UserInterface;
11
12
final class ProjectilePhalanx implements ProjectileAttackerInterface
13
{
14 17
    public function __construct(
15
        private ColonyInterface $colony,
16
        private ColonyStorageManagerInterface $colonyStorageManager
17
    ) {
18 17
    }
19
20 2
    public function hasSufficientEnergy(int $amount): bool
21
    {
22 2
        return $this->getEps() >= $amount;
23
    }
24
25 3
    private function getEps(): int
26
    {
27 3
        return $this->colony->getEps();
28
    }
29
30 1
    public function reduceEps(int $amount): void
31
    {
32 1
        $this->colony->setEps($this->getEps() - $amount);
33
    }
34
35 1
    public function getName(): string
36
    {
37 1
        return 'Orbitale Torpedophalanx';
38
    }
39
40 2
    public function getTorpedoState(): bool
41
    {
42 2
        return $this->getTorpedoCount() > 0;
43
    }
44
45 1
    public function getHitChance(): int
46
    {
47 1
        return 75;
48
    }
49
50 1
    public function getUser(): UserInterface
51
    {
52 1
        return $this->colony->getUser();
53
    }
54
55 5
    public function getTorpedoCount(): int
56
    {
57 5
        $torpedo = $this->getTorpedo();
58
59 5
        if ($torpedo != null) {
60 4
            $stor = $this->colony->getStorage()->get($torpedo->getCommodityId());
61
62 4
            if ($stor !== null) {
63 3
                return $stor->getAmount();
64
            }
65
        }
66
67 2
        return  0;
68
    }
69
70 2
    public function lowerTorpedoCount(int $amount): void
71
    {
72 2
        $torpedo = $this->getTorpedo();
73 2
        if ($torpedo === null) {
74 1
            return;
75
        }
76
77 1
        $this->colonyStorageManager->lowerStorage(
78 1
            $this->colony,
79 1
            $torpedo->getCommodity(),
80 1
            $amount
81 1
        );
82
    }
83
84
    public function isShieldPenetration(): bool
85
    {
86
        return false;
87
    }
88
89 9
    public function getTorpedo(): ?TorpedoTypeInterface
90
    {
91 9
        return $this->colony->getTorpedo();
92
    }
93
94 1
    public function getTorpedoVolleys(): int
95
    {
96 1
        return 7;
97
    }
98
99 2
    public function getProjectileWeaponDamage(bool $isCritical): int
100
    {
101 2
        $torpedo = $this->getTorpedo();
102 2
        if ($torpedo === null) {
103 1
            return 0;
104
        }
105
106 1
        $basedamage = $torpedo->getBaseDamage();
107 1
        $variance = (int) round($basedamage / 100 * $torpedo->getVariance());
108 1
        $damage = random_int($basedamage - $variance, $basedamage + $variance);
109
110 1
        return $isCritical ? $damage * 2 : $damage;
111
    }
112
}
113