Passed
Push — dev ( ac26ef...6b8aca )
by Nico
08:29
created

WarpDriveSystemData::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
ccs 0
cts 5
cp 0
crap 2
rs 10
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
17
    private ShipSystemRepositoryInterface $shipSystemRepository;
18
19
    public function __construct(ShipSystemRepositoryInterface $shipSystemRepository)
20
    {
21
        $this->shipSystemRepository = $shipSystemRepository;
22
    }
23
24
    public function update(): void
25
    {
26
        $this->updateSystemData(
27
            ShipSystemTypeEnum::SYSTEM_WARPDRIVE,
28
            $this,
29
            $this->shipSystemRepository
30
        );
31
    }
32
33
    public function getWarpDrive(): int
34
    {
35
        return $this->wd;
36
    }
37
38
    public function setWarpDrive(int $wd): WarpDriveSystemData
39
    {
40
        $this->wd = $wd;
41
        return $this;
42
    }
43
44
    public function lowerWarpDrive(int $amount): WarpDriveSystemData
45
    {
46
        $this->wd -= $amount;
47
        return $this;
48
    }
49
50
    public function setMaxWarpDrive(int $maxwd): WarpDriveSystemData
51
    {
52
        $this->maxwd = $maxwd;
53
        return $this;
54
    }
55
56
    public function getTheoreticalMaxWarpdrive(): int
57
    {
58
        return $this->maxwd;
59
    }
60
61
    /**
62
     * proportional to warpdrive system status
63
     */
64
    public function getMaxWarpDrive(): int
65
    {
66
        if (!$this->ship->hasShipSystem(ShipSystemTypeEnum::SYSTEM_WARPDRIVE)) {
67
            return $this->maxwd;
68
        }
69
70
        return (int) (ceil($this->maxwd
71
            * $this->ship->getShipSystem(ShipSystemTypeEnum::SYSTEM_WARPDRIVE)->getStatus() / 100));
72
    }
73
74
    public function getWarpDriveStatusBar(): string
75
    {
76
        return $this->getTalStatusBar(
77
            _('Warpantrieb'),
78
            $this->getWarpDrive(),
79
            $this->getMaxWarpDrive(),
80
            StatusBarColorEnum::STATUSBAR_BLUE
81
        )
82
            ->render();
83
    }
84
85
    public function getWarpDriveStatusBarBig(): string
86
    {
87
        return $this->getTalStatusBar(
88
            _('Warpantrieb'),
89
            $this->getWarpDrive(),
90
            $this->getMaxWarpDrive(),
91
            StatusBarColorEnum::STATUSBAR_BLUE
92
        )
93
            ->setSizeModifier(1.6)
94
            ->render();
95
    }
96
}
97