Passed
Push — dev ( 83c248...96a6f5 )
by Janko
10:53
created

SpacecraftAttacker::getPhaserHullDamageFactor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Spacecraft\Lib\Battle\Provider;
6
7
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use RuntimeException;
9
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
10
use Stu\Module\Control\StuRandom;
11
use Stu\Module\Spacecraft\Lib\Torpedo\ShipTorpedoManagerInterface;
12
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface;
13
use Stu\Orm\Entity\LocationInterface;
14
use Stu\Orm\Entity\ModuleInterface;
15
use Stu\Orm\Entity\SpacecraftInterface;
16
use Stu\Orm\Entity\TorpedoTypeInterface;
17
18
class SpacecraftAttacker extends AbstractEnergyAttacker implements ProjectileAttackerInterface
19
{
20 24
    public function __construct(
21
        private SpacecraftWrapperInterface $wrapper,
22
        private ShipTorpedoManagerInterface $shipTorpedoManager,
23
        StuRandom $stuRandom
24
    ) {
25 24
        parent::__construct($stuRandom);
26
    }
27
28 1
    #[Override]
29
    public function getPhaserVolleys(): int
30
    {
31 1
        return $this->get()->getRump()->getPhaserVolleys();
32
    }
33
34 1
    #[Override]
35
    public function getPhaserState(): bool
36
    {
37 1
        return $this->get()->getPhaserState();
38
    }
39
40 3
    #[Override]
41
    public function hasSufficientEnergy(int $amount): bool
42
    {
43 3
        $epsSystemData = $this->wrapper->getEpsSystemData();
44 3
        if ($epsSystemData === null) {
45 1
            return false;
46
        }
47 2
        return $epsSystemData->getEps() >= $amount;
48
    }
49
50 2
    #[Override]
51
    public function getWeaponModule(): ModuleInterface
52
    {
53 2
        if ($this->module === null) {
54 2
            $shipSystem = $this->get()->getSpacecraftSystem(SpacecraftSystemTypeEnum::PHASER);
55
56 2
            $module = $shipSystem->getModule();
57 2
            if ($module === null) {
58 1
                throw new RuntimeException('weapon system should have a module');
59
            }
60
61 1
            $this->module = $module;
62
        }
63
64 1
        return $this->module;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->module could return the type null which is incompatible with the type-hinted return Stu\Orm\Entity\ModuleInterface. Consider adding an additional type-check to rule them out.
Loading history...
65
    }
66
67 1
    #[Override]
68
    public function getEnergyWeaponBaseDamage(): int
69
    {
70 1
        return $this->get()->getBaseDamage();
71
    }
72
73 2
    #[Override]
74
    public function reduceEps(int $amount): void
75
    {
76 2
        $epsSystemData = $this->wrapper->getEpsSystemData();
77 2
        if ($epsSystemData === null) {
78 1
            return;
79
        }
80 1
        $epsSystemData->lowerEps($amount)->update();
81
    }
82
83 1
    #[Override]
84
    public function getName(): string
85
    {
86 1
        return $this->get()->getName();
87
    }
88
89 1
    #[Override]
90
    public function getUserId(): int
91
    {
92 1
        return $this->get()->getUser()->getId();
93
    }
94
95 17
    private function get(): SpacecraftInterface
96
    {
97 17
        return $this->wrapper->get();
98
    }
99
100 1
    #[Override]
101
    public function getHitChance(): int
102
    {
103 1
        return $this->get()->getHitChance();
104
    }
105
106 1
    #[Override]
107
    public function getPhaserShieldDamageFactor(): int
108
    {
109 1
        return $this->get()->getRump()->getPhaserShieldDamageFactor();
110
    }
111
112 1
    #[Override]
113
    public function getPhaserHullDamageFactor(): int
114
    {
115 1
        return $this->get()->getRump()->getPhaserHullDamageFactor();
116
    }
117
118 1
    #[Override]
119
    public function getTorpedoVolleys(): int
120
    {
121 1
        return $this->get()->getRump()->getTorpedoVolleys();
122
    }
123
124 1
    #[Override]
125
    public function getTorpedoState(): bool
126
    {
127 1
        return $this->get()->getTorpedoState();
128
    }
129
130 1
    #[Override]
131
    public function getTorpedoCount(): int
132
    {
133 1
        return $this->get()->getTorpedoCount();
134
    }
135
136 4
    #[Override]
137
    public function getTorpedo(): ?TorpedoTypeInterface
138
    {
139 4
        return $this->get()->getTorpedo();
140
    }
141
142 1
    #[Override]
143
    public function lowerTorpedoCount(int $amount): void
144
    {
145 1
        $this->shipTorpedoManager->changeTorpedo($this->wrapper, -$amount);
146
    }
147
148
    #[Override]
149
    public function isShieldPenetration(): bool
150
    {
151
        $systemData = $this->wrapper->getProjectileLauncherSystemData();
152
        if ($systemData === null) {
153
            throw new RuntimeException('this should not happen');
154
        }
155
156
        return $this->stuRandom->rand(1, 10000) <= $systemData->getShieldPenetration();
157
    }
158
159 3
    #[Override]
160
    public function getProjectileWeaponDamage(bool $isCritical): int
161
    {
162 3
        $torpedo = $this->getTorpedo();
163 3
        if ($torpedo === null) {
164 1
            return 0;
165
        }
166
167 2
        $module = $this->get()->getSpacecraftSystem(SpacecraftSystemTypeEnum::TORPEDO)->getModule();
168 2
        if ($module === null) {
169 1
            return 0;
170
        }
171
172 1
        $variance = (int) round($torpedo->getBaseDamage() / 100 * $torpedo->getVariance());
173 1
        $basedamage = $torpedo->getBaseDamage();
174 1
        $damage = random_int($basedamage - $variance, $basedamage + $variance);
175
176 1
        return $isCritical ? $damage * 2 : $damage;
177
    }
178
179
    #[Override]
180
    public function getLocation(): LocationInterface
181
    {
182
        return $this->get()->getLocation();
183
    }
184
}
185