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(){ 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){ if(!isset($this->modifiers[$type])){ throw new \UnexpectedValueException($type . " is not applicable to " . $this->getEntity()); } $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; } }