entity = $entity; $this->cause = $cause; if(is_array($damage)){ $this->modifiers = $damage; }else{ $this->modifiers = [ self::MODIFIER_BASE => $damage ]; } $this->originals = $this->modifiers; if(!isset($this->modifiers[self::MODIFIER_BASE])){ throw new \InvalidArgumentException("BASE Damage modifier missing"); } } /** * @return int */ public function getCause() : int{ return $this->cause; } /** * @param int $type * * @return float */ public function getOriginalDamage(int $type = self::MODIFIER_BASE) : float{ return $this->originals[$type] ?? 0.0; } /** * @param int $type * * @return float */ public function getDamage(int $type = self::MODIFIER_BASE) : float{ return $this->modifiers[$type] ?? 0.0; } /** * @param float $damage * @param int $type */ public function setDamage(float $damage, int $type = self::MODIFIER_BASE){ $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 array_sum($this->modifiers); } }