Passed
Push — master ( f05eff...e96706 )
by Paweł
02:59
created

Entity::isCorrupted()   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 AardsGerds\Game\Entity;
6
7
use AardsGerds\Game\Build\Attribute\Etherum;
8
use AardsGerds\Game\Build\Attribute\Health;
9
use AardsGerds\Game\Build\Attribute\Strength;
10
use AardsGerds\Game\Build\Talent\TalentCollection;
11
use AardsGerds\Game\Build\Talent\WeaponMastery\WeaponMasteryLevel;
12
use AardsGerds\Game\Fight\Fighter;
13
use AardsGerds\Game\Inventory\Inventory;
14
use AardsGerds\Game\Inventory\Weapon\Weapon;
15
use AardsGerds\Game\Shared\IntegerValueException;
16
17
abstract class Entity implements Fighter
18
{
19
    public function __construct(
20
        protected string $name,
21
        protected Health $health,
22
        protected Etherum $etherum,
23
        protected Strength $strength,
24
        protected TalentCollection $talentCollection,
25
        protected Inventory $inventory,
26
        protected ?Weapon $weapon,
27
        protected bool $corrupted = false,
28
    ) {}
29
30
    public function getName(): string
31
    {
32
        return $this->name;
33
    }
34
35
    public function getHealth(): Health
36
    {
37
        return $this->health;
38
    }
39
40
    public function getEtherum(): Etherum
41
    {
42
        return $this->etherum;
43
    }
44
45
    public function getStrength(): Strength
46
    {
47
        return $this->strength;
48
    }
49
50
    public function getTalents(): TalentCollection
51
    {
52
        return $this->talentCollection;
53
    }
54
55
    public function getWeaponMasteryLevel(): WeaponMasteryLevel
56
    {
57
        if ($this->weapon === null) {
58
            return WeaponMasteryLevel::inexperienced();
59
        }
60
61
        $weaponMastery = $this->talentCollection->findWeaponMasteryForWeaponType($this->weapon->getType());
62
        if ($weaponMastery === null) {
63
            return WeaponMasteryLevel::inexperienced();
64
        }
65
66
        return $weaponMastery->getLevel();
67
    }
68
69
    public function getWeapon(): ?Weapon
70
    {
71
        return $this->weapon;
72
    }
73
74
    public function isCorrupted(): bool
75
    {
76
        return $this->corrupted;
77
    }
78
79
    public function calculateCorruptionBoundary(): Etherum
80
    {
81
        $ascension = $this->talentCollection->findSecretKnowledge()?->getAscension();
82
        if ($ascension === null) {
83
            return new Etherum(2);
84
        }
85
86
        try {
87
            $nextAscensionEtherum = $ascension->increment()->getRequiredEtherum();
88
        } catch (IntegerValueException $exception) {
89
            // entity has 8th ascension
90
            $nextAscensionEtherum = new Etherum($ascension->getRequiredEtherum()->get() * 2);
91
        }
92
93
        // etherum required by next ascension + 0.5 x etherum required by next ascension
94
        return $nextAscensionEtherum->increaseBy(
95
            new Etherum((int) ($nextAscensionEtherum->get() * 0.5)),
96
        );
97
    }
98
}
99