-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpg.php
50 lines (41 loc) · 958 Bytes
/
rpg.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
require __DIR__.'/../vendor/autoload.php';
use Gksh\Bitmask\TinyBitmask;
enum AttackType: int
{
case None = 0;
case Melee = 1;
case Fire = 2;
case Ice = 4;
case Poison = 8;
}
class AttackTypes extends TinyBitmask
{
public function add(AttackType $type): AttackTypes
{
return $this->set($type->value);
}
public function remove(AttackType $type): AttackTypes
{
return $this->unset($type->value);
}
public function allows(AttackType $type): bool
{
return $this->has($type->value);
}
}
class Weapon
{
public function __construct(public AttackTypes $attackTypes)
{
}
}
$fireSword = new Weapon(
AttackTypes::make()
->add(AttackType::Melee)
->add(AttackType::Fire)
);
dump([
'allows_fire' => $fireSword->attackTypes->allows(AttackType::Fire), // true
'allows_ice' => $fireSword->attackTypes->allows(AttackType::Ice), // false
]);