private function attackSamurai(Player $player) { $gold = 0; $victory = false; $drop = false; $drop_display = null; $damage = [rand(1, $player->getStrength()), rand(10, 10 + round($player->getStrength() * 1.2))]; if (rand(0, 1)) { $damage[] = rand(30 + round($player->getStrength() * 0.2), 30 + round($player->getStrength() * 1.7)); } else { //Instant death. $damage[] = abs($player->health - $damage[0] - $damage[1]); } for ($i = 0; $i < count($damage) && $player->health > 0; ++$i) { $player->harm($damage[$i]); } if ($player->health > 0) { // Ninja still has health after all attacks $victory = true; $gold = rand(50, 50 + $damage[2] + $damage[1]); $player->addKills(1); $player->setGold($player->gold + $gold); $inventory = new Inventory($player); // If samurai dmg high, but ninja lived, give rewards if ($damage[2] > self::SAMURAI_REWARD_DMG) { $drop = true; if (rand(0, 1)) { $drop_display = 'mushroom powder'; $dropItem = 'amanita'; } else { $drop_display = 'a strange herb'; $dropItem = 'ginsengroot'; } $inventory->add($dropItem, 1); } // If the final damage was the exact max damage if ($damage[2] == $player->getStrength() * 3) { $drop = true; $drop_display = 'a black scroll'; $inventory->add('dimmak', 1); } } $player->save(); return ['npc.samurai.tpl', ['samurai_damage_array' => $damage, 'gold' => $gold, 'victory' => $victory, 'ninja_str' => $player->getStrength(), 'level' => $player->level, 'attacker_kills' => $player->kills, 'drop' => $drop, 'drop_display' => $drop_display]]; }