Passed
Pull Request — master (#1830)
by Nico
30:56
created

WarpDriveSystemData::__construct()   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 1
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
10
class WarpDriveSystemData extends AbstractSystemData
11
{
12
    // warpdrive fields
13
    public int $wd = 0;
14
    public int $maxwd = 0;
15
    public int $split = 100;
16
    public bool $autoCarryOver = false;
17
18
    function getSystemType(): ShipSystemTypeEnum
19
    {
20
        return ShipSystemTypeEnum::SYSTEM_WARPDRIVE;
21
    }
22
23
    public function update(): void
24
    {
25
        // Überprüfe und begrenze den Wert zwischen 0 und 100
26
        $this->split = max(0, min(100, $this->split));
27
28
        parent::update();
29
    }
30
31
    public function getWarpDrive(): int
32
    {
33
        return $this->wd;
34
    }
35
36
    public function setWarpDrive(int $wd): WarpDriveSystemData
37
    {
38
        $this->wd = $wd;
39
        return $this;
40
    }
41
42
    public function lowerWarpDrive(int $amount): WarpDriveSystemData
43
    {
44
        $this->wd -= $amount;
45
        return $this;
46
    }
47
48
    public function setMaxWarpDrive(int $maxwd): WarpDriveSystemData
49
    {
50
        $this->maxwd = $maxwd;
51
        return $this;
52
    }
53
54
    public function getTheoreticalMaxWarpdrive(): int
55
    {
56
        return $this->maxwd;
57
    }
58
59
    /**
60
     * proportional to warpdrive system status
61
     */
62
    public function getMaxWarpDrive(): int
63
    {
64
        return (int) (ceil($this->maxwd
65
            * $this->ship->getShipSystem(ShipSystemTypeEnum::SYSTEM_WARPDRIVE)->getStatus() / 100));
66
    }
67
68
    public function getWarpDriveSplit(): int
69
    {
70
        return $this->split;
71
    }
72
73
    public function setWarpDriveSplit(int $split): WarpDriveSystemData
74
    {
75
        $this->split = $split;
76
        return $this;
77
    }
78
79
    public function getAutoCarryOver(): bool
80
    {
81
        return $this->autoCarryOver;
82
    }
83
84
    public function setAutoCarryOver(bool $autoCarryOver): WarpDriveSystemData
85
    {
86
        $this->autoCarryOver = $autoCarryOver;
87
        return $this;
88
    }
89
90
    public function getWarpdrivePercentage(): int
91
    {
92
        $currentWarpdrive = $this->getWarpDrive();
93
        $maxWarpdrive = $this->getMaxWarpDrive();
94
95
        if ($currentWarpdrive === 0) {
96
            return 0;
97
        }
98
        if ($maxWarpdrive === 0) {
99
            return 100;
100
        }
101
102
        return (int)floor($currentWarpdrive / $maxWarpdrive * 100);
103
    }
104
105
    public function getWarpDriveStatusBar(): string
106
    {
107
        return $this->getTalStatusBar(
108
            _('Warpantrieb'),
109
            $this->getWarpDrive(),
110
            $this->getMaxWarpDrive(),
111
            StatusBarColorEnum::STATUSBAR_BLUE
112
        )
113
            ->render();
114
    }
115
116
    public function getWarpDriveStatusBarBig(): string
117
    {
118
        return $this->getTalStatusBar(
119
            _('Warpantrieb'),
120
            $this->getWarpDrive(),
121
            $this->getMaxWarpDrive(),
122
            StatusBarColorEnum::STATUSBAR_BLUE
123
        )
124
            ->setSizeModifier(1.6)
125
            ->render();
126
    }
127
}
128