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"); } if($entity->hasEffect(Effect::DAMAGE_RESISTANCE)){ $this->setDamage(-($this->getDamage(self::MODIFIER_BASE) * 0.20 * $entity->getEffect(Effect::DAMAGE_RESISTANCE)->getEffectLevel()), self::MODIFIER_RESISTANCE); } } /** * @return int */ public function getCause(){ return $this->cause; } /** * @param int $type * * @return int */ public function getOriginalDamage($type = self::MODIFIER_BASE){ if(isset($this->originals[$type])){ return $this->originals[$type]; } return 0; } /** * @param int $type * * @return int */ public function getDamage($type = self::MODIFIER_BASE){ if(isset($this->modifiers[$type])){ return $this->modifiers[$type]; } return 0; } /** * @param float $damage * @param int $type * * @throws \UnexpectedValueException */ public function setDamage($damage, $type = self::MODIFIER_BASE){ $this->modifiers[$type] = $damage; } /** * @param int $type * * @return bool */ public function isApplicable($type){ return isset($this->modifiers[$type]); } /** * @return int */ public function getFinalDamage(){ $damage = 0; foreach($this->modifiers as $type => $d){ $damage += $d; } return $damage; } }