| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | namespace HeroesofAbenez\Combat\CombatActions; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Tester\Assert; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use HeroesofAbenez\Combat\Character; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use HeroesofAbenez\Combat\CombatBase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use HeroesofAbenez\Combat\CombatLogger; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use HeroesofAbenez\Combat\StaticSuccessCalculator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use HeroesofAbenez\Combat\CombatLogEntry; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use HeroesofAbenez\Combat\SkillAttack as Skill; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use HeroesofAbenez\Combat\CharacterAttackSkill as CharacterSkill; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | require __DIR__ . "/../../../bootstrap.php"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @author Jakub Konečný | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @testCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | final class SkillAttackTest extends \Tester\TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     use \Testbench\TCompiledContainer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     protected CombatLogger $logger; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |     public function setUp(): void | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |         $this->logger = $this->getService(CombatLogger::class); // @phpstan-ignore assign.propertyType | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     private function generateCharacter(int $id): Character | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $stats = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             "id" => $id, "name" => "Player $id", "level" => 1, "initiativeFormula" => "1d2+DEX/4", "strength" => 10, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             "dexterity" => 10, "constitution" => 10, "intelligence" => 10, "charisma" => 10 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $skillData = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             "id" => 1, "name" => "Skill Attack", "baseDamage" => "60%", "damageGrowth" => "20%", "levels" => 5, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             "target" => Skill::TARGET_SINGLE, "strikes" => 2, "hitRate" => "100%", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $skill = new Skill($skillData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $characterSkill = new CharacterSkill($skill, 2); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         return new Character($stats, [], [], [$characterSkill]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     /*public function testShouldUse(): void { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |       $character1 = $this->generateCharacter(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |       $character2 = $this->generateCharacter(2); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |       $combat = new CombatBase(clone $this->logger, new StaticSuccessCalculator()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |       $combat->setDuelParticipants($character1, $character2); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |       $action = new SkillAttack(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |       Assert::false($action->shouldUse($combat, $character1)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |       for($i = 1; $i <= $character1->skills[0]->skill->cooldown; $i++) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $character1->skills[0]->decreaseCooldown(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |       } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |       Assert::true($action->shouldUse($combat, $character1)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     }*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     public function testDo(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $character1 = $this->generateCharacter(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $character2 = $this->generateCharacter(2); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $combat = new CombatBase(clone $this->logger, new StaticSuccessCalculator()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $combat->setDuelParticipants($character1, $character2); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $combat->onCombatStart($combat); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $combat->onRoundStart($combat); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         for ($i = 1; $i <= $character1->skills[0]->skill->cooldown; $i++) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             $character1->skills[0]->decreaseCooldown(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $action = new SkillAttack(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $action->do($combat, $character1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         Assert::same(42, $character2->hitpoints); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         Assert::same(8, $combat->team1Damage); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         Assert::count(1, $combat->log); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         Assert::count(2, $combat->log->getIterator()[1]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         /** @var CombatLogEntry $record */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $record = $combat->log->getIterator()[1][0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         Assert::type(CombatLogEntry::class, $record); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         Assert::same(SkillAttack::ACTION_NAME, $record->action); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         Assert::same("Skill Attack", $record->name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         Assert::true($record->result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         Assert::same(4, $record->amount); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         Assert::same($character1->name, $record->character1->name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         Assert::same($character2->name, $record->character2->name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | $test = new SkillAttackTest(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 90 |  |  | $test->run(); | 
            
                                                        
            
                                    
            
            
                | 91 |  |  |  |