public function testNpcsAlwaysHaveHealth() { $npcs = NpcFactory::npcs(); foreach ($npcs as $npc) { $this->assertGreaterThan(0, $npc->health(), 'For npc: [' . $npc->identity() . ']'); } }
public function __construct($content) { if (is_string($content) && trim($content)) { NpcFactory::fleshOut($content, $this); } else { NpcFactory::fleshOutFromData($content, $this); } }
$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! *** // **********************************************************
/** * Npcs that have essentially nothing interesting or useful defined about them yet. **/ public static function allTrivialNpcs() { $npcs = NpcFactory::allSortedByDifficulty(); $trivials = array_filter($npcs, function ($npc) { return (bool) ($npc->difficulty() < 1); }); return $trivials; }
return inventory_counts($char_id); } } // Redirect for any non-admins. $char_id = self_char_id(); $self = null; if (positive_int($char_id)) { $self = new Player($char_id); } if ($self instanceof Player && $self->isAdmin()) { // Admin possibilities start here. $view_char = null; $dupes = AdminViews::duped_ips(); $stats = AdminViews::high_rollers(); $npcs = NpcFactory::allNonTrivialNpcs(); $trivial_npcs = NpcFactory::allTrivialNpcs(); $char_name = in('char_name'); if (is_string($char_name) && trim($char_name)) { $view_char = get_char_id($char_name); } // If a request is made to view a character's info, show it. $view_char = $view_char ? $view_char : in('view'); $char_infos = $char_inventory = $message = null; if ($view_char) { $char_infos = AdminViews::split_char_infos($view_char); $char_inventory = AdminViews::char_inventory($view_char); $message = $char_infos[0]['messages']; // Split the message out as a separate var for space reasons unset($char_infos[0]['messages']); } display_page('ninjamaster.tpl', 'Admin Actions', ['stats' => $stats, 'char_infos' => $char_infos, 'dupes' => $dupes, 'char_inventory' => $char_inventory, 'char_name' => $char_name, 'npcs' => $npcs, 'trivial_npcs' => $trivial_npcs, 'message' => $message]);
$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)); }