/** * View items and gold of char */ public function index() { $char = new Player(self_char_id()); $inv_counts = inventory_counts($char->id()); $inventory = array(); if ($inv_counts) { // Standard item info. $standard_items = $this->standardItems(); // Make the information into a single, trivially usable, array. foreach ($inv_counts as $item_info) { $l_id = $item_info['item_type']; $l_name = $item_info['name']; $l_count = $item_info['count']; if (isset($standard_items[$l_id]) && isset($l_count)) { // If a type of item exists and has a non-zero count, join the array of it's count with it's standard info. $inventory[$l_name] = array('count' => $l_count) + $standard_items[$l_id]; } } } else { $inventory = false; } $parts = ['gold' => $char->gold(), 'gold_display' => number_format($char->gold()), 'inventory' => $inventory, 'username' => $char->name(), 'char_id' => $char->id()]; return $this->render($parts); }
public static function char_inventory($char_id) { return inventory_counts($char_id); }
public function index() { $target = $player = first_value(in('ninja'), in('player'), in('find'), in('target')); $target_id = first_value(in('target_id'), in('player_id'), get_char_id($target)); // Find target_id if possible. $target_player_obj = Player::find($target_id); $viewed_name_for_title = null; if ($target_player_obj !== null) { $viewed_name_for_title = $target_player_obj->name(); } if ($target_player_obj === null) { $template = 'no-player.tpl'; $parts = array(); } else { $player_info = $target_player_obj->as_array(); // Pull the info out of the object. if (!$player_info) { $template = 'no-player.tpl'; $parts = array(); } else { $viewing_player_obj = Player::find(self_char_id()); $self = self_char_id() && self_char_id() == $player_info['player_id']; // Record whether this is a self-viewing. if ($viewing_player_obj !== null) { $char_info = $viewing_player_obj->dataWithClan(); $char_id = $viewing_player_obj->id(); $username = $viewing_player_obj->name(); } else { $char_info = []; } $player = $target = $player_info['uname']; // reset the target and target_id vars. $target_id = $player_info['player_id']; // Get the player's kills for this date. $kills_today = query_item('select sum(killpoints) from levelling_log where _player_id = :player_id and killsdate = CURRENT_DATE and killpoints > 0', array(':player_id' => $target_id)); $viewers_clan = $viewing_player_obj !== null ? ClanFactory::clanOfMember($viewing_player_obj) : null; // Attack Legal section $params = array('required_turns' => 0, 'ignores_stealth' => true); // 0 for unstealth. $attack_error = 'You must become a ninja first.'; $attack_allowed = false; if (null !== $viewing_player_obj) { $AttackLegal = new AttackLegal($viewing_player_obj, $target_player_obj, $params); $attack_allowed = $AttackLegal->check(false); $attack_error = $AttackLegal->getError(); } $sel_rank_spot = "SELECT rank_id FROM rankings WHERE player_id = :char_id limit 1"; $rank_spot = query_item($sel_rank_spot, array(':char_id' => $player_info['player_id'])); // Display the player info. $status_list = get_status_list($player); $gurl = $gravatar_url = $target_player_obj->avatarUrl(); if ($viewing_player_obj !== null && !$attack_error && !$self) { // They're not dead or otherwise unattackable. // Attack or Duel $skillDAO = new SkillDAO(); $is_admin = false; if ($viewing_player_obj) { $is_admin = $viewing_player_obj->isAdmin(); } if (!$is_admin) { $combat_skills = $skillDAO->getSkillsByTypeAndClass($viewing_player_obj->_class_id, 'combat', $viewing_player_obj->level); $targeted_skills = $skillDAO->getSkillsByTypeAndClass($viewing_player_obj->_class_id, 'targeted', $viewing_player_obj->level); } else { $combat_skills = $skillDAO->all('combat'); $targeted_skills = $skillDAO->all('targeted'); } // Pull the items and some necessary data about them. $items = inventory_counts($char_id); $valid_items = rco($items); // row count } // End of the there-was-no-attack-error section $set_bounty_section = ''; $communication_section = ''; $player_clan_section = ''; $clan = ClanFactory::clanOfMember($player_info['player_id']); $same_clan = false; // Player clan and clan members if ($clan) { $viewer_clan = $viewing_player_obj ? ClanFactory::clanOfMember($viewing_player_obj) : null; $clan_id = $clan->getID(); $clan_name = $clan->getName(); if ($viewer_clan) { $same_clan = $clan->getID() == $viewer_clan->getID(); $display_clan_options = $viewing_player_obj && !$self && $same_clan && $viewing_player_obj->isClanLeader(); } else { $same_clan = $display_clan_options = false; } } // Send the info to the template. $template = 'player.tpl'; $parts = get_certain_vars(get_defined_vars(), array('char_info', 'viewing_player_obj', 'target_player_obj', 'combat_skills', 'targeted_skills', 'player_info', 'self', 'rank_spot', 'kills_today', 'gravatar_url', 'status_list', 'clan', 'items')); } } return ['template' => $template, 'title' => 'Ninja' . ($viewed_name_for_title ? ": {$viewed_name_for_title}" : ' Profile'), 'parts' => $parts, 'options' => ['quickstat' => 'player']]; }
<?php require_once LIB_ROOT . "control/lib_inventory.php"; $private = true; $alive = false; if ($error = init($private, $alive)) { display_error($error); } else { $username = self_name(); $user_id = self_char_id(); $inv_counts = inventory_counts($user_id); $inventory = array(); $gold = get_gold($char_id); if ($inv_counts) { // Standard item info. $standard_items = standard_items(); // Make the information into a single, trivially usable, array. foreach ($inv_counts as $item_info) { $l_id = $item_info['item_type']; $l_name = $item_info['name']; $l_count = $item_info['count']; if (isset($standard_items[$l_id]) && isset($l_count)) { // If a type of item exists and has a non-zero count, join the array of it's count with it's standard info. $inventory[$l_name] = array('count' => $l_count) + $standard_items[$l_id]; } } } else { $inventory = false; } display_page('inventory.tpl', 'Your Inventory', array('gold' => $gold, 'gold_display' => number_format($gold), 'inventory' => $inventory, 'username' => $username, 'char_id' => $user_id), array('quickstat' => 'viewinv')); }
$skillDAO = new SkillDAO(); $combat_skills = $skillDAO->getSkillsByTypeAndClass($viewing_player_obj->vo->_class_id, 'combat', $viewing_player_obj->vo->level)->fetchAll(); $targeted_skills = $skillDAO->getSkillsByTypeAndClass($viewing_player_obj->vo->_class_id, 'targeted', $viewing_player_obj->vo->level)->fetchAll(); // *** todo When Smarty3 is released, remove fetch all and change template to new foreach-as syntax *** // Check all the combat toggles to see if they should be checked on the profile page. foreach ($combat_skills as &$skill) { $skill['checked'] = 0; if (isset($combat_toggles[$skill['skill_internal_name']]) && $combat_toggles[$skill['skill_internal_name']]) { $skill['checked'] = 1; // Save the setting associatively back to the original array. } } $duel_checked = !!$combat_toggles['duel']; // Duel isn't in the general combat skills, so it gets set separately. // Pull the items and some necessary data about them. $items = inventory_counts($char_id, $last_item_used); $valid_items = rco($items); // row count //debug($items); } // End of the there-was-no-attack-error section $set_bounty_section = ''; $communication_section = ''; $player_clan_section = ''; $clan = get_clan_by_player_id($player_info['player_id']); $same_clan = false; $player_info = format_health_percent($player_info); // Player clan and clan members if ($clan) { $viewer_clan = is_logged_in() ? get_clan_by_player_id($viewing_player_obj->vo->player_id) : null; $clan_members = get_clan_members($clan->getID())->fetchAll();