if ($temp_index['robot_class'] == 'master' && !empty($temp_counter_robots[$token])){ $temp_counter_database['unlocked'] += 1; }
        elseif ($temp_index['robot_class'] == 'mecha' && !empty($array[''])){ $temp_counter_database['unlocked'] += 1; }
    
        $temp_counter_database['encountered'] += 1;
        $temp_counter_database['total'] += 1;
    }
    */
}
// Sort the points array for most-used
asort($temp_counter_points);
$temp_counter_points = array_reverse($temp_counter_points);
// Sort the levels array for most-used
asort($temp_counter_levels);
$temp_counter_levels = array_reverse($temp_counter_levels);
// Collect the most users player and most used robots
$temp_player_index = rpg_player::get_index();
$temp_top_player = '';
foreach ($temp_counter_points as $token => $value) {
    if ($token != 'total') {
        $temp_top_player = '<strong>' . $temp_player_index[$token]['player_name'] . '</strong>';
        break;
    }
}
$temp_top_robots = array();
// Collect the favourite robots if there are set
$temp_top_robots = array();
$temp_top_robots_tokens = array();
$temp_top_robots_counter = 5;
if (!empty($this_playerinfo['save_values']['robot_favourites'])) {
    //die('we have favourites, people!');
    $temp_top_robots_method = 'favourite';
Exemplo n.º 2
0
    $object_multi_token = 'robots';
}
// Define object class tokens for BOSSES
elseif ($this_current_sub == 'bosses'){
    $object_class_token = 'boss';
    $object_single_token = 'boss';
    $object_multi_token = 'bosses';
}

// Define the object names based on tokens
$object_single_name = ucfirst($object_single_token);
$object_multi_name = ucfirst($object_multi_token);

// Collect the various global indexes for display and looping
$type_index = rpg_type::get_index(true);
$player_index = rpg_player::get_index(true, true);
$field_index = rpg_field::get_index(true, true);
$ability_index = rpg_ability::get_index(true);

// Collect the robot ID from the request header
$robot_id = isset($_GET['num']) && is_numeric($_GET['num']) ? (int)($_GET['num']) : false;

// Collect robot fields to pull from the database
$robot_fields = rpg_robot::get_index_fields(true);

