public function findBestSpellToCast(Boss $boss, EffectTracker $effectTracker) { if ($this->recharge > 0 && $effectTracker->has(Spells\RechargeSpell::class) === false && $this->mana >= 229 && $this->mana < 402) { $this->recharge--; return new Spells\RechargeSpell(); } if ($this->shield > 0 && $effectTracker->has(Spells\ShieldSpell::class) === false && $this->health <= $boss->getDamage() * 3 && $this->mana >= 113) { $this->shield--; return new Spells\ShieldSpell(); } if ($this->drain > 0 && $effectTracker->has(Spells\DrainSpell::class) === false && $this->mana >= 73) { $this->drain--; return new Spells\DrainSpell(); } if ($boss->getHealth() <= 8 && $this->mana >= 53) { return new Spells\MagicMissileSpell(); } if ($effectTracker->has(Spells\PoisonSpell::class) === false && $this->mana >= 173) { return new Spells\PoisonSpell(); } if ($this->mana >= 53) { return new Spells\MagicMissileSpell(); } throw new OutOfManaException(); }
public function cast(Player $player, Boss $boss, EffectTracker $effects) { $player->reduceMana($this->getCost()); $effects->add($this); }
protected function simulateHarderBattle($health, $mana, $bossStats) { $numberOfRecharge = 0; $numberOfShield = 0; $numberOfDrain = 0; $iterations = 0; $shieldFailed = true; while (true) { $iterations++; $player = new PlayerTwo($health, $mana, $numberOfRecharge, $numberOfShield, $numberOfDrain, $this->output); $boss = new Boss($bossStats['Hit Points'], $bossStats['Damage'], $this->output); $effects = new EffectTracker($player, $boss); $spells = []; try { while (true) { $player->reduceHealth(1); if ($player->isDead()) { break; } $effects->apply(); if ($boss->isDead()) { break; } $spell = $player->findBestSpellToCast($boss, $effects); $spells[] = get_class($spell); $spell->cast($player, $boss, $effects); $effects->apply(); if ($boss->isDead()) { break; } $boss->attack($player); if ($player->isDead()) { break; } } } catch (OutOfManaException $e) { $numberOfRecharge++; continue; } if ($boss->isDead()) { break; } if ($shieldFailed === false) { $numberOfDrain++; $shieldFailed = true; } else { $numberOfShield++; $shieldFailed = false; } $numberOfRecharge = 0; } return $player->getManaSpent(); }