/** * Run the random encounter * * @note * Currently only random enc. is an Oni attack! Yay! They take turns and a * kill and do a little damage. */ private function randomEncounter(Player $player) { $oni_health_loss = rand(1, self::ONI_DAMAGE_CAP); $multiple_rewards = false; $oni_killed = false; $item = null; $player->changeTurns(-1 * self::ONI_TURN_LOSS); $player->harm($oni_health_loss); $player->subtractKills(self::ONI_KILL_LOSS); if ($player->health > 0) { // if you survive $inventory = new Inventory($player); if ($player->turns > self::HIGH_TURNS) { // And your turns are high/you are energetic, you can kill them. $oni_killed = true; $item = Item::findByIdentity('dimmak'); $quantity = 1; $inventory->add($item->identity(), $quantity); } else { if ($player->turns > floor(self::HIGH_TURNS / 2) && rand() & 1) { // If your turns are somewhat high/you have some energy, 50/50 chance you can kill them. $oni_killed = true; $item = Item::findByIdentity('ginsengroot'); $multiple_rewards = true; $quantity = 4; $inventory->add($item->identity(), $quantity); } } } $player->save(); return ['npc.oni.tpl', ['victory' => $oni_killed, 'item' => $item, 'multiple_rewards' => $multiple_rewards]]; }