// Collect robot info from the database if an ID was provided
if (!empty($robot_id)){
    $robot_info = $db->get_array("SELECT {$robot_fields} FROM mmrpg_index_robots WHERE robot_id = {$robot_id} AND robot_class = '{$object_class_token}';");
}
// Generate new robot info given a class and the database robot template
elseif ($robot_id === 0){
Exemplo n.º 3
0
function mmrpg_leaderboard_parse_index($board_key, $board_info, $quick_parse = false)
{
    global $mmrpg_index;
    global $this_cache_stamp, $this_cache_filename, $this_cache_filedir;
    global $this_leaderboard_count, $this_leaderboard_online_count;
    global $this_leaderboard_online_players, $this_leaderboard_online_pages;
    global $this_leaderboard_index;
    global $this_userid, $this_userinfo, $this_boardinfo;
    global $this_display_limit, $this_display_limit_default, $this_num_offset;
    global $this_time, $this_online_timeout, $place_counter, $points_counter, $this_start_key;
    // Collect this player's base info
    $this_stars = !empty($board_info['board_stars']) ? $board_info['board_stars'] : 0;
    $this_abilities = !empty($board_info['board_abilities']) ? $board_info['board_abilities'] : 0;
    //$this_battles = !empty($board_info['board_battles']) ? $board_info['board_battles'] : 0;
    $this_missions = !empty($board_info['board_missions']) ? $board_info['board_missions'] : 0;
    $this_awards = !empty($board_info['board_awards']) ? explode(',', $board_info['board_awards']) : array();
    $this_first_save = !empty($board_info['board_date_created']) ? $board_info['board_date_created'] : 0;
    $this_last_save = !empty($board_info['board_date_modified']) ? $board_info['board_date_modified'] : 0;
    $this_last_access = !empty($board_info['user_date_accessed']) ? $board_info['user_date_accessed'] : 0;
    $this_is_online = !empty($this_last_access) && $this_time - $this_last_access <= $this_online_timeout ? true : false;
    $this_last_save = !empty($this_last_save) ? date('Y/m/d @ H:i', $this_last_save) : '????-??-?? ??:??';
    $this_style = $this_is_online ? 'border-color: green; ' : '';
    $this_place = rpg_website::number_suffix($place_counter, true, true);
    //str_pad(($place_counter), 2, '0', STR_PAD_LEFT);
    $this_username = !empty($board_info['user_name_public']) ? $board_info['user_name_public'] : $board_info['user_name'];
    $this_username = htmlentities($this_username, ENT_QUOTES, 'UTF-8', true);
    $this_user_id = !empty($board_info['user_id']) ? $board_info['user_id'] : 0;
    if ($this_userid != MMRPG_SETTINGS_GUEST_ID && $this_user_id == $_SESSION['GAME']['USER']['userid']) {
        $this_boardinfo['board_rank'] = $place_counter;
        $_SESSION['GAME']['BOARD']['boardrank'] = $this_boardinfo['board_rank'];
    }
    //die('<pre>'.print_r($this_battles, true).'</pre>');
    // Define the current page this player is on
    $this_current_page_number = ceil($board_key / $this_display_limit_default);
    //echo('$board_key = '.$board_key.'; $this_display_limit_default = '.$this_display_limit_default.'; $this_current_page_number = '.$this_current_page_number);
    // If online, add this player to the array
    if ($this_is_online) {
        $this_leaderboard_online_count++;
        $this_leaderboard_online_players[] = array('id' => $this_user_id, 'name' => $this_username, 'token' => $board_info['user_name_clean'], 'place' => $this_place, 'placeint' => $place_counter, 'colour' => $board_info['user_colour_token'], 'image' => $board_info['user_image_path']);
        //$this_current_page_number = ceil($board_key / $this_display_limit);
        //echo('$board_key = '.$board_key.'; $this_display_limit = '.$this_display_limit.'; $this_current_page_number = '.$this_current_page_number);
        //$this_leaderboard_online_pages[] = $board_key;
        if (!in_array($this_current_page_number, $this_leaderboard_online_pages)) {
            $this_leaderboard_online_pages[] = $this_current_page_number;
        }
    }
    // If quick parse was requested, return now
    if ($quick_parse) {
        return '';
    }
    // Collect the points and increment the counter if necessary
    $this_points = $board_info['board_points'];
    if ($this_points != $points_counter) {
        $points_counter = $this_points;
    }
    // Define the awards strong and default to empty
    $this_user_awards = ' ';
    // Break apart the battle and battle values into arrays
    $temp_battles = !empty($board_info['board_battles']) ? explode(',', $board_info['board_battles']) : array();
    $board_info['board_battles'] = $temp_battles;
    // Loop through the available players
    $mmrpg_index_players = rpg_player::get_index();
    foreach ($mmrpg_index_players as $ptoken => $pinfo) {
        $ptoken2 = str_replace('-', '_', $ptoken);
        $temp_battles = !empty($board_info['board_battles_' . $ptoken2]) ? explode(',', $board_info['board_battles_' . $ptoken2]) : array();
        $board_info['board_battles_' . $ptoken2] = $temp_battles;
    }
    // Break apart the robot and battle values into arrays
    $temp_robots = !empty($board_info['board_robots']) ? $board_info['board_robots'] : array();
    if (!empty($temp_robots)) {
        $temp_robots = explode(',', $temp_robots);
        foreach ($temp_robots as $key => $string) {
            list($token, $level) = explode(':', substr($string, 1, -1));
            $temp_info = array('robot_token' => $token, 'robot_level' => $level);
            $temp_robots[$key] = $temp_info;
        }
    }
    $this_robots = $temp_robots;
    // Start the output buffer
    ob_start();
    // Only continue if markup is special constants have not been defined
    if (!defined('MMRPG_SKIP_MARKUP') || defined('MMRPG_SHOW_MARKUP_' . $this_user_id)) {
        // Only generate markup if we're withing the viewing range
        if ($board_key >= $this_start_key && $board_key < $this_display_limit || defined('MMRPG_SHOW_MARKUP_' . $this_user_id)) {
            $this_robots_count = !empty($this_robots) ? count($this_robots) : 0;
            $this_robots_count = $this_robots_count == 1 ? '1 Robot' : $this_robots_count . ' Robots';
            $this_stars_count = $this_stars;
            $this_abilities_count = $this_abilities;
            $this_missions_count = $this_missions;
            $this_stars_count = $this_stars_count == 1 ? '1 Star' : $this_stars_count . ' Stars';
            $this_abilities_count = $this_abilities_count == 1 ? '1 Ability' : $this_abilities_count . ' Abilities';
            $this_missions_count = $this_missions_count == 1 ? '1 Mission' : $this_missions_count . ' Missions';
            //$this_points_html = preg_replace('#^([0]+)([0-9]+)$#', '<span class="padding">$1</span><span class="value">$2</span>', str_pad((!empty($this_points) ? $this_points : 0), 13, '0', STR_PAD_LEFT)).' BP';
            $this_records_html = '<span class="count">' . $this_missions_count . '</span>';
            $this_records_html .= ' <span class="pipe">|</span> <span class="count">' . $this_robots_count . '</span>';
            $this_records_html .= ' <span class="pipe">|</span> <span class="count">' . $this_abilities_count . '</span>';
            $this_records_html .= ' <span class="pipe">|</span> <span class="count">' . $this_stars_count . '</span>';
            $this_points_html = '<span class="value">' . (!empty($this_points) ? number_format($this_points, 0, '.', ',') : 0) . '</span>' . ' BP';
            $this_points_plain = (!empty($this_points) ? number_format($this_points, 0, '.', ',') : 0) . ' BP';
            $this_details = '' . $this_last_save;
            // -- LEADERBOARD MARKUP -- //
            // Add the prototype complete flags if applicable
            if (count($board_info['board_battles_dr_light']) >= 17) {
                $this_user_awards .= '<span class="prototype_complete prototype_complete_dr-light" data-tooltip="Completed Dr. Light\'s Game" data-tooltip-type="player_type player_type_defense">&hearts;</span>';
            }
            if (count($board_info['board_battles_dr_wily']) >= 17) {
                $this_user_awards .= '<span class="prototype_complete prototype_complete_dr-wily" data-tooltip="Completed Dr. Wily\'s Game" data-tooltip-type="player_type player_type_attack">&clubs;</span>';
            }
            if (count($board_info['board_battles_dr_cossack']) >= 17) {
                $this_user_awards .= '<span class="prototype_complete prototype_complete_dr-cossack" data-tooltip="Completed Dr. Cossack\'s Game" data-tooltip-type="player_type player_type_speed">&diams;</span>';
            }
            if (in_array('ranking_first_place', $this_awards)) {
                $this_user_awards .= '<span class="prototype_complete prototype_complete_firstplace" data-tooltip="Reached First Place" data-tooltip-type="player_type player_type_level">&#9733;</span>';
            }
            //die('$this_awards = '.print_r($this_awards, true));
            // Display the user's save file listing
            //echo '<a data-id="'.$board_info['user_id'].'" data-player="'.$board_info['user_name_clean'].'" class="file file_'.$this_place.'" name="file_'.$key.'" style="'.$this_style.'" title="'.$this_title.'" href="leaderboard/'.$board_info['user_name_clean'].'/">'."\n";
            echo '<a data-id="' . $board_info['user_id'] . '" data-player="' . $board_info['user_name_clean'] . '" class="file file_' . strip_tags($this_place) . '" name="file_' . $key . '" style="' . $this_style . '" href="leaderboard/' . $board_info['user_name_clean'] . '/">' . "\n";
            echo '<div class="inset player_type_' . (!empty($board_info['user_colour_token']) ? $board_info['user_colour_token'] : 'none') . '">' . "\n";
            echo '<span class="place">' . $this_place . '</span>' . "\n";
            echo '<span class="userinfo"><strong class="username">' . $this_username . $this_user_awards . '</strong><span class="details">' . $this_details . '</span></span>' . "\n";
            echo '<span class="points">' . $this_points_html . '</span>' . "\n";
            echo '<span class="records">' . $this_records_html . '</span>' . "\n";
            echo '</div>' . "\n";
            if (!empty($board_info['user_image_path'])) {
                list($avatar_class, $avatar_token, $avatar_size) = explode('/', $board_info['user_image_path']);
            } else {
                $avatar_class = 'robots';
                $avatar_token = 'mega-man';
                $avatar_size = 40;
            }
            if (!empty($board_info['user_background_path'])) {
                list($background_class, $background_token) = explode('/', $board_info['user_background_path']);
            } else {
                $background_class = 'fields';
                $background_token = 'intro-field';
            }
            $avatar_size = $avatar_size * 2;
            $avatar_path = 'images/sprites/' . $avatar_class . '/' . $avatar_token . '/sprite_left_' . $avatar_size . 'x' . $avatar_size . '.png';
            $shadow_path = 'images/shadows/' . $avatar_class . '/' . preg_replace('/^([-a-z0-9]+)(_[a-z]+)?$/i', '$1', $avatar_token) . '/sprite_left_' . $avatar_size . 'x' . $avatar_size . '.png';
            if (!file_exists($shadow_path)) {
                $shadow_path = 'images/shadows/' . $avatar_class . '/' . preg_replace('/^([-a-z0-9]+)(_[a-z0-9]+)?$/i', '$1', $avatar_token) . '/sprite_left_' . $avatar_size . 'x' . $avatar_size . '.png';
            }
            echo '<span class="avatar"><span class="avatar_wrapper">';
            echo '<span class="sprite sprite_shadow sprite_' . $avatar_size . 'x' . $avatar_size . ' sprite_shadow_' . $avatar_size . 'x' . $avatar_size . ' sprite_' . $avatar_size . 'x' . $avatar_size . '_' . ($place_counter > 3 ? 'base' : 'victory') . '" style="background-image: url(' . $shadow_path . '?' . MMRPG_CONFIG_CACHE_DATE . ');">' . $this_username . '</span>';
            echo '<span class="sprite sprite_' . $avatar_size . 'x' . $avatar_size . ' sprite_' . $avatar_size . 'x' . $avatar_size . '_' . ($place_counter > 3 ? 'base' : 'victory') . '" style="background-image: url(' . $avatar_path . '?' . MMRPG_CONFIG_CACHE_DATE . ');">' . $this_username . '</span>';
            echo '</span></span>' . "\n";
            echo '</a>' . "\n";
        }
    }
    // Collect the output into the buffer
    return preg_replace('/\\s+/', ' ', ob_get_clean());
}
Exemplo n.º 4
0
 public static function player_select_markup($prototype_data, $player_token, $this_button_size = '1x4')
 {
     global $mmrpg_index, $db;
     $session_token = rpg_game::session_token();
     // Collect the player info
     $player_info = rpg_player::get_index_info($player_token);
     switch ($player_token) {
         case 'dr-light':
             $player_symbol = '&hearts;';
             $player_face = ':D';
             break;
         case 'dr-wily':
             $player_symbol = '&clubs;';
             $player_face = 'XD';
             break;
         case 'dr-cossack':
             $player_symbol = '&diams;';
             $player_face = '8D';
             break;
         default:
             $player_symbol = '';
             $player_face = ':|';
             break;
     }
     // Generate the markup for each of the robot sprites
     $temp_offset_x = 14;
     $temp_offset_z = 50;
     $temp_offset_y = -2;
     $temp_offset_opacity = 0.75;
     $text_sprites_markup = '';
     $temp_player_robots = rpg_game::robot_tokens_unlocked($player_token);
     //$_SESSION[$session_token]['values']['battle_settings'][$player_token]['player_robots'];
     // Collect the base index data for these robots
     $temp_token_string = array();
     foreach ($temp_player_robots as $token) {
         $temp_token_string[] = "'{$token}'";
     }
     $temp_token_string = implode(', ', $temp_token_string);
     $temp_robot_index = $db->get_array_list("SELECT * FROM mmrpg_index_robots WHERE robot_token IN ({$temp_token_string}) AND robot_flag_complete = 1;", 'robot_token');
     foreach ($temp_player_robots as $key => $robot_token) {
         $index = rpg_robot::parse_index_info($temp_robot_index[$robot_token]);
         $rewards = rpg_game::robot_rewards($player_token, $robot_token);
         $settings = rpg_game::robot_settings($player_token, $robot_token);
         $info = array_merge($index, $rewards, $settings);
         exit(PHP_EOL . PHP_EOL . $player_token . ' : ' . $robot_token . ' = ' . PHP_EOL . '$index = ' . print_r($index, true) . '$rewards = ' . print_r($rewards, true) . '$settings = ' . print_r($settings, true) . PHP_EOL . PHP_EOL);
         if (rpg_game::robot_unlocked($player_token, $robot_token)) {
             $temp_size = !empty($info['robot_image_size']) ? $info['robot_image_size'] : 40;
             $temp_size_text = $temp_size . 'x' . $temp_size;
             $temp_offset_x += $temp_size > 40 ? 0 : 20;
             $temp_offset_y = $temp_size > 40 ? -42 : -2;
             $temp_offset_z -= 1;
             $temp_offset_opacity -= 0.05;
             if ($temp_offset_opacity <= 0) {
                 $temp_offset_opacity = 0;
                 break;
             }
             $text_sprites_markup .= '<span class="sprite sprite_nobanner sprite_' . $temp_size_text . ' sprite_' . $temp_size_text . '_base" style="background-image: url(i/r/' . (!empty($info['robot_image']) ? $info['robot_image'] : $info['robot_token']) . '/sr' . $temp_size . '.png?' . MMRPG_CONFIG_CACHE_DATE . '); top: ' . $temp_offset_y . 'px; right: ' . $temp_offset_x . 'px;">' . $info['robot_name'] . '</span>';
             if ($temp_size > 40) {
                 $temp_offset_x += 20;
             }
         }
     }
     exit(PHP_EOL . PHP_EOL . $player_token . ' = ' . print_r($temp_robot_index, true) . PHP_EOL . PHP_EOL);
     // Generate the markup for the rest of the player container
     $text_robots_unlocked = number_format($prototype_data['robots_unlocked'], 0, '.', ',') . ' Robot' . ($prototype_data['robots_unlocked'] != 1 ? 's' : '');
     $text_abilities_unlocked = number_format($prototype_data['abilities_unlocked'], 0, '.', ',') . ' Ability' . ($prototype_data['abilities_unlocked'] != 1 ? 's' : '');
     $text_points_unlocked = number_format($prototype_data['points_unlocked'], 0, '.', ',') . ' Point' . ($prototype_data['points_unlocked'] != 1 ? 's' : '');
     $text_battles_complete = number_format($prototype_data['battles_complete'], 0, '.', ',') . ' Mission' . ($prototype_data['battles_complete'] != 1 ? 's' : '');
     $text_player_special = $prototype_data['prototype_complete'] ? true : false;
     $text_player_music = rpg_prototype::get_player_mission_music($player_token, $session_token);
     $text_sprites_markup = '<span class="sprite sprite_player sprite_40x40 sprite_40x40_base" style="background-image: url(images/sprites/players/' . $player_token . '/sprite_right_40x40.png); top: -2px; right: 14px;">' . $player_info['player_name'] . '</span>';
     $text_sprites_markup .= $text_sprites_markup;
     $text_player_subtext = $text_robots_unlocked;
     $text_player_subtext = $text_abilities_unlocked;
     // Put it all together for the player select markup
     $player_select_markup = '';
     $player_select_markup .= '<a data-music-token="' . $text_player_music . '" data-battle-complete="' . $prototype_data['battles_complete'] . '" class="option option_' . $this_button_size . ' option_this-player-select option_this-' . $player_token . '-player-select option_' . $player_token . ' block_1" data-token="' . $player_token . '">';
     $player_select_markup .= '<div class="platform"><div class="chrome"><div class="inset">';
     $player_select_markup .= '<label class="has_image">';
     $player_select_markup .= '<span class="multi">';
     $player_select_markup .= $text_sprites_markup;
     $player_select_markup .= '<span class="maintext">';
     $player_select_markup .= $player_info['player_name'] . (!empty($text_player_special) ? ' <span style="position: relative; bottom: 2px;" title="Thank you for playing!!! ' . $player_face . '">' . $player_symbol . '</span>' : '') . '</span><span class="subtext">' . $text_player_subtext . '</span><span class="subtext2">' . $text_points_unlocked . '</span></span><span class="arrow">&#9658;</span></label>';
     $player_select_markup .= '</div></div></div>';
     $player_select_markup .= '</a>' . "\n";
     // Return the generated markup
     return $player_select_markup;
 }
Exemplo n.º 5
0
}
// Require the database top include file
if ($this_class == 'mechas' || $this_class == 'fields') {
    define('DATA_DATABASE_SHOW_MECHAS', true);
}
if ($this_class == 'bosses' || $this_class == 'fields') {
    define('DATA_DATABASE_SHOW_BOSSES', true);
}
require_once '../data/database.php';
// Proceed based on the type of class the request is
switch ($this_class) {
    // If this was a player request
    case 'players':
        $key_counter = array_search($this_token, array_keys($mmrpg_database_players));
        $temp_player_info = $mmrpg_database_players[$this_token];
        $temp_player_markup = rpg_player::print_database_markup($temp_player_info, array('show_key' => $key_counter));
        $temp_player_markup = preg_replace('/\\s+/', ' ', $temp_player_markup);
        echo 'success : ' . $temp_player_markup;
        break;
        // If this was a robot request
    // If this was a robot request
    case 'robots':
        $key_counter = array_search($this_token, array_keys($mmrpg_database_robots));
        $temp_robot_info = $mmrpg_database_robots[$this_token];
        $temp_robot_markup = rpg_robot::print_database_markup($temp_robot_info, array('show_key' => $key_counter));
        $temp_robot_markup = preg_replace('/\\s+/', ' ', $temp_robot_markup);
        echo 'success : ' . $temp_robot_markup;
        break;
        // If this was a mecha request
    // If this was a mecha request
    case 'mechas':
Exemplo n.º 6
0
 /**
  * Get the formatted editor title markup for this field object given field info
  * @param array $field_info
  * @return string
  */
 public static function print_editor_title_markup($field_info)
 {
     // Collect references to global objects
     $db = cms_database::get_database();
     // Collect references to global indexes
     $mmrpg_types = rpg_type::get_index();
     $mmrpg_players = rpg_player::get_index();
     $mmrpg_robots = rpg_robot::get_index();
     // Expand the field index info
     $field_token = $field_info['field_token'];
     $field_info = rpg_field::get_index_info($field_token);
     if (empty($field_info) || empty($field_info)) {
         return false;
     }
     // Collect the field type info and expand master/mecha data
     $temp_field_type = !empty($field_info['field_type']) ? $mmrpg_types[$field_info['field_type']] : false;
     $temp_field_type2 = !empty($field_info['field_type2']) ? $mmrpg_types[$field_info['field_type2']] : false;
     $temp_field_master = !empty($field_info['field_master']) ? rpg_robot::parse_index_info($mmrpg_robots[$field_info['field_master']]) : false;
     $temp_field_mechas = !empty($field_info['field_mechas']) ? $field_info['field_mechas'] : array();
     foreach ($temp_field_mechas as $key => $token) {
         $temp_mecha = rpg_robot::parse_index_info($mmrpg_robots[$token]);
         if (!empty($temp_mecha)) {
             $temp_field_mechas[$key] = $temp_mecha['robot_name'];
         } else {
             unset($temp_field_mechas[$key]);
         }
     }
     // Generate the field title markup
     $temp_field_title = $field_info['field_name'];
     if (!empty($temp_field_type)) {
         $temp_field_title .= ' (' . $temp_field_type['type_name'] . ' Type)';
     }
     if (!empty($temp_field_type2)) {
         $temp_field_title = str_replace('Type', '/ ' . $temp_field_type2['type_name'] . ' Type', $temp_field_title);
     }
     $temp_field_title .= '  // ';
     if (!empty($temp_field_master)) {
         $temp_field_title .= 'Robot : ' . $temp_field_master['robot_name'] . ' // ';
     }
     if (!empty($temp_field_mechas)) {
         $temp_field_title .= 'Mecha : ' . implode(', ', array_unique($temp_field_mechas)) . ' // ';
     }
     // Return the generated markup
     return $temp_field_title;
 }
    Player Listing
    <?php 
    echo isset($this_current_filter) ? '<span class="count" style="float: right;">( ' . $this_current_filter_name . ' Type )</span>' : '';
    ?>
  </h2>
  <?php 
}
// If we're in the index view, loop through and display all players
if (empty($this_current_token)) {
    // Loop through the player database and display the appropriate data
    $key_counter = 0;
    foreach ($mmrpg_database_players as $player_key => $player_info) {
        // If a type filter has been applied to the player page
        if (isset($this_current_filter) && $this_current_filter == 'none' && $player_info['player_type'] != '') {
            $key_counter++;
            continue;
        } elseif (isset($this_current_filter) && $this_current_filter != 'none' && $player_info['player_type'] != $this_current_filter) {
            $key_counter++;
            continue;
        }
        // Collect information about this player
        $this_player_image = !empty($player_info['player_image']) ? $player_info['player_image'] : $player_info['player_token'];
        if ($this_player_image == 'player') {
            $this_seo_robots = 'noindex';
        }
        // Collect the markup for this player and print it to the browser
        $temp_player_markup = rpg_player::print_database_markup($player_info, array('layout_style' => 'website_compact', 'show_key' => $key_counter));
        echo $temp_player_markup;
        $key_counter++;
    }
}
Exemplo n.º 8
0
        //if ($temp_player == $player_token){ continue; }
        //elseif ($temp_total > $counter_player_players){ $allow_player_selector = false; }
        //}
        // Update the player key to the current counter
        $player_key = $key_counter;
        // Make a backup of the player selector
        $allow_player_selector_backup = $allow_player_selector;
        // Collect this player's field rewards and add them to the dropdown
        $player_field_rewards = !empty($player_rewards['player_fields']) ? $player_rewards['player_fields'] : array();
        // Collect this player's item rewards and add them to the dropdown
        $player_item_rewards = !empty($player_rewards['player_items']) ? $player_rewards['player_items'] : array();
        //if (!empty($player_field_rewards)){ sort($player_field_rewards); }
        // DEBUG
        //die(print_r($player_rewards, true));
        // Collect and print the editor markup for this player
        $temp_editor_markup = rpg_player::print_editor_markup($player_info);
        echo $temp_editor_markup;
        $key_counter++;
        // Return the backup of the player selector
        $allow_player_selector = $allow_player_selector_backup;
    }
    // Collect the contents of the buffer
    $edit_console_markup = ob_get_clean();
    $edit_console_markup = preg_replace('/\\s+/', ' ', trim($edit_console_markup));
}
// Generate the edit markup using the battles settings and rewards
$this_edit_markup = '';
if (true) {
    // Prepare the output buffer
    ob_start();
    // Determine the token for the very first player in the edit
function refresh_editor_arrays()
{
    global $allowed_edit_players, $allowed_edit_robots, $allowed_edit_data;
    global $allowed_edit_data_count, $allowed_edit_player_count, $allowed_edit_robot_count;
    // Collect the current session token
    $session_token = rpg_game::session_token();
    // Collect the player array and merge in session details
    $temp_player_array = array();
    if (!empty($_SESSION[$session_token]['values']['battle_rewards'])) {
        $temp_player_rewards = $_SESSION[$session_token]['values']['battle_rewards'];
        $temp_player_array = array_merge($temp_player_array, $temp_player_rewards);
    }
    if (!empty($_SESSION[$session_token]['values']['battle_settings'])) {
        $temp_player_settings = $_SESSION[$session_token]['values']['battle_settings'];
        $temp_player_array = array_merge($temp_player_array, $temp_player_settings);
    }
    // Define the editor indexes and count variables
    $allowed_edit_players = array();
    $allowed_edit_robots = array();
    $allowed_edit_data = array();
    $allowed_edit_data_count = 0;
    $allowed_edit_player_count = 0;
    $allowed_edit_robot_count = 0;
    // Collect a temporary player index
    $temp_player_tokens = array_keys($temp_player_array);
    $temp_player_index = rpg_player::get_index_custom($temp_player_tokens);
    // Now to actually loop through and update the allowed players, robots, and abilities arrays
    foreach ($temp_player_array as $player_token => $player_info) {
        if (empty($player_token) || !isset($temp_player_index[$player_token])) {
            continue;
        }
        $player_index_info = $temp_player_index[$player_token];
        // If this player has not yet completed chapter one, no robot editor
        $intro_complete = rpg_prototype::event_complete('completed-chapter_' . $player_token . '_one');
        $prototype_complete = rpg_prototype::campaign_complete($player_token);
        if (!$intro_complete && !$prototype_complete) {
            continue;
        }
        // Merge the player and index info then append the token and info
        $player_info = array_merge($player_index_info, $player_info);
        $allowed_edit_players[] = $player_token;
        $allowed_edit_data[$player_token] = $player_info;
        // Collect a temporary robot index
        $temp_robot_tokens = array_keys($player_info['player_robots']);
        $temp_robot_index = rpg_robot::get_index_custom($temp_robot_tokens);
        foreach ($player_info['player_robots'] as $robot_token => $robot_info) {
            if (empty($robot_token) || !isset($temp_robot_index[$robot_token])) {
                continue;
            }
            $robot_index_info = $temp_robot_index[$robot_token];
            // Merge the robot and index info then append the token and info
            $robot_info = array_merge($robot_index_info, $robot_info);
            $allowed_edit_robots[] = $robot_token;
            $allowed_edit_data[$player_token]['player_robots'][$robot_token] = $robot_info;
            // Collect a temporary ability index
            $temp_ability_tokens = array_keys($robot_info['robot_abilities']);
            $temp_ability_index = rpg_ability::get_index_custom($temp_ability_tokens);
            foreach ($robot_info['robot_abilities'] as $ability_token => $ability_info) {
                if (empty($ability_token) || !isset($temp_ability_index[$ability_token])) {
                    continue;
                }
                $ability_index_info = $temp_ability_index[$ability_token];
                // Merge the ability and index info then append the token and info
                $ability_info = array_merge($ability_index_info, $ability_info);
                $allowed_edit_data[$player_token]['player_robots'][$robot_token]['robot_abilities'][$ability_token] = $ability_info;
            }
        }
    }
    //$allowed_edit_data = array_reverse($allowed_edit_data, true);
    $allowed_edit_player_count = !empty($allowed_edit_players) ? count($allowed_edit_players) : 0;
    $allowed_edit_robot_count = !empty($allowed_edit_robots) ? count($allowed_edit_robots) : 0;
    $allowed_edit_data_count = 0;
    foreach ($allowed_edit_data as $pinfo) {
        $pcount = !empty($pinfo['player_robots']) ? count($pinfo['player_robots']) : 0;
        $allowed_edit_data_count += $pcount;
    }
}
Exemplo n.º 10
0
    $temp_condition .= $mmrpg_database_players_filter;
}
// Collect the database players and fields
$player_fields = rpg_player::get_index_fields(true);
$db->query("SET @player_row_number = 0;");
$mmrpg_database_players = $db->get_array_list("SELECT {$player_fields} FROM mmrpg_index_players WHERE player_flag_published = 1 AND (player_flag_hidden = 0 OR player_token = '{$this_current_token}') {$temp_condition} ORDER BY player_flag_hidden ASC, player_order ASC;", 'player_token');
$mmrpg_database_players_count = $db->get_value("SELECT COUNT(player_id) AS player_count FROM mmrpg_index_players WHERE player_flag_published = 1 AND player_flag_hidden = 0 {$temp_condition_unfiltered};", 'player_count');
$mmrpg_database_players_numbers = $db->get_array_list("SELECT player_token, (@player_row_number:=@player_row_number + 1) AS player_key FROM mmrpg_index_players WHERE player_flag_published = 1 {$temp_condition_unfiltered} ORDER BY player_flag_hidden ASC, player_order ASC;", 'player_token');
// Remove unallowed players from the database
foreach ($mmrpg_database_players as $temp_token => $temp_info) {
    // Define first player token if not set
    if (!isset($first_player_token)) {
        $first_player_token = $temp_token;
    }
    // Send this data through the player index parser
    $temp_info = rpg_player::parse_index_info($temp_info);
    // Collect this player's key in the index
    $temp_info['player_key'] = $mmrpg_database_players_numbers[$temp_token]['player_key'];
    // Ensure this player's image exists, else default to the placeholder
    $mmrpg_database_players[$temp_token]['player_image'] = $temp_token;
    // Update the main database array with the changes
    $mmrpg_database_players[$temp_token] = $temp_info;
}
// Loop through the database and generate the links for these players
$key_counter = 0;
$mmrpg_database_players_links = '';
$mmrpg_database_players_links .= '<div class="float link group" data-game="MM00">';
$mmrpg_database_players_links_counter = 0;
$mmrpg_database_players_count_complete = 0;
// Loop through the results and generate the links for these players
foreach ($mmrpg_database_players as $player_key => $player_info) {
Exemplo n.º 11
0
 public function trigger_disabled($target_robot, $this_ability, $trigger_options = array())
 {
     // Pull in the global variable
     global $mmrpg_index;
     // Import global variables
     $db = cms_database::get_database();
     $this_battle = rpg_battle::get_battle();
     $this_field = rpg_field::get_field();
     // Generate default trigger options if not set
     if (!isset($trigger_options['item_multiplier'])) {
         $trigger_options['item_multiplier'] = 1.0;
     }
     // If the battle has already ended, return false
     if (!empty($this_battle->flags['battle_complete_message_created'])) {
         return false;
     }
     // Create references to save time 'cause I'm tired
     // (rather than replace all target references to this references)
     $this_battle =& $this_battle;
     $this_player =& $this->player;
     // the player of the robot being disabled
     $this_robot =& $this;
     // the robot being disabled
     $target_player =& $target_robot->player;
     // the player of the other robot
     $target_robot =& $target_robot;
     // the other robot that isn't this one
     // If the target player is the same as the current or the target is dead
     if ($this_player->player_id == $target_player->player_id) {
         // Collect the actual target player from the battle values
         if (!empty($this_battle->values['players'])) {
             foreach ($this_battle->values['players'] as $id => $info) {
                 if ($this_player->player_id != $id) {
                     unset($target_player);
                     $target_player = new rpg_player($info);
                 }
             }
         }
         // Collect the actual target robot from the battle values
         if (!empty($target_player->values['robots_active'])) {
             foreach ($target_player->values['robots_active'] as $key => $info) {
                 if ($info['robot_position'] == 'active') {
                     $target_robot->robot_load($info);
                 }
             }
         }
     }
     // Update the target player's session
     $this_player->update_session();
     // Create the robot disabled event
     $disabled_text = in_array($this_robot->robot_token, array('dark-frag', 'dark-spire', 'dark-tower')) || $this_robot->robot_core == 'empty' ? 'destroyed' : 'disabled';
     $event_header = ($this_player->player_token != 'player' ? $this_player->player_name . '&#39;s ' : '') . $this_robot->robot_name;
     $event_body = ($this_player->player_token != 'player' ? $this_player->print_name() . '&#39;s ' : 'The target ') . ' ' . $this_robot->print_name() . ' was ' . $disabled_text . '!<br />';
     //'.($this_robot->robot_position == 'bench' ? ' and removed from battle' : '').'
     if (isset($this_robot->robot_quotes['battle_defeat'])) {
         $this_find = array('{target_player}', '{target_robot}', '{this_player}', '{this_robot}');
         $this_replace = array($target_player->player_name, $target_robot->robot_name, $this_player->player_name, $this_robot->robot_name);
         $event_body .= $this_robot->print_quote('battle_defeat', $this_find, $this_replace);
     }
     if ($target_robot->robot_status != 'disabled') {
         $target_robot->robot_frame = 'base';
     }
     $this_robot->robot_frame = 'defeat';
     $target_robot->update_session();
     $this_robot->update_session();
     $this_battle->events_create($this_robot, $target_robot, $event_header, $event_body, array('console_show_target' => false, 'canvas_show_disabled_bench' => $this_robot->robot_id . '_' . $this_robot->robot_token));
     /*
      * EFFORT VALUES / STAT BOOST BONUSES
      */
     // Define the event options array
     $event_options = array();
     $event_options['this_ability_results']['total_actions'] = 0;
     // Calculate the bonus boosts from defeating the target robot (if NOT player battle)
     if ($target_player->player_side == 'left' && $this_player->player_id == MMRPG_SETTINGS_TARGET_PLAYERID && $target_robot->robot_status != 'disabled') {
         // Boost this robot's attack if a boost is in order
         if (empty($target_robot->flags['robot_stat_max_attack'])) {
             $this_attack_boost = $this_robot->robot_base_attack / 100;
             //ceil($this_robot->robot_base_attack / 100);
             if ($this_robot->robot_class == 'mecha') {
                 $this_attack_boost = $this_attack_boost / 2;
             }
             if ($target_player->player_side == 'left' && $target_robot->robot_class == 'mecha') {
                 $this_attack_boost = $this_attack_boost * 2;
             }
             if ($target_robot->robot_attack + $this_attack_boost > MMRPG_SETTINGS_STATS_MAX) {
                 $this_attack_overboost = (MMRPG_SETTINGS_STATS_MAX - $target_robot->robot_attack) * -1;
                 $this_attack_boost = $this_attack_boost - $this_attack_overboost;
             }
             $this_attack_boost = round($this_attack_boost);
         } else {
             $this_attack_boost = 0;
         }
         // Boost this robot's defense if a boost is in order
         if (empty($target_robot->flags['robot_stat_max_defense'])) {
             $this_defense_boost = $this_robot->robot_base_defense / 100;
             //ceil($this_robot->robot_base_defense / 100);
             if ($this_robot->robot_class == 'mecha') {
                 $this_defense_boost = $this_defense_boost / 2;
             }
             if ($target_player->player_side == 'left' && $target_robot->robot_class == 'mecha') {
                 $this_defense_boost = $this_defense_boost * 2;
             }
             if ($target_robot->robot_defense + $this_defense_boost > MMRPG_SETTINGS_STATS_MAX) {
                 $this_defense_overboost = (MMRPG_SETTINGS_STATS_MAX - $target_robot->robot_defense) * -1;
                 $this_defense_boost = $this_defense_boost - $this_defense_overboost;
             }
             $this_defense_boost = round($this_defense_boost);
         } else {
             $this_defense_boost = 0;
         }
         // Boost this robot's speed if a boost is in order
         if (empty($target_robot->flags['robot_stat_max_speed'])) {
             $this_speed_boost = $this_robot->robot_base_speed / 100;
             //ceil($this_robot->robot_base_speed / 100);
             if ($this_robot->robot_class == 'mecha') {
                 $this_speed_boost = $this_speed_boost / 2;
             }
             if ($target_player->player_side == 'left' && $target_robot->robot_class == 'mecha') {
                 $this_speed_boost = $this_speed_boost * 2;
             }
             if ($target_robot->robot_speed + $this_speed_boost > MMRPG_SETTINGS_STATS_MAX) {
                 $this_speed_overboost = (MMRPG_SETTINGS_STATS_MAX - $target_robot->robot_speed) * -1;
                 $this_speed_boost = $this_speed_boost - $this_speed_overboost;
             }
             $this_speed_boost = round($this_speed_boost);
         } else {
             $this_speed_boost = 0;
         }
         // If the target robot is holding a Growth Module, double the stat bonuses
         if ($target_robot->robot_item == 'growth-module') {
             if (!$this_attack_boost) {
                 $this_attack_boost = $this_attack_boost * 2;
             }
             if (!$this_defense_boost) {
                 $this_defense_boost = $this_defense_boost * 2;
             }
             if (!$this_speed_boost) {
                 $this_speed_boost = $this_speed_boost * 2;
             }
         }
         // Define the temporary boost actions counter
         $temp_boost_actions = 1;
         // Increase reward if there are any pending stat boosts and clear session
         if ($target_player->player_side == 'left' && ($target_robot->robot_level == 100 && $target_robot->robot_class == 'master') && $target_robot->robot_base_attack < MMRPG_SETTINGS_STATS_MAX) {
             if (!empty($_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_attack_pending'])) {
                 $this_attack_boost += $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_attack_pending'];
                 $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_attack_pending'] = 0;
             }
         }
         // Increase reward if there are any pending stat boosts and clear session
         if ($target_player->player_side == 'left' && ($target_robot->robot_level == 100 && $target_robot->robot_class == 'master') && $target_robot->robot_base_defense < MMRPG_SETTINGS_STATS_MAX) {
             if (!empty($_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_defense_pending'])) {
                 $this_defense_boost += $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_defense_pending'];
                 $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_defense_pending'] = 0;
             }
         }
         // Increase reward if there are any pending stat boosts and clear session
         if ($target_player->player_side == 'left' && ($target_robot->robot_level == 100 && $target_robot->robot_class == 'master') && $target_robot->robot_base_speed < MMRPG_SETTINGS_STATS_MAX) {
             if (!empty($_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_speed_pending'])) {
                 $this_speed_boost += $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_speed_pending'];
                 $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_speed_pending'] = 0;
             }
         }
         // If the attack boost was not empty, process it
         if ($this_attack_boost > 0) {
             // If the robot is under level 100, stat boosts are pending
             if ($target_player->player_side == 'left' && $target_robot->robot_level < 100 && $target_robot->robot_class == 'master') {
                 // Update the session variables with the pending stat boost
                 if (empty($_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_attack_pending'])) {
                     $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_attack_pending'] = 0;
                 }
                 $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_attack_pending'] += $this_attack_boost;
             } elseif ($target_player->player_side == 'left' && ($target_robot->robot_level == 100 && $target_robot->robot_class == 'master' || $target_robot->robot_class == 'mecha') && $target_robot->robot_base_attack < MMRPG_SETTINGS_STATS_MAX) {
                 // Define the base attack boost based on robot base stats
                 $temp_attack_boost = ceil($this_attack_boost);
                 // If this action would boost the robot over their stat limits
                 if ($temp_attack_boost + $target_robot->robot_attack > MMRPG_SETTINGS_STATS_MAX) {
                     $temp_attack_boost = MMRPG_SETTINGS_STATS_MAX - $target_robot->robot_attack;
                 }
                 // Increment this robot's attack by the calculated amount and display an event
                 $target_robot->robot_attack = ceil($target_robot->robot_attack + $temp_attack_boost);
                 $target_robot->robot_base_attack = ceil($target_robot->robot_base_attack + $temp_attack_boost);
                 $event_options = array();
                 $event_options['this_ability_results']['trigger_kind'] = 'recovery';
                 $event_options['this_ability_results']['recovery_kind'] = 'attack';
                 $event_options['this_ability_results']['recovery_type'] = '';
                 $event_options['this_ability_results']['flag_affinity'] = true;
                 $event_options['this_ability_results']['flag_critical'] = true;
                 $event_options['this_ability_results']['this_amount'] = $temp_attack_boost;
                 $event_options['this_ability_results']['this_result'] = 'success';
                 $event_options['this_ability_results']['total_actions'] = $temp_boost_actions++;
                 $event_options['this_ability_user'] = $this->robot_id . '_' . $this->robot_token;
                 $event_options['this_ability_target'] = $target_robot->robot_id . '_' . $target_robot->robot_token;
                 $event_options['console_show_target'] = false;
                 $event_body = $target_robot->print_name() . ' downloads weapons data from the target robot! ';
                 $event_body .= '<br />';
                 $event_body .= $target_robot->print_name() . '&#39;s attack grew by <span class="recovery_amount">' . $temp_attack_boost . '</span>! ';
                 $target_robot->robot_frame = 'shoot';
                 $target_robot->update_session();
                 $target_player->update_session();
                 $this_battle->events_create($target_robot, $this_robot, $event_header, $event_body, $event_options);
                 // Update the session variables with the rewarded stat boost if not mecha
                 if ($target_robot->robot_class == 'master') {
                     if (empty($_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_attack'])) {
                         $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_attack'] = 0;
                     }
                     $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_attack'] = ceil($_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_attack']);
                     $temp_attack_session_boost = round($this_attack_boost);
                     if ($temp_attack_session_boost < 1) {
                         $temp_attack_session_boost = 1;
                     }
                     $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_attack'] += $temp_attack_session_boost;
                 }
             }
         }
         // If the defense boost was not empty, process it
         if ($this_defense_boost > 0) {
             // If the robot is under level 100, stat boosts are pending
             if ($target_player->player_side == 'left' && $target_robot->robot_level < 100 && $target_robot->robot_class == 'master') {
                 // Update the session variables with the pending stat boost
                 if (empty($_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_defense_pending'])) {
                     $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_defense_pending'] = 0;
                 }
                 $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_defense_pending'] += $this_defense_boost;
             } elseif ($target_player->player_side == 'left' && ($target_robot->robot_level == 100 && $target_robot->robot_class == 'master' || $target_robot->robot_class == 'mecha') && $target_robot->robot_base_defense < MMRPG_SETTINGS_STATS_MAX) {
                 // Define the base defense boost based on robot base stats
                 $temp_defense_boost = ceil($this_defense_boost);
                 // If this action would boost the robot over their stat limits
                 if ($temp_defense_boost + $target_robot->robot_defense > MMRPG_SETTINGS_STATS_MAX) {
                     $temp_defense_boost = MMRPG_SETTINGS_STATS_MAX - $target_robot->robot_defense;
                 }
                 // Increment this robot's defense by the calculated amount and display an event
                 $target_robot->robot_defense = ceil($target_robot->robot_defense + $temp_defense_boost);
                 $target_robot->robot_base_defense = ceil($target_robot->robot_base_defense + $temp_defense_boost);
                 $event_options = array();
                 $event_options['this_ability_results']['trigger_kind'] = 'recovery';
                 $event_options['this_ability_results']['recovery_kind'] = 'defense';
                 $event_options['this_ability_results']['recovery_type'] = '';
                 $event_options['this_ability_results']['flag_affinity'] = true;
                 $event_options['this_ability_results']['flag_critical'] = true;
                 $event_options['this_ability_results']['this_amount'] = $temp_defense_boost;
                 $event_options['this_ability_results']['this_result'] = 'success';
                 $event_options['this_ability_results']['total_actions'] = $temp_boost_actions++;
                 $event_options['this_ability_user'] = $this->robot_id . '_' . $this->robot_token;
                 $event_options['this_ability_target'] = $target_robot->robot_id . '_' . $target_robot->robot_token;
                 $event_options['console_show_target'] = false;
                 $event_body = $target_robot->print_name() . ' downloads shield data from the target robot! ';
                 $event_body .= '<br />';
                 $event_body .= $target_robot->print_name() . '&#39;s defense grew by <span class="recovery_amount">' . $temp_defense_boost . '</span>! ';
                 $target_robot->robot_frame = 'defend';
                 $target_robot->update_session();
                 $target_player->update_session();
                 $this_battle->events_create($target_robot, $this_robot, $event_header, $event_body, $event_options);
                 // Update the session variables with the rewarded stat boost if not mecha
                 if ($target_robot->robot_class == 'master') {
                     if (empty($_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_defense'])) {
                         $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_defense'] = 0;
                     }
                     $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_defense'] = ceil($_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_defense']);
                     $temp_defense_session_boost = round($this_defense_boost);
                     if ($temp_defense_session_boost < 1) {
                         $temp_defense_session_boost = 1;
                     }
                     $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_defense'] += $temp_defense_session_boost;
                 }
             }
         }
         // If the speed boost was not empty, process it
         if ($this_speed_boost > 0) {
             // If the robot is under level 100, stat boosts are pending
             if ($target_player->player_side == 'left' && $target_robot->robot_level < 100 && $target_robot->robot_class == 'master') {
                 // Update the session variables with the pending stat boost
                 if (empty($_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_speed_pending'])) {
                     $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_speed_pending'] = 0;
                 }
                 $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_speed_pending'] += $this_speed_boost;
             } elseif ($target_player->player_side == 'left' && ($target_robot->robot_level == 100 && $target_robot->robot_class == 'master' || $target_robot->robot_class == 'mecha') && $target_robot->robot_base_speed < MMRPG_SETTINGS_STATS_MAX) {
                 // Define the base speed boost based on robot base stats
                 $temp_speed_boost = ceil($this_speed_boost);
                 // If this action would boost the robot over their stat limits
                 if ($temp_speed_boost + $target_robot->robot_speed > MMRPG_SETTINGS_STATS_MAX) {
                     $temp_speed_boost = MMRPG_SETTINGS_STATS_MAX - $target_robot->robot_speed;
                 }
                 // Increment this robot's speed by the calculated amount and display an event
                 $target_robot->robot_speed = ceil($target_robot->robot_speed + $temp_speed_boost);
                 $target_robot->robot_base_speed = ceil($target_robot->robot_base_speed + $temp_speed_boost);
                 $event_options = array();
                 $event_options['this_ability_results']['trigger_kind'] = 'recovery';
                 $event_options['this_ability_results']['recovery_kind'] = 'speed';
                 $event_options['this_ability_results']['recovery_type'] = '';
                 $event_options['this_ability_results']['flag_affinity'] = true;
                 $event_options['this_ability_results']['flag_critical'] = true;
                 $event_options['this_ability_results']['this_amount'] = $temp_speed_boost;
                 $event_options['this_ability_results']['this_result'] = 'success';
                 $event_options['this_ability_results']['total_actions'] = $temp_boost_actions++;
                 $event_options['this_ability_user'] = $this->robot_id . '_' . $this->robot_token;
                 $event_options['this_ability_target'] = $target_robot->robot_id . '_' . $target_robot->robot_token;
                 $event_options['console_show_target'] = false;
                 $event_body = $target_robot->print_name() . ' downloads mobility data from the target robot! ';
                 $event_body .= '<br />';
                 $event_body .= $target_robot->print_name() . '&#39;s speed grew by <span class="recovery_amount">' . $temp_speed_boost . '</span>! ';
                 $target_robot->robot_frame = 'slide';
                 $target_robot->update_session();
                 $target_player->update_session();
                 $this_battle->events_create($target_robot, $this_robot, $event_header, $event_body, $event_options);
                 // Update the session variables with the rewarded stat boost if not mecha
                 if ($target_robot->robot_class == 'master') {
                     if (empty($_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_speed'])) {
                         $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_speed'] = 0;
                     }
                     $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_speed'] = ceil($_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_speed']);
                     $temp_speed_session_boost = round($this_speed_boost);
                     if ($temp_speed_session_boost < 1) {
                         $temp_speed_session_boost = 1;
                     }
                     $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$target_robot->robot_token]['robot_speed'] += $temp_speed_session_boost;
                 }
             }
         }
         // Update the target robot frame
         $target_robot->robot_frame = 'base';
         $target_robot->update_session();
     }
     // Ensure player and robot variables are updated
     $target_robot->update_session();
     $target_player->update_session();
     $this_robot->update_session();
     $this_player->update_session();
     /*
     // DEBUG
     $this_battle->events_create(false, false, 'DEBUG', 'we made it past the stat boosts... <br />'.
         '$this_robot->robot_token='.$this_robot->robot_token.'; $target_robot->robot_token='.$target_robot->robot_token.';<br />'.
         '$target_player->player_token='.$target_player->player_token.'; $target_player->player_side='.$target_player->player_side.';<br />'
         );
     */
     /*
      * ITEM REWARDS / EXPERIENCE POINTS / LEVEL UP
      * Reward the player and robots with items and experience if not in demo mode
      */
     if ($target_player->player_side == 'left' && $this_player->player_id == MMRPG_SETTINGS_TARGET_PLAYERID && rpg_game::is_user()) {
         // -- EXPERIENCE POINTS / LEVEL UP -- //
         // Filter out robots who were active in this battle in at least some way
         $temp_robots_active = $target_player->values['robots_active'];
         usort($temp_robots_active, array('rpg_functions', 'robot_sort_by_active'));
         // Define the boost multiplier and start out at zero
         $temp_boost_multiplier = 0;
         // DEBUG
         //$event_body = preg_replace('/\s+/', ' ', $this_robot->robot_token.' : $this_robot->counters = <pre>'.print_r($this_robot->counters, true).'</pre>');
         //$this_battle->events_create(false, false, 'DEBUG', $event_body);
         // If the target has had any damage flags triggered, update the multiplier
         //if ($this_robot->flags['triggered_immunity']){ $temp_boost_multiplier += 0; }
         //if (!empty($this_robot->flags['triggered_resistance'])){ $temp_boost_multiplier -= $this_robot->counters['triggered_resistance'] * 0.10; }
         //if (!empty($this_robot->flags['triggered_affinity'])){ $temp_boost_multiplier -= $this_robot->counters['triggered_affinity'] * 0.10; }
         //if (!empty($this_robot->flags['triggered_weakness'])){ $temp_boost_multiplier += $this_robot->counters['triggered_weakness'] * 0.10; }
         //if (!empty($this_robot->flags['triggered_critical'])){ $temp_boost_multiplier += $this_robot->counters['triggered_critical'] * 0.10; }
         // If we're in DEMO mode, give a 100% experience boost
         //if (rpg_game::is_demo()){ $temp_boost_multiplier += 1; }
         // Ensure the multiplier has not gone below 100%
         if ($temp_boost_multiplier < -0.99) {
             $temp_boost_multiplier = -0.99;
         } elseif ($temp_boost_multiplier > 0.99) {
             $temp_boost_multiplier = 0.99;
         }
         // Define the boost text to match the multiplier
         $temp_boost_text = '';
         if ($temp_boost_multiplier < 0) {
             $temp_boost_text = 'a lowered ';
         } elseif ($temp_boost_multiplier > 0) {
             $temp_boost_text = 'a boosted ';
         }
         /*
         $event_body = preg_replace('/\s+/', ' ', $this_robot->robot_token.'<pre>'.print_r($this_robot->flags, true).'</pre>');
         //$this_battle->events_create(false, false, 'DEBUG', $event_body);
         
         $event_body = preg_replace('/\s+/', ' ', $target_robot->robot_token.'<pre>'.print_r($target_robot->flags, true).'</pre>');
         //$this_battle->events_create(false, false, 'DEBUG', $event_body);
         */
         // Define the base experience for the target robot
         $temp_experience = $this_robot->robot_base_energy + $this_robot->robot_base_attack + $this_robot->robot_base_defense + $this_robot->robot_base_speed;
         // DEBUG
         //$event_body = preg_replace('/\s+/', ' ', $this_robot->robot_token.' : $temp_boost_multiplier = '.$temp_boost_multiplier.'; $temp_experience = '.$temp_experience.'; ');
         //$this_battle->events_create(false, false, 'DEBUG_'.__LINE__, $event_body);
         // Apply any boost multipliers to the experience earned
         if ($temp_boost_multiplier > 0 || $temp_boost_multiplier < 0) {
             $temp_experience += $temp_experience * $temp_boost_multiplier;
         }
         if ($temp_experience <= 0) {
             $temp_experience = 1;
         }
         $temp_experience = round($temp_experience);
         $temp_target_experience = array('level' => $this_robot->robot_level, 'experience' => $temp_experience);
         // DEBUG
         //$event_body = preg_replace('/\s+/', ' ', $this_robot->robot_token.' : $temp_target_experience = <pre>'.print_r($temp_target_experience, true).'</pre>');
         //$this_battle->events_create(false, false, 'DEBUG', $event_body);
         // Define the robot experience level and start at zero
         $target_robot_experience = 0;
         // Sort the active robots based on active or not
         /*
         function mmrpg_sort_temp_active_robots($info1, $info2){
             if ($info1['robot_position'] == 'active'){ return -1; }
             else { return 1; }
         }
         usort($temp_robots_active, 'mmrpg_sort_temp_active_robots');
         */
         // If the target was defeated with overkill, add it to the battle var
         if (!empty($this_robot->counters['defeat_overkill'])) {
             $overkill_bonus = $this_robot->counters['defeat_overkill'];
             //$overkill_bonus = $overkill_bonus - ceil($overkill_bonus * 0.90);
             //$overkill_divider = $target_robot->robot_level >= 100 ? 0.01 : (100 - $target_robot->robot_level) / 100;
             //$overkill_bonus = floor($overkill_bonus * $overkill_divider);
             //$this_battle->events_create(false, false, 'DEBUG', '<pre>'.preg_replace('/\s+/', ' ', print_r(array('$this_battle->battle_overkill' => $this_battle->battle_overkill, '$this_battle->battle_rewards_zenny' => $this_battle->battle_rewards_zenny), true)).'</pre>', $event_options);
             //$this_battle->events_create(false, false, 'DEBUG', '<pre>'.preg_replace('/\s+/', ' ', print_r(array('$overkill_bonus' => $overkill_bonus), true)).'</pre>', $event_options);
             //$this_battle->events_create(false, false, 'DEBUG', '<pre>'.preg_replace('/\s+/', ' ', print_r(array('$this_robot->robot_base_total' => $this_robot->robot_base_total, '$target_robot->robot_base_total' => $target_robot->robot_base_total), true)).'</pre>', $event_options);
             //if ($target_robot->robot_base_total > $this_robot->robot_base_total){ $overkill_bonus = floor($overkill_bonus * ($this_robot->robot_base_total / $target_robot->robot_base_total));   }
             //elseif ($target_robot->robot_base_total < $this_robot->robot_base_total){ $overkill_bonus = floor($overkill_bonus * ($target_robot->robot_base_total / $this_robot->robot_base_total));   }
             //$this_battle->events_create(false, false, 'DEBUG', '<pre>'.preg_replace('/\s+/', ' ', print_r(array('$overkill_bonus' => $overkill_bonus), true)).'</pre>', $event_options);
             $this_battle->battle_overkill += $this_robot->counters['defeat_overkill'];
             if (empty($this_battle->flags['starter_battle'])) {
                 $this_battle->battle_rewards_zenny += $overkill_bonus;
             }
             $this_battle->update_session();
             //$this_battle->events_create(false, false, 'DEBUG', '<pre>'.preg_replace('/\s+/', ' ', print_r(array('$this_battle->battle_overkill' => $this_battle->battle_overkill, '$this_battle->battle_rewards_zenny' => $this_battle->battle_rewards_zenny), true)).'</pre>', $event_options);
         }
         // Increment each of this player's robots
         $temp_robots_active_num = count($temp_robots_active);
         $temp_robots_active_num2 = $temp_robots_active_num;
         // This will be decremented for each non-experience gaining level 100 robots
         $temp_robots_active = array_reverse($temp_robots_active, true);
         usort($temp_robots_active, array('rpg_functions', 'robot_sort_by_active'));
         $temp_robot_active_position = false;
         foreach ($temp_robots_active as $temp_id => $temp_info) {
             $temp_robot = $target_robot->robot_id == $temp_info['robot_id'] ? $target_robot : new rpg_robot($target_player, $temp_info);
             if ($temp_robot->robot_level >= 100 || $temp_robot->robot_class != 'master') {
                 $temp_robots_active_num2--;
             }
             if ($temp_robot->robot_position == 'active') {
                 $temp_robot_active_position = $temp_robots_active[$temp_id];
                 unset($temp_robots_active[$temp_id]);
             }
         }
         $temp_unshift = array_unshift($temp_robots_active, $temp_robot_active_position);
         foreach ($temp_robots_active as $temp_id => $temp_info) {
             // Collect or define the robot points and robot rewards variables
             $temp_robot = $target_robot->robot_id == $temp_info['robot_id'] ? $target_robot : new rpg_robot($target_player, $temp_info);
             //if ($temp_robot->robot_class == 'mecha'){ continue; }
             $temp_robot_token = $temp_info['robot_token'];
             if ($temp_robot_token == 'robot') {
                 continue;
             }
             $temp_robot_experience = rpg_game::robot_experience($target_player->player_token, $temp_info['robot_token']);
             $temp_robot_rewards = !empty($temp_info['robot_rewards']) ? $temp_info['robot_rewards'] : array();
             if (empty($temp_robots_active_num2)) {
                 break;
             }
             // Continue if over already at level 100
             //if ($temp_robot->robot_level >= 100){ continue; }
             // Reset the robot experience points to zero
             $target_robot_experience = 0;
             // Continue with experience mods only if under level 100
             if ($temp_robot->robot_level < 100 && $temp_robot->robot_class == 'master') {
                 // Give a proportionate amount of experience based on this and the target robot's levels
                 if ($temp_robot->robot_level == $temp_target_experience['level']) {
                     $temp_experience_boost = $temp_target_experience['experience'];
                 } elseif ($temp_robot->robot_level < $temp_target_experience['level']) {
                     $temp_experience_boost = $temp_target_experience['experience'] + round(($temp_target_experience['level'] - $temp_robot->robot_level) / 100 * $temp_target_experience['experience']);
                     //$temp_experience_boost = $temp_target_experience['experience'] + ((($temp_target_experience['level']) / $temp_robot->robot_level) * $temp_target_experience['experience']);
                 } elseif ($temp_robot->robot_level > $temp_target_experience['level']) {
                     $temp_experience_boost = $temp_target_experience['experience'] - round(($temp_robot->robot_level - $temp_target_experience['level']) / 100 * $temp_target_experience['experience']);
                     //$temp_experience_boost = $temp_target_experience['experience'] - ((($temp_robot->robot_level - $temp_target_experience['level']) / 100) * $temp_target_experience['experience']);
                 }
                 // DEBUG
                 //$event_body = 'START EXPERIENCE | ';
                 //$event_body .= preg_replace('/\s+/', ' ', $this_robot->robot_token.' : $temp_experience_boost = '.$temp_experience_boost.'; $target_robot_experience = '.$target_robot_experience.'; ');
                 //$this_battle->events_create(false, false, 'DEBUG', $event_body);
                 //$temp_experience_boost = ceil($temp_experience_boost / 10);
                 $temp_experience_boost = ceil($temp_experience_boost / $temp_robots_active_num);
                 //$temp_experience_boost = ceil($temp_experience_boost / ($temp_robots_active_num * 2));
                 //$temp_experience_boost = ceil($temp_experience_boost / ($temp_robots_active_num2 * 2));
                 //$temp_experience_boost = ceil(($temp_experience_boost / $temp_robots_active_num2) * 1.00);
                 if ($temp_experience_boost > MMRPG_SETTINGS_STATS_MAX) {
                     $temp_experience_boost = MMRPG_SETTINGS_STATS_MAX;
                 }
                 $target_robot_experience += $temp_experience_boost;
                 // DEBUG
                 //$event_body = 'ACTIVE ROBOT DIVISION | ';
                 //$event_body .= preg_replace('/\s+/', ' ', $this_robot->robot_token.' : $temp_experience_boost = '.$temp_experience_boost.'; $target_robot_experience = '.$target_robot_experience.'; $temp_robots_active_num = '.$temp_robots_active_num.'; $temp_robots_active_num2 = '.$temp_robots_active_num2.'; ');
                 //$this_battle->events_create(false, false, 'DEBUG', $event_body);
                 // If this robot has been traded, give it an additional experience boost
                 $temp_experience_boost = 0;
                 $temp_robot_boost_text = $temp_boost_text;
                 $temp_player_boosted = false;
                 if ($temp_robot->player_token != $temp_robot->robot_original_player) {
                     $temp_player_boosted = true;
                     $temp_robot_boost_text = 'a player boosted ';
                     $temp_experience_bak = $target_robot_experience;
                     $target_robot_experience = $target_robot_experience * 2;
                     $temp_experience_boost = $target_robot_experience - $temp_experience_bak;
                     // DEBUG
                     //$event_body = 'PLAYER BOOSTED | ';
                     //$event_body .= preg_replace('/\s+/', ' ', $this_robot->robot_token.' : $temp_experience_boost = '.$temp_experience_boost.'; $target_robot_experience = '.$target_robot_experience.'; $temp_robot->player_token('.$temp_robot->player_token.') != $temp_robot->robot_original_player('.$temp_robot->robot_original_player.'); ');
                     //$this_battle->events_create(false, false, 'DEBUG', $event_body);
                 }
                 // If the target robot is holding a Growth Module, double the experience bonus
                 if ($temp_robot->robot_item == 'growth-module') {
                     $temp_robot_boost_text = $temp_player_boosted ? 'a player and module boosted ' : 'a module boosted ';
                     $temp_experience_bak = $target_robot_experience;
                     $target_robot_experience = $target_robot_experience * 2;
                     $temp_experience_boost = $target_robot_experience - $temp_experience_bak;
                     // DEBUG
                     //$event_body = 'MODULE BOOSTED | ';
                     //$event_body .= preg_replace('/\s+/', ' ', $this_robot->robot_token.' : $temp_experience_boost = '.$temp_experience_boost.'; $target_robot_experience = '.$target_robot_experience.'; $temp_robot->robot_item = '.$temp_robot->robot_item.'; ');
                     //$this_battle->events_create(false, false, 'DEBUG', $event_body);
                 }
                 // If there are field multipliers in place, apply them now
                 $temp_experience_boost = 0;
                 if (isset($this->field->field_multipliers['experience'])) {
                     //$temp_robot_boost_text = '(and '.$target_robot_experience.' multiplied by '.number_format($this->field->field_multipliers['experience'], 1).') ';
                     $temp_experience_bak = $target_robot_experience;
                     $target_robot_experience = ceil($target_robot_experience * $this->field->field_multipliers['experience']);
                     $temp_experience_boost = $target_robot_experience - $temp_experience_bak;
                 }
                 // DEBUG
                 //$event_body = 'FIELD MULTIPLIERS | ';
                 //$event_body .= preg_replace('/\s+/', ' ', $this_robot->robot_token.' : $temp_experience_boost = '.$temp_experience_boost.'; $target_robot_experience = '.$target_robot_experience.'; ');
                 //$this_battle->events_create(false, false, 'DEBUG', $event_body);
                 /*
                 // If this robot has any overkill, add that to the temp experience modifier
                 $temp_experience_boost = 0;
                 if (!empty($this_robot->counters['defeat_overkill'])){
                     if (empty($temp_robot_boost_text)){ $temp_robot_boost_text = 'an overkill boosted '; }
                     else { $temp_robot_boost_text = 'a player and overkill boosted '; }
                     $temp_experience_bak = $target_robot_experience;
                     $target_robot_experience += ceil($this_robot->counters['defeat_overkill'] / $temp_robots_active_num2);
                     $temp_experience_boost = $target_robot_experience - $temp_experience_bak;
                     //$this_battle->battle_overkill += $this_robot->counters['defeat_overkill'];
                     //$this_battle->update_session();
                     //$temp_robot_boost_text .= 'umm '.$this_battle->battle_overkill;
                 }
                 */
                 // DEBUG
                 //$event_body = 'OVERKILL BONUS | ';
                 //$event_body .= preg_replace('/\s+/', ' ', $this_robot->robot_token.' : $temp_experience_boost = '.$temp_experience_boost.'; $target_robot_experience = '.$target_robot_experience.'; ');
                 //$this_battle->events_create(false, false, 'DEBUG', $event_body);
                 /*
                 // If the target robot's core type has been boosted by starforce
                 if (!empty($temp_robot->robot_core) && !empty($_SESSION['GAME']['values']['star_force'][$temp_robot->robot_core])){
                     if (empty($temp_robot_boost_text)){ $temp_robot_boost_text = 'a starforce boosted '; }
                     elseif ($temp_robot_boost_text == 'an overkill boosted '){ $temp_robot_boost_text = 'an overkill and starforce boosted '; }
                     elseif ($temp_robot_boost_text == 'a player boosted '){ $temp_robot_boost_text = 'a player and starforce boosted '; }
                     else { $temp_robot_boost_text = 'a player, overkill, and starforce boosted '; }
                     $temp_starforce = $_SESSION['GAME']['values']['star_force'][$temp_robot->robot_core];
                     $temp_experience_bak = $target_robot_experience;
                     $target_robot_experience += ceil($target_robot_experience * ($temp_starforce / 10));
                     $temp_experience_boost = $target_robot_experience - $temp_experience_bak;
                 }
                 */
                 // DEBUG
                 //$event_body = 'STARFORCE BONUS | ';
                 //$event_body .= preg_replace('/\s+/', ' ', $temp_robot->robot_token.' : '.$temp_robot->robot_core.' : $temp_experience_boost = '.$temp_experience_boost.'; $target_robot_experience = '.$target_robot_experience.'; ');
                 //$this_battle->events_create(false, false, 'DEBUG', $event_body);
                 // If the experience is greater then the max, level it off at the max (sorry guys!)
                 if ($target_robot_experience > MMRPG_SETTINGS_STATS_MAX) {
                     $target_robot_experience = MMRPG_SETTINGS_STATS_MAX;
                 }
                 if ($target_robot_experience < MMRPG_SETTINGS_STATS_MIN) {
                     $target_robot_experience = MMRPG_SETTINGS_STATS_MIN;
                 }
                 // Collect the robot's current experience and level for reference later
                 $temp_start_experience = rpg_game::robot_experience($target_player->player_token, $temp_robot_token);
                 $temp_start_level = rpg_game::robot_level($target_player->player_token, $temp_robot_token);
                 // Increment this robots's points total with the battle points
                 if (!isset($_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$temp_robot_token]['robot_level'])) {
                     $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$temp_robot_token]['robot_level'] = 1;
                 }
                 if (!isset($_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$temp_robot_token]['robot_experience'])) {
                     $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$temp_robot_token]['robot_experience'] = 0;
                 }
                 $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$temp_robot_token]['robot_experience'] += $target_robot_experience;
                 // Define the new experience for this robot
                 $temp_required_experience = rpg_prototype::calculate_experience_required($temp_robot->robot_level);
                 $temp_new_experience = rpg_game::robot_experience($target_player->player_token, $temp_info['robot_token']);
                 // If the new experience is over the required, level up the robot
                 $level_boost = 0;
                 if ($temp_new_experience > $temp_required_experience) {
                     //$level_boost = floor($temp_new_experience / $temp_required_experience);
                     while ($temp_new_experience > $temp_required_experience) {
                         $level_boost += 1;
                         $temp_new_experience -= $temp_required_experience;
                         $temp_required_experience = rpg_prototype::calculate_experience_required($temp_robot->robot_level + $level_boost);
                     }
                     $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$temp_robot_token]['robot_level'] += $level_boost;
                     $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$temp_robot_token]['robot_experience'] = $temp_new_experience;
                     //$level_boost * $temp_required_experience;
                     if ($_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$temp_robot_token]['robot_level'] > 100) {
                         $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$temp_robot_token]['robot_level'] = 100;
                     }
                     $temp_new_experience = rpg_game::robot_experience($target_player->player_token, $temp_info['robot_token']);
                 }
                 // Define the new level for this robot
                 $temp_new_level = rpg_game::robot_level($target_player->player_token, $temp_robot_token);
             } else {
                 // Collect the robot's current experience and level for reference later
                 $temp_start_experience = rpg_game::robot_experience($target_player->player_token, $temp_robot_token);
                 $temp_start_level = rpg_game::robot_level($target_player->player_token, $temp_robot_token);
                 // Define the new experience for this robot
                 $temp_new_experience = $temp_start_experience;
                 $temp_new_level = $temp_start_level;
             }
             // Define the event options
             $event_options = array();
             $event_options['this_ability_results']['trigger_kind'] = 'recovery';
             $event_options['this_ability_results']['recovery_kind'] = 'experience';
             $event_options['this_ability_results']['recovery_type'] = '';
             $event_options['this_ability_results']['this_amount'] = $target_robot_experience;
             $event_options['this_ability_results']['this_result'] = 'success';
             $event_options['this_ability_results']['flag_affinity'] = true;
             $event_options['this_ability_results']['total_actions'] = 1;
             $event_options['this_ability_user'] = $this->robot_id . '_' . $this->robot_token;
             $event_options['this_ability_target'] = $temp_robot->robot_id . '_' . $temp_robot->robot_token;
             // Update player/robot frames and points for the victory
             $temp_robot->robot_frame = 'victory';
             $temp_robot->robot_level = $temp_new_level;
             $temp_robot->robot_experience = $temp_new_experience;
             $target_player->set_frame('victory');
             $temp_robot->update_session();
             // Only display the event if the player is under level 100
             if ($temp_robot->robot_level < 100 && $temp_robot->robot_class == 'master') {
                 // Display the win message for this robot with battle points
                 $temp_robot->robot_frame = 'taunt';
                 $temp_robot->robot_level = $temp_new_level;
                 if ($temp_start_level != $temp_new_level) {
                     $temp_robot->robot_experience = rpg_prototype::calculate_experience_required($temp_robot->robot_level);
                 }
                 $target_player->set_frame('victory');
                 $event_header = $temp_robot->robot_name . '&#39;s Rewards';
                 $event_multiplier_text = $temp_robot_boost_text;
                 $event_body = $temp_robot->print_name() . ' collects ' . $event_multiplier_text . '<span class="recovery_amount ability_type ability_type_cutter">' . $target_robot_experience . '</span> experience points! ';
                 $event_body .= '<br />';
                 if (isset($temp_robot->robot_quotes['battle_victory'])) {
                     $this_find = array('{target_player}', '{target_robot}', '{this_player}', '{this_robot}');
                     $this_replace = array($this_player->player_name, $this_robot->robot_name, $target_player->player_name, $temp_robot->robot_name);
                     $event_body .= $temp_robot->print_quote('battle_victory', $this_find, $this_replace);
                 }
                 //$event_options = array();
                 $event_options['console_show_target'] = false;
                 $event_options['this_header_float'] = $event_options['this_body_float'] = $target_player->player_side;
                 $temp_robot->update_session();
                 $this_battle->events_create($temp_robot, $this_robot, $event_header, $event_body, $event_options);
                 if ($temp_start_level != $temp_new_level) {
                     $temp_robot->robot_experience = $temp_new_experience;
                 }
                 if ($temp_robot->robot_core == 'copy') {
                     $temp_robot->robot_image = $temp_robot->robot_base_image;
                     $temp_robot->robot_image_overlay = array();
                 }
                 $temp_robot->update_session();
                 $target_player->update_session();
             }
             // Floor the robot's experience with or without the event
             $target_player->set_frame('victory');
             $temp_robot->robot_frame = 'base';
             if ($temp_start_level != $temp_new_level) {
                 $temp_robot->robot_experience = 0;
             }
             $temp_robot->update_session();
             // If the level has been boosted, display the stat increases
             if ($temp_start_level != $temp_new_level) {
                 // Define the event options
                 $event_options = array();
                 $event_options['this_ability_results']['trigger_kind'] = 'recovery';
                 $event_options['this_ability_results']['recovery_kind'] = 'level';
                 $event_options['this_ability_results']['recovery_type'] = '';
                 $event_options['this_ability_results']['flag_affinity'] = true;
                 $event_options['this_ability_results']['flag_critical'] = true;
                 $event_options['this_ability_results']['this_amount'] = $temp_new_level - $temp_start_level;
                 $event_options['this_ability_results']['this_result'] = 'success';
                 $event_options['this_ability_results']['total_actions'] = 2;
                 $event_options['this_ability_user'] = $this->robot_id . '_' . $this->robot_token;
                 $event_options['this_ability_target'] = $temp_robot->robot_id . '_' . $temp_robot->robot_token;
                 // Display the win message for this robot with battle points
                 $temp_robot->robot_frame = 'taunt';
                 $temp_robot->robot_level = $temp_new_level;
                 if ($temp_start_level != $temp_new_level) {
                     $temp_robot->robot_experience = rpg_prototype::calculate_experience_required($temp_robot->robot_level);
                 } else {
                     $temp_robot->robot_experience = $temp_new_experience;
                 }
                 $target_player->set_frame('victory');
                 $event_header = $temp_robot->robot_name . '&#39;s Rewards';
                 //$event_body = $temp_robot->print_name().' grew to <span class="recovery_amount'.($temp_new_level >= 100 ? ' ability_type ability_type_electric' : '').'">Level '.$temp_new_level.'</span>!<br /> ';
                 $event_body = $temp_robot->print_name() . ' grew to <span class="recovery_amount ability_type ability_type_level">Level ' . $temp_new_level . ($temp_new_level >= 100 ? ' &#9733;' : '') . '</span>!<br /> ';
                 $event_body .= $temp_robot->robot_name . '&#39;s energy, weapons, shields, and mobility were upgraded!';
                 //$event_options = array();
                 $event_options['console_show_target'] = false;
                 $event_options['this_header_float'] = $event_options['this_body_float'] = $target_player->player_side;
                 $temp_robot->update_session();
                 $this_battle->events_create($temp_robot, $this_robot, $event_header, $event_body, $event_options);
                 $temp_robot->robot_experience = 0;
                 $temp_robot->update_session();
                 // Collect the base robot template from the index for calculations
                 $temp_index_robot = rpg_robot::get_index_info($temp_robot->robot_token);
                 // Define the event options
                 $event_options['this_ability_results']['trigger_kind'] = 'recovery';
                 $event_options['this_ability_results']['recovery_type'] = '';
                 $event_options['this_ability_results']['this_amount'] = $this_defense_boost;
                 $event_options['this_ability_results']['this_result'] = 'success';
                 $event_options['this_ability_results']['total_actions'] = 0;
                 $event_options['this_ability_user'] = $this->robot_id . '_' . $this->robot_token;
                 $event_options['this_ability_target'] = $temp_robot->robot_id . '_' . $temp_robot->robot_token;
                 // Update the robot rewards array with any recent info
                 $temp_robot_rewards = rpg_game::robot_rewards($target_player->player_token, $temp_robot->robot_token);
                 //$this_battle->events_create(false, false, 'DEBUG', '<pre>'.preg_replace('/\s+/', ' ', print_r($temp_robot_rewards, true)).'</pre>', $event_options);
                 // Define the base energy boost based on robot base stats
                 $temp_energy_boost = ceil($level_boost * (0.05 * $temp_index_robot['robot_energy']));
                 // If this robot has reached level 100, the max level, create the flag in their session
                 if ($temp_new_level >= 100) {
                     $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$temp_robot->robot_token]['flags']['reached_max_level'] = true;
                 }
                 // Check if there are eny pending energy stat boosts for level up
                 if (!empty($temp_robot_rewards['robot_energy_pending'])) {
                     $temp_robot_rewards['robot_energy_pending'] = round($temp_robot_rewards['robot_energy_pending']);
                     $temp_energy_boost += $temp_robot_rewards['robot_energy_pending'];
                     if (!empty($temp_robot_rewards['robot_energy'])) {
                         $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$temp_robot->robot_token]['robot_energy'] += $temp_robot_rewards['robot_energy_pending'];
                     } else {
                         $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$temp_robot->robot_token]['robot_energy'] = $temp_robot_rewards['robot_energy_pending'];
                     }
                     $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$temp_robot->robot_token]['robot_energy_pending'] = 0;
                 }
                 // Increment this robot's energy by the calculated amount and display an event
                 $temp_robot->robot_energy += $temp_energy_boost;
                 $temp_base_energy_boost = ceil($level_boost * (0.05 * $temp_index_robot['robot_energy']));
                 $temp_robot->robot_base_energy += $temp_base_energy_boost;
                 $event_options['this_ability_results']['recovery_kind'] = 'energy';
                 $event_options['this_ability_results']['this_amount'] = $temp_energy_boost;
                 $event_options['this_ability_results']['total_actions']++;
                 $event_body = $temp_robot->print_name() . '&#39;s health improved! ';
                 $event_body .= '<br />';
                 $event_body .= $temp_robot->print_name() . '&#39;s energy grew by <span class="recovery_amount">' . $temp_energy_boost . '</span>! ';
                 $temp_robot->robot_frame = 'summon';
                 $temp_robot->update_session();
                 $target_player->update_session();
                 $this_battle->events_create($temp_robot, $this_robot, $event_header, $event_body, $event_options);
                 // Define the base attack boost based on robot base stats
                 $temp_attack_boost = ceil($level_boost * (0.05 * $temp_index_robot['robot_attack']));
                 // Check if there are eny pending attack stat boosts for level up
                 if (!empty($temp_robot_rewards['robot_attack_pending'])) {
                     $temp_robot_rewards['robot_attack_pending'] = round($temp_robot_rewards['robot_attack_pending']);
                     $temp_attack_boost += $temp_robot_rewards['robot_attack_pending'];
                     if (!empty($temp_robot_rewards['robot_attack'])) {
                         $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$temp_robot->robot_token]['robot_attack'] += $temp_robot_rewards['robot_attack_pending'];
                     } else {
                         $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$temp_robot->robot_token]['robot_attack'] = $temp_robot_rewards['robot_attack_pending'];
                     }
                     $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$temp_robot->robot_token]['robot_attack_pending'] = 0;
                 }
                 // Increment this robot's attack by the calculated amount and display an event
                 $temp_robot->robot_attack += $temp_attack_boost;
                 $temp_base_attack_boost = ceil($level_boost * (0.05 * $temp_index_robot['robot_attack']));
                 $temp_robot->robot_base_attack += $temp_base_attack_boost;
                 $event_options['this_ability_results']['recovery_kind'] = 'attack';
                 $event_options['this_ability_results']['this_amount'] = $temp_attack_boost;
                 $event_options['this_ability_results']['total_actions']++;
                 $event_body = $temp_robot->print_name() . '&#39;s weapons improved! ';
                 $event_body .= '<br />';
                 $event_body .= $temp_robot->print_name() . '&#39;s attack grew by <span class="recovery_amount">' . $temp_attack_boost . '</span>! ';
                 $temp_robot->robot_frame = 'shoot';
                 $temp_robot->update_session();
                 $target_player->update_session();
                 $this_battle->events_create($temp_robot, $this_robot, $event_header, $event_body, $event_options);
                 // Define the base defense boost based on robot base stats
                 $temp_defense_boost = ceil($level_boost * (0.05 * $temp_index_robot['robot_defense']));
                 // Check if there are eny pending defense stat boosts for level up
                 if (!empty($temp_robot_rewards['robot_defense_pending'])) {
                     $temp_robot_rewards['robot_defense_pending'] = round($temp_robot_rewards['robot_defense_pending']);
                     $temp_defense_boost += $temp_robot_rewards['robot_defense_pending'];
                     if (!empty($temp_robot_rewards['robot_defense'])) {
                         $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$temp_robot->robot_token]['robot_defense'] += $temp_robot_rewards['robot_defense_pending'];
                     } else {
                         $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$temp_robot->robot_token]['robot_defense'] = $temp_robot_rewards['robot_defense_pending'];
                     }
                     $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$temp_robot->robot_token]['robot_defense_pending'] = 0;
                 }
                 // Increment this robot's defense by the calculated amount and display an event
                 $temp_robot->robot_defense += $temp_defense_boost;
                 $temp_base_defense_boost = ceil($level_boost * (0.05 * $temp_index_robot['robot_defense']));
                 $temp_robot->robot_base_defense += $temp_base_defense_boost;
                 $event_options['this_ability_results']['recovery_kind'] = 'defense';
                 $event_options['this_ability_results']['this_amount'] = $temp_defense_boost;
                 $event_options['this_ability_results']['total_actions']++;
                 $event_body = $temp_robot->print_name() . '&#39;s shields improved! ';
                 $event_body .= '<br />';
                 $event_body .= $temp_robot->print_name() . '&#39;s defense grew by <span class="recovery_amount">' . $temp_defense_boost . '</span>! ';
                 $temp_robot->robot_frame = 'defend';
                 $temp_robot->update_session();
                 $target_player->update_session();
                 $this_battle->events_create($temp_robot, $this_robot, $event_header, $event_body, $event_options);
                 // Define the base speed boost based on robot base stats
                 $temp_speed_boost = ceil($level_boost * (0.05 * $temp_index_robot['robot_speed']));
                 // Check if there are eny pending speed stat boosts for level up
                 if (!empty($temp_robot_rewards['robot_speed_pending'])) {
                     $temp_robot_rewards['robot_speed_pending'] = round($temp_robot_rewards['robot_speed_pending']);
                     $temp_speed_boost += $temp_robot_rewards['robot_speed_pending'];
                     if (!empty($temp_robot_rewards['robot_speed'])) {
                         $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$temp_robot->robot_token]['robot_speed'] += $temp_robot_rewards['robot_speed_pending'];
                     } else {
                         $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$temp_robot->robot_token]['robot_speed'] = $temp_robot_rewards['robot_speed_pending'];
                     }
                     $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_robots'][$temp_robot_token]['robot_speed_pending'] = 0;
                 }
                 // Increment this robot's speed by the calculated amount and display an event
                 $temp_robot->robot_speed += $temp_speed_boost;
                 $event_options['this_ability_results']['recovery_kind'] = 'speed';
                 $event_options['this_ability_results']['this_amount'] = $temp_speed_boost;
                 $event_options['this_ability_results']['total_actions']++;
                 $temp_base_speed_boost = ceil($level_boost * (0.05 * $temp_index_robot['robot_speed']));
                 $temp_robot->robot_base_speed += $temp_base_speed_boost;
                 $event_body = $temp_robot->print_name() . '&#39;s mobility improved! ';
                 $event_body .= '<br />';
                 $event_body .= $temp_robot->print_name() . '&#39;s speed grew by <span class="recovery_amount">' . $temp_speed_boost . '</span>! ';
                 $temp_robot->robot_frame = 'slide';
                 $temp_robot->update_session();
                 $target_player->update_session();
                 $this_battle->events_create($temp_robot, $this_robot, $event_header, $event_body, $event_options);
                 // Update the robot frame
                 $temp_robot->robot_frame = 'base';
                 $temp_robot->update_session();
             }
             // Update the experience level for real this time
             $temp_robot->robot_experience = $temp_new_experience;
             $temp_robot->update_session();
             // Collect the robot info array
             $temp_robot_info = $temp_robot->export_array();
             // Collect the indexed robot rewards for new abilities
             $index_robot_rewards = $temp_robot_info['robot_rewards'];
             //$event_body = preg_replace('/\s+/', ' ', '<pre>'.print_r($index_robot_rewards, true).'</pre>');
             //$this_battle->events_create(false, false, 'DEBUG', $event_body);
             // Loop through the ability rewards for this robot if set
             if ($temp_robot->robot_class != 'mecha' && ($temp_start_level == 100 || $temp_start_level != $temp_new_level && !empty($index_robot_rewards['abilities']))) {
                 $temp_abilities_index = $db->get_array_list("SELECT * FROM mmrpg_index_abilities WHERE ability_flag_complete = 1;", 'ability_token');
                 foreach ($index_robot_rewards['abilities'] as $ability_reward_key => $ability_reward_info) {
                     // If the ability does not exist or is otherwise incomplete, continue
                     if (!isset($temp_abilities_index[$ability_reward_info['token']])) {
                         continue;
                     }
                     // If this ability is already unlocked, continue
                     if (rpg_game::ability_unlocked($target_player->player_token, $temp_robot_token, $ability_reward_info['token'])) {
                         continue;
                     }
                     // If we're in DEMO mode, continue
                     if (rpg_game::is_demo()) {
                         continue;
                     }
                     // Check if the required level has been met by this robot
                     if ($temp_new_level >= $ability_reward_info['level']) {
                         // Create the temporary ability object for event creation
                         $temp_ability_info = array('ability_id' => MMRPG_SETTINGS_BATTLEABILITIES_PERROBOT_MAX + $ability_reward_key, 'ability_token' => $ability_reward_info['token']);
                         $temp_ability = new rpg_ability($target_player, $temp_robot, $temp_ability_info);
                         // Collect or define the ability variables
                         $temp_ability_token = $ability_reward_info['token'];
                         // Display the robot reward message markup
                         $event_header = $temp_ability->ability_name . ' Unlocked';
                         $event_body = '<span class="robot_name">' . $temp_info['robot_name'] . '</span> unlocked new ability data!<br />';
                         $event_body .= $temp_ability->print_name() . ' can now be used in battle!';
                         $event_options = array();
                         $event_options['console_show_target'] = false;
                         $event_options['this_header_float'] = $target_player->player_side;
                         $event_options['this_body_float'] = $target_player->player_side;
                         $event_options['this_ability'] = $temp_ability;
                         $event_options['this_ability_image'] = 'icon';
                         $event_options['console_show_this_player'] = false;
                         $event_options['console_show_this_robot'] = false;
                         $event_options['console_show_this_ability'] = true;
                         $event_options['canvas_show_this_ability'] = false;
                         $temp_robot->robot_frame = $ability_reward_key % 2 == 2 ? 'taunt' : 'victory';
                         $temp_robot->update_session();
                         $temp_ability->ability_frame = 'base';
                         $temp_ability->update_session();
                         $this_battle->events_create($temp_robot, false, $event_header, $event_body, $event_options);
                         $temp_robot->robot_frame = 'base';
                         $temp_robot->update_session();
                         // Automatically unlock this ability for use in battle
                         $this_reward = rpg_ability::get_index_info($temp_ability_token);
                         //array('ability_token' => $temp_ability_token);
                         $temp_player_info = $target_player->export_array();
                         $show_event = !rpg_game::ability_unlocked('', '', $temp_ability_token) ? true : false;
                         rpg_game::unlock_ability($temp_player_info, $temp_robot_info, $this_reward, $show_event);
                         if ($temp_robot_info['robot_original_player'] == $temp_player_info['player_token']) {
                             rpg_game::unlock_ability($temp_player_info, false, $this_reward);
                         } else {
                             rpg_game::unlock_ability(array('player_token' => $temp_robot_info['robot_original_player']), false, $this_reward);
                         }
                         //$_SESSION['GAME']['values']['battle_rewards'][$target_player_token]['player_robots'][$temp_robot_token]['robot_abilities'][$temp_ability_token] = $this_reward;
                     }
                 }
             }
         }
         // -- ITEM REWARDS -- //
         // Define the temp player rewards array
         $target_player_rewards = array();
         // Define the chance multiplier and start at one
         $temp_chance_multiplier = $trigger_options['item_multiplier'];
         // Increase the item chance multiplier if one is set for the stage
         if (isset($this_battle->field->field_multipliers['items'])) {
             $temp_chance_multiplier = $temp_chance_multiplier * $this_battle->field->field_multipliers['items'];
         }
         // Define the available item drops for this battle
         $target_player_rewards['items'] = $this_battle->get_item_rewards();
         // Increase the multipliers if starter battle
         if (!empty($this_battle->flags['starter_battle'])) {
             $temp_chance_multiplier = 4;
         } else {
             // If the target holds a Fortune Module, increase the chance of dropps
             $temp_fortune_module = false;
             if ($target_robot->robot_item == 'fortune-module') {
                 $temp_fortune_module = true;
             }
             // If this robot was a MECHA class, it may drop SMALL SCREWS
             if ($this_robot->robot_class == 'mecha') {
                 $target_player_rewards['items'][] = array('chance' => 100, 'token' => 'small-screw', 'quantity' => mt_rand(1, $temp_fortune_module ? 9 : 6));
                 // If this robot was an empty core, it drops other items too
                 if (!empty($this_robot->robot_core) && $this_robot->robot_core == 'empty') {
                     $target_player_rewards['items'][] = array('chance' => 100, 'token' => 'super-pellet');
                 }
             }
             // If this robot was a MASTER class, it may drop LARGE SCREWS
             if ($this_robot->robot_class == 'master') {
                 $target_player_rewards['items'][] = array('chance' => 100, 'token' => 'large-screw', 'quantity' => mt_rand(1, $temp_fortune_module ? 6 : 3));
                 // If this robot was an empty core, it drops other items too
                 if (!empty($this_robot->robot_core) && $this_robot->robot_core == 'empty') {
                     $target_player_rewards['items'][] = array('chance' => 100, 'token' => 'super-capsule');
                 }
             }
             // If this robot was a BOSS class, it may drop EXTRA LIFE
             if ($this_robot->robot_class == 'boss') {
                 $target_player_rewards['items'][] = array('chance' => 100, 'token' => 'extra-life', 'quantity' => mt_rand(1, $temp_fortune_module ? 3 : 1));
             }
             // If this robot was holding an ITEM, it should also drop that at a high rate
             if (!empty($this_robot->robot_item)) {
                 $target_player_rewards['items'][] = array('chance' => 100, 'token' => $this_robot->robot_item);
             }
         }
         // Precount the item values for later use
         $temp_value_total = 0;
         $temp_count_total = 0;
         foreach ($target_player_rewards['items'] as $item_reward_key => $item_reward_info) {
             $temp_value_total += $item_reward_info['chance'];
             $temp_count_total += 1;
         }
         //$this_battle->events_create(false, false, 'DEBUG', '$temp_count_total = '.$temp_count_total.';<br /> $temp_value_total = '.$temp_value_total.'; ');
         // If this robot was a MECHA class and destroyed by WEAKNESS, it may drop a SHARD
         if ($this_robot->robot_class == 'mecha' && !empty($this_robot->flags['triggered_weakness'])) {
             $temp_shard_type = !empty($this->robot_core) ? $this->robot_core : 'none';
             $target_player_rewards['items'] = array();
             $target_player_rewards['items'][] = array('chance' => 100, 'token' => $temp_shard_type . '-shard');
         } elseif (in_array($this_robot->robot_class, array('master', 'boss')) && !empty($this_robot->flags['triggered_weakness'])) {
             $temp_core_type = !empty($this->robot_core) ? $this->robot_core : 'none';
             $target_player_rewards['items'] = array();
             $target_player_rewards['items'][] = array('chance' => 100, 'token' => $temp_core_type . '-core');
         }
         // Recount the item values for later use
         $temp_value_total = 0;
         $temp_count_total = 0;
         foreach ($target_player_rewards['items'] as $item_reward_key => $item_reward_info) {
             $temp_value_total += $item_reward_info['chance'];
             $temp_count_total += 1;
         }
         // Adjust item values for easier to understand percentages
         foreach ($target_player_rewards['items'] as $item_reward_key => $item_reward_info) {
             $target_player_rewards['items'][$item_reward_key]['chance'] = ceil($item_reward_info['chance'] / $temp_value_total * 100);
         }
         // Shuffle the rewards so it doesn't look to formulaic
         shuffle($target_player_rewards['items']);
         // DEBUG
         //$temp_string = '';
         //foreach ($target_player_rewards['items'] AS $info){ $temp_string .= $info['token'].' = '.$info['chance'].'%, '; }
         //$this_battle->events_create(false, false, 'DEBUG', '$target_player_rewards[\'items\'] = '.count($target_player_rewards['items']).'<br /> '.$temp_string);
         // Define a function for dealing with item drops
         if (!function_exists('temp_player_rewards_items')) {
             function temp_player_rewards_items($this_battle, $target_player, $target_robot, $this_robot, $item_reward_key, $item_reward_info, $item_drop_count = 1)
             {
                 global $mmrpg_index;
                 // Create the temporary ability object for event creation
                 $temp_info = array('ability_id' => MMRPG_SETTINGS_BATTLEABILITIES_PERROBOT_MAX + $item_reward_key + 300, 'ability_token' => $item_reward_info['ability_token']);
                 $temp_ability = new rpg_ability($target_player, $target_robot, $item_reward_info);
                 $temp_ability->ability_name = $item_reward_info['ability_name'];
                 $temp_ability->ability_image = $item_reward_info['ability_token'];
                 $temp_ability->update_session();
                 // Collect or define the ability variables
                 $temp_item_token = $item_reward_info['ability_token'];
                 $temp_item_name = $item_reward_info['ability_name'];
                 $temp_item_colour = !empty($item_reward_info['ability_type']) ? $item_reward_info['ability_type'] : 'none';
                 if (!empty($item_reward_info['ability_type2'])) {
                     $temp_item_colour .= '_' . $item_reward_info['ability_type2'];
                 }
                 $temp_type_name = !empty($item_reward_info['ability_type']) ? ucfirst($item_reward_info['ability_type']) : 'Neutral';
                 $allow_over_max = false;
                 $temp_is_shard = preg_match('/-shard$/i', $temp_item_token) ? true : false;
                 $temp_is_core = preg_match('/-core$/i', $temp_item_token) ? true : false;
                 // Define the max quantity limit for this particular item
                 if ($temp_is_shard) {
                     $temp_item_quantity_max = MMRPG_SETTINGS_SHARDS_MAXQUANTITY;
                     $allow_over_max = true;
                 } elseif ($temp_is_core) {
                     $temp_item_quantity_max = MMRPG_SETTINGS_CORES_MAXQUANTITY;
                 } else {
                     $temp_item_quantity_max = MMRPG_SETTINGS_ITEMS_MAXQUANTITY;
                 }
                 // Create the session variable for this item if it does not exist and collect its value
                 if (empty($_SESSION['GAME']['values']['battle_items'][$temp_item_token])) {
                     $_SESSION['GAME']['values']['battle_items'][$temp_item_token] = 0;
                 }
                 $temp_item_quantity = $_SESSION['GAME']['values']['battle_items'][$temp_item_token];
                 // If this item is already at the quantity limit, skip it entirely
                 if ($temp_item_quantity >= $temp_item_quantity_max) {
                     //$this_battle->events_create(false, false, 'DEBUG', 'max count for '.$temp_item_token.' of '.$temp_item_quantity_max.' has been reached ('.($allow_over_max ? 'allow' : 'disallow').')');
                     $_SESSION['GAME']['values']['battle_items'][$temp_item_token] = $temp_item_quantity_max;
                     $temp_item_quantity = $temp_item_quantity_max;
                     if (!$allow_over_max) {
                         return true;
                     }
                 }
                 // Define the new item quantity after increment
                 $temp_item_quantity_new = $temp_item_quantity + $item_drop_count;
                 $shards_remaining = false;
                 // If this is a shard piece
                 if ($temp_is_shard) {
                     // Define the number of shards remaining for a new core
                     $temp_item_quantity_max = MMRPG_SETTINGS_SHARDS_MAXQUANTITY;
                     $shards_remaining = $temp_item_quantity_max - $temp_item_quantity_new;
                     // If this player has collected enough shards to create a new core
                     if ($shards_remaining == 0) {
                         $temp_body_addon = 'The other ' . $temp_type_name . ' Shards from the inventory started glowing&hellip;';
                     } else {
                         $temp_body_addon = 'Collect ' . $shards_remaining . ' more shard' . ($shards_remaining > 1 ? 's' : '') . ' to create a new ' . $temp_type_name . ' Core!';
                     }
                 } elseif (preg_match('/-core$/i', $temp_item_token)) {
                     // Define the robot core drop text for displau
                     $temp_body_addon = $target_player->print_name() . ' added the new core to the inventory.';
                 } else {
                     // Define the normal item drop text for display
                     $temp_body_addon = $target_player->print_name() . ' added the dropped item' . ($item_drop_count > 1 ? 's' : '') . ' to the inventory.';
                 }
                 // Display the robot reward message markup
                 $event_header = $temp_item_name . ' Item Drop';
                 $event_body = rpg_functions::get_random_positive_word();
                 $event_body .= ' The disabled ' . $this_robot->print_name() . ' dropped ';
                 if ($item_drop_count == 1) {
                     $event_body .= (preg_match('/^(a|e|i|o|u)/i', $temp_item_name) ? 'an' : 'a') . ' <span class="ability_name ability_type ability_type_' . $temp_item_colour . '">' . $temp_item_name . '</span>!<br />';
                 } else {
                     $event_body .= 'x' . $item_drop_count . ' <span class="ability_name ability_type ability_type_' . $temp_item_colour . '">' . ($temp_item_name == 'Extra Life' ? 'Extra Lives' : $temp_item_name . 's') . '</span>!<br />';
                 }
                 $event_body .= $temp_body_addon;
                 $event_options = array();
                 $event_options['console_show_target'] = false;
                 $event_options['this_header_float'] = $target_player->player_side;
                 $event_options['this_body_float'] = $target_player->player_side;
                 $event_options['this_ability'] = $temp_ability;
                 $event_options['this_ability_image'] = 'icon';
                 $event_options['event_flag_victory'] = true;
                 $event_options['console_show_this_player'] = false;
                 $event_options['console_show_this_robot'] = false;
                 $event_options['console_show_this_ability'] = true;
                 $event_options['canvas_show_this_ability'] = true;
                 $target_player->set_frame($item_reward_key % 3 == 0 ? 'victory' : 'taunt');
                 $target_robot->robot_frame = $item_reward_key % 2 == 0 ? 'taunt' : 'base';
                 $target_robot->update_session();
                 $temp_ability->ability_frame = 'base';
                 $temp_ability->ability_frame_offset = array('x' => 220, 'y' => 0, 'z' => 10);
                 $temp_ability->update_session();
                 $this_battle->events_create($target_robot, $target_robot, $event_header, $event_body, $event_options);
                 // Create and/or increment the session variable for this item increasing its quantity
                 if (empty($_SESSION['GAME']['values']['battle_items'][$temp_item_token])) {
                     $_SESSION['GAME']['values']['battle_items'][$temp_item_token] = 0;
                 }
                 if ($temp_item_quantity < $temp_item_quantity_max) {
                     $_SESSION['GAME']['values']['battle_items'][$temp_item_token] += $item_drop_count;
                 }
                 // If this was a shard, and it was the LAST shard
                 if ($shards_remaining !== false && $shards_remaining < 1) {
                     // Define the new core token and increment value in session
                     $temp_core_token = str_replace('shard', 'core', $temp_item_token);
                     $temp_core_name = str_replace('Shard', 'Core', $temp_item_name);
                     $item_core_info = array('ability_token' => $temp_core_token, 'ability_name' => $temp_core_name, 'ability_type' => $item_reward_info['ability_type']);
                     // Create the temporary ability object for event creation
                     $temp_info['ability_id'] += 1;
                     $temp_info['ability_token'] = $temp_core_token;
                     $temp_core = new rpg_ability($target_player, $target_robot, $temp_info);
                     $temp_core->ability_name = $item_core_info['ability_name'];
                     $temp_core->ability_image = $item_core_info['ability_token'];
                     $temp_core->update_session();
                     // Collect or define the ability variables
                     //$temp_core_token = $item_core_info['ability_token'];
                     //$temp_core_name = $item_core_info['ability_name'];
                     $temp_type_name = !empty($temp_core->ability_type) ? ucfirst($temp_core->ability_type) : 'Neutral';
                     $temp_core_colour = !empty($temp_core->ability_type) ? $temp_core->ability_type : 'none';
                     // Define the max quantity limit for this particular item
                     $temp_core_quantity_max = MMRPG_SETTINGS_ITEMS_MAXQUANTITY;
                     // Create the session variable for this item if it does not exist and collect its value
                     if (empty($_SESSION['GAME']['values']['battle_items'][$temp_core_token])) {
                         $_SESSION['GAME']['values']['battle_items'][$temp_core_token] = 0;
                     }
                     $temp_core_quantity = $_SESSION['GAME']['values']['battle_items'][$temp_core_token];
                     // If this item is already at the quantity limit, skip it entirely
                     if ($temp_core_quantity >= $temp_core_quantity_max) {
                         //$this_battle->events_create(false, false, 'DEBUG', 'max count for '.$temp_core_token.' of '.$temp_core_quantity_max.' has been reached');
                         $_SESSION['GAME']['values']['battle_items'][$temp_core_token] = $temp_core_quantity_max;
                         $temp_core_quantity = $temp_core_quantity_max;
                         return true;
                     }
                     // Display the robot reward message markup
                     $event_header = $temp_core_name . ' Item Fusion';
                     $event_body = rpg_functions::get_random_positive_word() . ' The glowing shards fused to create a new ' . $temp_core->print_name() . '!<br />';
                     $event_body .= $target_player->print_name() . ' added the new core to the inventory.';
                     $event_options = array();
                     $event_options['console_show_target'] = false;
                     $event_options['this_header_float'] = $target_player->player_side;
                     $event_options['this_body_float'] = $target_player->player_side;
                     $event_options['this_ability'] = $temp_core;
                     $event_options['this_ability_image'] = 'icon';
                     $event_options['event_flag_victory'] = true;
                     $event_options['console_show_this_player'] = false;
                     $event_options['console_show_this_robot'] = false;
                     $event_options['console_show_this_ability'] = true;
                     $event_options['canvas_show_this_ability'] = true;
                     $target_player->set_frame($item_reward_key + 1 % 3 == 0 ? 'taunt' : 'victory');
                     $target_robot->robot_frame = $item_reward_key % 2 == 0 ? 'base' : 'taunt';
                     $target_robot->update_session();
                     $temp_core->ability_frame = 'base';
                     $temp_core->ability_frame_offset = array('x' => 220, 'y' => 0, 'z' => 10);
                     $temp_core->update_session();
                     $this_battle->events_create($target_robot, $target_robot, $event_header, $event_body, $event_options);
                     // Create and/or increment the session variable for this item increasing its quantity
                     if (empty($_SESSION['GAME']['values']['battle_items'][$temp_core_token])) {
                         $_SESSION['GAME']['values']['battle_items'][$temp_core_token] = 0;
                     }
                     if ($temp_core_quantity < $temp_core_quantity_max) {
                         $_SESSION['GAME']['values']['battle_items'][$temp_core_token] += 1;
                     }
                     // Set the old shard counter back to zero now that they've fused
                     $_SESSION['GAME']['values']['battle_items'][$temp_item_token] = 0;
                     $temp_item_quantity = 0;
                 }
                 // Return true on success
                 return true;
             }
         }
         // Loop through the ability rewards for this robot if set and NOT demo mode
         if (rpg_game::is_user() && !empty($target_player_rewards['items']) && $this->player->player_id == MMRPG_SETTINGS_TARGET_PLAYERID) {
             $temp_items_index = $db->get_array_list("SELECT * FROM mmrpg_index_abilities WHERE ability_flag_complete = 1;", 'ability_token');
             // Define the default success rate and multiply by the modifier
             $temp_success_value = $this_robot->robot_class == 'master' ? 50 : 25;
             $temp_success_value = ceil($temp_success_value * $temp_chance_multiplier);
             // Empty cores always have item drops
             if (!empty($this_robot->robot_core) && $this_robot->robot_core == 'empty') {
                 $temp_success_value = 100;
             }
             // If the target holds a Fortune Module, increase the chance of dropps
             if ($target_robot->robot_item == 'fortune-module') {
                 $temp_success_value = $temp_success_value * 2;
             }
             // Fix success values over 100
             if ($temp_success_value > 100) {
                 $temp_success_value = 100;
             }
             // Define the failure based on success rate
             $temp_failure_value = 100 - $temp_success_value;
             // Define the dropping result based on rates
             $temp_dropping_result = $temp_success_value == 100 ? 'success' : rpg_functions::weighted_chance(array('success', 'failure'), array($temp_success_value, $temp_failure_value));
             //$this_battle->events_create(false, false, 'DEBUG', '..and the result of the drop ('.$temp_success_value.' / '.$temp_failure_value.') is '.$temp_dropping_result);
             if ($temp_dropping_result == 'success') {
                 $temp_value_total = 0;
                 $temp_count_total = 0;
                 foreach ($target_player_rewards['items'] as $item_reward_key => $item_reward_info) {
                     $temp_value_total += $item_reward_info['chance'];
                     $temp_count_total += 1;
                 }
                 $temp_item_counts = array();
                 $temp_item_tokens = array();
                 $temp_item_weights = array();
                 if ($temp_value_total > 0) {
                     foreach ($target_player_rewards['items'] as $item_reward_key => $item_reward_info) {
                         $temp_item_tokens[] = $item_reward_info['token'];
                         $temp_item_weights[] = ceil($item_reward_info['chance'] / $temp_value_total * 100);
                         $temp_item_counts[$item_reward_info['token']] = isset($item_reward_info['quantity']) ? $item_reward_info['quantity'] : 1;
                     }
                 }
                 $temp_random_item = rpg_functions::weighted_chance($temp_item_tokens, $temp_item_weights);
                 $item_index_info = rpg_ability::parse_index_info($temp_items_index[$temp_random_item]);
                 $item_drop_count = $temp_item_counts[$temp_random_item];
                 temp_player_rewards_items($this_battle, $target_player, $target_robot, $this, $item_reward_key, $item_index_info, $item_drop_count);
             }
         }
     }
     // DEBUG
     //$this_battle->events_create(false, false, 'DEBUG', 'we made it past the experience boosts');
     // If the player has replacement robots and the knocked-out one was active
     if ($this_player->counters['robots_active'] > 0) {
         // Try to find at least one active POSITION robot before requiring a switch
         $has_active_positon_robot = false;
         foreach ($this_player->values['robots_active'] as $key => $robot) {
             //if ($robot['robot_position'] == 'active'){ $has_active_positon_robot = true; }
         }
         // If the player does NOT have an active position robot, trigger a switch
         if (!$has_active_positon_robot) {
             // If the target player is not on autopilot, require input
             if ($this_player->player_autopilot == false) {
                 // Empty the action queue to allow the player switch time
                 $this_battle->actions = array();
             } elseif ($this_player->player_autopilot == true) {
                 // && $this_player->player_next_action != 'switch'
                 // Empty the action queue to allow the player switch time
                 $this_battle->actions = array();
                 // Remove any previous switch actions for this player
                 $backup_switch_actions = $this_battle->actions_extract(array('this_player_id' => $this_player->player_id, 'this_action' => 'switch'));
                 //$this_battle->events_create(false, false, 'DEBUG DEBUG', 'This is a test from inside the dead trigger ['.count($backup_switch_actions).'].');
                 // If there were any previous switches removed
                 if (!empty($backup_switch_actions)) {
                     // If the target robot was faster, it should attack first
                     if ($this_robot->robot_speed > $target_robot->robot_speed) {
                         // Prepend an ability action for this robot
                         $this_battle->actions_prepend($this_player, $this_robot, $target_player, $target_robot, 'ability', '');
                     } else {
                         // Prepend an ability action for this robot
                         $this_battle->actions_append($this_player, $this_robot, $target_player, $target_robot, 'ability', '');
                     }
                 }
                 // Prepend a switch action for the target robot
                 $this_battle->actions_prepend($this_player, $this_robot, $target_player, $target_robot, 'switch', '');
             }
         }
     } else {
         // Trigger a battle complete action
         $this_battle->trigger_complete($target_player, $target_robot, $this_player, $this_robot);
     }
     // Either way, set the hidden flag on the robot
     //if (($this_robot->robot_status == 'disabled' || $this_robot->robot_energy < 1) && $this_robot->robot_position == 'bench'){
     if ($this_robot->robot_status == 'disabled' || $this_robot->robot_energy < 1) {
         //$this_robot->robot_status == 'disabled';
         $this_robot->flags['apply_disabled_state'] = true;
         if ($this_robot->robot_position == 'bench') {
             $this_robot->flags['hidden'] = true;
         }
         $this_robot->update_session();
     }
     // -- ROBOT UNLOCKING STUFF!!! -- //
     // Check if this target winner was a HUMAN player and update the robot database counter for defeats
     if ($target_player->player_side == 'left') {
         // Add this robot to the global robot database array
         if (!isset($_SESSION['GAME']['values']['robot_database'][$this->robot_token])) {
             $_SESSION['GAME']['values']['robot_database'][$this->robot_token] = array('robot_token' => $this->robot_token);
         }
         if (!isset($_SESSION['GAME']['values']['robot_database'][$this->robot_token]['robot_defeated'])) {
             $_SESSION['GAME']['values']['robot_database'][$this->robot_token]['robot_defeated'] = 0;
         }
         $_SESSION['GAME']['values']['robot_database'][$this->robot_token]['robot_defeated']++;
     }
     // Check if this battle has any robot rewards to unlock and the winner was a HUMAN player
     $temp_robot_rewards = $this_battle->get_robot_rewards();
     if ($target_player->player_side == 'left' && !empty($temp_robot_rewards)) {
         // DEBUG
         //$this_battle->events_create(false, false, 'DEBUG_'.__LINE__, $this->robot_token.' | trigger_disabled | battle_rewards_robots = '.count($temp_robot_rewards).'');
         foreach ($temp_robot_rewards as $temp_reward_key => $temp_reward_info) {
             // DEBUG
             //$this_battle->events_create(false, false, 'DEBUG_'.__LINE__, $this->robot_token.' | trigger_disabled | checking '.$this->robot_token.' == '.preg_replace('/\s+/', ' ', print_r($temp_reward_info, true)).'...');
             // Check if this robot was part of the rewards for this battle
             if (!rpg_game::robot_unlocked(false, $temp_reward_info['token']) && $this->robot_token == $temp_reward_info['token']) {
                 // DEBUG
                 //$this_battle->events_create(false, false, 'DEBUG_'.__LINE__, $this->robot_token.' | trigger_disabled | '.$this->robot_token.' == '.$temp_reward_info['token'].' is a match!');
                 // Check if this robot has been attacked with any elemental moves
                 if (!empty($this->history['triggered_damage_types'])) {
                     // Loop through all the damage types and check if they're not empty
                     foreach ($this->history['triggered_damage_types'] as $key => $types) {
                         if (!empty($types)) {
                             // DEBUG
                             //$this_battle->events_create(false, false, 'DEBUG_'.__LINE__, $this->robot_token.' | trigger_disabled | '.$this->robot_token.' was attacked with a '.implode(', ', $types).' type ability!<br />Removing from the battle rewards!');
                             // Generate the robot removed event showing the destruction
                             /*
                             $event_header = $this->robot_name.'&#39;s Data Destroyed';
                             $event_body = $this->print_name().'&#39;s battle data was damaged beyond repair!<br />';
                             $event_body .= $this->print_name().' could not be unlocked for use in battle&hellip;';
                             $event_options = array();
                             $event_options['console_show_target'] = false;
                             $event_options['this_header_float'] = $this_player->player_side;
                             $event_options['this_body_float'] = $this_player->player_side;
                             $event_options['console_show_this_player'] = false;
                             $event_options['console_show_this_robot'] = true;
                             $this_robot->robot_frame = 'defeat';
                             $this_robot->update_session();
                             $this_battle->events_create($this, false, $event_header, $event_body, $event_options);
                             */
                             // Remove this robot from the battle rewards array
                             unset($temp_robot_rewards[$temp_reward_key]);
                             // Break, we know all we need to
                             break;
                         }
                     }
                 }
                 // If this robot is somehow still a reward, print a message showing a good job
                 if (!empty($temp_robot_rewards[$temp_reward_key])) {
                     // Collect this reward's information
                     $robot_reward_info = $temp_robot_rewards[$temp_reward_key];
                     // Collect or define the robot points and robot rewards variables
                     //$this_robot_token = $robot_reward_info['token'];
                     $this_robot_level = !empty($robot_reward_info['level']) ? $robot_reward_info['level'] : 1;
                     $this_robot_experience = !empty($robot_reward_info['experience']) ? $robot_reward_info['experience'] : 0;
                     $this_robot_rewards = !empty($robot_info['robot_rewards']) ? $robot_info['robot_rewards'] : array();
                     // Create the temp new robot for the player
                     //$temp_index_robot = rpg_robot::get_index_info($this_robot_token);
                     $temp_index_robot['robot_id'] = MMRPG_SETTINGS_TARGET_PLAYERID * 2;
                     $temp_index_robot['robot_level'] = $this_robot_level;
                     $temp_index_robot['robot_experience'] = $this_robot_experience;
                     $temp_unlocked_robot = new rpg_robot($target_player, $temp_index_robot);
                     // Automatically unlock this robot for use in battle
                     //$temp_unlocked_player = $mmrpg_index['players'][$target_player->player_token];
                     rpg_game::unlock_robot($temp_unlocked_player, $temp_index_robot, true, true);
                     // Display the robot reward message markup
                     //$event_header = $temp_unlocked_robot->robot_name.' Unlocked';
                     $event_body = rpg_functions::get_random_positive_word() . ' ' . $target_player->print_name() . ' unlocked new robot data!<br />';
                     $event_body .= $temp_unlocked_robot->print_name() . ' can now be used in battle!';
                     $event_options = array();
                     $event_options['console_show_target'] = false;
                     $event_options['this_header_float'] = $target_player->player_side;
                     $event_options['this_body_float'] = $target_player->player_side;
                     $event_options['this_robot_image'] = 'mug';
                     $temp_unlocked_robot->robot_frame = 'base';
                     $temp_unlocked_robot->update_session();
                     $this_battle->events_create($temp_unlocked_robot, false, $event_header, $event_body, $event_options);
                 }
                 // Update the battle with robot reward changes
                 $temp_robot_rewards = array_values($temp_robot_rewards);
                 $this_battle->set_robot_rewards($temp_robot_rewards);
             }
         }
     }
     // Return true on success
     return true;
 }
