/** * 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]; }
/** * Leveling up Function * * @return boolean */ public function levelUp() { $health_to_add = 100; $turns_to_give = 50; $ki_to_give = 50; $stat_value_to_add = 5; $karma_to_give = 1; if ($this->isAdmin()) { // If the character is an admin, do not auto-level return false; } else { // For normal characters, do auto-level // Have to be under the max level and have enough kills. $level_up_possible = $this->level + 1 <= MAX_PLAYER_LEVEL && $this->kills >= $this->killsRequiredForNextLevel(); if ($level_up_possible) { // Perform the level up actions $this->set_health($this->health() + $health_to_add); $this->set_turns($this->turns() + $turns_to_give); $this->set_ki($this->ki() + $ki_to_give); // Must read from VO for these as accessors return modified values $this->setStamina($this->vo->stamina + $stat_value_to_add); $this->setStrength($this->vo->strength + $stat_value_to_add); $this->setSpeed($this->vo->speed + $stat_value_to_add); // no mutator for these yet $this->vo->kills = max(0, $this->kills - $this->killsRequiredForNextLevel()); $this->vo->karma = $this->karma + $karma_to_give; $this->vo->level = $this->level + 1; $this->save(); GameLog::recordLevelUp($this->id()); $account = AccountFactory::findByChar($this); $account->setKarmaTotal($account->getKarmaTotal() + $karma_to_give); AccountFactory::save($account); // Send a level-up message, for those times when auto-levelling happens. send_event($this->id(), $this->id(), "You levelled up! Your strength raised by {$stat_value_to_add}, speed by {$stat_value_to_add}, stamina by {$stat_value_to_add}, Karma by {$karma_to_give}, and your Ki raised {$ki_to_give}! You gained some health and turns, as well! You are now a level {$this->level} ninja! Go kill some stuff."); return true; } else { return false; } } }