|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace HeroesofAbenez\Combat; |
|
5
|
|
|
|
|
6
|
|
|
use Nexendrie\Utils\Constants; |
|
7
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Weapon |
|
11
|
|
|
* |
|
12
|
|
|
* @author Jakub Konečný |
|
13
|
|
|
* @property-read bool $ranged |
|
14
|
|
|
*/ |
|
15
|
1 |
|
class Weapon extends Equipment { |
|
16
|
|
|
public const TYPE_SWORD = "sword"; |
|
17
|
|
|
public const TYPE_AXE = "axe"; |
|
18
|
|
|
public const TYPE_CLUB = "club"; |
|
19
|
|
|
public const TYPE_DAGGER = "dagger"; |
|
20
|
|
|
public const TYPE_SPEAR = "spear"; |
|
21
|
|
|
public const TYPE_STAFF = "staff"; |
|
22
|
|
|
public const TYPE_BOW = "bow"; |
|
23
|
|
|
public const TYPE_CROSSBOW = "crossbow"; |
|
24
|
|
|
public const TYPE_THROWING_KNIFE = "throwing knife"; |
|
25
|
|
|
|
|
26
|
|
|
public function isRanged(): bool { |
|
27
|
1 |
|
return in_array($this->type, [ |
|
28
|
1 |
|
static::TYPE_STAFF, static::TYPE_BOW, static::TYPE_CROSSBOW, static::TYPE_THROWING_KNIFE, |
|
29
|
1 |
|
], true); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
protected function configureOptions(OptionsResolver $resolver): void { |
|
33
|
1 |
|
parent::configureOptions($resolver); |
|
34
|
1 |
|
$resolver->setAllowedTypes("type", ["string"]); |
|
35
|
1 |
|
$resolver->setAllowedValues("type", function(?string $value) { |
|
36
|
1 |
|
return is_null($value) OR in_array($value, $this->getAllowedTypes(), true); |
|
37
|
1 |
|
}); |
|
38
|
1 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
protected function getAllowedTypes(): array { |
|
41
|
1 |
|
return Constants::getConstantsValues(static::class, "TYPE_"); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
?> |