Exemplo n.º 12
0
 public static function save_session($user_id = 0)
 {
     // Reference global variables
     global $db;
     $session_token = self::session_token();
     $mmrpg_index_players = rpg_player::get_index();
     // Do NOT load, save, or otherwise alter the game file while viewing remote
     if (defined('MMRPG_REMOTE_GAME')) {
         return true;
     }
     // Collect or update the user ID in the session
     if (empty($user_id) && isset($_SESSION[$session_token]['USER']['userid'])) {
         $user_id = $_SESSION[$session_token]['USER']['userid'];
     } else {
         $_SESSION[$session_token]['USER']['userid'] = $user_id;
     }
     // Update the last saved value
     $_SESSION[$session_token]['values']['last_save'] = time();
     // If this is NOT demo mode, load from database
     if (empty($_SESSION[$session_token]['DEMO'])) {
         // UPDATE DATABASE INFO
         // Collect the save info
         $save = $_SESSION[$session_token];
         $this_user = $save['USER'];
         $this_cache_date = !empty($save['CACHE_DATE']) ? $save['CACHE_DATE'] : MMRPG_CONFIG_CACHE_DATE;
         $this_counters = !empty($save['counters']) ? $save['counters'] : array();
         $this_values = !empty($save['values']) ? $save['values'] : array();
         $this_flags = !empty($save['flags']) ? $save['flags'] : array();
         $this_settings = !empty($save['battle_settings']) ? $save['battle_settings'] : array();
         $this_stars = !empty($save['values']['battle_stars']) ? $save['values']['battle_stars'] : array();
         unset($save);
         // Collect this user's ID from the database if not set
         if (empty($user_id)) {
             // Generate new user, save, and board IDs for this listing
             $temp_user_id = $db->get_value('SELECT MAX(user_id) AS user_id FROM mmrpg_users WHERE user_id < ' . MMRPG_SETTINGS_GUEST_ID, 'user_id') + 1;
             $temp_save_id = $db->get_value('SELECT MAX(save_id) AS save_id FROM mmrpg_saves', 'save_id') + 1;
             $temp_board_id = $db->get_value('SELECT MAX(board_id) AS board_id FROM mmrpg_leaderboard', 'board_id') + 1;
             // Generate the USER details for import
             $temp_user_array = array();
             $temp_user_array['user_id'] = $temp_user_id;
             $temp_user_array['role_id'] = isset($this_user['roleid']) ? $this_user['roleid'] : 3;
             $temp_user_array['user_name'] = $this_user['username'];
             $temp_user_array['user_name_clean'] = $this_user['username_clean'];
             $temp_user_array['user_name_public'] = !empty($this_user['displayname']) ? $this_user['displayname'] : '';
             $temp_user_array['user_password'] = $this_user['password'];
             $temp_user_array['user_password_encoded'] = $this_user['password_encoded'];
             $temp_user_array['user_profile_text'] = !empty($this_user['profiletext']) ? $this_user['profiletext'] : '';
             $temp_user_array['user_credit_text'] = !empty($this_user['creditstext']) ? $this_user['creditstext'] : '';
             $temp_user_array['user_credit_line'] = !empty($this_user['creditsline']) ? $this_user['creditsline'] : '';
             $temp_user_array['user_image_path'] = !empty($this_user['imagepath']) ? $this_user['imagepath'] : '';
             $temp_user_array['user_background_path'] = !empty($this_user['backgroundpath']) ? $this_user['backgroundpath'] : '';
             $temp_user_array['user_colour_token'] = !empty($this_user['colourtoken']) ? $this_user['colourtoken'] : '';
             $temp_user_array['user_gender'] = !empty($this_user['gender']) ? $this_user['gender'] : '';
             $temp_user_array['user_email_address'] = !empty($this_user['emailaddress']) ? $this_user['emailaddress'] : '';
             $temp_user_array['user_website_address'] = !empty($this_user['websiteaddress']) ? $this_user['websiteaddress'] : '';
             $temp_user_array['user_date_created'] = time();
             $temp_user_array['user_date_accessed'] = time();
             $temp_user_array['user_date_modified'] = time();
             $temp_user_array['user_date_birth'] = !empty($this_user['dateofbirth']) ? $this_user['dateofbirth'] : 0;
             $temp_user_array['user_flag_approved'] = !empty($this_user['approved']) ? 1 : 0;
             // Generate the BOARD details for import
             $temp_board_array = array();
             $temp_board_array['board_id'] = $temp_board_id;
             $temp_board_array['user_id'] = $temp_user_id;
             $temp_board_array['save_id'] = $temp_save_id;
             $temp_board_array['board_points'] = !empty($this_counters['battle_points']) ? $this_counters['battle_points'] : 0;
             $temp_board_array['board_robots'] = array();
             $temp_board_array['board_battles'] = array();
             $temp_board_array['board_stars'] = 0;
             $temp_board_array['board_stars_dr_light'] = 0;
             $temp_board_array['board_stars_dr_wily'] = 0;
             $temp_board_array['board_stars_dr_cossack'] = 0;
             $temp_board_array['board_abilities'] = 0;
             $temp_board_array['board_abilities_dr_light'] = 0;
             $temp_board_array['board_abilities_dr_wily'] = 0;
             $temp_board_array['board_abilities_dr_cossack'] = 0;
             $temp_board_array['board_missions'] = 0;
             $temp_board_array['board_missions_dr_light'] = 0;
             $temp_board_array['board_missions_dr_wily'] = 0;
             $temp_board_array['board_missions_dr_cossack'] = 0;
             $temp_board_ability_tokens = array();
             if (!empty($this_values['battle_rewards'])) {
                 //foreach ($this_values['battle_rewards'] AS $player_token => $player_array){
                 foreach ($mmrpg_index_players as $player_token => $player_array) {
                     if ($player_token == 'player') {
                         continue;
                     }
                     $player_reward_array = !empty($this_values['battle_rewards'][$player_token]) ? $this_values['battle_rewards'][$player_token] : array();
                     $player_battles_array = !empty($this_values['battle_complete'][$player_token]) ? $this_values['battle_complete'][$player_token] : array();
                     $player_database_token = str_replace('-', '_', $player_token);
                     if (!empty($player_reward_array)) {
                         $temp_board_array['board_points_' . $player_database_token] = $player_reward_array['player_points'];
                         $temp_board_array['board_robots_' . $player_database_token] = array();
                         $temp_board_array['board_battles_' . $player_database_token] = array();
                         if (!empty($player_reward_array['player_robots'])) {
                             foreach ($player_reward_array['player_robots'] as $robot_token => $robot_array) {
                                 $temp_token = $robot_array['robot_token'];
                                 $temp_level = !empty($robot_array['robot_level']) ? $robot_array['robot_level'] : 1;
                                 $temp_robot_info = array('robot_token' => $temp_token, $temp_level);
                                 $temp_board_array['board_robots'][] = '[' . $temp_token . ':' . $temp_level . ']';
                                 $temp_board_array['board_robots_' . $player_database_token][] = '[' . $temp_token . ':' . $temp_level . ']';
                             }
                         }
                         if (!empty($player_reward_array['player_abilities'])) {
                             foreach ($player_reward_array['player_abilities'] as $ability_token => $ability_array) {
                                 //if (!isset($ability_array['ability_token'])){ die('player_abilities->'.print_r($ability_array, true)); }
                                 $temp_token = !empty($ability_array['ability_token']) ? $ability_array['ability_token'] : $ability_token;
                                 $temp_board_array['board_abilities_' . $player_database_token] += 1;
                                 if (!in_array($temp_token, $temp_board_ability_tokens)) {
                                     $temp_board_array['board_abilities'] += 1;
                                     $temp_board_ability_tokens[] = $temp_token;
                                 }
                             }
                         }
                         if (!empty($player_battles_array)) {
                             foreach ($player_battles_array as $battle_token => $battle_info) {
                                 $temp_token = $battle_info['battle_token'];
                                 $temp_board_array['board_battles'][] = '[' . $temp_token . ']';
                                 $temp_board_array['board_battles_' . $player_database_token][] = '[' . $temp_token . ']';
                                 $temp_board_array['board_missions'] += 1;
                                 $temp_board_array['board_missions_' . $player_database_token] += 1;
                             }
                         }
                     } else {
                         $temp_board_array['board_points_' . $player_database_token] = 0;
                         $temp_board_array['board_robots_' . $player_database_token] = array();
                         $temp_board_array['board_battles_' . $player_database_token] = array();
                     }
                     $temp_board_array['board_robots_' . $player_database_token] = !empty($temp_board_array['board_robots_' . $player_database_token]) ? implode(',', $temp_board_array['board_robots_' . $player_database_token]) : '';
                     $temp_board_array['board_battles_' . $player_database_token] = !empty($temp_board_array['board_battles_' . $player_database_token]) ? implode(',', $temp_board_array['board_battles_' . $player_database_token]) : '';
                 }
             }
             if (!empty($this_stars)) {
                 foreach ($this_stars as $temp_star_token => $temp_star_info) {
                     $temp_star_player = str_replace('-', '_', $temp_star_info['star_player']);
                     $temp_board_array['board_stars'] += 1;
                     $temp_board_array['board_stars_' . $temp_star_player] += 1;
                 }
             }
             $temp_board_array['board_robots'] = !empty($temp_board_array['board_robots']) ? implode(',', $temp_board_array['board_robots']) : '';
             $temp_board_array['board_battles'] = !empty($temp_board_array['board_battles']) ? implode(',', $temp_board_array['board_battles']) : '';
             $temp_board_array['board_date_created'] = $temp_user_array['user_date_created'];
             $temp_board_array['board_date_modified'] = $temp_user_array['user_date_modified'];
             // Generate the SAVE details for import
             $temp_save_array = array();
             if (!empty($this_values['battle_index'])) {
                 unset($this_values['battle_index']);
             }
             if (!empty($this_values['battle_complete'])) {
                 $temp_save_array['save_values_battle_complete'] = json_encode($this_values['battle_complete']);
                 $temp_hash = md5($temp_save_array['save_values_battle_complete']);
                 if (isset($this_values['battle_complete_hash']) && $this_values['battle_complete_hash'] == $temp_hash) {
                     unset($temp_save_array['save_values_battle_complete']);
                 }
                 unset($this_values['battle_complete'], $this_values['battle_complete_hash']);
             }
             if (!empty($this_values['battle_failure'])) {
                 $temp_save_array['save_values_battle_failure'] = json_encode($this_values['battle_failure']);
                 $temp_hash = md5($temp_save_array['save_values_battle_failure']);
                 if (isset($this_values['battle_failure_hash']) && $this_values['battle_failure_hash'] == $temp_hash) {
                     unset($temp_save_array['save_values_battle_failure']);
                 }
                 unset($this_values['battle_failure'], $this_values['battle_failure_hash']);
             }
             if (!empty($this_values['battle_rewards'])) {
                 $temp_save_array['save_values_battle_rewards'] = json_encode($this_values['battle_rewards']);
                 $temp_hash = md5($temp_save_array['save_values_battle_rewards']);
                 if (isset($this_values['battle_rewards_hash']) && $this_values['battle_rewards_hash'] == $temp_hash) {
                     unset($temp_save_array['save_values_battle_rewards']);
                 }
                 unset($this_values['battle_rewards'], $this_values['battle_rewards_hash']);
             }
             if (!empty($this_values['battle_settings'])) {
                 $temp_save_array['save_values_battle_settings'] = json_encode($this_values['battle_settings']);
                 $temp_hash = md5($temp_save_array['save_values_battle_settings']);
                 if (isset($this_values['battle_settings_hash']) && $this_values['battle_settings_hash'] == $temp_hash) {
                     unset($temp_save_array['save_values_battle_settings']);
                 }
                 unset($this_values['battle_settings'], $this_values['battle_settings_hash']);
             }
             if (!empty($this_values['battle_items'])) {
                 $temp_save_array['save_values_battle_items'] = json_encode($this_values['battle_items']);
                 $temp_hash = md5($temp_save_array['save_values_battle_items']);
                 if (isset($this_values['battle_items_hash']) && $this_values['battle_items_hash'] == $temp_hash) {
                     unset($temp_save_array['save_values_battle_items']);
                 }
                 unset($this_values['battle_items'], $this_values['battle_items_hash']);
             }
             if (!empty($this_values['battle_stars'])) {
                 $temp_save_array['save_values_battle_stars'] = json_encode($this_values['battle_stars']);
                 $temp_hash = md5($temp_save_array['save_values_battle_stars']);
                 if (isset($this_values['battle_stars_hash']) && $this_values['battle_stars_hash'] == $temp_hash) {
                     unset($temp_save_array['save_values_battle_stars']);
                 }
                 unset($this_values['battle_stars'], $this_values['battle_stars_hash']);
             }
             if (!empty($this_values['robot_database'])) {
                 $temp_save_array['save_values_robot_database'] = json_encode($this_values['robot_database']);
                 $temp_hash = md5($temp_save_array['save_values_robot_database']);
                 if (isset($this_values['robot_database_hash']) && $this_values['robot_database_hash'] == $temp_hash) {
                     unset($temp_save_array['save_values_robot_database']);
                 }
                 unset($this_values['robot_database'], $this_values['robot_database_hash']);
             }
             $temp_save_array['save_id'] = $temp_save_id;
             $temp_save_array['user_id'] = $temp_user_id;
             $temp_save_array['save_counters'] = json_encode($this_counters);
             $temp_save_array['save_values'] = json_encode($this_values);
             $temp_save_array['save_flags'] = json_encode($this_flags);
             $temp_save_array['save_settings'] = json_encode($this_settings);
             $temp_save_array['save_cache_date'] = $this_cache_date;
             $temp_save_array['save_file_name'] = $this_file['name'];
             $temp_save_array['save_file_path'] = $this_file['path'];
             $temp_save_array['save_date_created'] = $temp_user_array['user_date_created'];
             $temp_save_array['save_date_accessed'] = $temp_user_array['user_date_accessed'];
             $temp_save_array['save_date_modified'] = $temp_user_array['user_date_modified'];
             // Insert these users into the database
             $temp_user_array_return = $db->insert('mmrpg_users', $temp_user_array);
             $temp_save_array_return = $db->insert('mmrpg_saves', $temp_save_array);
             $temp_board_array_return = $db->insert('mmrpg_leaderboard', $temp_board_array);
             unset($temp_user_array, $temp_save_array, $temp_board_array);
             // Update the ID in the user array and continue
             $this_user['userid'] = $temp_user_id;
             $user_id = $temp_user_id;
         }
         // DEBUG
         $DEBUG = '';
         // Define the user database update array and populate
         $temp_user_array = array();
         $temp_user_array['user_name'] = $this_user['username'];
         $temp_user_array['user_name_clean'] = $this_user['username_clean'];
         $temp_user_array['user_name_public'] = !empty($this_user['displayname']) ? $this_user['displayname'] : '';
         $temp_user_array['user_password'] = $this_user['password'];
         $temp_user_array['user_password_encoded'] = $this_user['password_encoded'];
         $temp_user_array['user_profile_text'] = !empty($this_user['profiletext']) ? $this_user['profiletext'] : '';
         $temp_user_array['user_credit_text'] = !empty($this_user['creditstext']) ? $this_user['creditstext'] : '';
         $temp_user_array['user_credit_line'] = !empty($this_user['creditsline']) ? $this_user['creditsline'] : '';
         $temp_user_array['user_image_path'] = !empty($this_user['imagepath']) ? $this_user['imagepath'] : '';
         $temp_user_array['user_background_path'] = !empty($this_user['backgroundpath']) ? $this_user['backgroundpath'] : '';
         $temp_user_array['user_colour_token'] = !empty($this_user['colourtoken']) ? $this_user['colourtoken'] : '';
         $temp_user_array['user_gender'] = !empty($this_user['gender']) ? $this_user['gender'] : '';
         $temp_user_array['user_email_address'] = !empty($this_user['emailaddress']) ? $this_user['emailaddress'] : '';
         $temp_user_array['user_website_address'] = !empty($this_user['websiteaddress']) ? $this_user['websiteaddress'] : '';
         $temp_user_array['user_date_modified'] = time();
         $temp_user_array['user_date_accessed'] = time();
         $temp_user_array['user_date_birth'] = !empty($this_user['dateofbirth']) ? $this_user['dateofbirth'] : 0;
         $temp_user_array['user_flag_approved'] = !empty($this_user['approved']) ? 1 : 0;
         // Update this user's info in the database
         $db->update('mmrpg_users', $temp_user_array, 'user_id = ' . $this_user['userid']);
         unset($temp_user_array);
         // DEBUG
         //$DEBUG .= '$db->update(\'mmrpg_users\', $temp_user_array, \'user_id = \'.$this_user[\'userid\']);';
         //$DEBUG .= '<pre>$temp_user_array = '.print_r($temp_user_array, true).'</pre>';
         //$DEBUG .= '<pre>$this_user = '******'</pre>';
         // Define the board database update array and populate
         $temp_board_array = array();
         $temp_board_array['board_points'] = !empty($this_counters['battle_points']) ? $this_counters['battle_points'] : 0;
         $temp_board_array['board_robots'] = array();
         $temp_board_array['board_battles'] = array();
         $temp_board_array['board_stars'] = 0;
         $temp_board_array['board_stars_dr_light'] = 0;
         $temp_board_array['board_stars_dr_wily'] = 0;
         $temp_board_array['board_stars_dr_cossack'] = 0;
         $temp_board_array['board_abilities'] = 0;
         $temp_board_array['board_abilities_dr_light'] = 0;
         $temp_board_array['board_abilities_dr_wily'] = 0;
         $temp_board_array['board_abilities_dr_cossack'] = 0;
         $temp_board_array['board_missions'] = 0;
         $temp_board_array['board_missions_dr_light'] = 0;
         $temp_board_array['board_missions_dr_wily'] = 0;
         $temp_board_array['board_missions_dr_cossack'] = 0;
         $temp_board_array['board_awards'] = !empty($this_values['prototype_awards']) ? array_keys($this_values['prototype_awards']) : '';
         $temp_board_ability_tokens = array();
         if (!empty($this_values['battle_rewards'])) {
             //foreach ($this_values['battle_rewards'] AS $player_token => $player_array){
             foreach ($mmrpg_index_players as $player_token => $player_array) {
                 if ($player_token == 'player' || !self::player_unlocked($player_token)) {
                     continue;
                 }
                 $player_reward_array = !empty($this_values['battle_rewards'][$player_token]) ? $this_values['battle_rewards'][$player_token] : array();
                 $player_battles_array = !empty($this_values['battle_complete'][$player_token]) ? $this_values['battle_complete'][$player_token] : array();
                 $player_database_token = str_replace('-', '_', $player_token);
                 if (!empty($player_reward_array)) {
                     $temp_board_array['board_points_' . $player_database_token] = !empty($player_reward_array['player_points']) ? $player_reward_array['player_points'] : 0;
                     $temp_board_array['board_robots_' . $player_database_token] = array();
                     $temp_board_array['board_battles_' . $player_database_token] = array();
                     if (!empty($player_reward_array['player_robots'])) {
                         foreach ($player_reward_array['player_robots'] as $robot_token => $robot_array) {
                             //if (!isset($robot_array['robot_token'])){ die('player_robots->'.print_r($robot_array, true)); }
                             $temp_token = !empty($robot_array['robot_token']) ? $robot_array['robot_token'] : $robot_token;
                             $temp_level = !empty($robot_array['robot_level']) ? $robot_array['robot_level'] : 1;
                             $temp_robot_info = array('robot_token' => $temp_token, $temp_level);
                             $temp_board_array['board_robots'][] = '[' . $temp_token . ':' . $temp_level . ']';
                             $temp_board_array['board_robots_' . $player_database_token][] = '[' . $temp_token . ':' . $temp_level . ']';
                         }
                     }
                     if (!empty($player_reward_array['player_abilities'])) {
                         foreach ($player_reward_array['player_abilities'] as $ability_token => $ability_array) {
                             //if (!isset($ability_array['ability_token'])){ die('player_abilities->'.print_r($ability_array, true)); }
                             $temp_token = !empty($ability_array['ability_token']) ? $ability_array['ability_token'] : $ability_token;
                             $temp_board_array['board_abilities_' . $player_database_token] += 1;
                             if (!in_array($temp_token, $temp_board_ability_tokens)) {
                                 $temp_board_array['board_abilities'] += 1;
                                 $temp_board_ability_tokens[] = $temp_token;
                             }
                         }
                     }
                     if (!empty($player_battles_array)) {
                         foreach ($player_battles_array as $battle_token => $battle_info) {
                             $temp_token = $battle_info['battle_token'];
                             $temp_board_array['board_battles'][] = '[' . $temp_token . ']';
                             $temp_board_array['board_battles_' . $player_database_token][] = '[' . $temp_token . ']';
                             $temp_board_array['board_missions'] += 1;
                             $temp_board_array['board_missions_' . $player_database_token] += 1;
                         }
                     }
                 } else {
                     $temp_board_array['board_points_' . $player_database_token] = 0;
                     $temp_board_array['board_robots_' . $player_database_token] = array();
                     $temp_board_array['board_battles_' . $player_database_token] = array();
                 }
                 $temp_board_array['board_robots_' . $player_database_token] = !empty($temp_board_array['board_robots_' . $player_database_token]) ? implode(',', $temp_board_array['board_robots_' . $player_database_token]) : '';
                 $temp_board_array['board_battles_' . $player_database_token] = !empty($temp_board_array['board_battles_' . $player_database_token]) ? implode(',', $temp_board_array['board_battles_' . $player_database_token]) : '';
             }
         }
         if (!empty($this_stars)) {
             foreach ($this_stars as $temp_star_token => $temp_star_info) {
                 $temp_star_player = str_replace('-', '_', $temp_star_info['star_player']);
                 $temp_board_array['board_stars'] += 1;
                 $temp_board_array['board_stars_' . $temp_star_player] += 1;
             }
         }
         //$temp_board_array['board_robots'] = json_encode($temp_board_array['board_robots']);
         $temp_board_array['board_robots'] = !empty($temp_board_array['board_robots']) ? implode(',', $temp_board_array['board_robots']) : '';
         $temp_board_array['board_battles'] = !empty($temp_board_array['board_battles']) ? implode(',', $temp_board_array['board_battles']) : '';
         $temp_board_array['board_awards'] = !empty($temp_board_array['board_awards']) ? implode(',', $temp_board_array['board_awards']) : '';
         $temp_board_array['board_date_modified'] = time();
         // Update this board's info in the database
         $db->update('mmrpg_leaderboard', $temp_board_array, 'user_id = ' . $this_user['userid']);
         unset($temp_board_array);
         // Clear any leaderboard data that exists in the session, forcing it to recache
         if (isset($_SESSION[$session_token]['BOARD']['boardrank'])) {
             unset($_SESSION[$session_token]['BOARD']['boardrank']);
         }
         // Define the save database update array and populate
         $temp_save_array = array();
         if (!empty($this_values['battle_index'])) {
             ////foreach ($this_values['battle_index'] AS $key => $array){ $this_values['battle_index'][$key] = json_decode($array, true); }
             ////$temp_save_array['save_values_battle_index'] = json_encode($this_values['battle_index']);
             ////$temp_hash = md5($temp_save_array['save_values_battle_index']);
             ////if (isset($this_values['battle_index_hash']) && $this_values['battle_index_hash'] == $temp_hash){ unset($temp_save_array['save_values_battle_index']); }
             //unset($this_values['battle_index'], $this_values['battle_index_hash']);
             unset($this_values['battle_index']);
         }
         if (!empty($this_values['battle_complete'])) {
             $temp_save_array['save_values_battle_complete'] = json_encode($this_values['battle_complete']);
             $temp_hash = md5($temp_save_array['save_values_battle_complete']);
             if (isset($this_values['battle_complete_hash']) && $this_values['battle_complete_hash'] == $temp_hash) {
                 unset($temp_save_array['save_values_battle_complete']);
             }
             unset($this_values['battle_complete'], $this_values['battle_complete_hash']);
         }
         if (!empty($this_values['battle_failure'])) {
             $temp_save_array['save_values_battle_failure'] = json_encode($this_values['battle_failure']);
             $temp_hash = md5($temp_save_array['save_values_battle_failure']);
             if (isset($this_values['battle_failure_hash']) && $this_values['battle_failure_hash'] == $temp_hash) {
                 unset($temp_save_array['save_values_battle_failure']);
             }
             unset($this_values['battle_failure'], $this_values['battle_failure_hash']);
         }
         if (!empty($this_values['battle_rewards'])) {
             $temp_save_array['save_values_battle_rewards'] = json_encode($this_values['battle_rewards']);
             $temp_hash = md5($temp_save_array['save_values_battle_rewards']);
             if (isset($this_values['battle_rewards_hash']) && $this_values['battle_rewards_hash'] == $temp_hash) {
                 unset($temp_save_array['save_values_battle_rewards']);
             }
             unset($this_values['battle_rewards'], $this_values['battle_rewards_hash']);
         }
         if (!empty($this_values['battle_settings'])) {
             $temp_save_array['save_values_battle_settings'] = json_encode($this_values['battle_settings']);
             $temp_hash = md5($temp_save_array['save_values_battle_settings']);
             if (isset($this_values['battle_settings_hash']) && $this_values['battle_settings_hash'] == $temp_hash) {
                 unset($temp_save_array['save_values_battle_settings']);
             }
             unset($this_values['battle_settings'], $this_values['battle_settings_hash']);
         }
         if (!empty($this_values['battle_items'])) {
             $temp_save_array['save_values_battle_items'] = json_encode($this_values['battle_items']);
             $temp_hash = md5($temp_save_array['save_values_battle_items']);
             if (isset($this_values['battle_items_hash']) && $this_values['battle_items_hash'] == $temp_hash) {
                 unset($temp_save_array['save_values_battle_items']);
             }
             unset($this_values['battle_items'], $this_values['battle_items_hash']);
         }
         if (!empty($this_values['battle_stars'])) {
             $temp_save_array['save_values_battle_stars'] = json_encode($this_values['battle_stars']);
             $temp_hash = md5($temp_save_array['save_values_battle_stars']);
             if (isset($this_values['battle_stars_hash']) && $this_values['battle_stars_hash'] == $temp_hash) {
                 unset($temp_save_array['save_values_battle_stars']);
             }
             unset($this_values['battle_stars'], $this_values['battle_stars_hash']);
         }
         if (!empty($this_values['robot_database'])) {
             $temp_save_array['save_values_robot_database'] = json_encode($this_values['robot_database']);
             $temp_hash = md5($temp_save_array['save_values_robot_database']);
             if (isset($this_values['robot_database_hash']) && $this_values['robot_database_hash'] == $temp_hash) {
                 unset($temp_save_array['save_values_robot_database']);
             }
             unset($this_values['robot_database'], $this_values['robot_database_hash']);
         }
         $temp_save_array['save_counters'] = json_encode($this_counters);
         $temp_save_array['save_values'] = json_encode($this_values);
         $temp_save_array['save_flags'] = json_encode($this_flags);
         $temp_save_array['save_settings'] = json_encode($this_settings);
         $temp_save_array['save_cache_date'] = $this_cache_date;
         $temp_save_array['save_date_modified'] = time();
         // Update this save's info in the database
         $db->update('mmrpg_saves', $temp_save_array, 'user_id = ' . $this_user['userid']);
         unset($temp_save_array);
         // DEBUG
         //$DEBUG .= '$db->update(\'mmrpg_saves\', $temp_save_array, \'user_id = \'.$this_user[\'userid\']);';
         //$DEBUG .= '<pre>$temp_save_array = '.print_r($temp_save_array, true).'</pre>';
         //$DEBUG .= '<pre>$this_user = '******'</pre>';
         // DEBUG
         //$DEBUG .= '$db->update(\'mmrpg_leaderboard\', $temp_board_array, \'user_id = \'.$this_user[\'userid\']);';
         //$DEBUG .= '<pre>$temp_board_array = '.print_r($temp_board_array, true).'</pre>';
         //$DEBUG .= '<pre>$this_user = '******'</pre>';
     } else {
         // DEBUG
         //echo 'but we\'re in demo mode';
     }
     // Pull the updated user info from the database
     $user_fields = rpg_user::get_fields(true, 'user');
     $user_role_fields = rpg_user_role::get_fields(true, 'role');
     $this_userinfo = $db->get_array("SELECT\n          {$user_fields}, {$user_role_fields}\n          FROM mmrpg_users AS user\n          LEFT JOIN mmrpg_roles AS role ON role.role_id = user.role_id\n          WHERE user.user_id = '{$user_id}'\n          LIMIT 1");
     // Update the session with the new user info
     $_SESSION['GAME']['USER']['userinfo'] = $this_userinfo;
     // Return true on success
     return true;
 }
