/** * @param Combatant $defender * @return bool|mixed */ public function attack(Combatant $defender) { // Stunning blow $rand = mt_rand(1, 100); if ($rand <= 2) { $defender->stun(); } return parent::attack($defender); }
public function getStrength() { // Lucky Strike $strength = parent::getStrength(); $rand = mt_rand(1, 100); if ($rand <= 5) { $strength = $strength * 2; } return $strength; }
/** * @param Combatant $attacker * @return bool */ public function defend(Combatant $attacker) { $defended = parent::defend($attacker); // Counter attack if ($defended) { $health = $attacker->getHealth(); $attacker->setHealth($health - 10); } return $defended; }
public function describeCombatant(Combatant $combatant) { $this->displayTemplate(['name' => $combatant->getName(), 'class' => get_class($combatant), 'health' => $combatant->getHealth(), 'strength' => $combatant->getStrength(), 'defence' => $combatant->getDefence(), 'speed' => $combatant->getSpeed(), 'luck' => round($combatant->getLuck(), 2)], self::COMBATANT_DESCRIPTION_TPL); }
/** * @param Combatant $defender * @return bool|mixed */ public function attack(Combatant $defender) { // Damage = Attacker strength – Defender Defense $damage = $this->getStrength() - $defender->getDefense(); if ($defender->defend($this)) { return false; } $health = $defender->getHealth(); $defender->setHealth($health - $damage); return $damage; }