Passed
Push — master ( 4cbcfa...1ee8de )
by Nico
53:18 queued 29:25
created

EpsSystemData::isEBattUseable()   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\Component\Ship\System\Data;
6
7
use Stu\Component\Ship\System\ShipSystemTypeEnum;
8
use Stu\Module\Tal\StatusBarColorEnum;
9
use Stu\Orm\Repository\ShipSystemRepositoryInterface;
10
11
class EpsSystemData extends AbstractSystemData
12
{
13
    // eps fields
14
    public int $eps = 0;
15
    public int $maxEps = 0;
16
17
    // battery fields
18
    public int $maxBattery = 0;
19
    public int $battery = 0;
20
    public int $batteryCooldown = 0;
21
    public bool $reloadBattery = false;
22
23
    private ShipSystemRepositoryInterface $shipSystemRepository;
24
25 3
    public function __construct(ShipSystemRepositoryInterface $shipSystemRepository)
26
    {
27 3
        $this->shipSystemRepository = $shipSystemRepository;
28
    }
29
30
    public function update(): void
31
    {
32
        $this->updateSystemData(
33
            ShipSystemTypeEnum::SYSTEM_EPS,
34
            $this,
35
            $this->shipSystemRepository
36
        );
37
    }
38
39 3
    public function getEps(): int
40
    {
41 3
        return $this->eps;
42
    }
43
44 1
    public function setEps(int $eps): EpsSystemData
45
    {
46 1
        $this->eps = $eps;
47 1
        return $this;
48
    }
49
50
    public function lowerEps(int $amount): EpsSystemData
51
    {
52
        $this->eps -= $amount;
53
        return $this;
54
    }
55
56 1
    public function setMaxEps(int $maxEps): EpsSystemData
57
    {
58 1
        $this->maxEps = $maxEps;
59 1
        $this->maxBattery = (int) round($maxEps / 3);
60 1
        return $this;
61
    }
62
63 2
    public function getTheoreticalMaxEps(): int
64
    {
65 2
        return $this->maxEps;
66
    }
67
68
    /**
69
     * proportional to eps system status
70
     */
71 1
    public function getMaxEps(): int
72
    {
73 1
        if (!$this->ship->hasShipSystem(ShipSystemTypeEnum::SYSTEM_EPS)) {
74 1
            return $this->maxEps;
75
        }
76
77
        return (int) (ceil($this->maxEps
78
            * $this->ship->getShipSystem(ShipSystemTypeEnum::SYSTEM_EPS)->getStatus() / 100));
79
    }
80
81 2
    public function getMaxBattery(): int
82
    {
83 2
        return $this->maxBattery;
84
    }
85
86 2
    public function getBattery(): int
87
    {
88 2
        return $this->battery;
89
    }
90
91
    public function setBattery(int $battery): EpsSystemData
92
    {
93
        $this->battery = $battery;
94
        return $this;
95
    }
96
97 2
    public function getBatteryCooldown(): int
98
    {
99 2
        return $this->batteryCooldown;
100
    }
101
102
    public function setBatteryCooldown(int $batteryCooldown): EpsSystemData
103
    {
104
        $this->batteryCooldown = $batteryCooldown;
105
        return $this;
106
    }
107
108 2
    public function reloadBattery(): bool
109
    {
110 2
        return $this->reloadBattery;
111
    }
112
113
    public function setReloadBattery(bool $reloadBattery): EpsSystemData
114
    {
115
        $this->reloadBattery = $reloadBattery;
116
        return $this;
117
    }
118
119
    public function isEBattUseable(): bool
120
    {
121
        return $this->batteryCooldown < time();
122
    }
123
124 1
    public function getEpsPercentage(): int
125
    {
126 1
        return (int)floor($this->getEps() / $this->getMaxEps() * 100);
127
    }
128
129
    public function getEpsStatusBar(): string
130
    {
131
        return $this->getTalStatusBar(
132
            _('Energie'),
133
            $this->getEps(),
134
            $this->getMaxEps(),
135
            StatusBarColorEnum::STATUSBAR_YELLOW
136
        )
137
            ->render();
138
    }
139
140
    public function getEpsStatusBarBig(): string
141
    {
142
        return $this->getTalStatusBar(
143
            _('Energie'),
144
            $this->getEps(),
145
            $this->getMaxEps(),
146
            StatusBarColorEnum::STATUSBAR_YELLOW
147
        )
148
            ->setSizeModifier(1.6)
149
            ->render();
150
    }
151
}
152