@@ -2,7 +2,7 @@ |
||
2 | 2 | declare(strict_types=1); |
3 | 3 | |
4 | 4 | require __DIR__ . "/../vendor/autoload.php"; |
5 | -Testbench\Bootstrap::setup(__DIR__ . '/_temp', function (\Nette\Bootstrap\Configurator $configurator): void { |
|
6 | - $configurator->addStaticParameters(["appDir" => __DIR__,]); |
|
5 | +Testbench\Bootstrap::setup(__DIR__ . '/_temp', function(\Nette\Bootstrap\Configurator $configurator): void { |
|
6 | + $configurator->addStaticParameters(["appDir" => __DIR__, ]); |
|
7 | 7 | $configurator->addConfig(__DIR__ . "/tests.neon"); |
8 | 8 | }); |
@@ -39,12 +39,12 @@ |
||
39 | 39 | protected function configureOptions(OptionsResolver $resolver): void |
40 | 40 | { |
41 | 41 | parent::configureOptions($resolver); |
42 | - $allStats = ["baseDamage", "damageGrowth", "strikes", "hitRate",]; |
|
42 | + $allStats = ["baseDamage", "damageGrowth", "strikes", "hitRate", ]; |
|
43 | 43 | $resolver->setRequired($allStats); |
44 | 44 | $resolver->setAllowedTypes("baseDamage", "string"); |
45 | 45 | $resolver->setAllowedTypes("damageGrowth", "string"); |
46 | 46 | $resolver->setAllowedTypes("strikes", "integer"); |
47 | - $resolver->setAllowedValues("strikes", function (int $value): bool { |
|
47 | + $resolver->setAllowedValues("strikes", function(int $value): bool { |
|
48 | 48 | return ($value > 0); |
49 | 49 | }); |
50 | 50 | $resolver->setAllowedTypes("hitRate", ["string", "null"]); |
@@ -29,7 +29,7 @@ |
||
29 | 29 | |
30 | 30 | protected function getValue(): int |
31 | 31 | { |
32 | - if ($this->skill->type === SkillSpecial::TYPE_STUN) { |
|
32 | + if($this->skill->type === SkillSpecial::TYPE_STUN) { |
|
33 | 33 | return 0; |
34 | 34 | } |
35 | 35 | $value = $this->skill->value; |
@@ -52,27 +52,27 @@ discard block |
||
52 | 52 | |
53 | 53 | protected function configureOptions(OptionsResolver $resolver): void |
54 | 54 | { |
55 | - $allStats = ["id", "name", "slot", "type", "strength", "worn",]; |
|
55 | + $allStats = ["id", "name", "slot", "type", "strength", "worn", ]; |
|
56 | 56 | $resolver->setRequired($allStats); |
57 | 57 | $resolver->setAllowedTypes("id", "integer"); |
58 | 58 | $resolver->setAllowedTypes("name", "string"); |
59 | 59 | $resolver->setAllowedTypes("slot", "string"); |
60 | - $resolver->setAllowedValues("slot", function (string $value): bool { |
|
60 | + $resolver->setAllowedValues("slot", function(string $value): bool { |
|
61 | 61 | return in_array($value, $this->getAllowedSlots(), true); |
62 | 62 | }); |
63 | 63 | $resolver->setAllowedTypes("type", "null"); |
64 | 64 | $resolver->setDefault("type", null); |
65 | 65 | $resolver->setAllowedTypes("strength", "integer"); |
66 | - $resolver->setAllowedValues("strength", function (int $value): bool { |
|
66 | + $resolver->setAllowedValues("strength", function(int $value): bool { |
|
67 | 67 | return ($value >= 0); |
68 | 68 | }); |
69 | 69 | $resolver->setAllowedTypes("worn", "boolean"); |
70 | 70 | $resolver->setDefault("maxDurability", 0); |
71 | 71 | $resolver->setAllowedTypes("maxDurability", "integer"); |
72 | - $resolver->setAllowedValues("maxDurability", function (int $value): bool { |
|
72 | + $resolver->setAllowedValues("maxDurability", function(int $value): bool { |
|
73 | 73 | return ($value >= 0); |
74 | 74 | }); |
75 | - $resolver->setDefault("durability", function (Options $options) { |
|
75 | + $resolver->setDefault("durability", function(Options $options) { |
|
76 | 76 | return $options["maxDurability"]; |
77 | 77 | }); |
78 | 78 | $resolver->setAllowedTypes("durability", "integer"); |
@@ -85,13 +85,13 @@ discard block |
||
85 | 85 | |
86 | 86 | protected function getStrength(): int |
87 | 87 | { |
88 | - if ($this->durability >= $this->maxDurability * 0.7) { |
|
88 | + if($this->durability >= $this->maxDurability * 0.7) { |
|
89 | 89 | return $this->rawStrength; |
90 | - } elseif ($this->durability >= $this->maxDurability / 2) { |
|
90 | + } elseif($this->durability >= $this->maxDurability / 2) { |
|
91 | 91 | return (int) ($this->rawStrength * 0.75); |
92 | - } elseif ($this->durability >= $this->maxDurability / 4) { |
|
92 | + } elseif($this->durability >= $this->maxDurability / 4) { |
|
93 | 93 | return (int) ($this->rawStrength / 2); |
94 | - } elseif ($this->durability >= $this->maxDurability / 10) { |
|
94 | + } elseif($this->durability >= $this->maxDurability / 10) { |
|
95 | 95 | return (int) ($this->rawStrength / 4); |
96 | 96 | } |
97 | 97 | return 0; |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | |
128 | 128 | public function getCombatEffects(): array |
129 | 129 | { |
130 | - if (!$this->worn) { |
|
130 | + if(!$this->worn) { |
|
131 | 131 | return []; |
132 | 132 | } |
133 | 133 | return [new CharacterEffect($this->getDeployParams())]; |
@@ -20,13 +20,13 @@ discard block |
||
20 | 20 | public static function moreDamage(CombatBase $combat): int |
21 | 21 | { |
22 | 22 | $result = 0; |
23 | - if ($combat->round <= $combat->roundLimit) { |
|
24 | - if (!$combat->team1->hasAliveMembers()) { |
|
23 | + if($combat->round <= $combat->roundLimit) { |
|
24 | + if(!$combat->team1->hasAliveMembers()) { |
|
25 | 25 | $result = 2; |
26 | - } elseif (!$combat->team2->hasAliveMembers()) { |
|
26 | + } elseif(!$combat->team2->hasAliveMembers()) { |
|
27 | 27 | $result = 1; |
28 | 28 | } |
29 | - } elseif ($combat->round > $combat->roundLimit) { |
|
29 | + } elseif($combat->round > $combat->roundLimit) { |
|
30 | 30 | $result = ($combat->team1Damage > $combat->team2Damage) ? 1 : 2; |
31 | 31 | } |
32 | 32 | return $result; |
@@ -39,13 +39,13 @@ discard block |
||
39 | 39 | public static function eliminateSecondTeam(CombatBase $combat): int |
40 | 40 | { |
41 | 41 | $result = 0; |
42 | - if ($combat->round <= $combat->roundLimit) { |
|
43 | - if (!$combat->team1->hasAliveMembers()) { |
|
42 | + if($combat->round <= $combat->roundLimit) { |
|
43 | + if(!$combat->team1->hasAliveMembers()) { |
|
44 | 44 | $result = 2; |
45 | - } elseif (!$combat->team2->hasAliveMembers()) { |
|
45 | + } elseif(!$combat->team2->hasAliveMembers()) { |
|
46 | 46 | $result = 1; |
47 | 47 | } |
48 | - } elseif ($combat->round > $combat->roundLimit) { |
|
48 | + } elseif($combat->round > $combat->roundLimit) { |
|
49 | 49 | $result = (!$combat->team2->hasAliveMembers()) ? 1 : 2; |
50 | 50 | } |
51 | 51 | return $result; |
@@ -58,13 +58,13 @@ discard block |
||
58 | 58 | public static function firstTeamSurvives(CombatBase $combat): int |
59 | 59 | { |
60 | 60 | $result = 0; |
61 | - if ($combat->round <= $combat->roundLimit) { |
|
62 | - if (!$combat->team1->hasAliveMembers()) { |
|
61 | + if($combat->round <= $combat->roundLimit) { |
|
62 | + if(!$combat->team1->hasAliveMembers()) { |
|
63 | 63 | $result = 2; |
64 | - } elseif (!$combat->team2->hasAliveMembers()) { |
|
64 | + } elseif(!$combat->team2->hasAliveMembers()) { |
|
65 | 65 | $result = 1; |
66 | 66 | } |
67 | - } elseif ($combat->round > $combat->roundLimit) { |
|
67 | + } elseif($combat->round > $combat->roundLimit) { |
|
68 | 68 | $result = ($combat->team1->hasAliveMembers()) ? 1 : 2; |
69 | 69 | } |
70 | 70 | return $result; |
@@ -21,7 +21,7 @@ |
||
21 | 21 | ]; |
22 | 22 | $formula = str_replace(array_keys($stats), array_values($stats), $formula); |
23 | 23 | preg_match("/^([1-9]+)d([1-9]+)/", $formula, $dices); |
24 | - for ($i = 1; $i <= (int) $dices[1]; $i++) { |
|
24 | + for($i = 1; $i <= (int) $dices[1]; $i++) { |
|
25 | 25 | $result += rand(1, (int) $dices[2]); |
26 | 26 | } |
27 | 27 | preg_match("/\+([0-9]+)\/([0-9]+)/", $formula, $ammendum); |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | public const TARGET_PARTY = "party"; |
24 | 24 | public const TARGET_ENEMY_PARTY = "enemy_party"; |
25 | 25 | /** @var string[] */ |
26 | - public const NO_STAT_TYPES = [self::TYPE_STUN, self::TYPE_POISON, self::TYPE_HIDE,]; |
|
26 | + public const NO_STAT_TYPES = [self::TYPE_STUN, self::TYPE_POISON, self::TYPE_HIDE, ]; |
|
27 | 27 | |
28 | 28 | public readonly string $type; |
29 | 29 | public readonly ?string $stat; |
@@ -50,26 +50,26 @@ discard block |
||
50 | 50 | protected function configureOptions(OptionsResolver $resolver): void |
51 | 51 | { |
52 | 52 | parent::configureOptions($resolver); |
53 | - $allStats = ["type", "stat", "value", "valueGrowth", "duration",]; |
|
53 | + $allStats = ["type", "stat", "value", "valueGrowth", "duration", ]; |
|
54 | 54 | $resolver->setRequired($allStats); |
55 | 55 | $resolver->setAllowedTypes("type", "string"); |
56 | - $resolver->setAllowedValues("type", function (string $value): bool { |
|
56 | + $resolver->setAllowedValues("type", function(string $value): bool { |
|
57 | 57 | return in_array($value, $this->getAllowedTypes(), true); |
58 | 58 | }); |
59 | 59 | $resolver->setAllowedTypes("stat", ["string", "null"]); |
60 | - $resolver->setAllowedValues("stat", function (?string $value): bool { |
|
60 | + $resolver->setAllowedValues("stat", function(?string $value): bool { |
|
61 | 61 | return $value === null || in_array($value, $this->getAllowedStats(), true); |
62 | 62 | }); |
63 | 63 | $resolver->setAllowedTypes("value", "integer"); |
64 | - $resolver->setAllowedValues("value", function (int $value): bool { |
|
64 | + $resolver->setAllowedValues("value", function(int $value): bool { |
|
65 | 65 | return ($value >= 0); |
66 | 66 | }); |
67 | 67 | $resolver->setAllowedTypes("valueGrowth", "integer"); |
68 | - $resolver->setAllowedValues("valueGrowth", function (int $value): bool { |
|
68 | + $resolver->setAllowedValues("valueGrowth", function(int $value): bool { |
|
69 | 69 | return ($value >= 0); |
70 | 70 | }); |
71 | 71 | $resolver->setAllowedTypes("duration", "integer"); |
72 | - $resolver->setAllowedValues("duration", function (int $value): bool { |
|
72 | + $resolver->setAllowedValues("duration", function(int $value): bool { |
|
73 | 73 | return ($value >= 0); |
74 | 74 | }); |
75 | 75 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | public ICombatActionSelector $actionSelector = new CombatActionSelector() |
60 | 60 | ) { |
61 | 61 | $this->victoryCondition = [VictoryConditions::class, "moreDamage"]; |
62 | - $this->healers = function (): Team { |
|
62 | + $this->healers = function(): Team { |
|
63 | 63 | return new Team("healers"); |
64 | 64 | }; |
65 | 65 | $this->combatActions = new class extends Collection { |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function setTeams(Team $team1, Team $team2): void |
115 | 115 | { |
116 | - if (isset($this->team1)) { |
|
116 | + if(isset($this->team1)) { |
|
117 | 117 | throw new ImmutableException("Teams has already been set."); |
118 | 118 | } |
119 | 119 | $this->team1 = $team1; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | public function getWinner(): int |
192 | 192 | { |
193 | 193 | static $result = 0; |
194 | - if ($result === 0) { |
|
194 | + if($result === 0) { |
|
195 | 195 | $result = call_user_func($this->victoryCondition, $this); |
196 | 196 | $result = Numbers::range($result, 0, 2); |
197 | 197 | } |
@@ -218,30 +218,30 @@ discard block |
||
218 | 218 | { |
219 | 219 | /** @var Character[] $characters */ |
220 | 220 | $characters = array_merge($combat->team1->toArray(), $combat->team2->toArray()); |
221 | - foreach ($characters as $character) { |
|
221 | + foreach($characters as $character) { |
|
222 | 222 | $character->applyEffectProviders(); |
223 | 223 | } |
224 | 224 | } |
225 | 225 | |
226 | 226 | public function assignPositions(self $combat): void |
227 | 227 | { |
228 | - $assignPositions = function (Team $team): void { |
|
228 | + $assignPositions = function(Team $team): void { |
|
229 | 229 | $row = 1; |
230 | 230 | $column = 0; |
231 | 231 | /** @var Character $character */ |
232 | - foreach ($team as $character) { |
|
232 | + foreach($team as $character) { |
|
233 | 233 | try { |
234 | 234 | $column++; |
235 | - if ($character->positionRow > 0 && $character->positionColumn > 0) { |
|
235 | + if($character->positionRow > 0 && $character->positionColumn > 0) { |
|
236 | 236 | continue; |
237 | 237 | } |
238 | 238 | setPosition: |
239 | 239 | $team->setCharacterPosition($character->id, $row, $column); |
240 | - } catch (InvalidCharacterPositionException $e) { |
|
241 | - if ($e->getCode() === InvalidCharacterPositionException::ROW_FULL) { |
|
240 | + } catch(InvalidCharacterPositionException $e) { |
|
241 | + if($e->getCode() === InvalidCharacterPositionException::ROW_FULL) { |
|
242 | 242 | $row++; |
243 | 243 | $column = 1; |
244 | - } elseif ($e->getCode() === InvalidCharacterPositionException::POSITION_OCCUPIED) { |
|
244 | + } elseif($e->getCode() === InvalidCharacterPositionException::POSITION_OCCUPIED) { |
|
245 | 245 | $column++; |
246 | 246 | } else { |
247 | 247 | throw $e; |
@@ -258,9 +258,9 @@ discard block |
||
258 | 258 | { |
259 | 259 | /** @var Character[] $characters */ |
260 | 260 | $characters = array_merge($combat->team1->toArray(), $combat->team2->toArray()); |
261 | - foreach ($characters as $character) { |
|
262 | - foreach ($character->effects as $effect) { |
|
263 | - if (is_int($effect->duration)) { |
|
261 | + foreach($characters as $character) { |
|
262 | + foreach($character->effects as $effect) { |
|
263 | + if(is_int($effect->duration)) { |
|
264 | 264 | $effect->duration--; |
265 | 265 | } |
266 | 266 | } |
@@ -274,8 +274,8 @@ discard block |
||
274 | 274 | { |
275 | 275 | /** @var Character[] $characters */ |
276 | 276 | $characters = array_merge($combat->team1->toArray(), $combat->team2->toArray()); |
277 | - foreach ($characters as $character) { |
|
278 | - foreach ($character->skills as $skill) { |
|
277 | + foreach($characters as $character) { |
|
278 | + foreach($character->skills as $skill) { |
|
279 | 279 | $skill->decreaseCooldown(); |
280 | 280 | } |
281 | 281 | } |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | { |
289 | 289 | /** @var Character[] $characters */ |
290 | 290 | $characters = array_merge($combat->team1->toArray(), $combat->team2->toArray()); |
291 | - foreach ($characters as $character) { |
|
291 | + foreach($characters as $character) { |
|
292 | 292 | $character->effects->removeByFilter(["duration!=" => CharacterEffect::DURATION_FOREVER]); |
293 | 293 | } |
294 | 294 | } |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | { |
323 | 323 | /** @var Character[] $characters */ |
324 | 324 | $characters = array_merge($combat->team1->toArray(), $combat->team2->toArray()); |
325 | - foreach ($characters as $character) { |
|
325 | + foreach($characters as $character) { |
|
326 | 326 | $character->recalculateStats(); |
327 | 327 | } |
328 | 328 | } |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | { |
335 | 335 | /** @var Character[] $characters */ |
336 | 336 | $characters = array_merge($combat->team1->toArray(), $combat->team2->toArray()); |
337 | - foreach ($characters as $character) { |
|
337 | + foreach($characters as $character) { |
|
338 | 338 | $character->resetInitiative(); |
339 | 339 | } |
340 | 340 | } |
@@ -347,21 +347,21 @@ discard block |
||
347 | 347 | public function selectAttackTarget(Character $attacker): ?Character |
348 | 348 | { |
349 | 349 | $enemyTeam = $this->getEnemyTeam($attacker); |
350 | - $rangedWeapon = ($attacker->equipment->hasItems(["%class%" => Weapon::class, "worn" => true, "ranged" => true,])); |
|
351 | - if (!$rangedWeapon) { |
|
350 | + $rangedWeapon = ($attacker->equipment->hasItems(["%class%" => Weapon::class, "worn" => true, "ranged" => true, ])); |
|
351 | + if(!$rangedWeapon) { |
|
352 | 352 | $rowToAttack = $enemyTeam->rowToAttack; |
353 | - if ($rowToAttack === null) { |
|
353 | + if($rowToAttack === null) { |
|
354 | 354 | return null; |
355 | 355 | } |
356 | 356 | $enemies = Team::fromArray( |
357 | - $enemyTeam->getItems(["positionRow" => $rowToAttack, "hitpoints>" => 0, "hidden" => false,]), |
|
357 | + $enemyTeam->getItems(["positionRow" => $rowToAttack, "hitpoints>" => 0, "hidden" => false, ]), |
|
358 | 358 | $enemyTeam->name |
359 | 359 | ); |
360 | 360 | } else { |
361 | 361 | $enemies = $enemyTeam; |
362 | 362 | } |
363 | 363 | $target = $enemies->getLowestHpCharacter(); |
364 | - if ($target !== null) { |
|
364 | + if($target !== null) { |
|
365 | 365 | return $target; |
366 | 366 | } |
367 | 367 | return $enemies->getRandomCharacter(); |
@@ -376,13 +376,13 @@ discard block |
||
376 | 376 | { |
377 | 377 | /** @var Character[] $characters */ |
378 | 378 | $characters = array_merge($combat->team1->usableMembers, $combat->team2->usableMembers); |
379 | - usort($characters, function (Character $a, Character $b): int { |
|
379 | + usort($characters, function(Character $a, Character $b): int { |
|
380 | 380 | return -1 * strcmp((string) $a->initiative, (string) $b->initiative); |
381 | 381 | }); |
382 | - foreach ($characters as $character) { |
|
382 | + foreach($characters as $character) { |
|
383 | 383 | /** @var ICombatAction|null $combatAction */ |
384 | 384 | $combatAction = $combat->actionSelector->chooseAction($combat, $character); |
385 | - if ($combatAction === null) { |
|
385 | + if($combatAction === null) { |
|
386 | 386 | break; |
387 | 387 | } |
388 | 388 | $combatAction->do($combat, $character); |
@@ -396,18 +396,18 @@ discard block |
||
396 | 396 | */ |
397 | 397 | public function execute(): int |
398 | 398 | { |
399 | - if (!isset($this->team1)) { |
|
399 | + if(!isset($this->team1)) { |
|
400 | 400 | throw new InvalidStateException("Teams are not set."); |
401 | 401 | } |
402 | 402 | $this->onCombatStart($this); |
403 | - while ($this->round <= $this->roundLimit) { |
|
403 | + while($this->round <= $this->roundLimit) { |
|
404 | 404 | $this->onRoundStart($this); |
405 | - if ($this->getWinner() > 0) { |
|
405 | + if($this->getWinner() > 0) { |
|
406 | 406 | break; |
407 | 407 | } |
408 | 408 | $this->onRound($this); |
409 | 409 | $this->onRoundEnd($this); |
410 | - if ($this->getWinner() > 0) { |
|
410 | + if($this->getWinner() > 0) { |
|
411 | 411 | break; |
412 | 412 | } |
413 | 413 | } |
@@ -422,10 +422,10 @@ discard block |
||
422 | 422 | { |
423 | 423 | /** @var Character[] $characters */ |
424 | 424 | $characters = array_merge( |
425 | - $combat->team1->getItems(["hitpoints>" => 0, "poisoned!=" => false,]), |
|
426 | - $combat->team2->getItems(["hitpoints>" => 0, "poisoned!=" => false,]) |
|
425 | + $combat->team1->getItems(["hitpoints>" => 0, "poisoned!=" => false, ]), |
|
426 | + $combat->team2->getItems(["hitpoints>" => 0, "poisoned!=" => false, ]) |
|
427 | 427 | ); |
428 | - foreach ($characters as $character) { |
|
428 | + foreach($characters as $character) { |
|
429 | 429 | $poisonValue = $character->getStatus(Character::STATUS_POISONED); |
430 | 430 | $character->harm($poisonValue); |
431 | 431 | $action = [ |
@@ -28,10 +28,10 @@ discard block |
||
28 | 28 | public function shouldUse(CombatBase $combat, Character $character): bool |
29 | 29 | { |
30 | 30 | $attackTarget = $combat->selectAttackTarget($character); |
31 | - if ($attackTarget === null) { |
|
31 | + if($attackTarget === null) { |
|
32 | 32 | return false; |
33 | 33 | } |
34 | - if (count($character->usableSkills) < 1) { |
|
34 | + if(count($character->usableSkills) < 1) { |
|
35 | 35 | return false; |
36 | 36 | } |
37 | 37 | return ($character->usableSkills[0] instanceof CharacterAttackSkill); |
@@ -46,11 +46,11 @@ discard block |
||
46 | 46 | $result = []; |
47 | 47 | $result["result"] = $combat->successCalculator->hasHit($attacker, $defender, $skill); |
48 | 48 | $result["amount"] = 0; |
49 | - if ($result["result"]) { |
|
49 | + if($result["result"]) { |
|
50 | 50 | $amount = (int) (($attacker->damage - $defender->defense) / 100 * $skill->damage); |
51 | 51 | $result["amount"] = Numbers::range($amount, 0, $defender->hitpoints); |
52 | 52 | } |
53 | - if ($result["amount"] > 0) { |
|
53 | + if($result["amount"] > 0) { |
|
54 | 54 | $defender->harm($result["amount"]); |
55 | 55 | } |
56 | 56 | $result["action"] = $this->getName(); |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | Skill::TARGET_COLUMN => $combat->getTeam($primaryTarget)->getItems(["positionColumn" => $primaryTarget->positionColumn]), |
78 | 78 | default => throw new NotImplementedException("Target {$skill->skill->target} for attack skills is not implemented."), |
79 | 79 | }; |
80 | - foreach ($targets as $target) { |
|
81 | - for ($i = 1; $i <= $skill->skill->strikes; $i++) { |
|
82 | - if ($target->hitpoints > 0) { |
|
80 | + foreach($targets as $target) { |
|
81 | + for($i = 1; $i <= $skill->skill->strikes; $i++) { |
|
82 | + if($target->hitpoints > 0) { |
|
83 | 83 | $this->doSingleAttack($character, $target, $skill, $combat); |
84 | 84 | } |
85 | 85 | } |