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
|
|
|
* @property-read string $damageStat |
15
|
|
|
*/ |
16
|
1 |
|
class Weapon extends Equipment { |
17
|
|
|
public const TYPE_SWORD = "sword"; |
18
|
|
|
public const TYPE_AXE = "axe"; |
19
|
|
|
public const TYPE_CLUB = "club"; |
20
|
|
|
public const TYPE_DAGGER = "dagger"; |
21
|
|
|
public const TYPE_SPEAR = "spear"; |
22
|
|
|
public const TYPE_STAFF = "staff"; |
23
|
|
|
public const TYPE_BOW = "bow"; |
24
|
|
|
public const TYPE_CROSSBOW = "crossbow"; |
25
|
|
|
public const TYPE_THROWING_KNIFE = "throwing knife"; |
26
|
|
|
public const TYPE_INSTRUMENT = "instrument"; |
27
|
|
|
public const MELEE_TYPES = [ |
28
|
|
|
self::TYPE_SWORD, self::TYPE_AXE, self::TYPE_CLUB, self::TYPE_DAGGER, self::TYPE_SPEAR, |
29
|
|
|
]; |
30
|
|
|
public const RANGED_TYPES = [ |
31
|
|
|
self::TYPE_STAFF, self::TYPE_BOW, self::TYPE_CROSSBOW, self::TYPE_THROWING_KNIFE, self::TYPE_INSTRUMENT, |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
protected function isRanged(): bool { |
35
|
1 |
|
return in_array($this->type, static::RANGED_TYPES, true); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
protected function getDamageStat(): string { |
39
|
1 |
|
return match($this->type) { |
40
|
1 |
|
static::TYPE_STAFF => Character::STAT_INTELLIGENCE, |
41
|
1 |
|
static::TYPE_CLUB => Character::STAT_CONSTITUTION, |
42
|
1 |
|
static::TYPE_BOW, static::TYPE_THROWING_KNIFE => Character::STAT_DEXTERITY, |
43
|
1 |
|
static::TYPE_INSTRUMENT => Character::STAT_CHARISMA, |
44
|
1 |
|
default => Character::STAT_STRENGTH, |
45
|
|
|
}; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
protected function configureOptions(OptionsResolver $resolver): void { |
49
|
1 |
|
parent::configureOptions($resolver); |
50
|
1 |
|
$resolver->setAllowedTypes("type", "string"); |
51
|
1 |
|
$resolver->setAllowedValues("type", function(string $value): bool { |
52
|
1 |
|
return in_array($value, $this->getAllowedTypes(), true); |
53
|
1 |
|
}); |
54
|
1 |
|
} |
55
|
|
|
|
56
|
|
|
protected function getAllowedTypes(): array { |
57
|
1 |
|
return Constants::getConstantsValues(static::class, "TYPE_"); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
?> |