public function testForPresenceOfSomeNPCData() { $this->assertTrue(array_key_exists('fireflies', NpcFactory::npcsData()), 'Fireflies not present in npcs data array for some reason'); $this->assertTrue(array_key_exists('firefly', NpcFactory::npcsData()), 'Firefly not present in npcs data array for some reason'); $this->assertTrue(array_key_exists('spider', NpcFactory::npcsData())); $this->assertTrue(array_key_exists('kappa', NpcFactory::npcsData())); $this->assertTrue(array_key_exists('tengu', NpcFactory::npcsData())); if (defined('DEBUG') && DEBUG) { $this->assertTrue(array_key_exists('pig', NpcFactory::npcsData())); $this->assertTrue(array_key_exists('merchant2', NpcFactory::npcsData())); $this->assertTrue(array_key_exists('peasant2', NpcFactory::npcsData())); } }
public static function npcs($sort = null) { $npcs_data = NpcFactory::npcsData(); $npcs = []; foreach ($npcs_data as $identity => $npc_data) { assert((bool) $identity); $npcs[$identity] = new Npc($npc_data); } if ($sort) { $npc = reset($npcs); if (is_callable([$npc, $sort])) { // Sort the npcs by difficulty usort($npcs, function ($a, $b) use($sort) { $anum = $a->{$sort}(); $bnum = $b->{$sort}(); if ($anum == $bnum) { return 0; } return $anum < $bnum ? -1 : 1; }); } } return $npcs; }
$health = 1; $victim = in('victim'); $random_encounter = rand(1, 400) == 1; $combat_data = array(); $char_id = self_char_id(); $player = new Player($char_id); $error_template = 'npc.no-one.tpl'; // Error template also used down below. $npc_template = $error_template; // Error condition by default. $turns = $player->turns(); $is_villager = false; $ninja_str = $player->getStrength(); $ninja_health = $player->vo->health; $static_npcs = array('peasant', 'thief', 'merchant', 'guard', 'samurai'); $npcs = NpcFactory::npcsData(); $possible_npcs = array_merge($static_npcs, array_keys($npcs)); $victim = restrict_to($victim, $possible_npcs); // Filter to only the correct options. if ($turns > 0 && !empty($victim)) { // Strip stealth when attacking samurai or oni if ($player->hasStatus('stealth') && (strtolower($victim) == 'samurai' || strtolower($victim) == 'oni')) { $player->subtractStatus(STEALTH); } $attacker_str = $player->getStrength(); $attacker_health = $player->vo->health; $attacker_gold = $player->vo->gold; // Perform a random encounter (currently only oni). if ($random_encounter) { // *** ONI, M********a! *** // **********************************************************
$match_string = in('enemy_match', null, 'no filter'); $add_enemy = in('add_enemy', null, 'toInt'); $remove_enemy = in('remove_enemy', null, 'toInt'); $enemy_limit = 20; $max_enemies = false; $enemy_list = null; if ($match_string) { $found_enemies = get_enemy_matches($match_string); } else { $found_enemies = null; } if (is_numeric($remove_enemy) && $remove_enemy != 0) { remove_enemy($remove_enemy); } if (is_numeric($add_enemy) && $add_enemy != 0) { add_enemy($add_enemy); } if (count($enemy_list) > $enemy_limit - 1) { $max_enemies = true; } $enemy_list = get_current_enemies(); $enemyCount = $enemy_list->rowCount(); $enemy_list = $enemy_list->fetchAll(); $recent_attackers = get_recent_attackers($char)->fetchAll(); // Add enemies at the bottom of the fight page. // Array that simulates database display information for switching out for an npc database solution. $npcs = array(array('name' => 'Peasant', 'identity' => 'peasant', 'image' => 'fighter.png'), array('name' => 'Thief', 'identity' => 'thief', 'image' => 'thief.png'), array('name' => 'Merchant', 'identity' => 'merchant', 'image' => 'merchant.png'), array('name' => "Guard", 'identity' => 'guard', 'image' => 'guard.png'), array('name' => 'Samurai', 'identity' => 'samurai', 'image' => 'samurai.png')); // Generic/abstracted npcs $other_npcs = NpcFactory::npcsData(); display_page('enemies.tpl', 'Fight', get_certain_vars(get_defined_vars(), array('char_name', 'npcs', 'other_npcs', 'char_info', 'found_enemies', 'active_ninjas', 'recent_attackers', 'enemy_list', 'peers')), array('quickstat' => false)); }