|
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\SkillSpecial as Skill; |
|
13
|
|
|
use HeroesofAbenez\Combat\CharacterSpecialSkill as CharacterSkill; |
|
14
|
|
|
|
|
15
|
|
|
require __DIR__ . "/../../../bootstrap.php"; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @author Jakub Konečný |
|
19
|
|
|
* @testCase |
|
20
|
|
|
*/ |
|
21
|
|
|
final class SkillSpecialTest extends \Tester\TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
use \Testbench\TCompiledContainer; |
|
24
|
|
|
|
|
25
|
|
|
private 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 Special", "levels" => 5, "type" => Skill::TYPE_BUFF, "duration" => 3, |
|
40
|
|
|
"target" => Skill::TARGET_SELF, "stat" => Character::STAT_DAMAGE, "value" => 10, "valueGrowth" => 2, |
|
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 SkillSpecial(); |
|
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 SkillSpecial(); |
|
72
|
|
|
$action->do($combat, $character1); |
|
73
|
|
|
Assert::count(1, $combat->log); |
|
74
|
|
|
Assert::count(1, $combat->log->getIterator()[1]); |
|
75
|
|
|
/** @var CombatLogEntry $record */ |
|
76
|
|
|
$record = $combat->log->getIterator()[1][0]; |
|
77
|
|
|
Assert::type(CombatLogEntry::class, $record); |
|
78
|
|
|
Assert::same(SkillSpecial::ACTION_NAME, $record->action); |
|
79
|
|
|
Assert::same("Skill Special", $record->name); |
|
80
|
|
|
Assert::true($record->result); |
|
81
|
|
|
Assert::same(0, $record->amount); |
|
82
|
|
|
Assert::same($character1->name, $record->character1->name); |
|
83
|
|
|
Assert::same($character1->name, $record->character2->name); |
|
84
|
|
|
Assert::count(1, $character1->effects); |
|
85
|
|
|
$effect = $character1->effects[0]; |
|
86
|
|
|
Assert::same(Skill::TYPE_BUFF, $effect->type); |
|
87
|
|
|
Assert::same(Character::STAT_DAMAGE, $effect->stat); |
|
88
|
|
|
Assert::same(12, $effect->value); |
|
89
|
|
|
Assert::same(3, $effect->duration); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
$test = new SkillSpecialTest(); |
|
94
|
|
|
$test->run(); |
|
95
|
|
|
|