public function __construct($content) { if (is_string($content) && trim($content)) { NpcFactory::fleshOut($content, $this); } else { NpcFactory::fleshOutFromData($content, $this); } }
/** * @TODO Document me! */ private function configure() { $char = Player::find(SessionFactory::getSession()->get('player_id')); $peers = $char ? $this->getNearbyPeers($char->id()) : []; $active_ninjas = Player::findActive(5, true); $char_info = $char ? $char->data() : []; $other_npcs = NpcFactory::npcsData(); $npcs = NpcFactory::customNpcs(); $enemy_list = $char ? $this->getCurrentEnemies($char->id()) : []; $recent_attackers = $char ? $this->getRecentAttackers($char) : []; return ['logged_in' => (bool) $char, 'enemy_list' => $enemy_list, 'char_name' => $char ? $char->name() : '', 'npcs' => $npcs, 'other_npcs' => $other_npcs, 'char_info' => $char_info, 'active_ninjas' => $active_ninjas, 'recent_attackers' => $recent_attackers, 'enemy_list' => $enemy_list, 'peers' => $peers]; }
/** * @TODO Document me! */ private function configure() { $char = Player::find(self_char_id()); // Array that simulates database display information for switching out for an npc database solution. $npcs = [['name' => 'Peasant', 'identity' => 'peasant', 'image' => 'fighter.png'], ['name' => 'Thief', 'identity' => 'thief', 'image' => 'thief.png'], ['name' => 'Merchant', 'identity' => 'merchant', 'image' => 'merchant.png'], ['name' => 'Guard', 'identity' => 'guard', 'image' => 'guard.png'], ['name' => 'Samurai', 'identity' => 'samurai', 'image' => 'samurai.png']]; $peers = $char ? $this->getNearbyPeers($char->id()) : []; $active_ninjas = Player::findActive(5, true); $char_info = $char ? $char->dataWithClan() : []; // Generic/abstracted npcs $other_npcs = NpcFactory::npcsData(); $enemy_list = $char ? $this->getCurrentEnemies($char->id()) : []; $enemy_count = rco($enemy_list); $recent_attackers = $char ? $this->getRecentAttackers($char) : []; return ['logged_in' => (bool) $char, 'enemy_list' => $enemy_list, 'enemy_count' => $enemy_count, 'char_name' => $char ? $char->name() : '', 'npcs' => $npcs, 'other_npcs' => $other_npcs, 'char_info' => $char_info, 'active_ninjas' => $active_ninjas, 'recent_attackers' => $recent_attackers, 'enemy_list' => $enemy_list, 'peers' => $peers, 'max_enemies' => self::ENEMY_LIMIT <= $enemy_count]; }
/** * Display the main admin area * * Includes player viewing, account duplicates checking, npc balacing * * @return Response */ public function index() { $request = RequestWrapper::$request; if (!$this->self || !$this->self->isAdmin()) { return new RedirectResponse(WEB_ROOT); } $error = null; $char_infos = null; $char_inventory = null; $first_message = null; $first_char = null; $first_account = null; $first_description = null; $dupes = AdminViews::dupedIps(); $stats = AdminViews::highRollers(); $npcs = NpcFactory::allNonTrivialNpcs(); $trivial_npcs = NpcFactory::allTrivialNpcs(); $char_ids = preg_split("/[,\\s]+/", $request->get('view')); $char_name = trim($request->get('char_name')); if ($char_name) { // View a target non-self character $first_char = Player::findByName($char_name); if (null !== $first_char && null !== $first_char->id()) { $char_ids = [$first_char->id()]; } } if (is_array($char_ids)) { // Get a different first character if an array is specified $first_char = $first_char ? $first_char : Player::find(reset($char_ids)); if ($first_char) { assert($first_char instanceof Player); $first_account = Account::findByChar($first_char); $char_inventory = AdminViews::charInventory($first_char); $first_message = $first_char->messages; $first_description = $first_char->description; } // All the rest multi-character table view try { $char_infos = AdminViews::charInfos($char_ids); } catch (InvalidArgumentException $e) { $error = $e->getMessage(); } } $parts = ['error' => $error, 'stats' => $stats, 'first_char' => $first_char, 'first_description' => $first_description, 'first_message' => $first_message, 'first_account' => $first_account, 'char_infos' => $char_infos, 'dupes' => $dupes, 'char_inventory' => $char_inventory, 'char_name' => $char_name, 'npcs' => $npcs, 'trivial_npcs' => $trivial_npcs]; return new StreamedViewResponse('Admin Actions', 'ninjamaster.tpl', $parts); }
/** * Display the main admin area * * Includes player viewing, account duplicates checking, npc balacing * * @return ViewSpec|RedirectResponse */ public function index() { $result = $this->requireAdmin($this->self); if ($result instanceof RedirectResponse) { return $result; } $viewChar = null; // View a target non-self character $charName = in('char_name'); if (is_string($charName) && trim($charName)) { $viewChar = get_char_id($charName); } // If a request is made to view a character's info, show it. $viewChar = first_value($viewChar, in('view')); $dupes = AdminViews::duped_ips(); $stats = AdminViews::high_rollers(); $npcs = NpcFactory::allNonTrivialNpcs(); $trivialNpcs = NpcFactory::allTrivialNpcs(); $charInfos = null; $charInventory = null; $firstMessage = null; $firstChar = null; $firstAccount = null; $firstDescription = null; if ($viewChar) { $ids = explode(',', $viewChar); $firstChar = new Player(reset($ids)); $firstAccount = AccountFactory::findByChar($firstChar); $charInfos = AdminViews::split_char_infos($viewChar); $charInventory = AdminViews::char_inventory($viewChar); $firstMessage = $firstChar->message(); $firstDescription = $firstChar->description(); } $parts = ['stats' => $stats, 'first_char' => $firstChar, 'first_description' => $firstDescription, 'first_message' => $firstMessage, 'first_account' => $firstAccount, 'char_infos' => $charInfos, 'dupes' => $dupes, 'char_inventory' => $charInventory, 'char_name' => $charName, 'npcs' => $npcs, 'trivial_npcs' => $trivialNpcs]; return ['title' => 'Admin Actions', 'template' => 'ninjamaster.tpl', 'parts' => $parts, 'options' => null]; }
/** * Obtain the npcs data. * * @return Array */ private function npcs() { return ['abstract_npcs' => NpcFactory::npcsData(), 'custom_npcs' => NpcFactory::customNpcs()]; }
public function testFleshOutFailure() { $this->setExpectedException(NinjaWars\core\InvalidNpcException::class); NpcFactory::fleshOut('NotARealNPCByAnyMeans', null); }
<?php use NinjaWars\core\data\NpcFactory; // Npc matrix planning document: https://docs.google.com/spreadsheet/ccc?key=0AkoUgtBBP00HdGZ1eUhaekhTb1dnZVh3ZlpoRExWdGc#gid=0 NpcFactory::$data = ['firefly' => ['name' => 'Firefly', 'img' => 'firefly.png', 'strength' => 0, 'stamina' => 0, 'damage' => 0, 'race' => 'insect', 'gold' => 0], 'fireflies' => ['name' => 'Fireflies', 'img' => 'fireflies.png', 'strength' => 0, 'stamina' => 1, 'damage' => 0, 'race' => 'insect'], 'spider' => ['name' => 'Spider', 'img' => 'spider.png', 'strength' => 1, 'stamina' => 1, 'speed' => 1, 'damage' => 10, 'gold' => 10, 'race' => 'insect', 'ki' => 1], 'pig' => ['name' => 'Wild pig', 'short' => 'is bristling with tusks and wiry hair', 'stamina' => 3, 'strength' => 4, 'speed' => 10, 'damage' => 2, 'race' => 'animal'], 'viper' => ['name' => 'Black Viper', 'race' => 'animal', 'strength' => 1, 'stamina' => 1, 'speed' => 1, 'ki' => 1, 'damage' => 99, 'status' => POISON, 'gold' => 30, 'traits' => ['poisonous']], 'kappa' => ['name' => 'Kappa', 'strength' => 30, 'speed' => 10, 'stamina' => 80, 'short' => 'is a reptilian creature with a scooped-out head', 'race' => 'kappa', 'img' => 'kappa.jpg', 'inventory' => ['shell' => '.5'], 'traits' => ['armored']], 'nureonna' => ['name' => 'Nureonna', 'strength' => 30, 'speed' => 50, 'stamina' => 40, 'img' => 'nureonna', 'race' => 'yokai', 'img' => 'nureonna.jpg', 'status' => POISON, 'inventory' => ['charcoal' => 1], 'traits' => ['poisonous']], 'tengu' => ['name' => 'Tengu', 'short' => 'is a large winged demon', 'strength' => 70, 'speed' => 20, 'stamina' => 100, 'race' => 'tengu', 'inventory' => ['tetsubo' => '.05']], 'ushioni' => ['name' => 'Ushi-Oni', 'strength' => 90, 'stamina' => 130, 'speed' => 50, 'race' => 'ushioni', 'img' => 'ushioni2.jpg'], 'ryu' => ['name' => 'Ryu', 'strength' => 150, 'stamina' => 200, 'speed' => 190, 'short' => 'is a serpent-dragon, with the gleam of intelligence in its eyes and the glint of death on its claws', 'img' => 'hokusai-dragon.jpg', 'race' => 'ryu', 'traits' => ['armored', 'rich']]] + (!defined('DEBUG') || !DEBUG ? [] : ['peasant2' => ['name' => 'Peasant', 'race' => 'human', 'img' => 'fighter.png', 'strength' => 5, 'stamina' => 5, 'speed' => 5, 'ki' => 1, 'damage' => 1, 'gold' => 20, 'bounty_mod' => 1, 'traits' => ['villager', 'sometimes_disguised_ninja'], 'inventory' => ['kunai' => '.01', 'shuriken' => '.01']], 'merchant2' => ['name' => 'Merchant', 'race' => 'human', 'strength' => 10, 'stamina' => 20, 'speed' => 10, 'ki' => 1, 'damage' => 15, 'gold' => 50, 'bounty_mod' => 5, 'img' => 'merchant.png', 'inventory' => ['phosphor' => '.3'], 'traits' => ['villager', 'rich']], 'guard2' => ['name' => 'Guard', 'short' => 'is a member of the ashigaru foot soldiers, hired for various tasks', 'race' => 'human', 'strength' => 30, 'stamina' => 30, 'speed' => 12, 'ki' => 1, 'damage' => 0, 'gold' => 50, 'bounty_mod' => 10, 'img' => 'guard.png', 'inventory' => ['ginsengroot' => '.2'], 'traits' => ['partial_match_strength']], 'monk' => ['name' => 'Monk', 'strength' => 10, 'stamina' => 10, 'speed' => 10, 'ki' => 30, 'race' => 'human', 'inventory' => ['prayerwheel' => '.2'], 'traits' => ['deflection', 'defensive', 'self_heal']], 'geisha' => ['name' => 'Geisha', 'strength' => 5, 'stamina' => 10, 'speed' => 15, 'ki' => 10, 'gold' => 20, 'bounty_mod' => 30, 'race' => 'human', 'inventory' => ['sake' => '.2', 'mirror' => '.01', 'kimono' => '.01', 'tessen' => '.01'], 'traits' => ['packdynamic', 'guarded', 'villager']], 'koi' => ['name' => 'Koi', 'short' => 'swims through the water', 'img' => 'koi.jpg', 'strength' => 0, 'speed' => 5, 'stamina' => 2, 'damage' => 1, 'race' => 'fish', 'inventory' => ['sushi' => '.5']], 'chicken' => ['name' => 'Chicken', 'short' => 'saunters around like it owns the place', 'strength' => 1, 'speed' => 5, 'damage' => 0, 'race' => 'bird'], 'bees' => ['name' => 'Swarm of Bees', 'short' => 'swarms and buzzes through the air', 'strength' => 13, 'speed' => 30, 'damage' => 6, 'gold' => 0, 'race' => 'insect'], 'goat' => ['name' => 'Goat', 'short' => 'chews on anything it can get to', 'strength' => 10, 'speed' => 25, 'damage' => 3, 'race' => 'animal'], 'crow' => ['name' => 'Crow', 'short' => 'caws out its disdain', 'strength' => 3, 'speed' => 25, 'damage' => 3, 'race' => 'bird'], 'kingfisher' => ['name' => 'Kingfisher', 'short' => 'flashes by on its wings', 'strength' => 3, 'speed' => 30, 'damage' => 3, 'race' => 'bird'], 'horse' => ['name' => 'Horse', 'short' => '', 'strength' => 10, 'speed' => 40, 'stamina' => 30, 'damage' => 10, 'race' => 'animal'], 'ox' => ['name' => 'Ox', 'short' => '', 'strength' => 50, 'speed' => 20, 'stamina' => 40, 'damage' => 20, 'race' => 'animal'], 'dog' => ['name' => 'Dog', 'short' => 'barks wildly', 'strength' => 20, 'speed' => 20, 'stamina' => 10, 'damage' => 10, 'race' => 'animal'], 'ghost_dog' => ['name' => 'Ghost Dog', 'short' => 'howls hauntingly', 'strength' => 15, 'speed' => 15, 'stamina' => 10, 'race' => 'kami', 'traits' => 'whispy'], 'tiger' => ['name' => 'Tiger', 'short' => 'circles in for the kill', 'strength' => 60, 'speed' => 60, 'stamina' => 60, 'damage' => 60, 'race' => 'animal'], 'basan' => ['name' => 'Basan', 'img' => 'basan.jpg', 'strength' => 1, 'stamina' => 1, 'speed' => 1, 'traits' => ['poisonous']], 'kamaitachi' => ['name' => 'Kama-itachi', 'img' => 'kamaitachi.jpg', 'race' => 'yokai'], 'nuribotoke' => ['name' => 'Nuri-Botoke', 'img' => 'nuribotoke.jpg', 'race' => 'yokai'], 'hitodama' => ['name' => 'Hitodama', 'short' => 'are spirit orbs of fire', 'img' => 'hitodama.gif', 'race' => 'kami', 'traits' => ['whispy']], 'karakasaobake' => ['name' => 'Karakasa-obake', 'short' => 'a one-legged umbrella spirit', 'race' => 'kami'], 'kodama' => ['name' => 'Ko-dama', 'short' => 'is a tree spirit', 'race' => 'kami'], 'umibozu' => ['name' => 'Umi-Bozu', 'short' => 'are bulbous floating jellyfish', 'img' => 'umibozu.jpg', 'traits' => ['whispy']], 'shojo' => ['name' => 'Shojo', 'short' => 'is a monkey man', 'race' => 'yokai'], 'kamanari' => ['name' => 'Kamanari', 'short' => 'is a gateway spirit that inhabits an iron pot', 'race' => 'kami'], 'furaribi' => ['name' => 'Furaribi', 'short' => 'is a flame spirit', 'race' => 'kami', 'img' => 'furaribi.jpg', 'traits' => ['whispy']], 'jorogumo' => ['name' => 'Jorogumo', 'short' => 'spider woman', 'race' => 'yokai', 'img' => 'jorogumo.jpg'], 'tesso' => ['name' => 'Tesso', 'short' => 'rat man', 'race' => 'yokai', 'img' => 'tesso.jpg'], 'shoukera' => ['name' => 'Shoukera', 'short' => 'is a muscled demon that lies wait in the shadows', 'race' => 'yokai', 'img' => 'shoukera.jpg'], 'waira' => ['name' => 'Waira', 'short' => 'is a clawed beast', 'race' => 'yokai', 'img' => 'waira.jpg'], 'tsurebeotoshi' => ['name' => 'Tsurube-otoshi', 'short' => 'is a fire elemental', 'race' => 'kami', 'img' => 'tsurubeotoshi.jpg', 'traits' => ['whispy']], 'kasha' => ['name' => 'Kasha', 'img' => 'kasha.jpg', 'race' => 'yokai'], 'yanari' => ['name' => 'Yanari', 'short' => 'a group of small demons', 'img' => 'yanari.jpg', 'race' => 'yokai'], 'aobouzu' => ['name' => 'Ao-bouzu', 'short' => 'is a one eyed monk', 'img' => 'aobouzu.jpg', 'race' => 'yokai'], 'akashita' => ['name' => 'Akashita', 'short' => 'is a storm demon', 'img' => 'akashita.jpg', 'race' => 'kami'], 'kamakiri' => ['name' => 'Kama-Kiri', 'short' => 'is a hair eating beast', 'img' => 'kamakiri.jpg', 'race' => 'yokai'], 'hakutaku' => ['name' => 'Hakutaku', 'short' => 'is a winged lion demon', 'img' => 'hakutaku.jpg', 'race' => 'yokai'], 'hainu' => ['name' => 'Hainu', 'short' => 'is a winged wolf', 'race' => 'yokai'], 'oni' => ['name' => 'Oni', 'strength' => 25, 'stamina' => 5, 'speed' => 15, 'ki' => 10, 'short' => 'a horned demon', 'img' => 'hokusai-oni.jpg', 'race' => 'oni', 'traits' => ['demonic', 'stealthy', 'slowing', 'energy_vampire']]]);
/** * Obtain the npcs data. * * @return Array */ private function npcs() { return ['abstract_npcs' => NpcFactory::npcsData(), 'custom_npcs' => [['name' => 'Peasant', 'identity' => 'peasant', 'image' => 'fighter.png'], ['name' => 'Thief', 'identity' => 'thief', 'image' => 'thief.png'], ['name' => 'Merchant', 'identity' => 'merchant', 'image' => 'merchant.png'], ['name' => 'Guard', 'identity' => 'guard', 'image' => 'guard.png'], ['name' => 'Samurai', 'identity' => 'samurai', 'image' => 'samurai.png']]]; }