entity = $entity; $this->cause = $cause; $this->baseDamage = $this->originalBase = $damage; $this->modifiers = $modifiers; $this->originals = $this->modifiers; } /** * @return int */ public function getCause() : int{ return $this->cause; } /** * Returns the base amount of damage applied, before modifiers. * * @return float */ public function getBaseDamage() : float{ return $this->baseDamage; } /** * Sets the base amount of damage applied, optionally recalculating modifiers. * * TODO: add ability to recalculate modifiers when this is set * * @param float $damage */ public function setBaseDamage(float $damage) : void{ $this->baseDamage = $damage; } /** * Returns the original base amount of damage applied, before alterations by plugins. * * @return float */ public function getOriginalBaseDamage() : float{ return $this->originalBase; } /** * @return float[] */ public function getOriginalModifiers() : array{ return $this->originals; } /** * @param int $type * * @return float */ public function getOriginalModifier(int $type) : float{ return $this->originals[$type] ?? 0.0; } /** * @return float[] */ public function getModifiers() : array{ return $this->modifiers; } /** * @param int $type * * @return float */ public function getModifier(int $type) : float{ return $this->modifiers[$type] ?? 0.0; } /** * @param float $damage * @param int $type */ public function setModifier(float $damage, int $type) : void{ $this->modifiers[$type] = $damage; } /** * @param int $type * * @return bool */ public function isApplicable(int $type) : bool{ return isset($this->modifiers[$type]); } /** * @return float */ public function getFinalDamage() : float{ return $this->baseDamage + array_sum($this->modifiers); } /** * Returns whether an entity can use armour points to reduce this type of damage. * @return bool */ public function canBeReducedByArmor() : bool{ switch($this->cause){ case self::CAUSE_FIRE_TICK: case self::CAUSE_SUFFOCATION: case self::CAUSE_DROWNING: case self::CAUSE_STARVATION: case self::CAUSE_FALL: case self::CAUSE_VOID: case self::CAUSE_MAGIC: case self::CAUSE_SUICIDE: return false; } return true; } /** * Returns the cooldown in ticks before the target entity can be attacked again. * * @return int */ public function getAttackCooldown() : int{ return $this->attackCooldown; } /** * Sets the cooldown in ticks before the target entity can be attacked again. * * NOTE: This value is not used in non-Living entities * * @param int $attackCooldown */ public function setAttackCooldown(int $attackCooldown) : void{ $this->attackCooldown = $attackCooldown; } }