コード例 #1
0
 public function check_attachments(rpg_player $target_player, rpg_robot $target_robot)
 {
     // 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 has any attachments, loop through them
     if ($this_robot->has_attachments()) {
         $attachment_action_flag = false;
         $attachment_key = 0;
         $robot_attachments = $this_robot->get_attachments();
         foreach ($robot_attachments as $attachment_token => $attachment_info) {
             $attachment_debug_token = str_replace('ability_', '', $attachment_token);
             $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' checkpoint has attachment ' . $attachment_debug_token);
             // Load the attachment if it doesn't exist yet then collect a reference
             if (!$this_battle->attachment_exists($attachment_info['ability_id'])) {
                 $this_battle->add_attachment($this_player, $this_robot, $attachment_info);
             } else {
                 $this_battle->update_attachment($attachment_info['ability_id'], $attachment_info);
             }
             $this_attachment = $this_battle->get_attachment($attachment_info['ability_id']);
             // ATTACHMENT DURATION
             // If this attachment has DURATION counter
             if (isset($attachment_info['attachment_duration'])) {
                 $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' has duration ' . $attachment_info['attachment_duration']);
                 // DURATION COUNT -1
                 // If the duration is not empty, decrement it and continue
                 if ($attachment_info['attachment_duration'] > 0) {
                     $attachment_info['attachment_duration'] = $attachment_info['attachment_duration'] - 1;
                     $this_robot->set_attachment($attachment_token, $attachment_info);
                     $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' duration decreased to ' . $attachment_info['attachment_duration']);
                 } else {
                     // Remove this attachment and inflict damage on the robot
                     $this_robot->unset_attachment($attachment_token);
                     // ATTACHMENT DESTROY
                     if ($attachment_info['attachment_destroy'] !== false) {
                         $temp_trigger_type = !empty($attachment_info['attachment_destroy']['trigger']) ? $attachment_info['attachment_destroy']['trigger'] : 'damage';
                         $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' duration ended and has ' . $temp_trigger_type . ' trigger!');
                         // DESTORY DAMAGE
                         if ($temp_trigger_type == 'damage') {
                             $this_attachment->damage_options_update($attachment_info['attachment_destroy']);
                             $this_attachment->recovery_options_update($attachment_info['attachment_destroy']);
                             $temp_damage_kind = $attachment_info['attachment_destroy']['kind'];
                             $temp_trigger_options = isset($attachment_info['attachment_destroy']['options']) ? $attachment_info['attachment_destroy']['options'] : array('apply_modifiers' => false);
                             if (isset($attachment_info['attachment_' . $temp_damage_kind])) {
                                 // Collect the base damage amount
                                 $temp_damage_amount = $attachment_info['attachment_' . $temp_damage_kind];
                                 $temp_stat_amount = $this_robot->get_stat($temp_damage_kind);
                                 $temp_stat_base_amount = $this_robot->get_base_stat($temp_damage_kind);
                                 // If an attachment damage percent was provided, recalculate from current stat
                                 if (isset($attachment_info['attachment_' . $temp_damage_kind . '_percent'])) {
                                     $temp_damage_amount = ceil($temp_stat_amount * ($attachment_info['attachment_' . $temp_damage_kind . '_percent'] / 100));
                                     $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' triggers ' . $temp_damage_kind . ' damage of ' . $attachment_info['attachment_' . $temp_damage_kind . '_percent'] . '% of current <br /> ceil(' . $temp_stat_amount . ' * (' . $attachment_info['attachment_' . $temp_damage_kind . '_percent'] . ' / 100)) = ' . $temp_damage_amount . '');
                                 } elseif (isset($attachment_info['attachment_' . $temp_damage_kind . '_base_percent'])) {
                                     $temp_damage_amount = ceil($temp_stat_base_amount * ($attachment_info['attachment_' . $temp_damage_kind . '_base_percent'] / 100));
                                     $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' triggers ' . $temp_damage_kind . ' damage of ' . $attachment_info['attachment_' . $temp_damage_kind . '_base_percent'] . '% of base <br /> ceil(' . $temp_stat_base_amount . ' * (' . $attachment_info['attachment_' . $temp_damage_kind . '_base_percent'] . ' / 100)) = ' . $temp_damage_amount . '');
                                 } else {
                                     $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' triggers ' . $temp_damage_kind . ' damage of ' . $temp_damage_amount . '!');
                                 }
                                 // If this is energy we're dealing with, we must respect min and max limits
                                 if ($temp_damage_kind == 'energy' && $temp_stat_amount - $temp_damage_amount < 0) {
                                     $temp_damage_amount = $temp_stat_amount;
                                     $attachment_info['attachment_' . $temp_damage_kind . '_base_percent'] = round($temp_damage_amount / $temp_stat_base_amount * 100);
                                     $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' ' . $temp_damage_kind . ' damage too high, changed to ' . $attachment_info['attachment_' . $temp_damage_kind . '_base_percent'] . '% of base or ' . $temp_damage_amount . ' / ' . $temp_stat_base_amount);
                                 }
                                 // Only deal damage if the amount was greater than zero
                                 if ($temp_damage_amount > 0) {
                                     $this_robot->trigger_damage($this_robot, $this_attachment, $temp_damage_amount, false, $temp_trigger_options);
                                 }
                                 if ($this_attachment->ability_results['this_result'] != 'failure' && $this_attachment->ability_results['this_amount'] > 0) {
                                     $attachment_action_flag = true;
                                 }
                             } else {
                                 $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' ' . $temp_damage_kind . ' damage amount not found!');
                             }
                         } elseif ($temp_trigger_type == 'recovery') {
                             $this_attachment->recovery_options_update($attachment_info['attachment_destroy']);
                             $this_attachment->damage_options_update($attachment_info['attachment_destroy']);
                             $temp_recovery_kind = $attachment_info['attachment_destroy']['kind'];
                             $temp_trigger_options = isset($attachment_info['attachment_destroy']['options']) ? $attachment_info['attachment_destroy']['options'] : array('apply_modifiers' => false);
                             if (isset($attachment_info['attachment_' . $temp_recovery_kind])) {
                                 // Collect the base recovery amount
                                 $temp_recovery_amount = $attachment_info['attachment_' . $temp_recovery_kind];
                                 $temp_stat_amount = $this_robot->get_stat($temp_recovery_kind);
                                 $temp_stat_base_amount = $this_robot->get_base_stat($temp_recovery_kind);
                                 // If an attachment recovery percent was provided, recalculate from current stat
                                 if (isset($attachment_info['attachment_' . $temp_recovery_kind . '_percent'])) {
                                     $temp_recovery_amount = ceil($temp_stat_amount * ($attachment_info['attachment_' . $temp_recovery_kind . '_percent'] / 100));
                                     $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' triggers ' . $temp_recovery_kind . ' recovery of ' . $attachment_info['attachment_' . $temp_recovery_kind . '_percent'] . '% of current <br /> ceil(' . $temp_stat_amount . ' * (' . $attachment_info['attachment_' . $temp_recovery_kind . '_percent'] . ' / 100)) = ' . $temp_recovery_amount . '');
                                 } elseif (isset($attachment_info['attachment_' . $temp_recovery_kind . '_base_percent'])) {
                                     $temp_recovery_amount = ceil($temp_stat_base_amount * ($attachment_info['attachment_' . $temp_recovery_kind . '_base_percent'] / 100));
                                     $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' triggers ' . $temp_recovery_kind . ' recovery of ' . $attachment_info['attachment_' . $temp_recovery_kind . '_base_percent'] . '% of base <br /> ceil(' . $temp_stat_base_amount . ' * (' . $attachment_info['attachment_' . $temp_recovery_kind . '_base_percent'] . ' / 100)) = ' . $temp_recovery_amount . '');
                                 } else {
                                     $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' triggers ' . $temp_recovery_kind . ' recovery of ' . $temp_recovery_amount . '!');
                                 }
                                 // If this is energy we're dealing with, we must respect min and max limits
                                 if ($temp_recovery_kind == 'energy' && $temp_stat_amount + $temp_recovery_amount > $temp_stat_base_amount) {
                                     $temp_recovery_amount = $temp_stat_base_amount - $temp_stat_amount;
                                     $attachment_info['attachment_' . $temp_recovery_kind . '_base_percent'] = round($temp_recovery_amount / $temp_stat_base_amount * 100);
                                     $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' ' . $temp_recovery_kind . ' recovery too high, changed to ' . $attachment_info['attachment_' . $temp_recovery_kind . '_base_percent'] . '% of base or ' . $temp_recovery_amount . ' / ' . $temp_stat_base_amount);
                                 }
                                 // Only deal recovery if the amount was greater than zero
                                 if ($temp_recovery_amount > 0) {
                                     $this_robot->trigger_recovery($this_robot, $this_attachment, $temp_recovery_amount, false, $temp_trigger_options);
                                 }
                                 $temp_results = $this_attachment->get_results();
                                 if ($temp_results['this_result'] != 'failure' && $temp_results['this_amount'] > 0) {
                                     $attachment_action_flag = true;
                                 }
                             } else {
                                 $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' ' . $temp_recovery_kind . ' recovery amount not found!');
                             }
                         } elseif ($temp_trigger_type == 'special') {
                             $this_attachment->target_options_update($attachment_info['attachment_destroy']);
                             $this_attachment->recovery_options_update($attachment_info['attachment_destroy']);
                             $this_attachment->damage_options_update($attachment_info['attachment_destroy']);
                             $temp_trigger_options = isset($attachment_info['attachment_destroy']['options']) ? $attachment_info['attachment_destroy']['options'] : array();
                             $this_robot->trigger_damage($this_robot, $this_attachment, 0, false, $temp_trigger_options);
                             $attachment_action_flag = true;
                         }
                         // If the temp robot was disabled, trigger the event
                         if ($this_robot->get_energy() < 1) {
                             $this_robot->trigger_disabled($target_robot, $this_attachment);
                             // If this the player's last robot
                             $active_robots = $this_player->get_robots_active();
                             if (empty($active_robots)) {
                                 // Trigger the battle complete event
                                 $this_battle->trigger_complete($target_player, $target_robot, $this_player, $this_robot);
                                 $attachment_action_flag = true;
                             }
                         }
                     }
                 }
             }
             // ATTACHMENT REPEAT
             // If this attachment has REPEAT effects
             if (!empty($attachment_info['attachment_repeat'])) {
                 $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' has repeat!');
                 $temp_trigger_type = !empty($attachment_info['attachment_repeat']['trigger']) ? $attachment_info['attachment_repeat']['trigger'] : 'damage';
                 $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' has ' . $temp_trigger_type . ' trigger!');
                 // REPEAT DAMAGE
                 if ($temp_trigger_type == 'damage') {
                     // Define the system word based on the stat kind
                     $temp_damage_kind = $attachment_info['attachment_repeat']['kind'];
                     $temp_damage_words = rpg_functions::get_stat_damage_words($temp_damage_kind);
                     // Update the success message to reflect the current target
                     $attachment_info['attachment_repeat']['success'] = array(9, -10, -10, -10, 'The ' . $this_attachment->print_name() . ' ' . $temp_damage_words['action'] . ' ' . $this_robot->print_name() . '&#39;s ' . $temp_damage_words['object'] . ' systems!');
                     $this_attachment->damage_options_update($attachment_info['attachment_repeat']);
                     $this_attachment->recovery_options_update($attachment_info['attachment_repeat']);
                     $temp_trigger_options = isset($attachment_info['attachment_repeat']['options']) ? $attachment_info['attachment_repeat']['options'] : array('apply_modifiers' => false);
                     if (isset($attachment_info['attachment_' . $temp_damage_kind])) {
                         // Collect the base damage amount
                         $temp_damage_amount = $attachment_info['attachment_' . $temp_damage_kind];
                         $temp_stat_amount = $this_robot->get_stat($temp_damage_kind);
                         $temp_stat_base_amount = $this_robot->get_base_stat($temp_damage_kind);
                         // If an attachment damage percent was provided, recalculate from current stat
                         if (isset($attachment_info['attachment_' . $temp_damage_kind . '_percent'])) {
                             $temp_damage_amount = ceil($temp_stat_amount * ($attachment_info['attachment_' . $temp_damage_kind . '_percent'] / 100));
                             $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' triggers ' . $temp_damage_kind . ' damage of ' . $attachment_info['attachment_' . $temp_damage_kind . '_percent'] . '% of current <br /> ceil(' . $temp_stat_amount . ' * (' . $attachment_info['attachment_' . $temp_damage_kind . '_percent'] . ' / 100)) = ' . $temp_damage_amount . '');
                         } elseif (isset($attachment_info['attachment_' . $temp_damage_kind . '_base_percent'])) {
                             $temp_damage_amount = ceil($temp_stat_base_amount * ($attachment_info['attachment_' . $temp_damage_kind . '_base_percent'] / 100));
                             $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' triggers ' . $temp_damage_kind . ' damage of ' . $attachment_info['attachment_' . $temp_damage_kind . '_base_percent'] . '% of base <br /> ceil(' . $temp_stat_base_amount . ' * (' . $attachment_info['attachment_' . $temp_damage_kind . '_base_percent'] . ' / 100)) = ' . $temp_damage_amount . '');
                         } else {
                             $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' triggers ' . $temp_damage_kind . ' damage of ' . $temp_damage_amount . '!');
                         }
                         // If this is energy we're dealing with, we must respect min and max limits
                         if ($temp_damage_kind == 'energy' && $temp_stat_amount - $temp_damage_amount < 0) {
                             $temp_damage_amount = $temp_stat_amount;
                             $attachment_info['attachment_' . $temp_damage_kind . '_base_percent'] = round($temp_damage_amount / $temp_stat_base_amount * 100);
                             $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' ' . $temp_damage_kind . ' damage too high, changed to ' . $attachment_info['attachment_' . $temp_damage_kind . '_base_percent'] . '% of base or ' . $temp_damage_amount . ' / ' . $temp_stat_base_amount);
                         }
                         // Only deal damage if the amount was greater than zero
                         if ($temp_damage_amount > 0) {
                             $this_robot->trigger_damage($this_robot, $this_attachment, $temp_damage_amount, false, $temp_trigger_options);
                         }
                         $temp_results = $this_attachment->get_results();
                         if ($temp_results['this_result'] != 'failure' && $temp_results['this_amount'] > 0) {
                             $attachment_action_flag = true;
                         }
                     } else {
                         $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' ' . $temp_damage_kind . ' damage amount not found!');
                     }
                 } elseif ($temp_trigger_type == 'recovery') {
                     // Define the system word based on the stat kind
                     $temp_recovery_kind = $attachment_info['attachment_repeat']['kind'];
                     $temp_recovery_words = rpg_functions::get_stat_recovery_words($temp_recovery_kind);
                     // Update the success message to reflect the current target
                     $attachment_info['attachment_repeat']['success'] = array(9, -10, -10, -10, 'The ' . $this_attachment->print_name() . ' ' . $temp_recovery_words['action'] . ' ' . $this_robot->print_name() . '&#39;s ' . $temp_recovery_words['object'] . ' systems!');
                     $this_attachment->recovery_options_update($attachment_info['attachment_repeat']);
                     $this_attachment->damage_options_update($attachment_info['attachment_repeat']);
                     $temp_trigger_options = isset($attachment_info['attachment_repeat']['options']) ? $attachment_info['attachment_repeat']['options'] : array('apply_modifiers' => false);
                     if (isset($attachment_info['attachment_' . $temp_recovery_kind])) {
                         // Collect the base recovery amount
                         $temp_recovery_amount = $attachment_info['attachment_' . $temp_recovery_kind];
                         $temp_stat_amount = $this_robot->get_stat($temp_recovery_kind);
                         $temp_stat_base_amount = $this_robot->get_base_stat($temp_recovery_kind);
                         // If an attachment recovery percent was provided, recalculate from current stat
                         if (isset($attachment_info['attachment_' . $temp_recovery_kind . '_percent'])) {
                             $temp_recovery_amount = ceil($temp_stat_amount * ($attachment_info['attachment_' . $temp_recovery_kind . '_percent'] / 100));
                             $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' triggers ' . $temp_recovery_kind . ' recovery of ' . $attachment_info['attachment_' . $temp_recovery_kind . '_percent'] . '% of current <br /> ceil(' . $temp_stat_amount . ' * (' . $attachment_info['attachment_' . $temp_recovery_kind . '_percent'] . ' / 100)) = ' . $temp_recovery_amount . '');
                         } elseif (isset($attachment_info['attachment_' . $temp_recovery_kind . '_base_percent'])) {
                             $temp_recovery_amount = ceil($temp_stat_base_amount * ($attachment_info['attachment_' . $temp_recovery_kind . '_base_percent'] / 100));
                             $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' triggers ' . $temp_recovery_kind . ' recovery of ' . $attachment_info['attachment_' . $temp_recovery_kind . '_base_percent'] . '% of base <br /> ceil(' . $temp_stat_base_amount . ' * (' . $attachment_info['attachment_' . $temp_recovery_kind . '_base_percent'] . ' / 100)) = ' . $temp_recovery_amount . '');
                         } else {
                             $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' triggers ' . $temp_recovery_kind . ' recovery of ' . $temp_recovery_amount . '!');
                         }
                         // If this is energy we're dealing with, we must respect min and max limits
                         if ($temp_recovery_kind == 'energy' && $temp_stat_amount + $temp_recovery_amount > $temp_stat_base_amount) {
                             $temp_recovery_amount = $temp_stat_base_amount - $temp_stat_amount;
                             $attachment_info['attachment_' . $temp_recovery_kind . '_base_percent'] = round($temp_recovery_amount / $temp_stat_base_amount * 100);
                             $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' ' . $temp_recovery_kind . ' recovery too high, changed to ' . $attachment_info['attachment_' . $temp_recovery_kind . '_base_percent'] . '% of base or ' . $temp_recovery_amount . ' / ' . $temp_stat_base_amount);
                         }
                         // Only deal recovery if the amount was greater than zero
                         if ($temp_recovery_amount > 0) {
                             $this_robot->trigger_recovery($this_robot, $this_attachment, $temp_recovery_amount, false, $temp_trigger_options);
                         }
                         $temp_results = $this_attachment->get_results();
                         if ($temp_results['this_result'] != 'failure' && $temp_results['this_amount'] > 0) {
                             $attachment_action_flag = true;
                         }
                     } else {
                         $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' ' . $temp_recovery_kind . ' recovery amount not found!');
                     }
                 } elseif ($temp_trigger_type == 'special') {
                     $this_attachment->target_options_update($attachment_info['attachment_repeat']);
                     $this_attachment->recovery_options_update($attachment_info['attachment_repeat']);
                     $this_attachment->damage_options_update($attachment_info['attachment_repeat']);
                     $this_attachment->update_session();
                     $temp_trigger_options = isset($attachment_info['attachment_repeat']['options']) ? $attachment_info['attachment_repeat']['options'] : array();
                     $this_battle->events_debug(__FILE__, __LINE__, $this_robot->robot_token . ' attachment ' . $attachment_debug_token . ' triggers special!');
                     $this_robot->trigger_damage($this_robot, $this_attachment, 0, false, $temp_trigger_options);
                     $attachment_action_flag = true;
                 }
                 // If the temp robot was disabled, trigger the event
                 if ($temp_stat_amount < 1) {
                     $this_robot->trigger_disabled($target_robot, $this_attachment);
                     // If this the player's last robot
                     if ($this_player->counters['robots_active'] < 1) {
                         // Trigger the battle complete event
                         $this_battle->trigger_complete($target_player, $target_robot, $this_player, $this_robot);
                         $attachment_action_flag = true;
                     }
                 }
             }
             $attachment_key++;
         }
         // Create an empty field to remove any leftover frames
         if ($attachment_action_flag) {
             $this_battle->events_create();
         }
     }
 }