|
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 EquipmentTest extends \Tester\TestCase { |
|
15
|
|
|
public function testGetCombatEffects(): void { |
|
16
|
|
|
$equipment = new Equipment([ |
|
17
|
|
|
"id" => 1, "name" => "Novice Helmet", "slot" => Equipment::SLOT_HELMET, |
|
18
|
|
|
"strength" => 1, "worn" => false, |
|
19
|
|
|
]); |
|
20
|
|
|
Assert::count(0, $equipment->getCombatEffects()); |
|
21
|
|
|
$equipment->worn = true; |
|
22
|
|
|
Assert::count(1, $equipment->getCombatEffects()); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testDurability(): void { |
|
26
|
|
|
$data = [ |
|
27
|
|
|
"id" => 1, "name" => "Novice Helmet", "slot" => Equipment::SLOT_HELMET, |
|
28
|
|
|
"strength" => 20, "worn" => true, "maxDurability" => 10, |
|
29
|
|
|
]; |
|
30
|
|
|
$equipment = new Equipment($data); |
|
31
|
|
|
Assert::same($equipment->maxDurability, $equipment->durability); |
|
32
|
|
|
$data["durability"] = 0; |
|
33
|
|
|
$equipment = new Equipment($data); |
|
34
|
|
|
Assert::same(0, $equipment->durability); |
|
35
|
|
|
$equipment->durability = 20; |
|
36
|
|
|
Assert::same($equipment->maxDurability, $equipment->durability); |
|
37
|
|
|
Assert::same($equipment->rawStrength, $equipment->strength); |
|
38
|
|
|
Assert::same($equipment->rawStrength, $equipment->getCombatEffects()[0]->value); |
|
39
|
|
|
$equipment->durability = (int) ($equipment->maxDurability * 0.7 - 1); |
|
40
|
|
|
Assert::same((int) ($equipment->rawStrength * 0.75), $equipment->strength); |
|
41
|
|
|
Assert::same((int) ($equipment->rawStrength * 0.75), $equipment->getCombatEffects()[0]->value); |
|
42
|
|
|
$equipment->durability = (int) ($equipment->maxDurability / 2 - 1); |
|
43
|
|
|
Assert::same($equipment->rawStrength / 2, $equipment->strength); |
|
44
|
|
|
Assert::same($equipment->rawStrength / 2, $equipment->getCombatEffects()[0]->value); |
|
45
|
|
|
$equipment->durability = (int) ($equipment->maxDurability / 4 - 1); |
|
46
|
|
|
Assert::same($equipment->rawStrength / 4, $equipment->strength); |
|
47
|
|
|
Assert::same($equipment->rawStrength / 4, $equipment->getCombatEffects()[0]->value); |
|
48
|
|
|
$equipment->durability = (int) ($equipment->maxDurability / 10 - 1); |
|
49
|
|
|
Assert::same(0, $equipment->strength); |
|
50
|
|
|
Assert::same(0, $equipment->getCombatEffects()[0]->value); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$test = new EquipmentTest(); |
|
55
|
|
|
$test->run(); |
|
56
|
|
|
?> |