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