@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | public readonly string $stat; |
27 | 27 | public readonly int $value; |
28 | 28 | public readonly bool $valueAbsolute; |
29 | - protected int|string $duration; |
|
29 | + protected int | string $duration; |
|
30 | 30 | /** @var callable[] */ |
31 | 31 | public array $onApply = []; |
32 | 32 | /** @var callable[] */ |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | $resolver = new OptionsResolver(); |
38 | 38 | $this->configureOptions($resolver); |
39 | 39 | $effect = $resolver->resolve($effect); |
40 | - if (!in_array($effect["type"], SkillSpecial::NO_STAT_TYPES, true) && $effect["stat"] === "") { |
|
40 | + if(!in_array($effect["type"], SkillSpecial::NO_STAT_TYPES, true) && $effect["stat"] === "") { |
|
41 | 41 | throw new \InvalidArgumentException("The option stat with value '' is invalid."); |
42 | 42 | } |
43 | 43 | $this->id = $effect["id"]; |
@@ -51,15 +51,15 @@ discard block |
||
51 | 51 | |
52 | 52 | protected function registerDefaultHandlers(): void |
53 | 53 | { |
54 | - $this->onApply[] = function (Character $character, self $effect): void { |
|
54 | + $this->onApply[] = function(Character $character, self $effect): void { |
|
55 | 55 | $character->recalculateStats(); |
56 | - if ($effect->stat === Character::STAT_MAX_HITPOINTS) { |
|
56 | + if($effect->stat === Character::STAT_MAX_HITPOINTS) { |
|
57 | 57 | $character->heal($effect->value); |
58 | 58 | } |
59 | 59 | }; |
60 | - $this->onRemove[] = function (Character $character, self $effect): void { |
|
60 | + $this->onRemove[] = function(Character $character, self $effect): void { |
|
61 | 61 | $character->recalculateStats(); |
62 | - if ($effect->stat === Character::STAT_MAX_HITPOINTS) { |
|
62 | + if($effect->stat === Character::STAT_MAX_HITPOINTS) { |
|
63 | 63 | $character->harm($effect->value); |
64 | 64 | } |
65 | 65 | }; |
@@ -67,23 +67,23 @@ discard block |
||
67 | 67 | |
68 | 68 | protected function configureOptions(OptionsResolver $resolver): void |
69 | 69 | { |
70 | - $allStats = ["id", "type", "value", "valueAbsolute", "duration", "stat",]; |
|
70 | + $allStats = ["id", "type", "value", "valueAbsolute", "duration", "stat", ]; |
|
71 | 71 | $resolver->setRequired($allStats); |
72 | 72 | $resolver->setAllowedTypes("id", "string"); |
73 | 73 | $resolver->setAllowedTypes("type", "string"); |
74 | - $resolver->setAllowedValues("type", function (string $value): bool { |
|
74 | + $resolver->setAllowedValues("type", function(string $value): bool { |
|
75 | 75 | return in_array($value, $this->getAllowedTypes(), true); |
76 | 76 | }); |
77 | 77 | $resolver->setAllowedTypes("stat", "string"); |
78 | 78 | $resolver->setDefault("stat", ""); |
79 | - $resolver->setAllowedValues("stat", function (string $value): bool { |
|
79 | + $resolver->setAllowedValues("stat", function(string $value): bool { |
|
80 | 80 | return $value === "" || in_array($value, $this->getAllowedStats(), true); |
81 | 81 | }); |
82 | 82 | $resolver->setAllowedTypes("value", "integer"); |
83 | 83 | $resolver->setAllowedTypes("valueAbsolute", "bool"); |
84 | 84 | $resolver->setDefault("value", 0); |
85 | 85 | $resolver->setAllowedTypes("duration", ["string", "integer"]); |
86 | - $resolver->setAllowedValues("duration", function ($value): bool { |
|
86 | + $resolver->setAllowedValues("duration", function($value): bool { |
|
87 | 87 | return (in_array($value, $this->getDurations(), true)) || ($value > 0); |
88 | 88 | }); |
89 | 89 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | return Constants::getConstantsValues(static::class, "DURATION_"); |
110 | 110 | } |
111 | 111 | |
112 | - protected function getDuration(): int|string |
|
112 | + protected function getDuration(): int | string |
|
113 | 113 | { |
114 | 114 | return $this->duration; |
115 | 115 | } |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | /** |
118 | 118 | * @throws \InvalidArgumentException |
119 | 119 | */ |
120 | - protected function setDuration(string|int $value): void |
|
120 | + protected function setDuration(string | int $value): void |
|
121 | 121 | { |
122 | - if (!is_int($value) && !in_array($value, $this->getDurations(), true)) { |
|
122 | + if(!is_int($value) && !in_array($value, $this->getDurations(), true)) { |
|
123 | 123 | throw new \InvalidArgumentException( |
124 | 124 | "Invalid value set to CharacterEffect::\$duration. Expected string or integer." |
125 | 125 | ); |
@@ -14,8 +14,7 @@ discard block |
||
14 | 14 | * @method void onApply(Character $character, CharacterEffect $effect) |
15 | 15 | * @method void onRemove(Character $character, CharacterEffect $effect) |
16 | 16 | */ |
17 | -class CharacterEffect |
|
18 | -{ |
|
17 | +class CharacterEffect { |
|
19 | 18 | use \Nette\SmartObject; |
20 | 19 | |
21 | 20 | public const DURATION_COMBAT = "combat"; |
@@ -32,8 +31,7 @@ discard block |
||
32 | 31 | /** @var callable[] */ |
33 | 32 | public array $onRemove = []; |
34 | 33 | |
35 | - public function __construct(array $effect) |
|
36 | - { |
|
34 | + public function __construct(array $effect) { |
|
37 | 35 | $resolver = new OptionsResolver(); |
38 | 36 | $this->configureOptions($resolver); |
39 | 37 | $effect = $resolver->resolve($effect); |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | public const STATUS_POISONED = "poisoned"; |
86 | 86 | public const STATUS_HIDDEN = "hidden"; |
87 | 87 | |
88 | - protected int|string $id; |
|
88 | + protected int | string $id; |
|
89 | 89 | protected string $name; |
90 | 90 | protected string $gender = "male"; |
91 | 91 | protected string $race; |
@@ -162,51 +162,51 @@ discard block |
||
162 | 162 | |
163 | 163 | protected function registerDefaultStatuses(): void |
164 | 164 | { |
165 | - $this->registerStatus(static::STATUS_STUNNED, function (Character $character): bool { |
|
165 | + $this->registerStatus(static::STATUS_STUNNED, function(Character $character): bool { |
|
166 | 166 | return $character->effects->hasItems(["type" => SkillSpecial::TYPE_STUN]); |
167 | 167 | }); |
168 | - $this->registerStatus(static::STATUS_POISONED, function (Character $character): int { |
|
168 | + $this->registerStatus(static::STATUS_POISONED, function(Character $character): int { |
|
169 | 169 | $poisons = $character->effects->getItems(["type" => SkillSpecial::TYPE_POISON]); |
170 | 170 | $poisonValue = 0; |
171 | 171 | /** @var CharacterEffect $poison */ |
172 | - foreach ($poisons as $poison) { |
|
172 | + foreach($poisons as $poison) { |
|
173 | 173 | $poisonValue += $poison->value; |
174 | 174 | } |
175 | 175 | return $poisonValue; |
176 | 176 | }); |
177 | - $this->registerStatus(static::STATUS_HIDDEN, function (Character $character): bool { |
|
177 | + $this->registerStatus(static::STATUS_HIDDEN, function(Character $character): bool { |
|
178 | 178 | return $character->effects->hasItems(["type" => SkillSpecial::TYPE_HIDE]); |
179 | 179 | }); |
180 | 180 | } |
181 | 181 | |
182 | 182 | protected function setStats(array $stats): void |
183 | 183 | { |
184 | - $requiredStats = array_merge(["id", "name", "level", "initiativeFormula",], static::BASE_STATS); |
|
185 | - $allStats = array_merge($requiredStats, ["occupation", "race", "specialization", "gender",]); |
|
184 | + $requiredStats = array_merge(["id", "name", "level", "initiativeFormula", ], static::BASE_STATS); |
|
185 | + $allStats = array_merge($requiredStats, ["occupation", "race", "specialization", "gender", ]); |
|
186 | 186 | $numberStats = static::BASE_STATS; |
187 | - $textStats = ["name", "race", "occupation", "specialization", "initiativeFormula",]; |
|
187 | + $textStats = ["name", "race", "occupation", "specialization", "initiativeFormula", ]; |
|
188 | 188 | $resolver = new OptionsResolver(); |
189 | 189 | $resolver->setDefined($allStats); |
190 | - $resolver->setAllowedTypes("id", ["integer", "string",]); |
|
191 | - foreach ($numberStats as $stat) { |
|
190 | + $resolver->setAllowedTypes("id", ["integer", "string", ]); |
|
191 | + foreach($numberStats as $stat) { |
|
192 | 192 | $resolver->setAllowedTypes($stat, ["integer", "float"]); |
193 | - $resolver->setNormalizer($stat, function (OptionsResolver $resolver, $value): int { |
|
193 | + $resolver->setNormalizer($stat, function(OptionsResolver $resolver, $value): int { |
|
194 | 194 | return (int) $value; |
195 | 195 | }); |
196 | 196 | } |
197 | - foreach ($textStats as $stat) { |
|
198 | - $resolver->setNormalizer($stat, function (OptionsResolver $resolver, $value): string { |
|
197 | + foreach($textStats as $stat) { |
|
198 | + $resolver->setNormalizer($stat, function(OptionsResolver $resolver, $value): string { |
|
199 | 199 | return (string) $value; |
200 | 200 | }); |
201 | 201 | } |
202 | 202 | $resolver->setRequired($requiredStats); |
203 | - $stats = array_filter($stats, function ($key) use ($allStats): bool { |
|
203 | + $stats = array_filter($stats, function($key) use ($allStats): bool { |
|
204 | 204 | return in_array($key, $allStats, true); |
205 | 205 | }, ARRAY_FILTER_USE_KEY); |
206 | 206 | $stats = $resolver->resolve($stats); |
207 | - foreach ($stats as $key => $value) { |
|
207 | + foreach($stats as $key => $value) { |
|
208 | 208 | $this->$key = $value; |
209 | - if (in_array($key, $numberStats, true)) { |
|
209 | + if(in_array($key, $numberStats, true)) { |
|
210 | 210 | $this->{$key . "Base"} = $value; |
211 | 211 | } |
212 | 212 | } |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | $this->dodgeBase = $this->dodge; |
217 | 217 | } |
218 | 218 | |
219 | - protected function getId(): int|string |
|
219 | + protected function getId(): int | string |
|
220 | 220 | { |
221 | 221 | return $this->id; |
222 | 222 | } |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | { |
361 | 361 | /** @var Pet|null $pet */ |
362 | 362 | $pet = $this->pets->getItem(["deployed" => true]); |
363 | - if ($pet === null) { |
|
363 | + if($pet === null) { |
|
364 | 364 | return null; |
365 | 365 | } |
366 | 366 | return $pet->id; |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | { |
406 | 406 | $oldParser = $this->initiativeFormulaParser; |
407 | 407 | $this->initiativeFormulaParser = $initiativeFormulaParser; |
408 | - if ($oldParser !== $initiativeFormulaParser) { |
|
408 | + if($oldParser !== $initiativeFormulaParser) { |
|
409 | 409 | $this->recalculateStats(); |
410 | 410 | } |
411 | 411 | } |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | |
444 | 444 | public function getStatus(string $name): mixed |
445 | 445 | { |
446 | - if (!array_key_exists($name, $this->statuses)) { |
|
446 | + if(!array_key_exists($name, $this->statuses)) { |
|
447 | 447 | return null; |
448 | 448 | } |
449 | 449 | return (call_user_func($this->statuses[$name], $this)); |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | |
452 | 452 | public function hasStatus(string $status): bool |
453 | 453 | { |
454 | - if (!array_key_exists($status, $this->statuses)) { |
|
454 | + if(!array_key_exists($status, $this->statuses)) { |
|
455 | 455 | return false; |
456 | 456 | } |
457 | 457 | return (bool) (call_user_func($this->statuses[$status], $this)); |
@@ -462,9 +462,9 @@ discard block |
||
462 | 462 | */ |
463 | 463 | public function applyEffectProviders(): void |
464 | 464 | { |
465 | - foreach ($this->effectProviders as $item) { |
|
465 | + foreach($this->effectProviders as $item) { |
|
466 | 466 | $effects = $item->getCombatEffects(); |
467 | - array_walk($effects, function (CharacterEffect $effect): void { |
|
467 | + array_walk($effects, function(CharacterEffect $effect): void { |
|
468 | 468 | $this->effects->removeByFilter(["id" => $effect->id]); |
469 | 469 | $this->effects[] = $effect; |
470 | 470 | }); |
@@ -501,8 +501,8 @@ discard block |
||
501 | 501 | public function damageStat(): string |
502 | 502 | { |
503 | 503 | /** @var Weapon|null $item */ |
504 | - $item = $this->equipment->getItem(["%class%" => Weapon::class, "worn" => true,]); |
|
505 | - if ($item === null) { |
|
504 | + $item = $this->equipment->getItem(["%class%" => Weapon::class, "worn" => true, ]); |
|
505 | + if($item === null) { |
|
506 | 506 | return static::STAT_STRENGTH; |
507 | 507 | } |
508 | 508 | return $item->damageStat; |
@@ -518,13 +518,13 @@ discard block |
||
518 | 518 | static::STAT_DODGE => static::STAT_DEXTERITY, static::STAT_MAX_HITPOINTS => static::STAT_CONSTITUTION, |
519 | 519 | static::STAT_INITIATIVE => "", |
520 | 520 | ]; |
521 | - foreach ($stats as $secondary => $primary) { |
|
521 | + foreach($stats as $secondary => $primary) { |
|
522 | 522 | $gain = $this->$secondary - $this->{$secondary . "Base"}; |
523 | - if ($secondary === static::STAT_DAMAGE) { |
|
523 | + if($secondary === static::STAT_DAMAGE) { |
|
524 | 524 | $base = (int) round($this->$primary / 2); |
525 | - } elseif ($secondary === static::STAT_MAX_HITPOINTS) { |
|
525 | + } elseif($secondary === static::STAT_MAX_HITPOINTS) { |
|
526 | 526 | $base = $this->$primary * static::HITPOINTS_PER_CONSTITUTION; |
527 | - } elseif ($secondary === static::STAT_INITIATIVE) { |
|
527 | + } elseif($secondary === static::STAT_INITIATIVE) { |
|
528 | 528 | $base = $this->initiativeFormulaParser->calculateInitiative($this); |
529 | 529 | } else { |
530 | 530 | $base = $this->$primary * 3; |
@@ -541,31 +541,31 @@ discard block |
||
541 | 541 | { |
542 | 542 | $stats = array_merge(static::BASE_STATS, static::SECONDARY_STATS); |
543 | 543 | $debuffs = []; |
544 | - foreach ($stats as $stat) { |
|
544 | + foreach($stats as $stat) { |
|
545 | 545 | $$stat = $this->{$stat . "Base"}; |
546 | 546 | $debuffs[$stat] = 0; |
547 | 547 | } |
548 | 548 | $this->effects->removeByFilter(["duration<" => 1]); |
549 | - foreach ($this->effects as $effect) { |
|
549 | + foreach($this->effects as $effect) { |
|
550 | 550 | $stat = $effect->stat; |
551 | 551 | $type = $effect->type; |
552 | 552 | $bonus_value = 0; |
553 | - if (!in_array($type, SkillSpecial::NO_STAT_TYPES, true)) { |
|
553 | + if(!in_array($type, SkillSpecial::NO_STAT_TYPES, true)) { |
|
554 | 554 | $bonus_value = ($effect->valueAbsolute) ? $effect->value : $$stat / 100 * $effect->value; |
555 | 555 | } |
556 | - if ($type === SkillSpecial::TYPE_BUFF) { |
|
556 | + if($type === SkillSpecial::TYPE_BUFF) { |
|
557 | 557 | $$stat += $bonus_value; |
558 | - } elseif ($type === SkillSpecial::TYPE_DEBUFF) { |
|
558 | + } elseif($type === SkillSpecial::TYPE_DEBUFF) { |
|
559 | 559 | $debuffs[$stat] += $bonus_value; |
560 | 560 | } |
561 | 561 | unset($stat, $type, $bonus_value); |
562 | 562 | } |
563 | - foreach ($debuffs as $stat => $value) { |
|
563 | + foreach($debuffs as $stat => $value) { |
|
564 | 564 | $value = min($value, 80); |
565 | 565 | $bonus_value = $$stat / 100 * $value; |
566 | 566 | $$stat -= $bonus_value; |
567 | 567 | } |
568 | - foreach ($stats as $stat) { |
|
568 | + foreach($stats as $stat) { |
|
569 | 569 | $this->$stat = (int) round($$stat); |
570 | 570 | } |
571 | 571 | $this->recalculateSecondaryStats(); |
@@ -50,8 +50,7 @@ |
||
50 | 50 | * @property int $positionRow |
51 | 51 | * @property int $positionColumn |
52 | 52 | */ |
53 | -class Character |
|
54 | -{ |
|
53 | +class Character { |
|
55 | 54 | use \Nette\SmartObject; |
56 | 55 | |
57 | 56 | public const HITPOINTS_PER_CONSTITUTION = 5; |
@@ -30,16 +30,16 @@ discard block |
||
30 | 30 | |
31 | 31 | private function configureOptions(OptionsResolver $resolver): void |
32 | 32 | { |
33 | - $allStats = ["id", "deployed", "bonusStat", "bonusValue",]; |
|
33 | + $allStats = ["id", "deployed", "bonusStat", "bonusValue", ]; |
|
34 | 34 | $resolver->setRequired($allStats); |
35 | 35 | $resolver->setAllowedTypes("id", "integer"); |
36 | 36 | $resolver->setAllowedTypes("deployed", "boolean"); |
37 | 37 | $resolver->setAllowedTypes("bonusStat", "string"); |
38 | - $resolver->setAllowedValues("bonusStat", function (string $value): bool { |
|
38 | + $resolver->setAllowedValues("bonusStat", function(string $value): bool { |
|
39 | 39 | return in_array($value, $this->getAllowedStats(), true); |
40 | 40 | }); |
41 | 41 | $resolver->setAllowedTypes("bonusValue", "integer"); |
42 | - $resolver->setAllowedValues("bonusValue", function (int $value): bool { |
|
42 | + $resolver->setAllowedValues("bonusValue", function(int $value): bool { |
|
43 | 43 | return ($value >= 0); |
44 | 44 | }); |
45 | 45 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | |
64 | 64 | public function getCombatEffects(): array |
65 | 65 | { |
66 | - if (!$this->deployed) { |
|
66 | + if(!$this->deployed) { |
|
67 | 67 | return []; |
68 | 68 | } |
69 | 69 | return [new CharacterEffect($this->getDeployParams())]; |
@@ -10,15 +10,13 @@ |
||
10 | 10 | * |
11 | 11 | * @author Jakub Konečný |
12 | 12 | */ |
13 | -final class Pet implements ICharacterEffectsProvider |
|
14 | -{ |
|
13 | +final class Pet implements ICharacterEffectsProvider { |
|
15 | 14 | public readonly int $id; |
16 | 15 | public bool $deployed; |
17 | 16 | public readonly string $bonusStat; |
18 | 17 | public readonly int $bonusValue; |
19 | 18 | |
20 | - public function __construct(array $data) |
|
21 | - { |
|
19 | + public function __construct(array $data) { |
|
22 | 20 | $resolver = new OptionsResolver(); |
23 | 21 | $this->configureOptions($resolver); |
24 | 22 | $data = $resolver->resolve($data); |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | protected function getAliveMembers(): array |
48 | 48 | { |
49 | - return $this->getItems(["hitpoints>" => 0,]); |
|
49 | + return $this->getItems(["hitpoints>" => 0, ]); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -76,14 +76,14 @@ discard block |
||
76 | 76 | */ |
77 | 77 | public function setCharacterPosition($id, int $row, int $column): void |
78 | 78 | { |
79 | - if (!$this->hasItems(["id" => $id])) { |
|
79 | + if(!$this->hasItems(["id" => $id])) { |
|
80 | 80 | throw new \OutOfBoundsException("Character $id is not in the team"); |
81 | - } elseif (count($this->getItems(["positionRow" => $row])) >= $this->maxRowSize) { |
|
81 | + } elseif(count($this->getItems(["positionRow" => $row])) >= $this->maxRowSize) { |
|
82 | 82 | throw new InvalidCharacterPositionException( |
83 | 83 | "Row $row is full.", |
84 | 84 | InvalidCharacterPositionException::ROW_FULL |
85 | 85 | ); |
86 | - } elseif ($this->hasItems(["positionRow" => $row, "positionColumn" => $column])) { |
|
86 | + } elseif($this->hasItems(["positionRow" => $row, "positionColumn" => $column])) { |
|
87 | 87 | throw new InvalidCharacterPositionException( |
88 | 88 | "Row $row column $column is occupied.", |
89 | 89 | InvalidCharacterPositionException::POSITION_OCCUPIED |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | public function getRandomCharacter(): ?Character |
98 | 98 | { |
99 | 99 | $characters = $this->aliveMembers; |
100 | - if (count($characters) === 0) { |
|
100 | + if(count($characters) === 0) { |
|
101 | 101 | return null; |
102 | - } elseif (count($characters) === 1) { |
|
102 | + } elseif(count($characters) === 1) { |
|
103 | 103 | return $characters[0]; |
104 | 104 | } |
105 | 105 | $roll = rand(0, count($characters) - 1); |
@@ -110,16 +110,16 @@ discard block |
||
110 | 110 | { |
111 | 111 | $lowestHp = PHP_INT_MAX; |
112 | 112 | $lowestIndex = PHP_INT_MIN; |
113 | - if (count($this->aliveMembers) === 0) { |
|
113 | + if(count($this->aliveMembers) === 0) { |
|
114 | 114 | return null; |
115 | 115 | } |
116 | - foreach ($this->aliveMembers as $index => $member) { |
|
117 | - if ($member->hitpoints <= $member->maxHitpoints * $threshold && $member->hitpoints < $lowestHp) { |
|
116 | + foreach($this->aliveMembers as $index => $member) { |
|
117 | + if($member->hitpoints <= $member->maxHitpoints * $threshold && $member->hitpoints < $lowestHp) { |
|
118 | 118 | $lowestHp = $member->hitpoints; |
119 | 119 | $lowestIndex = $index; |
120 | 120 | } |
121 | 121 | } |
122 | - if ($lowestIndex === PHP_INT_MIN) { |
|
122 | + if($lowestIndex === PHP_INT_MIN) { |
|
123 | 123 | return null; |
124 | 124 | } |
125 | 125 | return $this->aliveMembers[$lowestIndex]; |
@@ -127,8 +127,8 @@ discard block |
||
127 | 127 | |
128 | 128 | protected function getRowToAttack(): ?int |
129 | 129 | { |
130 | - for ($i = 1; $i <= $this->maxRowSize; $i++) { |
|
131 | - if ($this->hasItems(["positionRow" => $i, "hitpoints>" => 0,])) { |
|
130 | + for($i = 1; $i <= $this->maxRowSize; $i++) { |
|
131 | + if($this->hasItems(["positionRow" => $i, "hitpoints>" => 0, ])) { |
|
132 | 132 | return $i; |
133 | 133 | } |
134 | 134 | } |
@@ -15,8 +15,7 @@ discard block |
||
15 | 15 | * @property int $maxRowSize |
16 | 16 | * @property-read int|null $rowToAttack |
17 | 17 | */ |
18 | -final class Team extends Collection |
|
19 | -{ |
|
18 | +final class Team extends Collection { |
|
20 | 19 | use \Nette\SmartObject; |
21 | 20 | |
22 | 21 | private const LOWEST_HP_THRESHOLD = 0.5; |
@@ -24,8 +23,7 @@ discard block |
||
24 | 23 | protected string $class = Character::class; |
25 | 24 | private int $maxRowSize = 5; |
26 | 25 | |
27 | - public function __construct(public readonly string $name) |
|
28 | - { |
|
26 | + public function __construct(public readonly string $name) { |
|
29 | 27 | parent::__construct(); |
30 | 28 | } |
31 | 29 |
@@ -77,15 +77,15 @@ |
||
77 | 77 | public function setCharacterPosition($id, int $row, int $column): void |
78 | 78 | { |
79 | 79 | if (!$this->hasItems(["id" => $id])) { |
80 | - throw new \OutOfBoundsException("Character $id is not in the team"); |
|
80 | + throw new \OutOfBoundsException("character $id is not in the team"); |
|
81 | 81 | } elseif (count($this->getItems(["positionRow" => $row])) >= $this->maxRowSize) { |
82 | 82 | throw new InvalidCharacterPositionException( |
83 | - "Row $row is full.", |
|
83 | + "row $row is full.", |
|
84 | 84 | InvalidCharacterPositionException::ROW_FULL |
85 | 85 | ); |
86 | 86 | } elseif ($this->hasItems(["positionRow" => $row, "positionColumn" => $column])) { |
87 | 87 | throw new InvalidCharacterPositionException( |
88 | - "Row $row column $column is occupied.", |
|
88 | + "row $row column $column is occupied.", |
|
89 | 89 | InvalidCharacterPositionException::POSITION_OCCUPIED |
90 | 90 | ); |
91 | 91 | } |
@@ -8,8 +8,7 @@ |
||
8 | 8 | * |
9 | 9 | * @author Jakub Konečný |
10 | 10 | */ |
11 | -final class StaticSuccessCalculator implements ISuccessCalculator |
|
12 | -{ |
|
11 | +final class StaticSuccessCalculator implements ISuccessCalculator { |
|
13 | 12 | public function hasHit(Character $character1, Character $character2, ?CharacterAttackSkill $skill = null): bool |
14 | 13 | { |
15 | 14 | return true; |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | protected function setTemplate(string $template): void |
30 | 30 | { |
31 | - if (!is_file($template)) { |
|
31 | + if(!is_file($template)) { |
|
32 | 32 | throw new \RuntimeException("File $template does not exist."); |
33 | 33 | } |
34 | 34 | $this->template = $template; |
@@ -40,22 +40,22 @@ discard block |
||
40 | 40 | return $this->latte->renderToString($this->template, $params); |
41 | 41 | } |
42 | 42 | |
43 | - public function renderItem(CombatLogEntry|string $item): string |
|
43 | + public function renderItem(CombatLogEntry | string $item): string |
|
44 | 44 | { |
45 | - if (!$item instanceof CombatLogEntry) { |
|
45 | + if(!$item instanceof CombatLogEntry) { |
|
46 | 46 | return $item; |
47 | 47 | } |
48 | 48 | $character1 = $item->character1->name; |
49 | 49 | $character2 = $item->character2->name; |
50 | - switch ($item->action) { |
|
50 | + switch($item->action) { |
|
51 | 51 | case CombatActions\Attack::ACTION_NAME: |
52 | 52 | $message = ($item->result) ? "combat.log.attackHits" : "combat.log.attackFails"; |
53 | 53 | $text = $this->translator->translate( |
54 | 54 | $message, |
55 | 55 | $item->amount, |
56 | - ["character1" => $character1, "character2" => $character2,] |
|
56 | + ["character1" => $character1, "character2" => $character2, ] |
|
57 | 57 | ); |
58 | - if ($item->result && $item->character2->hitpoints < 1) { |
|
58 | + if($item->result && $item->character2->hitpoints < 1) { |
|
59 | 59 | $text .= $this->translator->translate("combat.log.characterFalls"); |
60 | 60 | } |
61 | 61 | return $text; |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | $text = $this->translator->translate( |
65 | 65 | $message, |
66 | 66 | $item->amount, |
67 | - ["character1" => $character1, "character2" => $character2, "name" => $item->name,] |
|
67 | + ["character1" => $character1, "character2" => $character2, "name" => $item->name, ] |
|
68 | 68 | ); |
69 | - if ($item->result && $item->character2->hitpoints < 1) { |
|
69 | + if($item->result && $item->character2->hitpoints < 1) { |
|
70 | 70 | $text .= $this->translator->translate("combat.log.characterFalls"); |
71 | 71 | } |
72 | 72 | return $text; |
@@ -75,14 +75,14 @@ discard block |
||
75 | 75 | return $this->translator->translate( |
76 | 76 | $message, |
77 | 77 | 0, |
78 | - ["character1" => $character1, "character2" => $character2, "name" => $item->name,] |
|
78 | + ["character1" => $character1, "character2" => $character2, "name" => $item->name, ] |
|
79 | 79 | ); |
80 | 80 | case CombatActions\Heal::ACTION_NAME: |
81 | 81 | $message = ($item->result) ? "combat.log.healingSuccess" : "combat.log.healingFailure"; |
82 | 82 | return $this->translator->translate( |
83 | 83 | $message, |
84 | 84 | $item->amount, |
85 | - ["character1" => $character1, "character2" => $character2,] |
|
85 | + ["character1" => $character1, "character2" => $character2, ] |
|
86 | 86 | ); |
87 | 87 | case CombatLogEntry::ACTION_POISON: |
88 | 88 | return $this->translator->translate("combat.log.poison", $item->amount, ["character1" => $character1]); |
@@ -11,15 +11,13 @@ |
||
11 | 11 | * |
12 | 12 | * @property-write string $template |
13 | 13 | */ |
14 | -final class TextCombatLogRender implements ICombatLogRender |
|
15 | -{ |
|
14 | +final class TextCombatLogRender implements ICombatLogRender { |
|
16 | 15 | use \Nette\SmartObject; |
17 | 16 | |
18 | 17 | private \Latte\Engine $latte; |
19 | 18 | private string $template = __DIR__ . "/CombatLog.latte"; |
20 | 19 | |
21 | - public function __construct(LatteFactory $latteFactory, private readonly Translator $translator) |
|
22 | - { |
|
20 | + public function __construct(LatteFactory $latteFactory, private readonly Translator $translator) { |
|
23 | 21 | $this->latte = $latteFactory->create(); |
24 | 22 | } |
25 | 23 |
@@ -29,7 +29,7 @@ |
||
29 | 29 | protected function setTemplate(string $template): void |
30 | 30 | { |
31 | 31 | if (!is_file($template)) { |
32 | - throw new \RuntimeException("File $template does not exist."); |
|
32 | + throw new \RuntimeException("file $template does not exist."); |
|
33 | 33 | } |
34 | 34 | $this->template = $template; |
35 | 35 | } |
@@ -12,16 +12,16 @@ |
||
12 | 12 | { |
13 | 13 | public function chooseAction(CombatBase $combat, Character $character): ?ICombatAction |
14 | 14 | { |
15 | - if (!$character->canAct()) { |
|
15 | + if(!$character->canAct()) { |
|
16 | 16 | return null; |
17 | 17 | } |
18 | 18 | /** @var ICombatAction[] $actions */ |
19 | 19 | $actions = $combat->combatActions->toArray(); |
20 | - usort($actions, function (ICombatAction $a, ICombatAction $b): int { |
|
20 | + usort($actions, function(ICombatAction $a, ICombatAction $b): int { |
|
21 | 21 | return $a->getPriority() <=> $b->getPriority(); |
22 | 22 | }); |
23 | - foreach ($actions as $action) { |
|
24 | - if ($action->shouldUse($combat, $character)) { |
|
23 | + foreach($actions as $action) { |
|
24 | + if($action->shouldUse($combat, $character)) { |
|
25 | 25 | return $action; |
26 | 26 | } |
27 | 27 | } |
@@ -8,8 +8,7 @@ |
||
8 | 8 | * |
9 | 9 | * @author Jakub Konečný |
10 | 10 | */ |
11 | -final class CombatActionSelector implements ICombatActionSelector |
|
12 | -{ |
|
11 | +final class CombatActionSelector implements ICombatActionSelector { |
|
13 | 12 | public function chooseAction(CombatBase $combat, Character $character): ?ICombatAction |
14 | 13 | { |
15 | 14 | if (!$character->canAct()) { |
@@ -41,7 +41,7 @@ |
||
41 | 41 | try { |
42 | 42 | /** @var CharacterEffect $item */ |
43 | 43 | $item = Arrays::get($this->items, $index); |
44 | - } catch (\Nette\InvalidArgumentException) { |
|
44 | + } catch(\Nette\InvalidArgumentException) { |
|
45 | 45 | throw new \OutOfRangeException("Offset invalid or out of range."); |
46 | 46 | } |
47 | 47 | parent::offsetUnset($index); |
@@ -13,8 +13,7 @@ |
||
13 | 13 | { |
14 | 14 | protected string $class = CharacterEffect::class; |
15 | 15 | |
16 | - public function __construct(private readonly Character $character) |
|
17 | - { |
|
16 | + public function __construct(private readonly Character $character) { |
|
18 | 17 | parent::__construct(); |
19 | 18 | } |
20 | 19 |
@@ -57,7 +57,7 @@ |
||
57 | 57 | |
58 | 58 | public function decreaseCooldown(): void |
59 | 59 | { |
60 | - if ($this->cooldown > 0) { |
|
60 | + if($this->cooldown > 0) { |
|
61 | 61 | $this->cooldown--; |
62 | 62 | } |
63 | 63 | } |
@@ -15,15 +15,13 @@ |
||
15 | 15 | * @property-read string $skillType |
16 | 16 | * @property-read bool $usable |
17 | 17 | */ |
18 | -abstract class BaseCharacterSkill |
|
19 | -{ |
|
18 | +abstract class BaseCharacterSkill { |
|
20 | 19 | use \Nette\SmartObject; |
21 | 20 | |
22 | 21 | protected int $level; |
23 | 22 | protected int $cooldown = 0; |
24 | 23 | |
25 | - public function __construct(protected BaseSkill $skill, int $level) |
|
26 | - { |
|
24 | + public function __construct(protected BaseSkill $skill, int $level) { |
|
27 | 25 | $this->setLevel($level); |
28 | 26 | $this->resetCooldown(); |
29 | 27 | } |