|
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\Team; |
|
9
|
|
|
use HeroesofAbenez\Combat\CombatBase; |
|
10
|
|
|
use HeroesofAbenez\Combat\CombatLogger; |
|
11
|
|
|
use HeroesofAbenez\Combat\StaticSuccessCalculator; |
|
12
|
|
|
use HeroesofAbenez\Combat\CombatLogEntry; |
|
13
|
|
|
|
|
14
|
|
|
require __DIR__ . "/../../../bootstrap.php"; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @author Jakub Konečný |
|
18
|
|
|
* @testCase |
|
19
|
|
|
*/ |
|
20
|
|
|
final class HealTest extends \Tester\TestCase { |
|
21
|
|
|
protected CombatLogger $logger; |
|
22
|
|
|
|
|
23
|
|
|
use \Testbench\TCompiledContainer; |
|
24
|
|
|
|
|
25
|
|
|
public function setUp() { |
|
26
|
|
|
$this->logger = $this->getService(CombatLogger::class); // @phpstan-ignore assign.propertyType |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
protected function generateCharacter(int $id): Character { |
|
30
|
|
|
$stats = [ |
|
31
|
|
|
"id" => $id, "name" => "Player $id", "level" => 1, "initiativeFormula" => "1d2+DEX/4", "strength" => 10, |
|
32
|
|
|
"dexterity" => 10, "constitution" => 10, "intelligence" => 10, "charisma" => 10 |
|
33
|
|
|
]; |
|
34
|
|
|
return new Character($stats); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testShouldUse(): void { |
|
38
|
|
|
$character1 = $this->generateCharacter(1); |
|
39
|
|
|
$character2 = $this->generateCharacter(2); |
|
40
|
|
|
$combat = new CombatBase(clone $this->logger, new StaticSuccessCalculator()); |
|
41
|
|
|
$combat->setDuelParticipants($character1, $character2); |
|
42
|
|
|
$combat->healers = function(Team $team1, Team $team2) { |
|
|
|
|
|
|
43
|
|
|
return Team::fromArray($team1->toArray(), "healers"); |
|
44
|
|
|
}; |
|
45
|
|
|
$action = new Heal(); |
|
46
|
|
|
Assert::false($action->shouldUse($combat, $character1)); |
|
47
|
|
|
$character1->harm(30); |
|
48
|
|
|
Assert::true($action->shouldUse($combat, $character1)); |
|
49
|
|
|
$character1->harm(20); |
|
50
|
|
|
Assert::false($action->shouldUse($combat, $character1)); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testDo(): void { |
|
54
|
|
|
$character1 = $this->generateCharacter(1); |
|
55
|
|
|
$character2 = $this->generateCharacter(2); |
|
56
|
|
|
$combat = new CombatBase(clone $this->logger, new StaticSuccessCalculator()); |
|
57
|
|
|
$combat->setDuelParticipants($character1, $character2); |
|
58
|
|
|
$combat->healers = function(Team $team1, Team $team2) { |
|
|
|
|
|
|
59
|
|
|
return Team::fromArray($team1->toArray(), "healers"); |
|
60
|
|
|
}; |
|
61
|
|
|
$combat->onCombatStart($combat); |
|
62
|
|
|
$combat->onRoundStart($combat); |
|
63
|
|
|
$action = new Heal(); |
|
64
|
|
|
$character1->harm(30); |
|
65
|
|
|
Assert::same(20, $character1->hitpoints); |
|
66
|
|
|
$action->do($combat, $character1); |
|
67
|
|
|
Assert::same(25, $character1->hitpoints); |
|
68
|
|
|
Assert::count(1, $combat->log); |
|
69
|
|
|
Assert::count(1, $combat->log->getIterator()[1]); |
|
70
|
|
|
/** @var CombatLogEntry $record */ |
|
71
|
|
|
$record = $combat->log->getIterator()[1][0]; |
|
72
|
|
|
Assert::type(CombatLogEntry::class, $record); |
|
73
|
|
|
Assert::same(Heal::ACTION_NAME, $record->action); |
|
74
|
|
|
Assert::same("", $record->name); |
|
75
|
|
|
Assert::true($record->result); |
|
76
|
|
|
Assert::same(5, $record->amount); |
|
77
|
|
|
Assert::same($character1->name, $record->character1->name); |
|
78
|
|
|
Assert::same($character1->name, $record->character2->name); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
$test = new HealTest(); |
|
83
|
|
|
$test->run(); |
|
84
|
|
|
?> |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.