Пример #1
0
 /**
  * Create a new RPG player object
  * @param array $player_info (optional)
  * @return rpg_player
  */
 public function __construct($player_info = array())
 {
     // Update the session keys for this object
     $this->session_key = 'PLAYERS';
     $this->session_token = 'player_token';
     $this->session_id = 'player_id';
     $this->class = 'player';
     // Collect any provided arguments
     $args = func_get_args();
     // Define the internal class identifier
     $this->class = 'player';
     // 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;
     // Collect current player data from the function if available
     $this_playerinfo = !empty($player_info) ? $player_info : array();
     if (!isset($this_playerinfo['player_id'])) {
         $this_playerinfo['player_id'] = 0;
     }
     if (!isset($this_playerinfo['player_token'])) {
         $this_playerinfo['player_token'] = 'player';
     }
     // Load the player data based on the ID and fallback token
     $this_playerinfo = $this->player_load($this_playerinfo['player_id'], $this_playerinfo['player_token'], $this_playerinfo);
     // Now load the player data from the session or index
     if (empty($this_playerinfo)) {
         // Player data could not be loaded
         die('Player data could not be loaded :<br />$this_playerinfo = <pre>' . print_r($this_playerinfo, true) . '</pre>');
         return false;
     }
     // Update the session variable
     $this->update_session();
     // Return true on success
     return true;
 }
Пример #2
0
 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;
 }
Пример #3
0
 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);
         }
     }
 }
