public function trigger_ability(rpg_player $target_player, rpg_robot $target_robot, rpg_ability $this_ability) { // Extract all objects into the current scope global $db; $this_battle = $this->battle; $this_field = $this->field; $this_player = $this->player; $this_robot = $this; $this_battle->refresh(); $this_field->refresh(); $this_player->refresh(); $this_robot->refresh(); $target_player->refresh(); $target_robot->refresh(); $this_ability->refresh(); // Update this robot's history with the triggered ability $this_robot->add_history('triggered_abilities', $this_ability->ability_token); // Set the ability active flag in the battle $this_battle->set_flag('robot_ability_in_progress', 1); // Define a variable to hold the ability results $ability_results = array(); $ability_results['total_result'] = ''; $ability_results['total_actions'] = 0; $ability_results['total_strikes'] = 0; $ability_results['total_misses'] = 0; $ability_results['total_amount'] = 0; $ability_results['total_overkill'] = 0; $ability_results['this_result'] = ''; $ability_results['this_amount'] = 0; $ability_results['this_overkill'] = 0; $ability_results['this_text'] = ''; $ability_results['counter_criticals'] = 0; $ability_results['counter_affinities'] = 0; $ability_results['counter_weaknesses'] = 0; $ability_results['counter_resistances'] = 0; $ability_results['counter_immunities'] = 0; $ability_results['counter_coreboosts'] = 0; $ability_results['flag_critical'] = false; $ability_results['flag_affinity'] = false; $ability_results['flag_weakness'] = false; $ability_results['flag_resistance'] = false; $ability_results['flag_immunity'] = false; $this_ability->set_results($ability_results); // Reset the ability options to default $this_ability->target_options_reset(); $this_ability->damage_options_reset(); $this_ability->recovery_options_reset(); // Determine how much weapon energy this should take $temp_ability_energy = $this_robot->calculate_weapon_energy($this_ability); // Decrease this robot's weapon energy $this_robot->set_weapons($this_robot->robot_weapons - $temp_ability_energy); // Default this and the target robot's frames to their base $this_robot->set_frame('base'); $target_robot->set_frame('base'); // Default the robot's stances to attack/defend $this_robot->set_stance('attack'); $target_robot->set_stance('defend'); // If this is a copy core robot and the ability type does not match its core $temp_image_changed = false; $temp_ability_type = !empty($this_ability->ability_type) ? $this_ability->ability_type : ''; $temp_ability_type2 = !empty($this_ability->ability_type2) ? $this_ability->ability_type2 : $temp_ability_type; if (!empty($temp_ability_type) && $this->robot_base_core == 'copy') { $this_robot->set_image_overlay('copy_type1', $this->robot_base_image . '_' . $temp_ability_type . '2'); $this_robot->set_image_overlay('copy_type2', $this->robot_base_image . '_' . $temp_ability_type2 . '3'); $temp_image_changed = true; } // Copy the ability function to local scope and execute it $this_ability_function = $this_ability->ability_function; $this_ability_function($this_battle, $this_field, $this_player, $this_robot, $target_player, $target_robot, $this_ability); // If this robot's image has been changed, reveert it back to what it was if ($temp_image_changed) { $this_robot->unset_image_overlay('copy_type1'); $this_robot->unset_image_overlay('copy_type2'); } // Update this ability's history with the triggered ability data and results $this_ability->add_history('ability_results', $this_ability->ability_results); // Update this ability's history with the triggered ability damage options $this_ability->add_history('ability_options', $this_ability->ability_options); // Reset the robot's stances to the base $this_robot->set_stance('base'); $target_robot->set_stance('base'); // -- CHECK ATTACHMENTS -- // // If this robot has any attachments, loop through them if ($this_robot->has_attachments()) { //$this->battle->events_create(false, false, 'DEBUG_'.__LINE__, 'checkpoint has attachments'); $attachment_key = 0; foreach ($this->robot_attachments as $attachment_token => $attachment_info) { // Ensure this ability has a type before checking weaknesses, resistances, etc. if (!empty($this_ability->ability_type)) { // If this attachment has weaknesses defined and this ability is a match if (!empty($attachment_info['attachment_weaknesses']) && (in_array($this_ability->ability_type, $attachment_info['attachment_weaknesses']) || in_array($this_ability->ability_type2, $attachment_info['attachment_weaknesses']))) { //$this->battle->events_create(false, false, 'DEBUG_'.__LINE__, 'checkpoint weaknesses'); // Remove this attachment and inflict damage on the robot unset($this->robot_attachments[$attachment_token]); $this->update_session(); if ($attachment_info['attachment_destroy'] !== false) { $temp_info = array('ability_id' => MMRPG_SETTINGS_BATTLEABILITIES_PERROBOT_MAX + $attachment_key + 100, 'ability_token' => $attachment_info['ability_token']); $temp_attachment = new rpg_ability($this->player, $this, $temp_info); $temp_trigger_type = !empty($attachment_info['attachment_destroy']['trigger']) ? $attachment_info['attachment_destroy']['trigger'] : 'damage'; //$this_battle->events_create(false, false, 'DEBUG', 'checkpoint has attachments '.$attachment_token.' trigger '.$temp_trigger_type.'!'); //$this_battle->events_create(false, false, 'DEBUG', 'checkpoint has attachments '.$attachment_token.' trigger '.$temp_trigger_type.' info:<br />'.preg_replace('/\s+/', ' ', htmlentities(print_r($attachment_info['attachment_destroy'], true), ENT_QUOTES, 'UTF-8', true))); if ($temp_trigger_type == 'damage') { $temp_attachment->damage_options_update($attachment_info['attachment_destroy']); $temp_attachment->recovery_options_update($attachment_info['attachment_destroy']); $temp_attachment->update_session(); $temp_damage_kind = $attachment_info['attachment_destroy']['kind']; if (isset($attachment_info['attachment_' . $temp_damage_kind])) { $temp_damage_amount = $attachment_info['attachment_' . $temp_damage_kind]; $temp_trigger_options = array('apply_modifiers' => false); $this->trigger_damage($target_robot, $temp_attachment, $temp_damage_amount, false, $temp_trigger_options); } } elseif ($temp_trigger_type == 'recovery') { $temp_attachment->recovery_options_update($attachment_info['attachment_destroy']); $temp_attachment->damage_options_update($attachment_info['attachment_destroy']); $temp_attachment->update_session(); $temp_recovery_kind = $attachment_info['attachment_destroy']['kind']; if (isset($attachment_info['attachment_' . $temp_recovery_kind])) { $temp_recovery_amount = $attachment_info['attachment_' . $temp_recovery_kind]; $temp_trigger_options = array('apply_modifiers' => false); $this->trigger_recovery($target_robot, $temp_attachment, $temp_recovery_amount, false, $temp_trigger_options); } } elseif ($temp_trigger_type == 'special') { $temp_attachment->target_options_update($attachment_info['attachment_destroy']); $temp_attachment->recovery_options_update($attachment_info['attachment_destroy']); $temp_attachment->damage_options_update($attachment_info['attachment_destroy']); $temp_attachment->update_session(); $this->trigger_target($target_robot, $temp_attachment, array('canvas_show_this_ability' => false, 'prevent_default_text' => true)); } } // If this robot was disabled, process experience for the target if ($this->robot_status == 'disabled') { break; } } } $attachment_key++; } } // Unset the ability active flag in the battle unset($this->battle->flags['robot_ability_in_progress']); // Update internal variables $target_robot->update_session(); $this_ability->update_session(); // Return the ability results return $this_ability->ability_results; }