function rpg_attachment()
 {
     // Update the session keys for this object
     $this->session_key = 'ATTACHMENTS';
     $this->session_token = 'ability_token';
     $this->session_id = 'ability_id';
     $this->class = 'ability';
     // Collect any provided arguments
     $args = func_get_args();
     // Define the internal battle pointer
     $this->battle = rpg_battle::get_battle();
     $this->battle_id = $this->battle->battle_id;
     $this->battle_token = $this->battle->battle_token;
     // Define the internal battle pointer
     $this->field = rpg_field::get_field;
     $this->field_id = $this->field->field_id;
     $this->field_token = $this->field->field_token;
     // Define the internal player values using the provided array
     $this->player = isset($args[0]) && is_a($args[0], 'rpg_player') ? $args[0] : new rpg_player();
     $this->player_id = $this->player->player_id;
     $this->player_token = $this->player->player_token;
     // Define the internal robot values using the provided array
     $this->robot = isset($args[1]) && is_a($args[1], 'rpg_robot') ? $args[0] : new rpg_robot();
     $this->robot_id = $this->robot->robot_id;
     $this->robot_token = $this->robot->robot_token;
     // Collect current ability data from the function if available
     $attachment_info = isset($args[2]) && is_array($args[2]) && !empty($args[2]) ? $args[2] : array('ability_id' => 0, 'ability_token' => 'ability');
     // Load the ability data based on the ID and fallback token
     $attachment_info = $this->ability_load($attachment_info['ability_id'], $attachment_info['ability_token']);
     // Now load the ability data from the session or index
     if (empty($attachment_info)) {
         // Attachment data could not be loaded
         die('Attachment data could not be loaded :<br />$attachment_info = <pre>' . print_r($attachment_info, true) . '</pre>');
         return false;
     }
     // Update the session variable
     $this->update_session();
     // Return true on success
     return true;
 }
 /**
  * Create a new RPG field object
  * @param array $field_info (optional)
  * @return rpg_field
  */
 public function __construct($field_info = array())
 {
     // Update the session keys for this object
     $this->session_key = 'FIELDS';
     $this->session_token = 'field_token';
     $this->session_id = 'field_id';
     $this->class = 'field';
     // Collect any provided arguments
     $args = func_get_args();
     // Define the internal class identifier
     $this->class = 'field';
     // Define the internal battle pointer
     $this->battle = rpg_battle::get_battle();
     $this->battle_id = $this->battle->battle_id;
     $this->battle_token = $this->battle->battle_token;
     // Collect current field data from the function if available
     $field_info = !empty($field_info) ? $field_info : array();
     if (!isset($this_fieldinfo['field_id'])) {
         $this_fieldinfo['field_id'] = 0;
     }
     if (!isset($this_fieldinfo['field_token'])) {
         $this_fieldinfo['field_token'] = 'field';
     }
     // Load the field data based on the ID and fallback token
     $field_info = $this->field_load($field_info['field_id'], $field_info['field_token'], $field_info);
     // Now load the field data from the session or index
     if (empty($field_info)) {
         // Player data could not be loaded
         die('Field data could not be loaded :<br />$this_fieldinfo = <pre>' . print_r($this_fieldinfo, true) . '</pre>');
         return false;
     }
     // Update the session variable
     $this->update_session();
     // Return true on success
     return true;
 }
 public static function generate_fortress($this_prototype_data, $temp_battle_level, $temp_index_token, $temp_battle_token, $temp_robot_masters = array(), $temp_support_mechas = array(), $temp_player_info = array())
 {
     // Pull in global variables for this function
     global $mmrpg_index, $db;
     // Collect the battle index for this foress battle
     $temp_battle_index = rpg_battle::get_index_info($temp_index_token);
     $temp_robot_index = rpg_robot::get_index();
     //ksort($_SESSION['GAME']['values']['battle_index']);
     //exit('$session_values_battle_index = <pre>'.print_r($_SESSION['GAME']['values']['battle_index'], true).'</pre>');
     //unset($_SESSION['GAME']['values']['battle_index'][$temp_battle_token]);
     //die('$temp_battle_index = <pre>'.print_r($temp_battle_index, true).'</pre>');
     // Copy over any completion records from the old, index-based name
     if (!empty($_SESSION['GAME']['values']['battle_complete'][$this_prototype_data['this_player_token']][$temp_index_token])) {
         $_SESSION['GAME']['values']['battle_complete'][$this_prototype_data['this_player_token']][$temp_battle_token] = $_SESSION['GAME']['values']['battle_complete'][$this_prototype_data['this_player_token']][$temp_index_token];
         unset($_SESSION['GAME']['values']['battle_complete'][$this_prototype_data['this_player_token']][$temp_index_token]);
     }
     // Copy over any completion records from the old, index-based name
     if (!empty($_SESSION['GAME']['values']['battle_failure'][$this_prototype_data['this_player_token']][$temp_index_token])) {
         $_SESSION['GAME']['values']['battle_failure'][$this_prototype_data['this_player_token']][$temp_battle_token] = $_SESSION['GAME']['values']['battle_failure'][$this_prototype_data['this_player_token']][$temp_index_token];
         unset($_SESSION['GAME']['values']['battle_failure'][$this_prototype_data['this_player_token']][$temp_index_token]);
     }
     // Collect and define the rest of the details
     $temp_battle_omega = $temp_battle_index;
     $temp_battle_complete = rpg_prototype::battle_complete($this_prototype_data['this_player_token'], $temp_battle_token);
     $temp_battle_targets = !empty($temp_battle_omega['battle_target_player']['player_robots']) ? count($temp_battle_omega['battle_target_player']['player_robots']) : 0;
     $temp_battle_omega['option_chapter'] = $this_prototype_data['this_current_chapter'];
     $temp_battle_omega['battle_token'] = $temp_battle_token;
     $temp_battle_omega['battle_phase'] = $this_prototype_data['battle_phase'];
     $temp_battle_omega['battle_level'] = $temp_battle_level;
     //$this_prototype_data['this_chapter_levels'][5];
     // If the battle is complete, remove the player from the description and increase the level
     if (!empty($temp_battle_complete)) {
         $temp_base_level = $temp_battle_omega['battle_level'];
         $temp_battle_omega['battle_level'] += !empty($temp_battle_complete['battle_count']) ? $temp_battle_complete['battle_count'] : 0;
         if ($temp_battle_omega['battle_level'] > $temp_base_level * 2) {
             $temp_battle_omega['battle_level'] = $temp_base_level * 2;
         }
         $temp_battle_omega['battle_target_player']['player_token'] = 'player';
         $temp_battle_omega['battle_description'] = preg_replace('/^Defeat (Dr. (Wily|Light|Cossack)\'s)/i', 'Defeat', $temp_battle_omega['battle_description']);
     }
     // If robot masters were provided to the function, update them in the battle array
     if (!empty($temp_robot_masters)) {
         $temp_battle_omega['battle_target_player']['player_robots'] = $temp_robot_masters;
     }
     // If support mechas were provided to the function, update them in the battle array
     if (!empty($temp_support_mechas)) {
         $temp_battle_omega['battle_field_info']['field_mechas'] = $temp_support_mechas;
     }
     // Start all the point-based battle vars at zero
     $temp_battle_omega['battle_points'] = 0;
     $temp_battle_omega['battle_zenny'] = 0;
     $temp_battle_omega['battle_turns_limit'] = 0;
     $temp_battle_omega['battle_robots_limit'] = 0;
     // If the player info array was provided, merge into current
     if (!empty($temp_player_info)) {
         $temp_battle_omega['battle_target_player'] = array_merge($temp_battle_omega['battle_target_player'], $temp_player_info);
     }
     // Loop through and adjust the levels of robots
     if (!empty($temp_battle_omega['battle_target_player']['player_robots'])) {
         $stat_boost_amount = !empty($temp_battle_complete['battle_count']) ? $temp_battle_complete['battle_count'] * $temp_battle_level : 0;
         if ($stat_boost_amount >= 1000) {
             $stat_boost_amount = 1000;
         }
         foreach ($temp_battle_omega['battle_target_player']['player_robots'] as $key => $robot) {
             $index = $temp_robot_index[$robot['robot_token']];
             $robot['robot_level'] = $temp_battle_omega['battle_level'];
             if (!empty($stat_boost_amount)) {
                 $robot['values'] = array();
                 $robot['values']['robot_rewards'] = array();
                 $robot['values']['robot_rewards']['robot_energy'] = $stat_boost_amount;
                 $robot['values']['robot_rewards']['robot_attack'] = $stat_boost_amount;
                 $robot['values']['robot_rewards']['robot_defense'] = $stat_boost_amount;
                 $robot['values']['robot_rewards']['robot_speed'] = $stat_boost_amount;
             }
             // Increment the battle's turn limit based on the class of target robot
             if ($index['robot_class'] == 'master') {
                 $temp_battle_omega['battle_turns_limit'] += MMRPG_SETTINGS_BATTLETURNS_PERROBOT;
             } elseif ($index['robot_class'] == 'mecha') {
                 $temp_battle_omega['battle_turns_limit'] += MMRPG_SETTINGS_BATTLETURNS_PERMECHA;
             } elseif ($index['robot_class'] == 'boss') {
                 $temp_battle_omega['battle_turns_limit'] += MMRPG_SETTINGS_BATTLETURNS_PERBOSS;
             }
             // Increment the battle's point reward based on the class of target robot
             if ($index['robot_class'] == 'master') {
                 $temp_battle_omega['battle_points'] += $robot['robot_level'] * MMRPG_SETTINGS_BATTLEPOINTS_PERROBOT;
             } elseif ($index['robot_class'] == 'mecha') {
                 $temp_battle_omega['battle_points'] += $robot['robot_level'] * MMRPG_SETTINGS_BATTLEPOINTS_PERMECHA;
             } elseif ($index['robot_class'] == 'boss') {
                 $temp_battle_omega['battle_points'] += $robot['robot_level'] * MMRPG_SETTINGS_BATTLEPOINTS_PERBOSS;
             }
             // Increment the battle's zenny reward based on the class of target robot
             if ($index['robot_class'] == 'master') {
                 $temp_battle_omega['battle_zenny'] += $robot['robot_level'] * MMRPG_SETTINGS_BATTLEZENNY_PERROBOT;
             } elseif ($index['robot_class'] == 'mecha') {
                 $temp_battle_omega['battle_zenny'] += $robot['robot_level'] * MMRPG_SETTINGS_BATTLEZENNY_PERMECHA;
             } elseif ($index['robot_class'] == 'boss') {
                 $temp_battle_omega['battle_zenny'] += $robot['robot_level'] * MMRPG_SETTINGS_BATTLEZENNY_PERBOSS;
             }
             // Increment the battle's robot limit based on the class of target robot
             if ($index['robot_class'] == 'master') {
                 $temp_battle_omega['battle_robots_limit'] += MMRPG_SETTINGS_BATTLEROBOTS_PERROBOT;
             } elseif ($index['robot_class'] == 'mecha') {
                 $temp_battle_omega['battle_robots_limit'] += MMRPG_SETTINGS_BATTLEROBOTS_PERMECHA;
             } elseif ($index['robot_class'] == 'boss') {
                 $temp_battle_omega['battle_robots_limit'] += MMRPG_SETTINGS_BATTLEROBOTS_PERBOSS;
             }
             $temp_battle_omega['battle_target_player']['player_robots'][$key] = $robot;
         }
     }
     //$temp_battle_omega['battle_field_info']['field_name'] = 'stat boost '.$stat_boost_amount.' '.$temp_battle_omega['battle_target_player']['player_robots'][$key]['values']['robot_rewards']['robot_energy'].' | ';
     // Fix any zero or invalid battle values
     if ($temp_battle_omega['battle_points'] < 1) {
         $temp_battle_omega['battle_points'] = 1;
     } else {
         $temp_battle_omega['battle_points'] = ceil($temp_battle_omega['battle_points']);
     }
     if ($temp_battle_omega['battle_turns_limit'] < 1) {
         $temp_battle_omega['battle_turns_limit'] = 1;
     } else {
         $temp_battle_omega['battle_turns_limit'] = ceil($temp_battle_omega['battle_turns_limit']);
     }
     if ($temp_battle_omega['battle_robots_limit'] < 1) {
         $temp_battle_omega['battle_robots_limit'] = 1;
     } else {
         $temp_battle_omega['battle_robots_limit'] = ceil($temp_battle_omega['battle_robots_limit']);
     }
     // Return the generated omega battle data
     return $temp_battle_omega;
 }
 public function ability_load($ability_id = 0, $ability_token = 'ability', $custom_info = array())
 {
     /*
     // If this is a special system ability, hard-code its ID, otherwise base off robot
     $temp_system_abilities = array('attachment-defeat');
     if (in_array($ability_token, $temp_system_abilities)){
         $ability_id = $this->player_id.player_id.str_pad(array_search($ability_token, $temp_system_abilities), 3, '0', STR_PAD_LEFT);
     }
     // Else if this is an item, tweak it's ID as well
     elseif (in_array($ability_token, $this->player->player_items)){
         $ability_id = $this->player_id.str_pad(array_search($ability_token, $this->player->player_items), 3, '0', STR_PAD_LEFT);
     }
     // Else if this was any other ability, combine ID with robot owner
     else {
         $ability_id = $this->robot_id.str_pad($ability_id, 3, '0', STR_PAD_LEFT);
     }
     */
     // If the ability token was not provided, return false
     if (!isset($ability_token)) {
         die("ability token must be set!\n\$this_abilityinfo\n" . print_r($this_abilityinfo, true));
         return false;
     }
     // Collect current ability data from the session if available
     if (isset($_SESSION['ABILITIES'][$ability_id])) {
         $this_abilityinfo = $_SESSION['ABILITIES'][$ability_id];
         if ($this_abilityinfo['ability_token'] != $ability_token) {
             die("ability token and ID mismatch {$ability_id}:{$ability_token}!\n");
             return false;
         }
     } else {
         $this_abilityinfo = self::get_index_info($ability_token);
         if (empty($this_abilityinfo)) {
             die("ability data could not be loaded for {$ability_id}:{$ability_token}!\n");
             return false;
         }
     }
     // If the custom data was not empty, merge now
     if (!empty($custom_info)) {
         $this_abilityinfo = array_merge($this_abilityinfo, $custom_info);
     }
     // Define the internal ability values using the provided array
     $this->flags = isset($this_abilityinfo['flags']) ? $this_abilityinfo['flags'] : array();
     $this->counters = isset($this_abilityinfo['counters']) ? $this_abilityinfo['counters'] : array();
     $this->values = isset($this_abilityinfo['values']) ? $this_abilityinfo['values'] : array();
     $this->history = isset($this_abilityinfo['history']) ? $this_abilityinfo['history'] : array();
     $this->ability_id = isset($this_abilityinfo['ability_id']) ? $this_abilityinfo['ability_id'] : $ability_id;
     $this->ability_key = isset($this_abilityinfo['ability_key']) ? $this_abilityinfo['ability_key'] : 0;
     $this->ability_name = isset($this_abilityinfo['ability_name']) ? $this_abilityinfo['ability_name'] : 'Ability';
     $this->ability_token = isset($this_abilityinfo['ability_token']) ? $this_abilityinfo['ability_token'] : 'ability';
     $this->ability_description = isset($this_abilityinfo['ability_description']) ? $this_abilityinfo['ability_description'] : '';
     $this->ability_class = isset($this_abilityinfo['ability_class']) ? $this_abilityinfo['ability_class'] : 'master';
     $this->ability_subclass = isset($this_abilityinfo['ability_subclass']) ? $this_abilityinfo['ability_subclass'] : '';
     $this->ability_master = isset($this_abilityinfo['ability_master']) ? $this_abilityinfo['ability_master'] : '';
     $this->ability_number = isset($this_abilityinfo['ability_number']) ? $this_abilityinfo['ability_number'] : '';
     $this->ability_type = isset($this_abilityinfo['ability_type']) ? $this_abilityinfo['ability_type'] : '';
     $this->ability_type2 = isset($this_abilityinfo['ability_type2']) ? $this_abilityinfo['ability_type2'] : '';
     $this->ability_speed = isset($this_abilityinfo['ability_speed']) ? $this_abilityinfo['ability_speed'] : 1;
     $this->ability_energy = isset($this_abilityinfo['ability_energy']) ? $this_abilityinfo['ability_energy'] : 4;
     $this->ability_energy_percent = isset($this_abilityinfo['ability_energy_percent']) ? $this_abilityinfo['ability_energy_percent'] : true;
     $this->ability_damage = isset($this_abilityinfo['ability_damage']) ? $this_abilityinfo['ability_damage'] : 0;
     $this->ability_damage2 = isset($this_abilityinfo['ability_damage2']) ? $this_abilityinfo['ability_damage2'] : 0;
     $this->ability_damage_percent = isset($this_abilityinfo['ability_damage_percent']) ? $this_abilityinfo['ability_damage_percent'] : false;
     $this->ability_damage2_percent = isset($this_abilityinfo['ability_damage2_percent']) ? $this_abilityinfo['ability_damage2_percent'] : false;
     $this->ability_recovery = isset($this_abilityinfo['ability_recovery']) ? $this_abilityinfo['ability_recovery'] : 0;
     $this->ability_recovery2 = isset($this_abilityinfo['ability_recovery2']) ? $this_abilityinfo['ability_recovery2'] : 0;
     $this->ability_recovery_percent = isset($this_abilityinfo['ability_recovery_percent']) ? $this_abilityinfo['ability_recovery_percent'] : false;
     $this->ability_recovery2_percent = isset($this_abilityinfo['ability_recovery2_percent']) ? $this_abilityinfo['ability_recovery2_percent'] : false;
     $this->ability_accuracy = isset($this_abilityinfo['ability_accuracy']) ? $this_abilityinfo['ability_accuracy'] : 0;
     $this->ability_target = isset($this_abilityinfo['ability_target']) ? $this_abilityinfo['ability_target'] : 'auto';
     $this->ability_functions = isset($this_abilityinfo['ability_functions']) ? $this_abilityinfo['ability_functions'] : 'abilities/ability.php';
     $this->ability_image = isset($this_abilityinfo['ability_image']) ? $this_abilityinfo['ability_image'] : $this->ability_token;
     $this->ability_image_size = isset($this_abilityinfo['ability_image_size']) ? $this_abilityinfo['ability_image_size'] : 40;
     $this->ability_frame = isset($this_abilityinfo['ability_frame']) ? $this_abilityinfo['ability_frame'] : 'base';
     $this->ability_frame_span = isset($this_abilityinfo['ability_frame_span']) ? $this_abilityinfo['ability_frame_span'] : 1;
     $this->ability_frame_animate = isset($this_abilityinfo['ability_frame_animate']) ? $this_abilityinfo['ability_frame_animate'] : array($this->ability_frame);
     $this->ability_frame_index = isset($this_abilityinfo['ability_frame_index']) ? $this_abilityinfo['ability_frame_index'] : array('base');
     $this->ability_frame_offset = isset($this_abilityinfo['ability_frame_offset']) ? $this_abilityinfo['ability_frame_offset'] : array('x' => 0, 'y' => 0, 'z' => 1);
     $this->ability_frame_styles = isset($this_abilityinfo['ability_frame_styles']) ? $this_abilityinfo['ability_frame_styles'] : '';
     $this->ability_frame_classes = isset($this_abilityinfo['ability_frame_classes']) ? $this_abilityinfo['ability_frame_classes'] : '';
     $this->ability_results = array();
     $this->ability_options = array();
     $this->target_options = array();
     $this->damage_options = array();
     $this->recovery_options = array();
     $this->attachment_options = array();
     // Collect any functions associated with this ability
     $temp_functions_path = file_exists(MMRPG_CONFIG_ROOTDIR . 'data/' . $this->ability_functions) ? $this->ability_functions : 'abilities/ability.php';
     require MMRPG_CONFIG_ROOTDIR . 'data/' . $temp_functions_path;
     $this->ability_function = isset($ability['ability_function']) ? $ability['ability_function'] : function () {
     };
     $this->ability_function_onload = isset($ability['ability_function_onload']) ? $ability['ability_function_onload'] : function () {
     };
     $this->ability_function_attachment = isset($ability['ability_function_attachment']) ? $ability['ability_function_attachment'] : function () {
     };
     unset($ability);
     // Define the internal robot base values using the robots index array
     $this->ability_base_key = isset($this_abilityinfo['ability_base_key']) ? $this_abilityinfo['ability_base_key'] : $this->ability_key;
     $this->ability_base_name = isset($this_abilityinfo['ability_base_name']) ? $this_abilityinfo['ability_base_name'] : $this->ability_name;
     $this->ability_base_token = isset($this_abilityinfo['ability_base_token']) ? $this_abilityinfo['ability_base_token'] : $this->ability_token;
     $this->ability_base_description = isset($this_abilityinfo['ability_base_description']) ? $this_abilityinfo['ability_base_description'] : $this->ability_description;
     $this->ability_base_image = isset($this_abilityinfo['ability_base_image']) ? $this_abilityinfo['ability_base_image'] : $this->ability_image;
     $this->ability_base_image_size = isset($this_abilityinfo['ability_base_image_size']) ? $this_abilityinfo['ability_base_image_size'] : $this->ability_image_size;
     $this->ability_base_type = isset($this_abilityinfo['ability_base_type']) ? $this_abilityinfo['ability_base_type'] : $this->ability_type;
     $this->ability_base_type2 = isset($this_abilityinfo['ability_base_type2']) ? $this_abilityinfo['ability_base_type2'] : $this->ability_type2;
     $this->ability_base_energy = isset($this_abilityinfo['ability_base_energy']) ? $this_abilityinfo['ability_base_energy'] : $this->ability_energy;
     $this->ability_base_speed = isset($this_abilityinfo['ability_base_speed']) ? $this_abilityinfo['ability_base_speed'] : $this->ability_speed;
     $this->ability_base_damage = isset($this_abilityinfo['ability_base_damage']) ? $this_abilityinfo['ability_base_damage'] : $this->ability_damage;
     $this->ability_base_damage_percent = isset($this_abilityinfo['ability_base_damage_percent']) ? $this_abilityinfo['ability_base_damage_percent'] : $this->ability_damage_percent;
     $this->ability_base_damage2 = isset($this_abilityinfo['ability_base_damage2']) ? $this_abilityinfo['ability_base_damage2'] : $this->ability_damage2;
     $this->ability_base_damage2_percent = isset($this_abilityinfo['ability_base_damage2_percent']) ? $this_abilityinfo['ability_base_damage2_percent'] : $this->ability_damage2_percent;
     $this->ability_base_recovery = isset($this_abilityinfo['ability_base_recovery']) ? $this_abilityinfo['ability_base_recovery'] : $this->ability_recovery;
     $this->ability_base_recovery_percent = isset($this_abilityinfo['ability_base_recovery_percent']) ? $this_abilityinfo['ability_base_recovery_percent'] : $this->ability_recovery_percent;
     $this->ability_base_recovery2 = isset($this_abilityinfo['ability_base_recovery2']) ? $this_abilityinfo['ability_base_recovery2'] : $this->ability_recovery2;
     $this->ability_base_recovery2_percent = isset($this_abilityinfo['ability_base_recovery2_percent']) ? $this_abilityinfo['ability_base_recovery2_percent'] : $this->ability_recovery2_percent;
     $this->ability_base_accuracy = isset($this_abilityinfo['ability_base_accuracy']) ? $this_abilityinfo['ability_base_accuracy'] : $this->ability_accuracy;
     $this->ability_base_target = isset($this_abilityinfo['ability_base_target']) ? $this_abilityinfo['ability_base_target'] : $this->ability_target;
     // Define a the default ability results
     $this->ability_results_reset();
     // Reset the ability options to default
     $this->target_options_reset();
     $this->damage_options_reset();
     $this->recovery_options_reset();
     // Trigger the onload function if it exists
     $this_battle = rpg_battle::get_battle();
     $this_field = rpg_field::get_field();
     $this_player = $this->player;
     $this_robot = $this->robot;
     $target_side = $this_player->player_side != 'right' ? 'right' : 'left';
     $target_player = $this_battle->find_player(array('player_side' => $target_side));
     $target_robot = $this_battle->find_robot(array('robot_side' => $target_side, 'robot_position' => 'active'));
     $temp_function = $this->ability_function_onload;
     $temp_result = $temp_function(array('this_battle' => $this_battle, 'this_field' => $this_field, 'this_player' => $this_player, 'this_robot' => $this_robot, 'target_player' => $target_player, 'target_robot' => $target_robot, 'this_ability' => $this));
     // Return true on success
     return true;
 }
 /**
  * Reset internal variables of this player object
  * @return rpg_robot
  */
 public function get_active_robot()
 {
     $this_battle = rpg_battle::get_battle();
     $this_robot = $this_battle->find_robot(array('player_id' => $this->player_id, 'robot_status' => 'active', 'robot_position' => 'active'));
     if (empty($this_robot)) {
         $this_robot = $this_battle->find_robot(array('player_id' => $this->player_id, 'robot_status' => 'active'));
         if (empty($this_robot)) {
             $this_robot = $this_battle->find_robot(array('player_id' => $this->player_id));
         }
     }
     return $this_robot;
 }
 public static function options_markup(&$battle_options, $player_token)
 {
     // Refence the global config and index objects for easy access
     global $mmrpg_index, $db;
     $mmrpg_index_fields = rpg_field::get_index();
     // Define the variable to collect option markup
     $this_markup = '';
     // Count the number of completed battle options for this group and update the variable
     foreach ($battle_options as $this_key => $this_info) {
         // Define the chapter if not set
         if (!isset($this_info['option_chapter'])) {
             $this_info['option_chapter'] = '0';
         }
         // If this is an event message type option, simply display the text/images
         if (!empty($this_info['option_type']) && $this_info['option_type'] == 'message') {
             // Generate the option markup for the event message
             $temp_optiontitle = $this_info['option_maintext'];
             $temp_optionimages = !empty($this_info['option_images']) ? $this_info['option_images'] : '';
             $temp_optiontext = '<span class="multi"><span class="maintext">' . $this_info['option_maintext'] . '</span></span>';
             $this_markup .= '<a data-chapter="' . $this_info['option_chapter'] . '" class="option option_message option_1x4 option_this-' . $player_token . '-message" style="' . (!empty($this_info['option_style']) ? $this_info['option_style'] : '') . '"><div class="chrome"><div class="inset"><label class="' . (!empty($temp_optionimages) ? 'has_image' : '') . '">' . $temp_optionimages . $temp_optiontext . '</label></div></div></a>' . "\n";
         } else {
             // If the skip flag is set, continue to the next index
             //if (isset($this_info['flag_skip']) && $this_info['flag_skip'] == true){ continue; }
             // Collect the current battle and field info from the index
             if (!isset($this_info['battle_token'])) {
                 echo '$this_key(' . $this_key . ') = ' . print_r($this_info, true);
             }
             $this_battleinfo = rpg_battle::get_index_info($this_info['battle_token']);
             //if (!empty($this_battleinfo)){ $this_battleinfo = array_replace($this_battleinfo, $this_info); }
             $temp_flags = isset($this_battleinfo['flags']) ? $this_battleinfo['flags'] : array();
             $temp_values = isset($this_battleinfo['values']) ? $this_battleinfo['values'] : array();
             $temp_counters = isset($this_battleinfo['counters']) ? $this_battleinfo['counters'] : array();
             if (!empty($this_battleinfo)) {
                 $this_battleinfo = array_merge($this_battleinfo, $this_info);
             } else {
                 $this_battleinfo = $this_info;
             }
             $this_battleinfo['flags'] = !empty($this_battleinfo['flags']) ? array_merge($this_battleinfo['flags'], $temp_flags) : $temp_flags;
             $this_battleinfo['values'] = !empty($this_battleinfo['values']) ? array_merge($this_battleinfo['values'], $temp_values) : $temp_values;
             $this_battleinfo['counters'] = !empty($this_battleinfo['counters']) ? array_merge($this_battleinfo['counters'], $temp_counters) : $temp_counters;
             //if (!is_array($this_battleinfo['battle_field_info'])){ echo('Key '.$this_key.' in $battle_options_reversed = <pre>'.print_r($battle_options_reversed, true).'</pre>'); }
             //if (!is_array($this_battleinfo['battle_field_info'])){ echo('$this_battleinfo[\'battle_field_info\'] = <pre>'.print_r($this_battleinfo, true).'</pre>'); }
             //if (!is_array($this_battleinfo['battle_field_info'])){ echo('$db->INDEX[\'BATTLES\']['.$this_info['battle_token'].'] = <pre>'.print_r($db->INDEX['BATTLES'][$this_info['battle_token']], true).'</pre>'); }
             if (!isset($this_battleinfo['battle_field_info'])) {
                 echo print_r($this_battleinfo, true);
             }
             $this_fieldtoken = $this_battleinfo['battle_field_info']['field_token'];
             $this_fieldinfo = !empty($mmrpg_index_fields[$this_fieldtoken]) ? array_replace(rpg_field::parse_index_info($mmrpg_index_fields[$this_fieldtoken]), $this_battleinfo['battle_field_info']) : $this_battleinfo['battle_field_info'];
             $this_targetinfo = !empty($mmrpg_index['players'][$this_battleinfo['battle_target_player']['player_token']]) ? array_replace($mmrpg_index['players'][$this_battleinfo['battle_target_player']['player_token']], $this_battleinfo['battle_target_player']) : $this_battleinfo['battle_target_player'];
             // Collect the robot index for calculation purposes
             $this_robot_index = $db->get_array_list("SELECT * FROM mmrpg_index_robots WHERE robot_flag_complete = 1;", 'robot_token');
             // Check the GAME session to see if this battle has been completed, increment the counter if it was
             $this_battleinfo['battle_option_complete'] = rpg_prototype::battle_complete($player_token, $this_info['battle_token']);
             $this_battleinfo['battle_option_failure'] = rpg_prototype::battle_failure($player_token, $this_info['battle_token']);
             // Generate the markup fields for display
             $this_option_token = $this_battleinfo['battle_token'];
             $this_option_limit = !empty($this_battleinfo['battle_robots_limit']) ? $this_battleinfo['battle_robots_limit'] : 8;
             $this_option_frame = !empty($this_battleinfo['battle_sprite_frame']) ? $this_battleinfo['battle_sprite_frame'] : 'base';
             $this_option_status = !empty($this_battleinfo['battle_status']) ? $this_battleinfo['battle_status'] : 'enabled';
             $this_option_points = !empty($this_battleinfo['battle_points']) ? $this_battleinfo['battle_points'] : 0;
             $this_option_complete = $this_battleinfo['battle_option_complete'];
             $this_option_failure = $this_battleinfo['battle_option_failure'];
             $this_option_targets = !empty($this_targetinfo['player_robots']) ? count($this_targetinfo['player_robots']) : 0;
             $this_option_encore = isset($this_battleinfo['battle_encore']) ? $this_battleinfo['battle_encore'] : true;
             $this_option_disabled = !empty($this_option_complete) && !$this_option_encore ? true : false;
             $this_has_field_star = !empty($this_battleinfo['values']['field_star']) && !rpg_game::star_unlocked($this_battleinfo['values']['field_star']['star_token']) ? true : false;
             $this_has_dark_tower = !empty($this_battleinfo['flags']['dark_tower']) ? true : false;
             $this_option_class = 'option option_fieldback option_this-' . $player_token . '-battle-select option_' . $this_battleinfo['battle_size'] . ' option_' . $this_option_status . ' block_' . ($this_key + 1) . ' ' . ($this_option_complete && !$this_has_field_star && !$this_has_dark_tower ? 'option_complete ' : '') . ($this_option_disabled ? 'option_disabled ' . ($this_option_encore ? 'option_disabled_clickable ' : '') : '');
             $this_option_style = 'background-position: -' . mt_rand(5, 50) . 'px -' . mt_rand(5, 50) . 'px; ';
             if (!empty($this_fieldinfo['field_type'])) {
                 $this_option_class .= 'field_type field_type_' . $this_fieldinfo['field_type'] . (!empty($this_fieldinfo['field_type2']) && $this_fieldinfo['field_type2'] != $this_fieldinfo['field_type'] ? '_' . $this_fieldinfo['field_type2'] : '');
             } else {
                 $this_option_class .= 'field_type field_type_none';
             }
             if (!empty($this_fieldinfo['field_background'])) {
                 //$this_background_x = $this_background_y = -20;
                 //$this_option_style = 'background-position: 0 0; background-size: 100% auto; background-image: url(images/sprites/fields/'.$this_fieldinfo['field_background'].'/battle-field_preview.png?'.MMRPG_CONFIG_CACHE_DATE.'); ';
                 $this_option_style = 'background-image: url(images/sprites/fields/' . $this_fieldinfo['field_background'] . '/battle-field_preview.png?' . MMRPG_CONFIG_CACHE_DATE . ') !important; ';
             }
             $this_option_label = '';
             $this_option_platform_style = '';
             if (!empty($this_fieldinfo['field_foreground'])) {
                 //$this_background_x = $this_background_y = -20;
                 //$this_option_platform_style = 'background-position: 0 -76px; background-size: 100% auto; background-image: url(images/sprites/fields/'.$this_fieldinfo['field_foreground'].'/battle-field_foreground_base.png?'.MMRPG_CONFIG_CACHE_DATE.'); ';
                 $this_option_platform_style = 'background-image: url(images/sprites/fields/' . $this_fieldinfo['field_foreground'] . '/battle-field_foreground_base.png?' . MMRPG_CONFIG_CACHE_DATE . '); ';
             }
             $this_option_min_level = false;
             $this_option_max_level = false;
             $this_option_star_boost = !empty($this_targetinfo['player_starforce']) ? array_sum($this_targetinfo['player_starforce']) : 0;
             $this_battleinfo['battle_sprite'] = array();
             $this_targetinfo = !empty($mmrpg_index['players'][$this_targetinfo['player_token']]) ? array_merge($mmrpg_index['players'][$this_targetinfo['player_token']], $this_targetinfo) : $mmrpg_index['players']['player'];
             if ($this_targetinfo['player_token'] != 'player') {
                 $this_battleinfo['battle_sprite'][] = array('path' => 'players/' . $this_targetinfo['player_token'], 'size' => !empty($this_targetinfo['player_image_size']) ? $this_targetinfo['player_image_size'] : 40);
             }
             if (!empty($this_targetinfo['player_robots'])) {
                 // Count the number of masters in this battle
                 $this_master_count = 0;
                 $this_mecha_count = 0;
                 $temp_robot_tokens = array();
                 foreach ($this_targetinfo['player_robots'] as $robo_key => $this_robotinfo) {
                     //if (empty($this_robotinfo['robot_token'])){ die('<pre>'.$this_battleinfo['battle_token'].print_r($this_robotinfo, true).'</pre>'); }
                     if ($this_robotinfo['robot_token'] == 'robot') {
                         unset($this_targetinfo['player_robots'][$robo_key]);
                         continue;
                     }
                     if (isset($this_robot_index[$this_robotinfo['robot_token']])) {
                         $this_robotindex = rpg_robot::parse_index_info($this_robot_index[$this_robotinfo['robot_token']]);
                     } else {
                         continue;
                     }
                     $temp_robot_tokens[] = $this_robotinfo['robot_token'];
                     $this_robotinfo = array_merge($this_robotindex, $this_robotinfo);
                     $this_targetinfo['player_robots'][$robo_key] = $this_robotinfo;
                     if (!empty($this_robotinfo['robot_class']) && $this_robotinfo['robot_class'] == 'mecha') {
                         $this_mecha_count++;
                     } elseif (empty($this_robotinfo['robot_class']) || $this_robotinfo['robot_class'] == 'master') {
                         $this_master_count++;
                     }
                     unset($this_robotindex);
                 }
                 $temp_robot_tokens = array_unique($temp_robot_tokens);
                 $temp_robot_tokens_count = count($temp_robot_tokens);
                 $temp_robot_target_count = count($this_targetinfo['player_robots']);
                 // Create a list of the different robot tokens in this battle
                 // Now loop through robots again and display 'em
                 foreach ($this_targetinfo['player_robots'] as $this_robotinfo) {
                     // HIDE MECHAS
                     if (empty($this_battleinfo['flags']['starter_battle']) && empty($this_battleinfo['flags']['player_battle']) && !empty($this_robotinfo['robot_class']) && $this_robotinfo['robot_class'] == 'mecha' && $temp_robot_tokens_count > 1 && $this_master_count > 0) {
                         continue;
                     }
                     // HIDE MECHAS in FORTRESS
                     if (!empty($this_battleinfo['flags']['fortress_battle']) && !empty($this_robotinfo['robot_class']) && $this_robotinfo['robot_class'] == 'mecha') {
                         continue;
                     }
                     // HIDE HIDDEN
                     if (!empty($this_robotinfo['flags']['hide_from_mission_select'])) {
                         continue;
                     }
                     $this_robotinfo['robot_image'] = !empty($this_robotinfo['robot_image']) ? $this_robotinfo['robot_image'] : $this_robotinfo['robot_token'];
                     //if (!empty($this_battleinfo['flags']['player_battle'])){ $this_robotinfo['robot_image'] = 'robot'; }
                     //if (!empty($this_robotinfo['flags']['hide_from_mission_'])){ $temp_path = 'robots/robot'; }
                     //else { $temp_path = 'robots/'.$this_robotinfo['robot_image']; }
                     //$temp_path = 'robots/'.(empty($this_battleinfo['flags']['player_battle']) ? $this_robotinfo['robot_image'] : 'robot');
                     $temp_path = 'robots/' . $this_robotinfo['robot_image'];
                     $temp_size = !empty($this_robotinfo['robot_image_size']) ? $this_robotinfo['robot_image_size'] : 40;
                     if (!empty($this_battleinfo['flags']['player_battle'])) {
                         $temp_path = in_array($this_robotinfo['robot_token'], array('roll', 'disco', 'rhythm', 'splash-woman')) ? 'robots/robot2' : 'robots/robot';
                         $temp_size = 40;
                     }
                     $this_battleinfo['battle_sprite'][] = array('path' => $temp_path, 'size' => $temp_size);
                     $this_robot_level = !empty($this_robotinfo['robot_level']) ? $this_robotinfo['robot_level'] : 1;
                     if ($this_option_min_level === false || $this_option_min_level > $this_robot_level) {
                         $this_option_min_level = $this_robot_level;
                     }
                     if ($this_option_max_level === false || $this_option_max_level < $this_robot_level) {
                         $this_option_max_level = $this_robot_level;
                     }
                 }
             }
             // Add the field/fusion star sprite if one has been added
             if ($this_has_field_star) {
                 //$this_option_complete = false;
                 $this_option_disabled = false;
                 // Check if this is a field star or fusion star
                 $temp_star_data = $this_battleinfo['values']['field_star'];
                 //die('<pre>'.print_r($temp_star_data, true).'</pre>');
                 $temp_star_kind = $temp_star_data['star_kind'];
                 // Collect the star image info from the index based on type
                 $temp_field_type_1 = !empty($temp_star_data['star_type']) ? $temp_star_data['star_type'] : 'none';
                 $temp_field_type_2 = !empty($temp_star_data['star_type2']) ? $temp_star_data['star_type2'] : $temp_field_type_1;
                 // If this is a field star, we can add sprite normally
                 if ($temp_star_kind == 'field') {
                     $temp_star_back_info = rpg_prototype::star_image($temp_field_type_1);
                     $temp_star_front_info = rpg_prototype::star_image($temp_field_type_1);
                     $temp_star_back = array('path' => 'abilities/item-star-base-' . $temp_star_front_info['sheet'], 'size' => 40, 'frame' => $temp_star_front_info['frame']);
                     $temp_star_front = array('path' => 'abilities/item-star-' . $temp_star_kind . '-' . $temp_star_back_info['sheet'], 'size' => 40, 'frame' => $temp_star_back_info['frame']);
                     array_unshift($this_battleinfo['battle_sprite'], $temp_star_back, $temp_star_front);
                 } elseif ($temp_star_kind == 'fusion') {
                     $temp_star_back_info = rpg_prototype::star_image($temp_field_type_2);
                     $temp_star_front_info = rpg_prototype::star_image($temp_field_type_1);
                     $temp_star_back = array('path' => 'abilities/item-star-base-' . $temp_star_front_info['sheet'], 'size' => 40, 'frame' => $temp_star_front_info['frame']);
                     $temp_star_front = array('path' => 'abilities/item-star-' . $temp_star_kind . '-' . $temp_star_back_info['sheet'], 'size' => 40, 'frame' => $temp_star_back_info['frame']);
                     array_unshift($this_battleinfo['battle_sprite'], $temp_star_back, $temp_star_front);
                 }
             }
             // Add the dark tower sprite if one has been added
             if ($this_has_dark_tower) {
                 //$this_option_complete = false;
                 $this_option_disabled = false;
                 // Add the dark tower sprite to the mission select
                 $temp_tower_sprite = array('path' => 'abilities/item-dark-tower', 'size' => 40, 'frame' => 0);
                 array_unshift($this_battleinfo['battle_sprite'], $temp_tower_sprite);
             }
             // Loop through the battle sprites and display them
             if (!empty($this_battleinfo['battle_sprite'])) {
                 $temp_right = false;
                 $temp_layer = 100;
                 $temp_count = count($this_battleinfo['battle_sprite']);
                 $temp_last_size = 0;
                 foreach ($this_battleinfo['battle_sprite'] as $temp_key => $this_battle_sprite) {
                     $temp_opacity = $temp_layer == 10 ? 1 : 1 - $temp_key * 0.09;
                     $temp_path = $this_battle_sprite['path'];
                     $temp_size = $this_battle_sprite['size'];
                     $temp_frame = !empty($this_battle_sprite['frame']) ? $this_battle_sprite['frame'] : '';
                     $temp_size_text = $temp_size . 'x' . $temp_size;
                     $temp_top = -2 + (40 - $temp_size);
                     if (!preg_match('/^abilities/i', $temp_path)) {
                         if ($temp_right === false) {
                             //die('<pre>'.print_r($temp_right, true).'</pre>');
                             if ($temp_size == 40) {
                                 $temp_right_inc = 0;
                                 $temp_right = 18 + $temp_right_inc;
                             } else {
                                 $temp_right_inc = -1 * ceil(($temp_size - 40) * 0.5);
                                 $temp_right = 18 + $temp_right_inc;
                             }
                         } else {
                             if ($temp_size == 40) {
                                 $temp_right_inc = ceil($temp_size * 0.5);
                                 $temp_right += $temp_right_inc;
                             } else {
                                 $temp_right_inc = ceil(($temp_size - 40) * 0.5);
                                 //ceil($temp_size * 0.5);
                                 $temp_right += $temp_right_inc;
                             }
                             if ($temp_size > $temp_last_size) {
                                 $temp_right -= ceil(($temp_size - $temp_last_size) / 2);
                             } elseif ($temp_size < $temp_last_size) {
                                 $temp_right += ceil(($temp_last_size - $temp_size) / 2);
                             }
                         }
                     } else {
                         $temp_right = 5;
                     }
                     $temp_path_full = 'images/sprites/' . $temp_path . '/sprite_left_' . $temp_size_text . '.png';
                     // Find and replace length path names with shorter ones for smaller request sizes
                     $temp_find_paths = array('images/sprites/players/', 'images/shadows/players/', 'images/sprites/robots/', 'images/shadows/robots/', 'images/sprites/abilities/', '/sprite_left_40x40', '/sprite_left_80x80', '/sprite_left_160x160', '/sprite_right_40x40', '/sprite_right_80x80', '/sprite_right_160x160', '/mug_left_40x40', '/mug_left_80x80', '/mug_left_160x160', '/mug_right_40x40', '/mug_right_80x80', '/mug_right_160x160', '/icon_left_40x40', '/icon_left_80x80', '/icon_left_160x160', '/icon_right_40x40', '/icon_right_80x80', '/icon_right_160x160');
                     $temp_replace_paths = array('i/p/', 'i/ps/', 'i/r/', 'i/rs/', 'i/a/', '/sl40', '/sl80', '/sl160', '/sr40', '/sr80', '/sr160', '/ml40', '/ml80', '/ml160', '/mr40', '/mr80', '/mr160', '/il40', '/il80', '/il160', '/ir40', '/ir80', '/ir160');
                     $temp_path_full = str_replace($temp_find_paths, $temp_replace_paths, $temp_path_full);
                     if (preg_match('/^abilities/i', $temp_path)) {
                         $this_option_label .= '<span class="sprite sprite_' . $temp_size_text . ' sprite_' . $temp_size_text . '_' . str_pad($temp_frame, 2, '0', STR_PAD_LEFT) . ' " style="background-image: url(' . $temp_path_full . '?' . MMRPG_CONFIG_CACHE_DATE . '); top: 1px; right: -3px;">&nbsp;</span>';
                     } else {
                         $this_option_label .= '<span class="sprite sprite_' . $temp_size_text . ' ' . ($this_option_complete && !$this_has_field_star && !$this_has_dark_tower && $this_option_frame == 'base' ? 'sprite_' . $temp_size_text . '_defeat ' : 'sprite_' . $temp_size_text . '_' . $this_option_frame . ' ') . '" style="background-image: url(' . $temp_path_full . '?' . MMRPG_CONFIG_CACHE_DATE . '); top: ' . $temp_top . 'px; right: ' . $temp_right . 'px;">&nbsp;</span>';
                     }
                     //'.$this_battleinfo['battle_name'].'
                     $temp_layer -= 1;
                     $temp_last_size = $temp_size;
                 }
             }
             //if ($this_battleinfo['battle_token'] == 'base-spark-man') die('<pre>'.print_r(htmlentities($this_option_label), true).'</pre>');
             //$this_option_button_text = !empty($this_battleinfo['battle_button']) ? $this_battleinfo['battle_button'] : '';
             //$this_option_button_text = !empty($this_fieldinfo['field_name']) ? $this_fieldinfo['field_name'] : '';
             if (!isset($this_battleinfo['battle_robots_limit'])) {
                 $this_battleinfo['battle_robots_limit'] = 1;
             }
             if (!isset($this_battleinfo['battle_points'])) {
                 $this_battleinfo['battle_points'] = 0;
             }
             if (!isset($this_battleinfo['battle_zenny'])) {
                 $this_battleinfo['battle_zenny'] = 0;
             }
             if (!empty($this_battleinfo['battle_button'])) {
                 $this_option_button_text = $this_battleinfo['battle_button'];
             } elseif (!empty($this_fieldinfo['field_name'])) {
                 $this_option_button_text = $this_fieldinfo['field_name'];
             } else {
                 $this_option_button_text = 'Battle';
             }
             if ($this_option_min_level < 1) {
                 $this_option_min_level = 1;
             }
             if ($this_option_max_level > 100) {
                 $this_option_max_level = 100;
             }
             $this_option_level_range = $this_option_min_level == $this_option_max_level ? 'Level ' . $this_option_min_level : 'Levels ' . $this_option_min_level . '-' . $this_option_max_level;
             $this_option_star_force = !empty($this_targetinfo['player_starforce']) ? ' | +' . number_format($this_option_star_boost * MMRPG_SETTINGS_STARS_ATTACKBOOST, 0, '.', ',') . ' Boost' : '';
             $this_option_point_amount = number_format($this_option_points, 0, '.', ',') . ' Point' . ($this_option_points != 1 ? 's' : '');
             //$this_option_label .= (!empty($this_option_button_text) ? '<span class="multi"><span class="maintext">'.$this_option_button_text.'</span><span class="subtext">'.$this_option_level_range.str_replace('|', '<span class="pipe">|</span>', $this_option_star_force).'</span><span class="subtext2">'.$this_option_point_amount.'</span></span>'.(!$this_has_field_star && (!$this_option_complete || ($this_option_complete && $this_option_encore)) ? '<span class="arrow"> &#9658;</span>' : '') : '<span class="single">???</span>');
             if (!empty($this_option_button_text)) {
                 $this_option_label .= '<span class="multi"><span class="maintext">' . $this_option_button_text . '</span><span class="subtext">' . $this_option_point_amount . '</span><span class="subtext2">' . $this_option_level_range . '</span></span>' . (!$this_has_field_star && (!$this_option_complete || $this_option_complete && $this_option_encore) ? '<span class="arrow"> &#9658;</span>' : '');
             } else {
                 $this_option_label .= '<span class="single">???</span>';
             }
             // Generate this options hover tooltip details
             $this_option_title = '';
             //$this_battleinfo['battle_button'];
             //$this_option_title .= '$this_master_count = '.$this_master_count.'; $this_mecha_count = '.$this_mecha_count.'; ';
             //if ($this_battleinfo['battle_button'] != $this_battleinfo['battle_name']){ $this_option_title .= ' | '.$this_battleinfo['battle_name']; }
             $this_option_title .= '&laquo; ' . $this_battleinfo['battle_name'] . ' &raquo;';
             $this_option_title .= ' <br />' . $this_fieldinfo['field_name'];
             if (!empty($this_fieldinfo['field_type'])) {
                 if (!empty($this_fieldinfo['field_type2'])) {
                     $this_option_title .= ' | ' . ucfirst($this_fieldinfo['field_type']) . ' / ' . ucfirst($this_fieldinfo['field_type2']) . ' Type';
                 } else {
                     $this_option_title .= ' | ' . ucfirst($this_fieldinfo['field_type']) . ' Type';
                 }
             }
             $this_option_title .= ' | ' . $this_option_level_range . ' <br />';
             //.$this_option_star_force;
             $this_option_title .= 'Target : ' . ($this_battleinfo['battle_turns_limit'] == 1 ? '1 Turn' : $this_battleinfo['battle_turns_limit'] . ' Turns') . ' with ' . ($this_battleinfo['battle_robots_limit'] == 1 ? '1 Robot' : $this_battleinfo['battle_robots_limit'] . ' Robots') . ' <br />';
             $this_option_title .= 'Reward : ' . ($this_battleinfo['battle_points'] == 1 ? '1 Point' : number_format($this_battleinfo['battle_points'], 0, '.', ',') . ' Points') . ' and ' . ($this_battleinfo['battle_zenny'] == 1 ? '1 Zenny' : number_format($this_battleinfo['battle_zenny'], 0, '.', ',') . ' Zenny');
             $this_option_title .= ' <br />' . $this_battleinfo['battle_description'] . (!empty($this_battleinfo['battle_description2']) ? ' ' . $this_battleinfo['battle_description2'] : '');
             /*
             if (!empty($this_option_complete) || !empty($this_option_failure) || !empty($this_has_field_star)){
                 $this_option_title .= ' <hr />&laquo; Battle Records &raquo;';
                 $this_option_title .= ' <br />Cleared : '.(!empty($this_option_complete['battle_count']) ? ($this_option_complete['battle_count'] == 1 ? '1 Time' : $this_option_complete['battle_count'].' Times') : '0 Times');
                 $this_option_title .= ' | Failed : '.(!empty($this_option_failure['battle_count']) ? ($this_option_failure['battle_count'] == 1 ? '1 Time' : $this_option_failure['battle_count'].' Times') : '0 Times');
                 if (!empty($this_option_complete)){
                     if (!empty($this_option_complete['battle_max_points'])){
                         $this_option_title .= ' <br />Max Points : '.(!empty($this_option_complete['battle_max_points']) ? number_format($this_option_complete['battle_max_points']) : 0).'';
                         $this_option_title .= ' | Min Points : '.(!empty($this_option_complete['battle_min_points']) ? number_format($this_option_complete['battle_min_points']) : 0).'';
                     }
                     if (!empty($this_option_complete['battle_max_turns'])){
                         $this_option_title .= ' <br />Max Turns : '.(!empty($this_option_complete['battle_max_turns']) ? number_format($this_option_complete['battle_max_turns']) : 0).'';
                         $this_option_title .= ' | Min Turns : '.(!empty($this_option_complete['battle_min_turns']) ? number_format($this_option_complete['battle_min_turns']) : 0).'';
                     }
                     if (!empty($this_option_complete['battle_max_robots'])){
                         $this_option_title .= ' <br />Max Robots : '.(!empty($this_option_complete['battle_max_robots']) ? number_format($this_option_complete['battle_max_robots']) : 0).'';
                         $this_option_title .= ' | Min Robots : '.(!empty($this_option_complete['battle_min_robots']) ? number_format($this_option_complete['battle_min_robots']) : 0).'';
                     }
                 }
             }
             */
             $this_option_title_plain = strip_tags(str_replace('<br />', '&#10;', $this_option_title));
             $this_option_title_tooltip = htmlentities($this_option_title, ENT_QUOTES, 'UTF-8');
             // Define the field multipliers
             $temp_field_multipliers = array();
             if (!empty($this_fieldinfo['field_multipliers'])) {
                 $temp_multiplier_list = $this_fieldinfo['field_multipliers'];
                 asort($temp_multiplier_list);
                 $temp_multiplier_list = array_reverse($temp_multiplier_list, true);
                 foreach ($temp_multiplier_list as $temp_type => $temp_multiplier) {
                     if ($temp_multiplier == 1) {
                         continue;
                     }
                     $temp_field_multipliers[] = $temp_type . '*' . number_format($temp_multiplier, 1);
                 }
             }
             $temp_field_multipliers = !empty($temp_field_multipliers) ? implode('|', $temp_field_multipliers) : '';
             // DEBUG DEBUG
             //$this_battleinfo['battle_description'] .= json_encode($this_battleinfo['battle_rewards']);
             // Print out the option button markup with sprite and name
             $this_markup .= '<a data-chapter="' . $this_info['option_chapter'] . '" data-tooltip="' . $this_option_title_tooltip . '" data-field="' . htmlentities($this_fieldinfo['field_name'], ENT_QUOTES, 'UTF-8', true) . '" data-description="' . htmlentities($this_battleinfo['battle_description'] . (!empty($this_battleinfo['battle_description2']) ? ' ' . $this_battleinfo['battle_description2'] : ''), ENT_QUOTES, 'UTF-8', true) . '" data-multipliers="' . $temp_field_multipliers . '" data-background="' . (!empty($this_fieldinfo['field_background']) ? $this_fieldinfo['field_background'] : '') . '" data-foreground="' . (!empty($this_fieldinfo['field_foreground']) ? $this_fieldinfo['field_foreground'] : '') . '" class="' . $this_option_class . '" data-token="' . $this_option_token . '" data-next-limit="' . $this_option_limit . '" style="' . $this_option_style . (!empty($this_info['option_style']) ? ' ' . $this_info['option_style'] : '') . '"><div class="platform" style="' . $this_option_platform_style . '"><div class="chrome"><div class="inset"><label class="' . (!empty($this_battleinfo['battle_sprite']) ? 'has_image' : 'no_image') . '">' . $this_option_label . '</label></div></div></div></a>' . "\r\n";
             // Update the main battle option array with recent changes
             $this_battleinfo['flag_skip'] = true;
             $battle_options[$this_key] = $this_battleinfo;
         }
     }
     // Return the generated markup
     return $this_markup;
 }
