| 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\Initiative; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use AardsGerds\Game\Build\Attribute\Strength; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use AardsGerds\Game\Build\Talent\SecretKnowledge\Ascension; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use AardsGerds\Game\Build\Talent\TalentCollection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use AardsGerds\Game\Build\Talent\WeaponMastery\WeaponMasteryLevel; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use AardsGerds\Game\Fight\Fighter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use AardsGerds\Game\Inventory\Inventory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use AardsGerds\Game\Inventory\Weapon\Weapon; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use AardsGerds\Game\Shared\IntegerValueException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | abstract class Entity implements Fighter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 | 6 |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         protected string $name, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         protected Health $health, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         protected Etherum $etherum, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         protected Strength $strength, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         protected Initiative $initiative, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         protected TalentCollection $talentCollection, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         protected Inventory $inventory, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         protected ?Weapon $weapon = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         protected ?Corruption $corruption = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 6 |  |     ) {} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 | 6 |  |     public function getName(): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 6 |  |         return $this->name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 38 | 6 |  |     public function getHealth(): Health | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 40 | 6 |  |         return $this->health; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 1 |  |     public function getEtherum(): Etherum | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 1 |  |         return $this->etherum; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 6 |  |     public function getStrength(): Strength | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 6 |  |         return $this->strength; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 6 |  |     public function getInitiative(): Initiative | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 6 |  |         return $this->initiative; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 6 |  |     public function getTalents(): TalentCollection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 6 |  |         return $this->talentCollection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 4 |  |     public function getWeaponMasteryLevel(): WeaponMasteryLevel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 4 |  |         if ($this->weapon === null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 2 |  |             return WeaponMasteryLevel::inexperienced(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 4 |  |         $weaponMastery = $this->talentCollection->findWeaponMasteryForWeaponType($this->weapon->getType()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 | 4 |  |         if ($weaponMastery === null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             return WeaponMasteryLevel::inexperienced(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 4 |  |         return $weaponMastery->getLevel(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 2 |  |     public function getInventory(): Inventory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 2 |  |         return $this->inventory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 6 |  |     public function getWeapon(): ?Weapon | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 | 6 |  |         return $this->weapon; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 | 6 |  |     public function hasWeapon(): bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 | 6 |  |         return $this->weapon !== null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 | 1 |  |     public function getCorruption(): ?Corruption | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 1 |  |         return $this->corruption; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 | 3 |  |     public function isCorrupted(): bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 | 3 |  |         return $this->corruption !== null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     public function __toString(): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         return $this->name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 | 3 |  |     protected function calculateCorruptionBoundary(): Etherum | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 | 3 |  |         $ascension = $this->talentCollection->findSecretKnowledge()?->getAscension(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 | 3 |  |         if ($ascension === null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |             return new Etherum(2); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 | 3 |  |             $nextAscensionEtherum = (new Ascension($ascension->get()))->increment()->getRequiredEtherum(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 | 1 |  |         } catch (IntegerValueException) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |             // entity has 8th ascension | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 | 1 |  |             $nextAscensionEtherum = new Etherum(Ascension::eighthAscension()->getRequiredEtherum()->get() * 2); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         // etherum required by next ascension + 0.5 x etherum required by next ascension | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 | 3 |  |         return $nextAscensionEtherum->increaseBy( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 | 3 |  |             new Etherum((int) ($nextAscensionEtherum->get() * 0.5)), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 126 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 127 |  |  |  |