1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace HeroesofAbenez\Combat; |
5
|
|
|
|
6
|
|
|
require __DIR__ . "/../../bootstrap.php"; |
7
|
|
|
|
8
|
|
|
use Tester\Assert; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @author Jakub Konečný |
12
|
|
|
* @testCase |
13
|
|
|
*/ |
14
|
|
|
final class CharacterTest extends \Tester\TestCase { |
15
|
|
|
protected function generateCharacter(int $id): Character { |
16
|
|
|
$stats = [ |
17
|
|
|
"id" => $id, "name" => "Player $id", "level" => 1, "initiativeFormula" => "1d2+DEX/4", "strength" => 10, |
18
|
|
|
"dexterity" => 10, "constitution" => 10, "intelligence" => 10, "charisma" => 10 |
19
|
|
|
]; |
20
|
|
|
return new Character($stats); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testGetActivePet(): void { |
24
|
|
|
$stats = [ |
25
|
|
|
"id" => 1, "name" => "Player 1", "level" => 1, "initiativeFormula" => "1d2+DEX/4", "strength" => 10, |
26
|
|
|
"dexterity" => 10, "constitution" => 10, "intelligence" => 10, "charisma" => 10 |
27
|
|
|
]; |
28
|
|
|
$petStats = [ |
29
|
|
|
"id" => 1, "deployed" => false, "bonusStat" => Character::STAT_STRENGTH, "bonusValue" => 10, |
30
|
|
|
]; |
31
|
|
|
$pet = new Pet($petStats); |
32
|
|
|
$character = new Character($stats, [], [$pet]); |
33
|
|
|
Assert::null($character->activePet); |
34
|
|
|
$pet->deployed = true; |
35
|
|
|
Assert::same(1, $character->activePet); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testAddAndRemoveEffect(): void { |
39
|
|
|
$character = $this->generateCharacter(1); |
40
|
|
|
Assert::count(0, $character->effects); |
41
|
|
|
Assert::same(5, $character->damage); |
42
|
|
|
$character->effects[] = new CharacterEffect([ |
43
|
|
|
"id" => "equipment1bonusEffect", |
44
|
|
|
"type" => "buff", |
45
|
|
|
"stat" => Character::STAT_DAMAGE, |
46
|
|
|
"value" => 10, |
47
|
|
|
"valueAbsolute" => true, |
48
|
|
|
"duration" => CharacterEffect::DURATION_COMBAT, |
49
|
|
|
]); |
50
|
|
|
Assert::count(1, $character->effects); |
51
|
|
|
Assert::same(15, $character->damage); |
52
|
|
|
$character->effects->removeByFilter(["id" => "equipment1bonusEffect"]); |
53
|
|
|
Assert::count(0, $character->effects); |
54
|
|
|
Assert::same(5, $character->damage); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testInitiativeFormulaParser(): void { |
58
|
|
|
$character = $this->generateCharacter(1); |
59
|
|
|
Assert::type(InitiativeFormulaParser::class, $character->initiativeFormulaParser); |
60
|
|
|
Assert::notEqual(0, $character->initiative); |
61
|
|
|
$character->initiativeFormulaParser = new ConstantInitiativeFormulaParser(0); |
62
|
|
|
Assert::equal(0, $character->initiative); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testDebuffsCap(): void { |
66
|
|
|
$character = $this->generateCharacter(1); |
67
|
|
|
$effect = new CharacterEffect([ |
68
|
|
|
"id" => "skillEffect", "type" => SkillSpecial::TYPE_DEBUFF, "valueAbsolute" => false, |
69
|
|
|
"value" => 1000, "duration" => 1, "stat" => "constitution", |
70
|
|
|
]); |
71
|
|
|
$character->effects[] = $effect; |
72
|
|
|
Assert::same(2, $character->constitution); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testDamageStat(): void { |
76
|
|
|
$stats = [ |
77
|
|
|
"id" => 1, "name" => "Player 1", "level" => 1, "initiativeFormula" => "1d2+DEX/4", "strength" => 10, |
78
|
|
|
"dexterity" => 10, "constitution" => 10, "intelligence" => 10, "charisma" => 10 |
79
|
|
|
]; |
80
|
|
|
$equipment = [ |
81
|
|
|
new Weapon([ |
82
|
|
|
"id" => 1, "name" => "Novice Sword", "slot" => Equipment::SLOT_WEAPON, "type" => Weapon::TYPE_SWORD, |
83
|
|
|
"strength" => 1, "worn" => true |
84
|
|
|
]), |
85
|
|
|
new Weapon([ |
86
|
|
|
"id" => 2, "name" => "Novice Staff", "slot" => Equipment::SLOT_WEAPON, "type" => Weapon::TYPE_STAFF, |
87
|
|
|
"strength" => 1, "worn" => true |
88
|
|
|
]) |
89
|
|
|
]; |
90
|
|
|
$character = new Character($stats, $equipment); |
91
|
|
|
Assert::same(Character::STAT_STRENGTH, $character->damageStat()); |
92
|
|
|
$equipment[0]->worn = false; |
93
|
|
|
Assert::same(Character::STAT_INTELLIGENCE, $character->damageStat()); |
94
|
|
|
$equipment[1]->worn = false; |
95
|
|
|
Assert::same(Character::STAT_STRENGTH, $character->damageStat()); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testStatus(): void { |
99
|
|
|
$character = $this->generateCharacter(1); |
100
|
|
|
Assert::false($character->hasStatus("abc")); |
101
|
|
|
Assert::null($character->getStatus("abc")); |
102
|
|
|
Assert::false($character->hasStatus(Character::STATUS_STUNNED)); |
103
|
|
|
$character->effects[] = new CharacterEffect([ |
104
|
|
|
"id" => "stunEffect", |
105
|
|
|
"type" => SkillSpecial::TYPE_STUN, |
106
|
|
|
"duration" => CharacterEffect::DURATION_COMBAT, |
107
|
|
|
"valueAbsolute" => false, |
108
|
|
|
]); |
109
|
|
|
Assert::true($character->hasStatus(Character::STATUS_STUNNED)); |
110
|
|
|
$character->effects->removeByFilter(["id" => "stunEffect"]); |
111
|
|
|
Assert::false($character->hasStatus(Character::STATUS_STUNNED)); |
112
|
|
|
$character->effects[] = new CharacterEffect([ |
113
|
|
|
"id" => "poisonEffect", |
114
|
|
|
"type" => SkillSpecial::TYPE_POISON, |
115
|
|
|
"duration" => CharacterEffect::DURATION_COMBAT, |
116
|
|
|
"value" => 5, |
117
|
|
|
"valueAbsolute" => false, |
118
|
|
|
]); |
119
|
|
|
Assert::true($character->hasStatus(Character::STATUS_POISONED)); |
120
|
|
|
$character->effects->removeByFilter(["id" => "poisonEffect"]); |
121
|
|
|
Assert::false($character->hasStatus(Character::STATUS_POISONED)); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function testCanAct(): void { |
125
|
|
|
$character = $this->generateCharacter(1); |
126
|
|
|
Assert::true($character->canAct()); |
127
|
|
|
$character->effects[] = new CharacterEffect([ |
128
|
|
|
"id" => "stunEffect", |
129
|
|
|
"type" => SkillSpecial::TYPE_STUN, |
130
|
|
|
"duration" => CharacterEffect::DURATION_COMBAT, |
131
|
|
|
"valueAbsolute" => false, |
132
|
|
|
]); |
133
|
|
|
Assert::false($character->canAct()); |
134
|
|
|
$character->effects->removeByFilter(["id" => "stunEffect"]); |
135
|
|
|
Assert::true($character->canAct()); |
136
|
|
|
$character->harm($character->hitpoints / 2); |
137
|
|
|
Assert::true($character->canAct()); |
138
|
|
|
$character->harm($character->hitpoints); |
139
|
|
|
Assert::false($character->canAct()); |
140
|
|
|
$character->heal(1); |
141
|
|
|
Assert::true($character->canAct()); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function testCanDefend(): void { |
145
|
|
|
$character = $this->generateCharacter(1); |
146
|
|
|
Assert::true($character->canDefend()); |
147
|
|
|
$character->effects[] = new CharacterEffect([ |
148
|
|
|
"id" => "stunEffect", |
149
|
|
|
"type" => SkillSpecial::TYPE_STUN, |
150
|
|
|
"duration" => CharacterEffect::DURATION_COMBAT, |
151
|
|
|
"valueAbsolute" => false, |
152
|
|
|
]); |
153
|
|
|
Assert::false($character->canDefend()); |
154
|
|
|
$character->effects->removeByFilter(["id" => "stunEffect"]); |
155
|
|
|
Assert::true($character->canDefend()); |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
$test = new CharacterTest(); |
160
|
|
|
$test->run(); |
161
|
|
|
?> |