22declare(strict_types=1);
29use
function array_sum;
39 public const MODIFIER_ARMOR = 1;
40 public const MODIFIER_STRENGTH = 2;
41 public const MODIFIER_WEAKNESS = 3;
42 public const MODIFIER_RESISTANCE = 4;
43 public const MODIFIER_ABSORPTION = 5;
44 public const MODIFIER_ARMOR_ENCHANTMENTS = 6;
45 public const MODIFIER_CRITICAL = 7;
46 public const MODIFIER_TOTEM = 8;
47 public const MODIFIER_WEAPON_ENCHANTMENTS = 9;
48 public const MODIFIER_PREVIOUS_DAMAGE_COOLDOWN = 10;
49 public const MODIFIER_ARMOR_HELMET = 11;
51 public const CAUSE_CONTACT = 0;
52 public const CAUSE_ENTITY_ATTACK = 1;
53 public const CAUSE_PROJECTILE = 2;
54 public const CAUSE_SUFFOCATION = 3;
55 public const CAUSE_FALL = 4;
56 public const CAUSE_FIRE = 5;
57 public const CAUSE_FIRE_TICK = 6;
58 public const CAUSE_LAVA = 7;
59 public const CAUSE_DROWNING = 8;
60 public const CAUSE_BLOCK_EXPLOSION = 9;
61 public const CAUSE_ENTITY_EXPLOSION = 10;
62 public const CAUSE_VOID = 11;
63 public const CAUSE_SUICIDE = 12;
64 public const CAUSE_MAGIC = 13;
65 public const CAUSE_CUSTOM = 14;
66 public const CAUSE_STARVATION = 15;
67 public const CAUSE_FALLING_BLOCK = 16;
69 private float $baseDamage;
70 private float $originalBase;
73 private array $originals;
74 private int $attackCooldown = 10;
83 private array $modifiers = []
86 $this->baseDamage = $this->originalBase = $damage;
87 $this->originals = $modifiers;
90 public function getCause() : int{
98 return $this->baseDamage;
107 $this->baseDamage = $damage;
114 return $this->originalBase;
121 return $this->originals;
124 public function getOriginalModifier(
int $type) : float{
125 return $this->originals[$type] ?? 0.0;
132 return $this->modifiers;
135 public function getModifier(
int $type) : float{
136 return $this->modifiers[$type] ?? 0.0;
139 public function setModifier(
float $damage,
int $type) : void{
140 $this->modifiers[$type] = $damage;
143 public function isApplicable(
int $type) : bool{
144 return isset($this->modifiers[$type]);
147 public function getFinalDamage() : float{
148 return max(0, $this->baseDamage + array_sum($this->modifiers));
155 switch($this->cause){
156 case self::CAUSE_FIRE_TICK:
157 case self::CAUSE_SUFFOCATION:
158 case self::CAUSE_DROWNING:
159 case self::CAUSE_STARVATION:
160 case self::CAUSE_FALL:
161 case self::CAUSE_VOID:
162 case self::CAUSE_MAGIC:
163 case self::CAUSE_SUICIDE:
175 return $this->attackCooldown;
184 $this->attackCooldown = $attackCooldown;
__construct(Entity $entity, private int $cause, float $damage, private array $modifiers=[])
setBaseDamage(float $damage)
setAttackCooldown(int $attackCooldown)