Exemple #7
0
    // Load the object data for this and the target player from the battle
    echo basename(__FILE__) . ' on line ' . __LINE__ . "\n";
    $this_player = $this_battle->get_player($this_player_id);
    echo basename(__FILE__) . ' on line ' . __LINE__ . "\n";
    $target_player = $this_battle->get_player($target_player_id);
    // Load the object data for this and the target robot from the battle
    $this_robot = $this_battle->get_robot($this_robot_id);
    $target_robot = $this_battle->get_robot($target_robot_id);
} elseif ($this_action == 'start') {
    // Collect the preset battle info from the index
    $this_preset_battle = rpg_battle::get_index_info($this_battleinfo['battle_token']);
    if (!empty($this_preset_battle)) {
        $this_battleinfo = array_replace($this_preset_battle, $this_battleinfo);
    }
    // Define the battle object using the loaded battle data and update session
    $this_battle = new rpg_battle($this_battleinfo);
    // Start the battle turn off at zero
    $this_battle->set_counter('battle_turn', 0);
    // Collect preset field info from the battle
    $this_preset_field = $this_battle->get_field_info();
    if (!empty($this_preset_field)) {
        $this_fieldinfo = array_replace($this_preset_field, $this_fieldinfo);
    }
    // Collect this player's preset info from the battle
    $this_preset_player = $this_battle->get_this_player();
    if (!empty($this_preset_player)) {
        $this_playerinfo = array_merge($this_preset_player, $this_playerinfo);
    }
    // Collect this player's preset robots from the battle
    $this_preset_robots = array();
    if (isset($this_playerinfo['player_robots'])) {
Exemple #8
0
//$debug_flag_animation = false;
//$debug_flag_scanlines = false;
// Collect the battle tokens from the URL
$this_battle_id = isset($_GET['this_battle_id']) ? $_GET['this_battle_id'] : 0;
$this_battle_token = isset($_GET['this_battle_token']) ? $_GET['this_battle_token'] : '';
$this_field_id = isset($_GET['this_field_id']) ? $_GET['this_field_id'] : 0;
$this_field_token = isset($_GET['this_field_token']) ? $_GET['this_field_token'] : '';
$this_player_id = isset($_GET['this_player_id']) ? $_GET['this_player_id'] : 0;
$this_player_token = isset($_GET['this_player_token']) ? $_GET['this_player_token'] : '';
$this_player_robots = isset($_GET['this_player_robots']) ? $_GET['this_player_robots'] : '';
$target_player_id = isset($_GET['target_player_id']) ? $_GET['target_player_id'] : 0;
$target_player_token = isset($_GET['target_player_token']) ? $_GET['target_player_token'] : '';
// -- COLLECT BATLE INFO -- //
// Collect the battle index data if available
if (!empty($this_battle_token)) {
    $this_battle_data = rpg_battle::get_index_info($this_battle_token);
    if (empty($this_battle_data['battle_id'])) {
        $this_battle_id = !empty($this_battle_id) ? $this_battle_id : 1;
        $this_battle_data['battle_id'] = $this_battle_id;
    }
} else {
    $this_battle_id = 0;
    $this_battle_token = '';
    $this_battle_data = array();
}
// -- COLLECT FIELD INFO -- //
// Define the field data object as empty
$this_field_data = array();
// Collect the field data object values if available
if (!empty($this_field_token)) {
    // Collect the field data from the index directly
 public function check_weapons(rpg_player $target_player, rpg_robot $target_robot, $regen_weapons = true)
 {
     // Collect references to global objects
     $db = cms_database::get_database();
     $this_battle = rpg_battle::get_battle();
     $this_field = rpg_field::get_field();
     // Collect references to relative player and robot objects
     $this_player = $this->player;
     $this_robot = $this;
     // Hide any disabled robots and return
     if ($this_robot->get_status() == 'disabled') {
         $this_robot->set_flag('apply_disabled_state', true);
         $this_battle->events_create();
         return;
     }
     // If this robot is not at full weapon energy, increase it by one
     $temp_weapons = $this_robot->get_weapons();
     $temp_base_weapons = $this_robot->get_base_weapons();
     if ($temp_weapons < $temp_base_weapons) {
         // Ensure the regen weapons flag has been set to true
         if ($regen_weapons) {
             // Define the multiplier based on position
             $temp_multiplier = $this_robot->get_position() == 'bench' ? 2 : 1;
             // Increment this robot's weapons by one point and update
             $temp_weapons += MMRPG_SETTINGS_RECHARGE_WEAPONS * $temp_multiplier;
             $this_robot->set_weapons($temp_weapons);
         }
     }
 }
 /**
  * Empty all actions in the global battle queue
  */
 public function actions_empty()
 {
     $this_battle = rpg_battle::get_battle();
     $this_battle->actions = array();
     return $this_battle->actions;
 }