/** * 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->subtractTurns(self::ONI_TURN_LOSS); $player->harm($oni_health_loss); $player->subtractKills(self::ONI_KILL_LOSS); if ($player->health() > 0) { // if you survive if ($player->turns() > self::HIGH_TURNS) { // And your turns are high/you are energetic, you can kill them. $oni_killed = true; $item = new Item('dimmak'); $quantity = 1; add_item($player->id(), $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 = new Item('ginsengroot'); $multiple_rewards = true; $quantity = 4; add_item($player->id(), $item->identity(), $quantity); } } } $player->save(); return ['npc.oni.tpl', ['victory' => $oni_killed, 'item' => $item, 'multiple_rewards' => $multiple_rewards]]; }
public function testRetrievingAShuriken() { $shuriken = new Item('shuriken'); $this->assertTrue($shuriken instanceof Item); $this->assertEquals('shuriken', $shuriken->identity()); }
/** * @return void */ private function transferOwnership(Player $giver, Player $recipient, Item $item, $quantity) { $giver_inventory = new Inventory($giver); $taker_inventory = new Inventory($recipient); $taker_inventory->add($item->identity(), $quantity); $giver_inventory->remove($item->identity(), $quantity); }