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 CharacterEffectTest extends \Tester\TestCase |
15
|
|
|
{ |
16
|
|
|
private function generateCharacter(int $id): Character |
17
|
|
|
{ |
18
|
|
|
$stats = [ |
19
|
|
|
"id" => $id, "name" => "Player $id", "level" => 1, "initiativeFormula" => "1d2+DEX/4", "strength" => 10, |
20
|
|
|
"dexterity" => 10, "constitution" => 10, "intelligence" => 10, "charisma" => 10 |
21
|
|
|
]; |
22
|
|
|
return new Character($stats); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testInitiativeEffect(): void |
26
|
|
|
{ |
27
|
|
|
$character = $this->generateCharacter(1); |
28
|
|
|
$character->initiativeFormulaParser = new ConstantInitiativeFormulaParser(1); |
29
|
|
|
Assert::same(1, $character->initiative); |
30
|
|
|
Assert::same(1, $character->initiativeBase); |
31
|
|
|
$effect = new CharacterEffect([ |
32
|
|
|
"id" => "equipment1bonusEffect", |
33
|
|
|
"type" => "buff", |
34
|
|
|
"stat" => Character::STAT_INITIATIVE, |
35
|
|
|
"value" => 10, |
36
|
|
|
"valueAbsolute" => true, |
37
|
|
|
"duration" => CharacterEffect::DURATION_COMBAT, |
38
|
|
|
]); |
39
|
|
|
$character->effects[] = $effect; |
40
|
|
|
Assert::same(11, $character->initiative); |
41
|
|
|
Assert::same(1, $character->initiativeBase); |
42
|
|
|
$character->effects->removeByFilter(["id" => $effect->id]); |
43
|
|
|
Assert::same(1, $character->initiative); |
44
|
|
|
Assert::same(1, $character->initiativeBase); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testHitpointsEffect(): void |
48
|
|
|
{ |
49
|
|
|
$character = $this->generateCharacter(1); |
50
|
|
|
$baseHitpoints = $character->constitution * Character::HITPOINTS_PER_CONSTITUTION; |
51
|
|
|
Assert::same($baseHitpoints, $character->maxHitpointsBase); |
52
|
|
|
Assert::same($baseHitpoints, $character->maxHitpoints); |
53
|
|
|
Assert::same($baseHitpoints, $character->hitpoints); |
54
|
|
|
$effect = new CharacterEffect([ |
55
|
|
|
"id" => "equipment1bonusEffect", |
56
|
|
|
"type" => "buff", |
57
|
|
|
"stat" => Character::STAT_MAX_HITPOINTS, |
58
|
|
|
"value" => 10, |
59
|
|
|
"valueAbsolute" => true, |
60
|
|
|
"duration" => CharacterEffect::DURATION_COMBAT, |
61
|
|
|
]); |
62
|
|
|
$character->effects[] = $effect; |
63
|
|
|
Assert::same($baseHitpoints, $character->maxHitpointsBase); |
64
|
|
|
Assert::same(60, $character->maxHitpoints); |
65
|
|
|
Assert::same(60, $character->hitpoints); |
66
|
|
|
$character->effects->removeByFilter(["id" => "equipment1bonusEffect"]); |
67
|
|
|
Assert::same($baseHitpoints, $character->maxHitpointsBase); |
68
|
|
|
Assert::same($baseHitpoints, $character->maxHitpoints); |
69
|
|
|
Assert::same($baseHitpoints, $character->hitpoints); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$test = new CharacterEffectTest(); |
74
|
|
|
$test->run(); |
75
|
|
|
|