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
|
|
|
|
27
|
|
|
public function isRanged(): bool { |
28
|
1 |
|
return in_array($this->type, [ |
29
|
1 |
|
static::TYPE_STAFF, static::TYPE_BOW, static::TYPE_CROSSBOW, static::TYPE_THROWING_KNIFE, |
30
|
1 |
|
], true); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function getDamageStat(): string { |
34
|
1 |
|
switch($this->type) { |
35
|
1 |
|
case static::TYPE_STAFF: |
36
|
|
|
return Character::STAT_INTELLIGENCE; |
37
|
1 |
|
case static::TYPE_CLUB: |
38
|
|
|
return Character::STAT_CONSTITUTION; |
39
|
1 |
|
case static::TYPE_BOW: |
40
|
1 |
|
case static::TYPE_THROWING_KNIFE: |
41
|
|
|
return Character::STAT_DEXTERITY; |
42
|
|
|
default: |
43
|
1 |
|
return Character::STAT_STRENGTH; |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
protected function configureOptions(OptionsResolver $resolver): void { |
48
|
1 |
|
parent::configureOptions($resolver); |
49
|
1 |
|
$resolver->setAllowedTypes("type", "string"); |
50
|
1 |
|
$resolver->setAllowedValues("type", function(string $value) { |
51
|
1 |
|
return in_array($value, $this->getAllowedTypes(), true); |
52
|
1 |
|
}); |
53
|
1 |
|
} |
54
|
|
|
|
55
|
|
|
protected function getAllowedTypes(): array { |
56
|
1 |
|
return Constants::getConstantsValues(static::class, "TYPE_"); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
?> |