Passed
Pull Request — master (#1686)
by Nico
31:24
created

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