Пример #4
0
 /**
  * Generate the console message markup for this frame of battle including players, robots, abilities etc.
  * @param array $eventinfo
  * @param array $options (optional)
  * @return string
  */
 public function get_console_markup($eventinfo, $options = array())
 {
     // Collect references to global objects
     $db = cms_database::get_database();
     $this_battle = self::get_battle();
     $this_field = rpg_field::get_field();
     // Default the return markup to empty
     $this_markup = '';
     // Ensure this side is allowed to be shown before generating any markup
     if ($options['console_show_this'] != false) {
         // Define the necessary text markup for the current player if allowed and exists
         if (!empty($eventinfo['this_player'])) {
             // Collect the console data for this player
             $this_player_data = $eventinfo['this_player']->get_console_markup($options);
         } else {
             // Define empty console data for this player
             $this_player_data = array();
             $options['console_show_this_player'] = false;
         }
         // Define the necessary text markup for the current robot if allowed and exists
         if (!empty($eventinfo['this_robot'])) {
             // Collect the console data for this robot
             $this_robot_data = $eventinfo['this_robot']->get_console_markup($options, $this_player_data);
         } else {
             // Define empty console data for this robot
             $this_robot_data = array();
             $options['console_show_this_robot'] = false;
         }
         // Define the necessary text markup for the current ability if allowed and exists
         if (!empty($options['this_ability'])) {
             // Collect the console data for this ability
             $this_ability_data = $options['this_ability']->get_console_markup($options, $this_player_data, $this_robot_data);
         } else {
             // Define empty console data for this ability
             $this_ability_data = array();
             $options['console_show_this_ability'] = false;
         }
         // Define the necessary text markup for the current star if allowed and exists
         if (!empty($options['this_star'])) {
             // Collect the console data for this star
             $this_star_data = rpg_functions::get_star_console_markup($options['this_star'], $this_player_data, $this_robot_data);
         } else {
             // Define empty console data for this star
             $this_star_data = array();
             $options['console_show_this_star'] = false;
         }
         // If no objects would found to display, turn the left side off
         if (empty($options['console_show_this_player']) && empty($options['console_show_this_robot']) && empty($options['console_show_this_ability']) && empty($options['console_show_this_star'])) {
             // Automatically set the console option to false
             $options['console_show_this'] = false;
         }
     } else {
         // Default all of this side's objects to empty arrays
         $this_player_data = array();
         $this_robot_data = array();
         $this_ability_data = array();
         $this_star_data = array();
     }
     // Ensure the target side is allowed to be shown before generating any markup
     if ($options['console_show_target'] != false) {
         // Define the necessary text markup for the target player if allowed and exists
         if (!empty($eventinfo['target_player'])) {
             // Collect the console data for this player
             $target_player_data = $eventinfo['target_player']->get_console_markup($options);
         } else {
             // Define empty console data for this player
             $target_player_data = array();
             $options['console_show_target_player'] = false;
         }
         // Define the necessary text markup for the target robot if allowed and exists
         if (!empty($eventinfo['target_robot'])) {
             // Collect the console data for this robot
             $target_robot_data = $eventinfo['target_robot']->get_console_markup($options, $target_player_data);
         } else {
             // Define empty console data for this robot
             $target_robot_data = array();
             $options['console_show_target_robot'] = false;
         }
         // Define the necessary text markup for the target ability if allowed and exists
         if (!empty($options['target_ability'])) {
             // Collect the console data for this ability
             $target_ability_data = $options['target_ability']->get_console_markup($options, $target_player_data, $target_robot_data);
         } else {
             // Define empty console data for this ability
             $target_ability_data = array();
             $options['console_show_target_ability'] = false;
         }
         // If no objects would found to display, turn the right side off
         if (empty($options['console_show_target_player']) && empty($options['console_show_target_robot']) && empty($options['console_show_target_ability'])) {
             // Automatically set the console option to false
             $options['console_show_target'] = false;
         }
     } else {
         // Default all of the target side's objects to empty arrays
         $target_player_data = array();
         $target_robot_data = array();
         $target_ability_data = array();
     }
     // Assign player-side based floats for the header and body if not set
     if (empty($options['console_header_float']) && !empty($this_robot_data)) {
         $options['console_header_float'] = $this_robot_data['robot_float'];
     }
     if (empty($options['console_body_float']) && !empty($this_robot_data)) {
         $options['console_body_float'] = $this_robot_data['robot_float'];
     }
     // Append the generated console markup if not empty
     if (!empty($eventinfo['event_header']) && !empty($eventinfo['event_body'])) {
         // Define the container class based on height
         $event_class = 'event ';
         $event_style = '';
         if ($options['console_container_height'] == 1) {
             $event_class .= 'event_single ';
         }
         if ($options['console_container_height'] == 2) {
             $event_class .= 'event_double ';
         }
         if ($options['console_container_height'] == 3) {
             $event_class .= 'event_triple ';
         }
         if (!empty($options['console_container_classes'])) {
             $event_class .= $options['console_container_classes'];
         }
         if (!empty($options['console_container_styles'])) {
             $event_style .= $options['console_container_styles'];
         }
         // Generate the opening event tag
         $this_markup .= '<div class="' . $event_class . '" style="' . $event_style . '">';
         // Generate this side's markup if allowed
         if ($options['console_show_this'] != false) {
             // Append this player's markup if allowed
             if ($options['console_show_this_player'] != false) {
                 $this_markup .= $this_player_data['player_markup'];
             } elseif ($options['console_show_this_robot'] != false) {
                 $this_markup .= $this_robot_data['robot_markup'];
             } elseif ($options['console_show_this_ability'] != false) {
                 $this_markup .= $this_ability_data['ability_markup'];
             } elseif ($options['console_show_this_star'] != false) {
                 $this_markup .= $this_star_data['star_markup'];
             }
         }
         // Generate the target side's markup if allowed
         if ($options['console_show_target'] != false) {
             // Append the target player's markup if allowed
             if ($options['console_show_target_player'] != false) {
                 $this_markup .= $target_player_data['player_markup'];
             } elseif ($options['console_show_target_robot'] != false) {
                 $this_markup .= $target_robot_data['robot_markup'];
             } elseif ($options['console_show_target_ability'] != false) {
                 $this_markup .= $target_ability_data['ability_markup'];
             }
         }
         // Prepend the turn counter to the header if necessary
         if (!empty($this_battle->counters['battle_turn']) && $this_battle->battle_status != 'complete') {
             $eventinfo['event_header'] = 'Turn #' . $this_battle->counters['battle_turn'] . ' : ' . $eventinfo['event_header'];
         }
         // Display the event header and event body
         $this_markup .= '<div class="header header_' . $options['console_header_float'] . '">' . $eventinfo['event_header'] . '</div>';
         $this_markup .= '<div class="body body_' . $options['console_body_float'] . '">' . $eventinfo['event_body'] . '</div>';
         // Displat the closing event tag
         $this_markup .= '</div>';
     }
     // Return the generated markup and robot data
     return $this_markup;
 }