Exemplo n.º 13
0
 /**
  * Trigger the battle complete action and end the current mission
  * @param rpg_player this_player
  * @param rpg_robot this_robot
  * @param rpg_player target_player
  * @param rpg_robot target_robot
  */
 public function trigger_complete(rpg_player $this_player, rpg_robot $this_robot, rpg_player $target_player, rpg_robot $target_robot)
 {
     // Collect references to global objects
     $db = cms_database::get_database();
     $this_battle = self::get_battle();
     $this_field = rpg_field::get_field();
     // Default the return variable to false
     $this_return = false;
     //$this_battle->events_create(false, false, 'DEBUG', 'Battle complete trigger triggered!');
     // Return false if anything is missing
     if (empty($this_player) || empty($this_robot)) {
         return false;
     }
     if (empty($target_player) || empty($target_robot)) {
         return false;
     }
     // Return true if the battle status is already complete
     if ($this_battle->battle_status == 'complete') {
         return true;
     }
     // Update the battle status to complete
     $this_battle->set_info('battle_status', 'complete');
     if ($this_battle->battle_result == 'pending') {
         $this_battle->set_info('battle_result', $target_player->player_side == 'right' ? 'victory' : 'defeat');
         $event_options = array();
         if ($this_battle->battle_result == 'victory') {
             $event_options['event_flag_victory'] = true;
         } elseif ($this_battle->battle_result == 'defeat') {
             $event_options['event_flag_defeat'] = true;
         }
         $this_battle->events_create(false, false, '', '', $event_options);
     }
     // -- CALCULATE REWARDS -- //
     // Define variables for the human's rewards in this scenario
     $temp_human_token = $target_player->player_side == 'left' ? $target_player->player_token : $this_player->player_token;
     $temp_human_info = $target_player->player_side == 'left' ? $target_player->export_array() : $this_player->export_array();
     $temp_human_rewards = array();
     $temp_human_rewards['battle_points'] = 0;
     $temp_human_rewards['battle_zenny'] = 0;
     $temp_human_rewards['battle_complete'] = isset($_SESSION['GAME']['values']['battle_complete'][$temp_human_token][$this_battle->battle_token]['battle_count']) ? $_SESSION['GAME']['values']['battle_complete'][$temp_human_token][$this_battle->battle_token]['battle_count'] : 0;
     $temp_human_rewards['battle_failure'] = isset($_SESSION['GAME']['values']['battle_failure'][$temp_human_token][$this_battle->battle_token]['battle_count']) ? $_SESSION['GAME']['values']['battle_failure'][$temp_human_token][$this_battle->battle_token]['battle_count'] : 0;
     $temp_human_rewards['checkpoint'] = 'start: ';
     // Calculate the base point and zenny rewards for this battle
     $temp_reward_points_base = !empty($this_battle->battle_rewards_points) ? $this_battle->battle_rewards_points : 0;
     $temp_reward_zenny_base = !empty($this_battle->battle_rewards_zenny) ? $this_battle->battle_rewards_zenny : 0;
     // Default the bonus to zero and calulate based on turns
     $temp_turn_bonus = 0;
     if ($this_battle->counters['battle_turn'] < $this_battle->battle_turns_limit) {
         $temp_turn_bonus = round(($this_battle->battle_turns_limit - $this_battle->counters['battle_turn']) * 10);
     } elseif ($this_battle->counters['battle_turn'] > $this_battle->battle_turns_limit) {
         $temp_turn_bonus = round(($this_battle->counters['battle_turn'] - $this_battle->battle_turns_limit) * 10) * -1;
     }
     // Default the bonus to zero and calulate based on turns
     $temp_robot_bonus = 0;
     if ($temp_human_info['counters']['robots_masters_total'] < $this_battle->battle_robots_limit) {
         $temp_robot_bonus = round(($this_battle->battle_robots_limit - $temp_human_info['counters']['robots_masters_total']) * 10);
     } elseif ($temp_human_info['counters']['robots_masters_total'] > $this_battle->battle_robots_limit) {
         $temp_robot_bonus = $temp_robot_bonus = round(($temp_human_info['counters']['robots_masters_total'] - $this_battle->battle_robots_limit) * 10) * -1;
     }
     // Calculate the bonus points and zenny for the turns
     $temp_turn_bonus_points = (int) ($temp_reward_points_base * ($temp_turn_bonus / 100));
     $temp_turn_bonus_zenny = (int) ($temp_reward_zenny_base * ($temp_turn_bonus / 100));
     // Calculate the bonus points and zenny for the turns
     $temp_robot_bonus_points = (int) ($temp_reward_points_base * ($temp_robot_bonus / 100));
     $temp_robot_bonus_zenny = (int) ($temp_reward_zenny_base * ($temp_robot_bonus / 100));
     // Calculate the final reward points based on above
     if ($this_battle->battle_result == 'victory') {
         $temp_reward_points_final = $temp_reward_points_base + $temp_turn_bonus_points + $temp_robot_bonus_points;
         $temp_reward_zenny_final = $temp_reward_zenny_base + $temp_turn_bonus_zenny + $temp_robot_bonus_zenny;
         if ($temp_reward_points_final < 0) {
             $temp_reward_points_final = 0;
         }
         if ($temp_reward_zenny_final < 0) {
             $temp_reward_zenny_final = 0;
         }
     } else {
         $temp_reward_points_final = 0;
         $temp_reward_zenny_final = 0;
     }
     // Define the number of stars to show for this mission
     $temp_rating_stars = 0;
     if ($this_battle->battle_result == 'victory') {
         $temp_rating_stars += 1;
         if ($temp_turn_bonus >= 0) {
             $temp_rating_stars += 1;
         }
         if ($temp_robot_bonus >= 0) {
             $temp_rating_stars += 1;
         }
         if (empty($temp_human_info['counters']['robots_disabled'])) {
             $temp_rating_stars += 1;
         }
         if (empty($temp_human_info['counters']['items_used_this_battle'])) {
             $temp_rating_stars += 1;
         }
     }
     // Generate the markup for this stars
     $temp_rating_stars_markup = '';
     for ($i = 1; $i <= 5; $i++) {
         $temp_rating_stars_markup .= $i <= $temp_rating_stars ? '&#9733;' : '&#9734;';
     }
     // (HUMAN) TARGET DEFEATED
     // Check if the target was the human character
     if ($target_player->player_side == 'left') {
         // Increment the main game's points total with the battle points
         $_SESSION['GAME']['counters']['battle_points'] += $temp_reward_points_final;
         $_SESSION['GAME']['counters']['battle_zenny'] += $temp_reward_zenny_final;
         // Increment this player's points total with the battle points
         if (!isset($_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_points'])) {
             $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_points'] = 0;
         }
         if (!isset($_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_zenny'])) {
             $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_zenny'] = 0;
         }
         $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_points'] += $temp_reward_points_final;
         $_SESSION['GAME']['values']['battle_rewards'][$target_player->player_token]['player_zenny'] += $temp_reward_zenny_final;
         // Update the global variable with the points reward
         $temp_human_rewards['battle_points'] = $temp_reward_points_final;
         $temp_human_rewards['battle_zenny'] = $temp_reward_zenny_final;
         // Update the GAME session variable with the failed battle token
         $save_records = $this_battle->has_flag('save_records') ? $this_battle->get_flag('save_records') : true;
         if ($save_records) {
             $bak_session_array = isset($_SESSION['GAME']['values']['battle_failure'][$target_player->player_token][$this_battle->battle_token]) ? $_SESSION['GAME']['values']['battle_failure'][$target_player->player_token][$this_battle->battle_token] : array();
             $new_session_array = array('battle_token' => $this_battle->battle_token, 'battle_count' => 0, 'battle_level' => 0);
             if (!empty($bak_session_array['battle_count'])) {
                 $new_session_array['battle_count'] = $bak_session_array['battle_count'];
             }
             if (!empty($bak_session_array['battle_level'])) {
                 $new_session_array['battle_level'] = $bak_session_array['battle_level'];
             }
             $new_session_array['battle_level'] = $this_battle->battle_level;
             $new_session_array['battle_count']++;
             $_SESSION['GAME']['values']['battle_failure'][$target_player->player_token][$this_battle->battle_token] = $new_session_array;
             $temp_human_rewards['battle_failure'] = $_SESSION['GAME']['values']['battle_failure'][$target_player->player_token][$this_battle->battle_token]['battle_count'];
         }
     }
     // NON-INVISIBLE PLAYER DEFEATED
     // Display the defeat message for the target character if not default/hidden
     if ($target_player->player_token != 'player') {
         // (HUMAN) TARGET DEFEATED BY (INVISIBLE/COMPUTER)
         // If this was a player battle and the human user lost against the ghost target (this/computer/victory | target/human/defeat)
         if ($this_player->player_id == MMRPG_SETTINGS_TARGET_PLAYERID && $target_player->player_side == 'left' && $this_robot->robot_class != 'mecha') {
             // Calculate how many points the other player is rewarded for winning
             $target_player_robots = $target_player->values['robots_disabled'];
             $target_player_robots_count = count($target_player_robots);
             $other_player_points = 0;
             $other_player_turns = $target_player_robots_count * MMRPG_SETTINGS_BATTLETURNS_PERROBOT;
             foreach ($target_player_robots as $disabled_robotinfo) {
                 $other_player_points += $disabled_robotinfo['robot_level'] * MMRPG_SETTINGS_BATTLEPOINTS_PERROBOT * MMRPG_SETTINGS_BATTLEPOINTS_PLAYERBATTLE_MULTIPLIER;
             }
             // Create the victory event for the target player
             $this_robot->robot_frame = 'victory';
             $this_robot->update_session();
             $event_header = $this_robot->robot_name . ' Undefeated';
             $event_body = '';
             $event_body .= $this_robot->print_name() . ' could not be defeated! ';
             $event_body .= '<br />';
             $event_options = array();
             $event_options['console_show_this_robot'] = true;
             $event_options['console_show_target'] = false;
             $event_options['event_flag_defeat'] = true;
             $event_options['this_header_float'] = $event_options['this_body_float'] = $this_robot->player->player_side;
             if ($this_robot->robot_token != 'robot' && isset($this_robot->robot_quotes['battle_victory'])) {
                 $this_find = array('{target_player}', '{target_robot}', '{this_player}', '{this_robot}');
                 $this_replace = array($target_player->player_name, $target_robot->robot_name, $this_player->player_name, $this_robot->robot_name);
                 $event_body .= $this_robot->print_quote('battle_victory', $this_find, $this_replace);
             }
             $this_battle->events_create($this_robot, $target_robot, $event_header, $event_body, $event_options);
         }
         $target_player->set_frame('defeat');
         $target_robot->update_session();
         $event_header = $target_player->player_name . ' Defeated';
         $event_body = $target_player->print_name() . ' was defeated' . ($target_player->player_side == 'left' ? '&hellip;' : '!') . ' ';
         $event_body .= '<br />';
         $event_options = array();
         $event_options['console_show_this_player'] = true;
         $event_options['console_show_target'] = false;
         $event_options['event_flag_defeat'] = true;
         $event_options['this_header_float'] = $event_options['this_body_float'] = $target_player->player_side;
         if ($target_player->player_token != 'player' && isset($target_player->player_quotes['battle_defeat'])) {
             $this_find = array('{target_player}', '{target_robot}', '{this_player}', '{this_robot}');
             $this_replace = array($this_player->player_name, $this_robot->robot_name, $target_player->player_name, $target_robot->robot_name);
             $this_quote_text = str_replace($this_find, $this_replace, $target_player->player_quotes['battle_defeat']);
             $event_body .= $target_player->print_quote('battle_defeat', $this_find, $this_replace);
         }
         $this_battle->events_create($target_robot, $this_robot, $event_header, $event_body, $event_options);
         // (HUMAN) TARGET DEFEATED BY (GHOST/COMPUTER)
         // If this was a player battle and the human user lost against the ghost target (this/computer/victory | target/human/defeat)
         if ($this_player->player_id != MMRPG_SETTINGS_TARGET_PLAYERID && $target_player->player_side == 'left') {
             // Calculate how many points the other player is rewarded for winning
             $target_player_robots = $target_player->values['robots_disabled'];
             $target_player_robots_count = count($target_player_robots);
             $other_player_points = 0;
             $other_player_turns = $target_player_robots_count * MMRPG_SETTINGS_BATTLETURNS_PERROBOT;
             foreach ($target_player_robots as $disabled_robotinfo) {
                 $other_player_points += $disabled_robotinfo['robot_level'] * MMRPG_SETTINGS_BATTLEPOINTS_PERROBOT * MMRPG_SETTINGS_BATTLEPOINTS_PLAYERBATTLE_MULTIPLIER;
             }
             // Create the victory event for the target player
             $this_player->set_frame('victory');
             $target_robot->update_session();
             $event_header = $this_player->player_name . ' Victorious';
             $event_body = $this_player->print_name() . ' was victorious! ';
             $event_body .= $this_player->print_name() . ' could not be defeated!';
             $event_body .= '<br />';
             $event_options = array();
             $event_options['console_show_this_player'] = true;
             $event_options['console_show_target'] = false;
             $event_options['event_flag_defeat'] = true;
             $event_options['this_header_float'] = $event_options['this_body_float'] = $this_player->player_side;
             if ($this_player->player_token != 'player' && isset($this_player->player_quotes['battle_victory'])) {
                 $this_find = array('{target_player}', '{target_robot}', '{this_player}', '{this_robot}');
                 $this_replace = array($target_player->player_name, $target_robot->robot_name, $this_player->player_name, $this_robot->robot_name);
                 $event_body .= $this_player->print_quote('battle_victory', $this_find, $this_replace);
             }
             $this_battle->events_create($this_robot, $target_robot, $event_header, $event_body, $event_options);
         }
     }
     // (HUMAN) TARGET DEFEATED BY (COMPUTER)
     // Check if the target was the human character (and they LOST)
     if ($target_player->player_side == 'left') {
         // Collect the robot info array
         $temp_player_info = $target_player->export_array();
         // Collect or define the player points and player rewards variables
         $temp_player_token = $temp_player_info['player_token'];
         $temp_player_points = rpg_game::player_points($temp_player_info['player_token']);
         $temp_player_rewards = rpg_game::player_rewards($temp_player_info['player_token']);
         //!empty($temp_player_info['player_rewards']) ? $temp_player_info['player_rewards'] : array();
         // -- ABILITY REWARDS for HUMAN PLAYER -- //
         // Loop through the ability rewards for this robot if set
         if (!empty($temp_player_rewards['abilities']) && rpg_game::is_user()) {
             $temp_abilities_index = $db->get_array_list("SELECT * FROM mmrpg_index_abilities WHERE ability_flag_complete = 1;", 'ability_token');
             foreach ($temp_player_rewards['abilities'] as $ability_reward_key => $ability_reward_info) {
                 // If this ability is already unlocked, continue
                 if (rpg_game::ability_unlocked($target_player->player_token, false, $ability_reward_info['token'])) {
                     continue;
                 }
                 // Check if the required level has been met by this robot
                 if ($temp_player_points >= $ability_reward_info['points'] && rpg_game::is_user()) {
                     // Collect the ability info from the index
                     $ability_info = array('ability_id' => MMRPG_SETTINGS_BATTLEABILITIES_PERROBOT_MAX + $ability_reward_key, 'ability_token' => $ability_reward_info['token']);
                     // Create the temporary ability object for event creation
                     $temp_ability = new rpg_ability($target_player, $target_robot, $ability_info);
                     // Collect or define the ability variables
                     $temp_ability_token = $ability_info['ability_token'];
                     // Display the robot reward message markup
                     $event_header = $temp_ability->ability_name . ' Unlocked';
                     $event_body = rpg_functions::get_random_positive_word() . ' <span class="player_name">' . $temp_player_info['player_name'] . '</span> unlocked new ability data!<br />';
                     $event_body .= '<span class="ability_name">' . $temp_ability->ability_name . '</span> can now be used in battle!';
                     $event_options = array();
                     $event_options['console_show_target'] = false;
                     $event_options['this_header_float'] = $target_player->player_side;
                     $event_options['this_body_float'] = $target_player->player_side;
                     $event_options['this_ability'] = $temp_ability;
                     $event_options['this_ability_image'] = 'icon';
                     $event_options['event_flag_victory'] = true;
                     $event_options['console_show_this_player'] = false;
                     $event_options['console_show_this_robot'] = false;
                     $event_options['console_show_this_ability'] = true;
                     $event_options['canvas_show_this_ability'] = false;
                     $target_player->set_frame($ability_reward_key % 2 == 0 ? 'victory' : 'taunt');
                     $temp_ability->ability_frame = 'base';
                     $temp_ability->update_session();
                     $this_battle->events_create($target_robot, $target_robot, $event_header, $event_body, $event_options);
                     // Automatically unlock this ability for use in battle
                     $this_reward = array('ability_token' => $temp_ability_token);
                     $show_event = !rpg_game::ability_unlocked('', '', $temp_ability_token) ? true : false;
                     rpg_game::unlock_ability($temp_player_info, false, $this_reward, $show_event);
                 }
             }
         }
     }
     // (COMPUTER) TARGET DEFEATED BY (HUMAN)
     // Check if this player was the human player (and they WON)
     if ($this_player->player_side == 'left') {
         // Increment the main game's points total with the battle points
         $_SESSION['GAME']['counters']['battle_points'] += $temp_reward_points_final;
         $_SESSION['GAME']['counters']['battle_zenny'] += $temp_reward_zenny_final;
         // Reference the number of points this player gets
         $this_player_points = $temp_reward_points_final;
         $this_player_zenny = $temp_reward_zenny_final;
         // Increment this player's points total with the battle points
         $player_token = $this_player->player_token;
         $player_info = $this_player->export_array();
         if (!isset($_SESSION['GAME']['values']['battle_rewards'][$player_token]['player_points'])) {
             $_SESSION['GAME']['values']['battle_rewards'][$player_token]['player_points'] = 0;
         }
         $_SESSION['GAME']['values']['battle_rewards'][$player_token]['player_points'] += $this_player_points;
         if (!isset($_SESSION['GAME']['values']['battle_rewards'][$player_token]['player_zenny'])) {
             $_SESSION['GAME']['values']['battle_rewards'][$player_token]['player_zenny'] = 0;
         }
         $_SESSION['GAME']['values']['battle_rewards'][$player_token]['player_zenny'] += $this_player_zenny;
         // Update the global variable with the points reward
         $temp_human_rewards['battle_points'] = $this_player_points;
         $temp_human_rewards['battle_zenny'] = $this_player_zenny;
         // Display the win message for this player with battle points
         $this_robot->robot_frame = 'victory';
         $this_player->set_frame('victory');
         $this_robot->update_session();
         $event_header = $this_player->player_name . ' Victorious';
         $event_body = $this_player->print_name() . ' was victorious! ';
         $event_body .= 'The ' . ($target_player->counters['robots_disabled'] > 1 ? 'targets were' : 'target was') . ' defeated!';
         $event_body .= '<br />';
         $event_options = array();
         $event_options['console_show_this_player'] = true;
         $event_options['console_show_target'] = false;
         $event_options['event_flag_victory'] = true;
         $event_options['this_header_float'] = $event_options['this_body_float'] = $this_player->player_side;
         if ($this_player->player_token != 'player' && isset($this_player->player_quotes['battle_victory'])) {
             $this_find = array('{target_player}', '{target_robot}', '{this_player}', '{this_robot}');
             $this_replace = array($target_player->player_name, $target_robot->robot_name, $this_player->player_name, $this_robot->robot_name);
             $event_body .= $this_player->print_quote('battle_victory', $this_find, $this_replace);
         }
         $this_battle->events_create($this_robot, $target_robot, $event_header, $event_body, $event_options);
         /*
          * PLAYER REWARDS
          */
         // Check if the the player was a human character
         if ($this_player->player_side == 'left') {
             // Collect the robot info array
             $temp_player_info = $this_player->export_array();
             // Collect or define the player points and player rewards variables
             $temp_player_token = $temp_player_info['player_token'];
             $temp_player_points = rpg_game::player_points($temp_player_info['player_token']);
             $temp_player_rewards = !empty($temp_player_info['player_rewards']) ? $temp_player_info['player_rewards'] : array();
             // -- ABILITY REWARDS for HUMAN PLAYER -- //
             // Loop through the ability rewards for this player if set
             if (!empty($temp_player_rewards['abilities']) && rpg_game::is_user()) {
                 $temp_abilities_index = $db->get_array_list("SELECT * FROM mmrpg_index_abilities WHERE ability_flag_complete = 1;", 'ability_token');
                 foreach ($temp_player_rewards['abilities'] as $ability_reward_key => $ability_reward_info) {
                     // If this ability is already unlocked, continue
                     if (rpg_game::ability_unlocked($this_player->player_token, false, $ability_reward_info['token'])) {
                         continue;
                     }
                     // Check if the required level has been met by this robot
                     if ($temp_player_points >= $ability_reward_info['points']) {
                         // Collect the ability info from the index
                         $ability_info = rpg_ability::parse_index_info($temp_abilities_index[$ability_reward_info['token']]);
                         // Create the temporary ability object for event creation
                         $temp_ability = new rpg_ability($this_player, $this_robot, $ability_info);
                         // Collect or define the ability variables
                         $temp_ability_token = $ability_info['ability_token'];
                         // Display the robot reward message markup
                         $event_header = $ability_info['ability_name'] . ' Unlocked';
                         $event_body = rpg_functions::get_random_positive_word() . ' <span class="player_name">' . $temp_player_info['player_name'] . '</span> unlocked new ability data!<br />';
                         $event_body .= '<span class="ability_name">' . $ability_info['ability_name'] . '</span> can now be used in battle!';
                         $event_options = array();
                         $event_options['console_show_target'] = false;
                         $event_options['this_header_float'] = $this_player->player_side;
                         $event_options['this_body_float'] = $this_player->player_side;
                         $event_options['this_ability'] = $temp_ability;
                         $event_options['this_ability_image'] = 'icon';
                         $event_options['event_flag_victory'] = true;
                         $event_options['console_show_this_player'] = false;
                         $event_options['console_show_this_robot'] = false;
                         $event_options['console_show_this_ability'] = true;
                         $event_options['canvas_show_this_ability'] = false;
                         $this_player->set_frame($ability_reward_key % 2 == 0 ? 'victory' : 'taunt');
                         $this_robot->robot_frame = $ability_reward_key % 2 == 0 ? 'taunt' : 'base';
                         $this_robot->update_session();
                         $temp_ability->ability_frame = 'base';
                         $temp_ability->update_session();
                         $this_battle->events_create($this_robot, $this_robot, $event_header, $event_body, $event_options);
                         // Automatically unlock this ability for use in battle
                         $this_reward = array('ability_token' => $temp_ability_token);
                         $show_event = !rpg_game::ability_unlocked('', '', $temp_ability_token) ? true : false;
                         rpg_game::unlock_ability($temp_player_info, false, $this_reward, $show_event);
                     }
                 }
             }
         }
     }
     /*
      * BATTLE REWARDS
      */
     // Collect or define the player variables
     $this_player_token = $this_player->player_token;
     $this_player_info = $this_player->export_array();
     // Collect or define the target player variables
     $target_player_token = $target_player->player_token;
     $target_player_info = $target_player->export_array();
     // Check if this player was the human player
     if ($this_player->player_side == 'left') {
         // Update the GAME session variable with the completed battle token
         $save_records = $this_battle->has_flag('save_records') ? $this_battle->get_flag('save_records') : true;
         if ($save_records) {
             // Back up the current session array for this battle complete counter
             $bak_session_array = isset($_SESSION['GAME']['values']['battle_complete'][$this_player->player_token][$this_battle->battle_token]) ? $_SESSION['GAME']['values']['battle_complete'][$this_player->player_token][$this_battle->battle_token] : array();
             // Create the new session array from scratch to ensure all values exist
             $new_session_array = array('battle_token' => $this_battle->battle_token, 'battle_count' => 0, 'battle_min_level' => 0, 'battle_max_level' => 0, 'battle_min_turns' => 0, 'battle_max_turns' => 0, 'battle_min_points' => 0, 'battle_max_points' => 0, 'battle_min_robots' => 0, 'battle_max_robots' => 0);
             // Recollect applicable battle values from the backup session array
             if (!empty($bak_session_array['battle_count'])) {
                 $new_session_array['battle_count'] = $bak_session_array['battle_count'];
             }
             if (!empty($bak_session_array['battle_level'])) {
                 $new_session_array['battle_min_level'] = $bak_session_array['battle_level'];
             }
             // LEGACY
             if (!empty($bak_session_array['battle_min_level'])) {
                 $new_session_array['battle_min_level'] = $bak_session_array['battle_min_level'];
             }
             if (!empty($bak_session_array['battle_max_level'])) {
                 $new_session_array['battle_max_level'] = $bak_session_array['battle_max_level'];
             }
             if (!empty($bak_session_array['battle_min_turns'])) {
                 $new_session_array['battle_min_turns'] = $bak_session_array['battle_min_turns'];
             }
             if (!empty($bak_session_array['battle_max_turns'])) {
                 $new_session_array['battle_max_turns'] = $bak_session_array['battle_max_turns'];
             }
             if (!empty($bak_session_array['battle_min_points'])) {
                 $new_session_array['battle_min_points'] = $bak_session_array['battle_min_points'];
             }
             if (!empty($bak_session_array['battle_max_points'])) {
                 $new_session_array['battle_max_points'] = $bak_session_array['battle_max_points'];
             }
             if (!empty($bak_session_array['battle_min_robots'])) {
                 $new_session_array['battle_min_robots'] = $bak_session_array['battle_min_robots'];
             }
             if (!empty($bak_session_array['battle_max_robots'])) {
                 $new_session_array['battle_max_robots'] = $bak_session_array['battle_max_robots'];
             }
             // Update and/or increment the appropriate battle variables in the new array
             if ($new_session_array['battle_max_level'] == 0 || $this_battle->battle_level > $new_session_array['battle_max_level']) {
                 $new_session_array['battle_max_level'] = $this_battle->battle_level;
             }
             if ($new_session_array['battle_min_level'] == 0 || $this_battle->battle_level < $new_session_array['battle_min_level']) {
                 $new_session_array['battle_min_level'] = $this_battle->battle_level;
             }
             if ($new_session_array['battle_max_turns'] == 0 || $this_battle->counters['battle_turn'] > $new_session_array['battle_max_turns']) {
                 $new_session_array['battle_max_turns'] = $this_battle->counters['battle_turn'];
             }
             if ($new_session_array['battle_min_turns'] == 0 || $this_battle->counters['battle_turn'] < $new_session_array['battle_min_turns']) {
                 $new_session_array['battle_min_turns'] = $this_battle->counters['battle_turn'];
             }
             if ($new_session_array['battle_max_points'] == 0 || $temp_human_rewards['battle_points'] > $new_session_array['battle_max_points']) {
                 $new_session_array['battle_max_points'] = $temp_human_rewards['battle_points'];
             }
             if ($new_session_array['battle_min_points'] == 0 || $temp_human_rewards['battle_points'] < $new_session_array['battle_min_points']) {
                 $new_session_array['battle_min_points'] = $temp_human_rewards['battle_points'];
             }
             if ($new_session_array['battle_max_robots'] == 0 || $this_player->counters['robots_total'] > $new_session_array['battle_max_robots']) {
                 $new_session_array['battle_max_robots'] = $this_player->counters['robots_total'];
             }
             if ($new_session_array['battle_min_robots'] == 0 || $this_player->counters['robots_total'] < $new_session_array['battle_min_robots']) {
                 $new_session_array['battle_min_robots'] = $this_player->counters['robots_total'];
             }
             $new_session_array['battle_count']++;
             // Update the session variable for this player with the updated battle values
             $_SESSION['GAME']['values']['battle_complete'][$this_player->player_token][$this_battle->battle_token] = $new_session_array;
             $temp_human_rewards['battle_complete'] = $_SESSION['GAME']['values']['battle_complete'][$this_player->player_token][$this_battle->battle_token]['battle_count'];
         }
         // Refresh the player info array
         $this_player_info = $this_player->export_array();
         // ROBOT REWARDS
         // Loop through any robot rewards for this battle
         $this_robot_rewards = $this_battle->get_robot_rewards();
         if (!empty($this_robot_rewards) && rpg_game::is_user()) {
             foreach ($this_robot_rewards as $robot_reward_key => $robot_reward_info) {
                 // If this robot has already been unlocked by anyone, continue
                 if (rpg_game::robot_unlocked(false, $robot_reward_info['token'])) {
                     continue;
                 }
                 // Collect the robot info from the index
                 $robot_info = rpg_robot::get_index_info($robot_reward_info['token']);
                 // Search this player's base robots for the robot ID
                 $robot_info['robot_id'] = 0;
                 foreach ($this_player->player_base_robots as $base_robot) {
                     if ($robot_info['robot_token'] == $base_robot['robot_token']) {
                         $robot_info['robot_id'] = $base_robot['robot_id'];
                         break;
                     }
                 }
                 // Create the temporary robot object for event creation
                 $temp_robot = new rpg_robot($this_player, $robot_info);
                 // Collect or define the robot points and robot rewards variables
                 $this_robot_token = $robot_reward_info['token'];
                 $this_robot_level = !empty($robot_reward_info['level']) ? $robot_reward_info['level'] : 1;
                 $this_robot_experience = !empty($robot_reward_info['experience']) ? $robot_reward_info['experience'] : 0;
                 $this_robot_rewards = !empty($robot_info['robot_rewards']) ? $robot_info['robot_rewards'] : array();
                 // Automatically unlock this robot for use in battle
                 $this_reward = $robot_info;
                 $this_reward['robot_level'] = $this_robot_level;
                 $this_reward['robot_experience'] = $this_robot_experience;
                 rpg_game::unlock_robot($this_player_info, $this_reward, true, true);
             }
         }
         // ABILITY REWARDS
         // Loop through any ability rewards for this battle
         $this_ability_rewards = $this_battle->get_ability_rewards();
         if (!empty($this_ability_rewards) && rpg_game::is_user()) {
             $temp_abilities_index = $db->get_array_list("SELECT * FROM mmrpg_index_abilities WHERE ability_flag_complete = 1;", 'ability_token');
             foreach ($this_ability_rewards as $ability_reward_key => $ability_reward_info) {
                 // Collect the ability info from the index
                 $ability_info = rpg_ability::parse_index_info($temp_abilities_index[$ability_reward_info['token']]);
                 // Create the temporary robot object for event creation
                 $temp_ability = new rpg_ability($this_player, $this_robot, $ability_info);
                 // Collect or define the robot points and robot rewards variables
                 $this_ability_token = $ability_info['ability_token'];
                 // Now loop through all active robots on this side of the field
                 foreach ($this_player_info['values']['robots_active'] as $temp_key => $temp_info) {
                     // If this robot is a mecha, skip it!
                     if (!empty($temp_info['robot_class']) && $temp_info['robot_class'] == 'mecha') {
                         continue;
                     }
                     // Equip this ability to the robot is there was a match found
                     if (rpg_robot::has_ability_compatibility($temp_info['robot_token'], $ability_info['ability_token'])) {
                         if (!isset($_SESSION['GAME']['values']['battle_settings'][$this_player_info['player_token']]['player_robots'][$temp_info['robot_token']]['robot_abilities'])) {
                             $_SESSION['GAME']['values']['battle_settings'][$this_player_info['player_token']]['player_robots'][$temp_info['robot_token']]['robot_abilities'] = array();
                         }
                         if (count($_SESSION['GAME']['values']['battle_settings'][$this_player_info['player_token']]['player_robots'][$temp_info['robot_token']]['robot_abilities']) < 8) {
                             $_SESSION['GAME']['values']['battle_settings'][$this_player_info['player_token']]['player_robots'][$temp_info['robot_token']]['robot_abilities'][$ability_info['ability_token']] = array('ability_token' => $ability_info['ability_token']);
                         }
                     }
                 }
                 // If this ability has already been unlocked by the player, continue
                 if (rpg_game::ability_unlocked($this_player_token, false, $ability_reward_info['token'])) {
                     continue;
                 }
                 // Automatically unlock this ability for use in battle
                 $this_reward = array('ability_token' => $this_ability_token);
                 $show_event = !rpg_game::ability_unlocked('', '', $this_ability_token) ? true : false;
                 rpg_game::unlock_ability($this_player_info, false, $this_reward, $show_event);
                 // Display the robot reward message markup
                 $event_header = $ability_info['ability_name'] . ' Unlocked';
                 $event_body = rpg_functions::get_random_positive_word() . ' <span class="player_name">' . $this_player_info['player_name'] . '</span> unlocked new ability data!<br />';
                 $event_body .= '<span class="ability_name">' . $ability_info['ability_name'] . '</span> can now be used in battle!';
                 $event_options = array();
                 $event_options['console_show_target'] = false;
                 $event_options['this_header_float'] = $this_player->player_side;
                 $event_options['this_body_float'] = $this_player->player_side;
                 $event_options['this_ability'] = $temp_ability;
                 $event_options['this_ability_image'] = 'icon';
                 $event_options['console_show_this_player'] = false;
                 $event_options['console_show_this_robot'] = false;
                 $event_options['console_show_this_ability'] = true;
                 $event_options['canvas_show_this_ability'] = false;
                 $this_player->set_frame('victory');
                 $temp_ability->ability_frame = 'base';
                 $temp_ability->update_session();
                 $this_battle->events_create($this_robot, false, $event_header, $event_body, $event_options);
             }
         }
     }
     // end of BATTLE REWARDS
     // Check if there is a field star for this stage to collect
     if ($this_battle->battle_result == 'victory' && !empty($this_battle->values['field_star'])) {
         // Collect the field star data for this battle
         $temp_field_star = $this_battle->values['field_star'];
         // Print out the event for collecting the new field star
         $temp_name_markup = '<span class="field_name field_type field_type_' . (!empty($temp_field_star['star_type']) ? $temp_field_star['star_type'] : 'none') . (!empty($temp_field_star['star_type2']) ? '_' . $temp_field_star['star_type2'] : '') . '">' . $temp_field_star['star_name'] . ' Star</span>';
         $temp_event_header = $this_player->player_name . '&#39;s ' . ucfirst($temp_field_star['star_kind']) . ' Star';
         $temp_event_body = $this_player->print_name() . ' collected the ' . $temp_name_markup . '!<br />';
         $temp_event_body .= 'The new ' . ucfirst($temp_field_star['star_kind']) . ' Star amplifies your Starforce!';
         $temp_event_options = array();
         $temp_event_options['console_show_this_player'] = false;
         $temp_event_options['console_show_target_player'] = false;
         $temp_event_options['console_show_this_robot'] = false;
         $temp_event_options['console_show_target_robot'] = false;
         $temp_event_options['console_show_this_ability'] = false;
         $temp_event_options['console_show_this'] = true;
         $temp_event_options['console_show_this_star'] = true;
         $temp_event_options['this_header_float'] = $temp_event_options['this_body_float'] = $this_player->player_side;
         $temp_event_options['this_star'] = $temp_field_star;
         $temp_event_options['this_ability'] = false;
         $this_battle->events_create(false, false, $temp_event_header, $temp_event_body, $temp_event_options);
         // Update the session with this field star data
         $_SESSION['GAME']['values']['battle_stars'][$temp_field_star['star_token']] = $temp_field_star;
         // DEBUG DEBUG
         //$this_battle->events_create($this_robot, $target_robot, 'DEBUG FIELD STAR', 'You got a field star! The field star names '.implode(' | ', $temp_field_star));
     }
     // If this robot's image has been changed, reveert it back to what it was
     if ($this_robot->robot_core == 'copy') {
         if (isset($this_robot->robot_image_overlay['copy_type1'])) {
             unset($this_robot->robot_image_overlay['copy_type1']);
         }
         if (isset($this_robot->robot_image_overlay['copy_type2'])) {
             unset($this_robot->robot_image_overlay['copy_type2']);
         }
         $this_robot->update_session();
     }
     // If the target robot's image has been changed, reveert it back to what it was
     if ($target_robot->robot_core == 'copy') {
         if (isset($target_robot->robot_image_overlay['copy_type1'])) {
             unset($target_robot->robot_image_overlay['copy_type1']);
         }
         if (isset($target_robot->robot_image_overlay['copy_type2'])) {
             unset($target_robot->robot_image_overlay['copy_type2']);
         }
         $target_robot->update_session();
     }
     // Define the first event body markup, regardless of player type
     $first_event_header = $this_battle->battle_name . ($this_battle->battle_result == 'victory' ? ' Complete' : ' Failure') . ' <span class="pipe">|</span> ' . $this_battle->battle_field->field_name;
     if ($this_battle->battle_result == 'victory') {
         $first_event_body = 'Mission complete! <span class="pipe">|</span> ' . ($temp_human_rewards['battle_complete'] > 1 ? rpg_functions::get_random_positive_word() . ' That&#39;s ' . $temp_human_rewards['battle_complete'] . ' times now! ' : '') . rpg_functions::get_random_victory_quote();
     } elseif ($this_battle->battle_result == 'defeat') {
         $first_event_body = 'Mission failure. <span class="pipe">|</span> ' . ($temp_human_rewards['battle_failure'] > 1 ? 'That&#39;s ' . $temp_human_rewards['battle_failure'] . ' times now&hellip; ' : '') . rpg_functions::get_random_defeat_quote();
     }
     $first_event_body .= ' <span class="pipe">|</span> ' . $temp_rating_stars_markup . '<br />';
     // Print out the table and markup for the battle
     $first_event_body .= '<table class="full">';
     $first_event_body .= '<colgroup><col width="30%" /><col width="15%" /><col width="15%" /><col width="20%" /><col width="20%" /></colgroup>';
     $first_event_body .= '<tbody>';
     $first_event_body .= '<tr>';
     $first_event_body .= '<td class="left">Base Values</td>';
     $first_event_body .= '<td class="center"></td>';
     $first_event_body .= '<td class="center"></td>';
     $first_event_body .= '<td class="right">' . ($temp_reward_points_base == 1 ? '1 Point' : number_format($temp_reward_points_base, 0, '.', ',') . ' Points') . '</td>';
     $first_event_body .= '<td class="right">' . ($temp_reward_zenny_base == 1 ? '1 Zenny' : number_format($temp_reward_zenny_base, 0, '.', ',') . ' Zenny') . '</td>';
     $first_event_body .= '</tr> ';
     // Only grant bonuses if there was a victory
     if ($this_battle->battle_result == 'victory') {
         // Print out the label and target vs actual turn stats
         $first_event_body .= '<tr>';
         $first_event_body .= '<td class="left">Target Turns</td>';
         $first_event_body .= '<td class="center">' . $this_battle->counters['battle_turn'] . ' &nbsp;/&nbsp; ' . $this_battle->battle_turns_limit . '</td>';
         // Print the markup for the bonus/penalty percent
         if ($temp_turn_bonus > 0) {
             $first_event_body .= '<td class="center positive">+' . $temp_turn_bonus . '%</td>';
         } elseif ($temp_turn_bonus < 0) {
             $first_event_body .= '<td class="center negative">' . $temp_turn_bonus . '%</td>';
         } else {
             $first_event_body .= '<td class="center">+0%</td>';
         }
         // Print out any mods to the points
         $markup = $temp_turn_bonus_points == 1 ? '1 Point' : number_format($temp_turn_bonus_points, 0, '.', ',') . ' Points';
         if ($temp_turn_bonus_points > 0) {
             $first_event_body .= '<td class="right positive">+' . $markup . '</td>';
         } elseif ($temp_turn_bonus_points < 0) {
             $first_event_body .= '<td class="right negative">' . $markup . '</td>';
         } else {
             $first_event_body .= '<td class="right">-</td>';
         }
         // Print out any mods to the zenny
         $markup = $temp_turn_bonus_zenny == 1 ? '1 Zenny' : number_format($temp_turn_bonus_zenny, 0, '.', ',') . ' Zenny';
         if ($temp_turn_bonus_zenny > 0) {
             $first_event_body .= '<td class="right positive">+' . $markup . '</td>';
         } elseif ($temp_turn_bonus_zenny < 0) {
             $first_event_body .= '<td class="right negative">' . $markup . '</td>';
         } else {
             $first_event_body .= '<td class="right">-</td>';
         }
         $first_event_body .= '</tr>';
         // Print out the label and target vs actual robot stats
         $first_event_body .= '<tr>';
         $first_event_body .= '<td class="left">Target Robots</td>';
         $first_event_body .= '<td class="center">' . $this_player_info['counters']['robots_masters_total'] . ' &nbsp;/&nbsp; ' . $this_battle->battle_robots_limit . '</td>';
         // Print the markup for the bonus/penalty percent
         if ($temp_robot_bonus > 0) {
             $first_event_body .= '<td class="center positive">+' . $temp_robot_bonus . '%</td>';
         } elseif ($temp_robot_bonus < 0) {
             $first_event_body .= '<td class="center negative">' . $temp_robot_bonus . '%</td>';
         } else {
             $first_event_body .= '<td class="center">+0%</td>';
         }
         // Print out any mods to the points
         $markup = $temp_robot_bonus_points == 1 ? '1 Point' : number_format($temp_robot_bonus_points, 0, '.', ',') . ' Points';
         if ($temp_robot_bonus_points > 0) {
             $first_event_body .= '<td class="right positive">+' . $markup . '</td>';
         } elseif ($temp_robot_bonus_points < 0) {
             $first_event_body .= '<td class="right negative">' . $markup . '</td>';
         } else {
             $first_event_body .= '<td class="right">-</td>';
         }
         // Print out any mods to the zenny
         $markup = $temp_robot_bonus_zenny == 1 ? '1 Zenny' : number_format($temp_robot_bonus_zenny, 0, '.', ',') . ' Zenny';
         if ($temp_robot_bonus_zenny > 0) {
             $first_event_body .= '<td class="right positive">+' . $markup . '</td>';
         } elseif ($temp_robot_bonus_zenny < 0) {
             $first_event_body .= '<td class="right negative">' . $markup . '</td>';
         } else {
             $first_event_body .= '<td class="right">-</td>';
         }
         $first_event_body .= '</tr>';
     } elseif ($this_battle->battle_result == 'defeat') {
         // Print out the label and target vs actual turn stats
         $first_event_body .= '<tr>';
         $first_event_body .= '<td class="left">Target Turns</td>';
         $first_event_body .= '<td class="center">' . $this_battle->counters['battle_turn'] . ' &nbsp;/&nbsp; ' . $this_battle->battle_turns_limit . '</td>';
         // Print the markup for the empty fields
         $first_event_body .= '<td class="center">-</td>';
         $first_event_body .= '<td class="right">-</td>';
         $first_event_body .= '<td class="right">-</td>';
         $first_event_body .= '</tr>';
         // Print out the label and target vs actual robot stats
         $first_event_body .= '<tr>';
         $first_event_body .= '<td class="left">Target Robots</td>';
         $first_event_body .= '<td class="center">' . $this_player_info['counters']['robots_masters_total'] . ' &nbsp;/&nbsp; ' . $this_battle->battle_robots_limit . '</td>';
         // Print the markup for the empty fields
         $first_event_body .= '<td class="center">-</td>';
         $first_event_body .= '<td class="right">-</td>';
         $first_event_body .= '<td class="right">-</td>';
         $first_event_body .= '</tr>';
     }
     // Print out the final rewards for this battle
     $first_event_body .= '<tr>';
     $first_event_body .= '<td class="left"><strong>Final Rewards</strong></td>';
     $first_event_body .= '<td class="center"></td>';
     $first_event_body .= '<td class="center"></td>';
     $first_event_body .= '<td class="right"><strong>' . ($temp_reward_points_final != 1 ? number_format($temp_reward_points_final, 0, '.', ',') . ' Points' : '1 Point') . '</strong></td>';
     $first_event_body .= '<td class="right"><strong>' . ($temp_reward_zenny_final != 1 ? number_format($temp_reward_zenny_final, 0, '.', ',') . ' Zenny' : '1 Zenny') . '</strong></td>';
     $first_event_body .= '</tr>';
     // Finalize the table body for the results
     $first_event_body .= '</tbody>';
     $first_event_body .= '</table>';
     // Print the battle complete message
     $event_options = array();
     $event_options['this_header_float'] = 'center';
     $event_options['this_body_float'] = 'center';
     $event_options['this_event_class'] = false;
     $event_options['console_show_this'] = false;
     $event_options['console_show_target'] = false;
     $event_options['console_container_classes'] = 'field_type field_type_event field_type_' . ($this_battle->battle_result == 'victory' ? 'nature' : 'flame');
     $this_battle->events_create($target_robot, $this_robot, $first_event_header, $first_event_body, $event_options);
     // Add the flag to prevent any further messages from appearing
     $this_battle->set_flag('battle_complete_message_created', true);
     // Return the result for this battle function
     return $this_return;
 }
Exemplo n.º 14
0
/*
 * INDEX PAGE : ADMIN
 */
// Require actions file for form processing
require_once MMRPG_CONFIG_ROOTDIR . 'pages/admin_index_actions.php';
// Define the SEO variables for this page
$this_seo_title = 'Admin Index | ' . $this_seo_title;
$this_seo_description = 'Admin control panel index for the Mega Man RPG World.';
$this_seo_robots = '';
// Define the MARKUP variables for this page
$this_markup_header = '';
// Count the numer of users in the database
$mmrpg_user_count = $db->get_value("SELECT COUNT(user_id) AS user_count FROM mmrpg_users WHERE user_id <> 0;", 'user_count');
// Count the numer of players in the database
$mmrpg_players = rpg_player::get_index();
$mmrpg_player_count = count($mmrpg_players);
// Count the numer of mechas in the database
$mmrpg_mecha_count = $db->get_value("SELECT COUNT(robot_id) AS robot_count FROM mmrpg_index_robots WHERE robot_id <> 0 AND robot_class IN ('mecha');", 'robot_count');
// Count the numer of robots in the database
$mmrpg_robot_count = $db->get_value("SELECT COUNT(robot_id) AS robot_count FROM mmrpg_index_robots WHERE robot_id <> 0 AND robot_class IN ('master');", 'robot_count');
// Count the numer of bosses in the database
$mmrpg_boss_count = $db->get_value("SELECT COUNT(robot_id) AS robot_count FROM mmrpg_index_robots WHERE robot_id <> 0 AND robot_class IN ('boss');", 'robot_count');
// Count the numer of abilities in the database
$mmrpg_ability_count = $db->get_value("SELECT COUNT(ability_id) AS ability_count FROM mmrpg_index_abilities WHERE ability_id <> 0;", 'ability_count');
// Count the numer of items in the database
$mmrpg_item_count = $db->get_value("SELECT COUNT(item_id) AS item_count FROM mmrpg_index_items WHERE item_id <> 0;", 'item_count');
// Count the numer of fields in the database
$mmrpg_field_count = $db->get_value("SELECT COUNT(field_id) AS field_count FROM mmrpg_index_fields WHERE field_id <> 0;", 'field_count');
// Start generating the page markup
ob_start();
Exemplo n.º 15
0
                                 elseif ($active && $sort_direction == 'desc'){ echo ' <sup>&#8593;</sup>'; }
                             echo '</th>'.PHP_EOL;
                         } else {
                             echo '<th class="'.$class.'">&nbsp;</th>'.PHP_EOL;
                         }
                     }
                     ?>
                 </tr>
             </thead>
             <tbody>
                 <?
                 // Loop through collected players and list their details
                 if (!empty($player_index)){
                     foreach ($player_index AS $player_id => $player_info){
                         // Parse the player info before displaying it
                         $player_info = rpg_player::parse_index_info($player_info);
                         // Collect the display fields from the array
                         $player_token = $player_info['player_token'];
                         $player_name = $player_info['player_name'];
                         $player_group = '<span class="token">'.$player_info['player_group'].'</span>';
                         $player_type1 = !empty($player_info['player_type']) && !empty($type_index[$player_info['player_type']]) ? $type_index[$player_info['player_type']] : $type_index['none'];
                         $type_string = '<span class="type '.$player_type1['type_token'].'">'.$player_type1['type_name'].'</span>';
                         $edit_link = 'admin/players/'.$player_id.'/';
                         $view_link = 'database/players/'.$player_token.'/';
                         $complete = $player_info['player_flag_complete'] ? true : false;
                         $published = $player_info['player_flag_published'] ? true : false;
                         $hidden = $player_info['player_flag_hidden'] ? true : false;
                         // Print out the player info as a table row
                         ?>
                         <tr class="object<?php 
 echo !$published ? ' unpublished' : '';