Esempio n. 1
0
 /**
  * Apply startup stat bonuses to this robot object, usually at the start of the battle
  * @return bool
  */
 public function apply_stat_bonuses()
 {
     // Pull in the global index
     global $mmrpg_index;
     // Collect references to global objects
     $this_battle = rpg_battle::get_battle();
     $this_field = rpg_field::get_field();
     $this_player = $this->player;
     $this_player_token = $this_player->get_token();
     $this_robot = $this;
     $this_robot_token = $this_robot->get_token();
     // Only continue if this hasn't been done already
     if ($this_robot->has_flag('apply_stat_bonuses')) {
         return false;
     }
     // -- COLLECT BASE VALUES -- //
     // If this is robot's player is human controlled
     if (!$this_player->is_autopilot() && !$this_robot->is_class('mecha')) {
         // Collect this robot's rewards and settings
         $this_settings = rpg_game::robot_settings($this_player_token, $this_robot_token);
         $this_rewards = rpg_game::robot_rewards($this_player_token, $this_robot_token);
         // Update this robot's original player with any session settings
         $original_player = rpg_game::robot_original_player($this_player_token, $this_robot_token);
         $this_robot->set_original_player($original_player);
         // Update this robot's experience with any session rewards
         $this_experience = rpg_game::robot_experience($this_player_token, $this_robot_token);
         $this_robot->set_experience($this_experience);
         $this_robot->set_base_experience($this_experience);
         // Update this robot's level with any session rewards
         $this_level = rpg_game::robot_level($this_player_token, $this_robot_token);
         $this_robot->set_level($this_level);
         $this_robot->set_base_level($this_level);
     } else {
         // Create an empty settings and reward array to prevent errors
         $this_settings = !empty($this->values['robot_settings']) ? $this->values['robot_settings'] : array();
         $this_rewards = !empty($this->values['robot_rewards']) ? $this->values['robot_rewards'] : array();
         // Collect this robot's other current values into variables
         $original_player = $this_robot->get_original_player();
         $this_experience = $this_robot->get_experience();
         $this_level = $this_robot->get_level();
     }
     // Calculate required experience for this robot
     $required_experience = rpg_prototype::calculate_experience_required($this_level);
     // If this is a player battle, automatically set all robot levels to the same value
     $player_battle_level = $this_battle->get_value('player_battle_level');
     if (!empty($player_battle_level)) {
         $this_experience = $required_experience;
         $this_level = $player_battle_level;
     }
     // If the robot experience is over the required points, level up and reset
     if ($this_experience > $required_experience) {
         $level_boost = floor($this_experience / $required_experience);
         $this_experience -= $level_boost * $required_experience;
         $this_level += $level_boost;
     }
     // Fix the level if it's over 100
     if ($this_level > 100) {
         $this_level = 100;
     }
     // Update this robot's experience and level any changes
     $this_robot->set_experience($this_experience);
     $this_robot->set_base_experience($this_experience);
     $this_robot->set_level($this_level);
     $this_robot->set_base_level($this_level);
     // Collect this robot's stats for manipulation
     $this_base_energy = $this_energy = $this_robot->get_energy();
     $this_base_weapons = $this_weapons = $this_robot->get_weapons();
     $this_base_attack = $this_attack = $this_robot->get_attack();
     $this_base_defense = $this_defense = $this_robot->get_defense();
     $this_base_speed = $this_speed = $this_robot->get_speed();
     // Collect this player's stat rewards if any so we can apply
     $this_player_energy = $this_player->get_energy();
     $this_player_weapons = $this_player->get_weapons();
     $this_player_attack = $this_player->get_attack();
     $this_player_defense = $this_player->get_defense();
     $this_player_speed = $this_player->get_speed();
     // Collect the maximum values for each of these stats for later
     $this_max_energy = MMRPG_SETTINGS_STATS_GET_ROBOTMAX($this_base_energy, $this_level);
     $this_max_attack = MMRPG_SETTINGS_STATS_GET_ROBOTMAX($this_base_attack, $this_level);
     $this_max_defense = MMRPG_SETTINGS_STATS_GET_ROBOTMAX($this_base_defense, $this_level);
     $this_max_speed = MMRPG_SETTINGS_STATS_GET_ROBOTMAX($this_base_speed, $this_level);
     // -- LEVEL UP REWARDS -- //
     // If the robot's level is greater than one, increase stats
     if ($this_level > 1) {
         // If this robot's level is at the max value or greater, set a flag for later
         if ($this_level >= 100) {
             $this_robot->set_flag('robot_stat_max_level', true);
         }
         // Update the robot stats with a small boost based on experience level
         $this_energy += MMRPG_SETTINGS_STATS_GET_LEVELBOOST($this_base_energy, $this_level);
         $this_attack += MMRPG_SETTINGS_STATS_GET_LEVELBOOST($this_base_attack, $this_level);
         $this_defense += MMRPG_SETTINGS_STATS_GET_LEVELBOOST($this_base_defense, $this_level);
         $this_speed += MMRPG_SETTINGS_STATS_GET_LEVELBOOST($this_base_speed, $this_level);
     }
     // -- BONUS STAT REWARDS -- //
     // Increase this robot's stats by any reward values
     if (!empty($this_rewards['robot_energy'])) {
         $this_energy += $this_rewards['robot_energy'];
     }
     if (!empty($this_rewards['robot_attack'])) {
         $this_attack += $this_rewards['robot_attack'];
     }
     if (!empty($this_rewards['robot_defense'])) {
         $this_defense += $this_rewards['robot_defense'];
     }
     if (!empty($this_rewards['robot_speed'])) {
         $this_speed += $this_rewards['robot_speed'];
     }
     // -- BASE STAT OVERFLOW -- //
     // If this robot's energy rating is at the max value or greater, set a flag for later
     if ($this_energy > $this_max_energy) {
         $this_robot->set_flag('robot_stat_max_energy', true);
         $max_stat_overflow += $this_energy - $this_max_energy;
         $this_energy = $this_max_energy;
     }
     // If this robot's attack rating is at the max value or greater, set a flag for later
     if ($this_attack > $this_max_attack) {
         $this_robot->set_flag('robot_stat_max_attack', true);
         $max_stat_overflow += $this_attack - $this_max_attack;
         $this_attack = $this_max_attack;
     }
     // If this robot's defense rating is at the max value or greater, set a flag for later
     if ($this_defense > $this_max_defense) {
         $this_robot->set_flag('robot_stat_max_defense', true);
         $max_stat_overflow += $this_defense - $this_max_defense;
         $this_defense = $this_max_defense;
     }
     // If this robot's speed rating is at the max value or greater, set a flag for later
     if ($this_speed > $this_max_speed) {
         $this_robot->set_flag('robot_stat_max_speed', true);
         $max_stat_overflow += $this_speed - $this_max_speed;
         $this_speed = $this_max_speed;
     }
     // -- PLAYER STAT REWARDS -- //
     // If this player has bonuses, apply them on top of the robot stats
     if (!empty($this_player_energy)) {
         $this_energy += ceil($this_energy * ($this_player_energy / 100));
     }
     if (!empty($this_player_attack)) {
         $this_attack += ceil($this_attack * ($this_player_attack / 100));
     }
     if (!empty($this_player_defense)) {
         $this_defense += ceil($this_defense * ($this_player_defense / 100));
     }
     if (!empty($this_player_speed)) {
         $this_speed += ceil($this_speed * ($this_player_speed / 100));
     }
     // -- ROBOT ITEM REWARDS -- //
     // If this robot is holder a relavant item, apply stat upgrades
     $this_robot_item = $this_robot->get_item();
     switch ($this_robot_item) {
         // If this robot is holding an Energy Upgrade, double the life energy stat
         case 'energy-upgrade':
             $this_energy = $this_energy * 2;
             break;
             // Else if this robot is holding a Weapon Upgrade, double the life energy stat
         // Else if this robot is holding a Weapon Upgrade, double the life energy stat
         case 'weapon-upgrade':
             $this_weapons = $this_weapons * 2;
             break;
     }
     // -- FINAL STAT LIMITS -- //
     // Limit all stats to maximums for display purposes
     if ($this_energy > MMRPG_SETTINGS_STATS_MAX) {
         $this_energy = MMRPG_SETTINGS_STATS_MAX;
     }
     if ($this_attack > MMRPG_SETTINGS_STATS_MAX) {
         $this_attack = MMRPG_SETTINGS_STATS_MAX;
     }
     if ($this_defense > MMRPG_SETTINGS_STATS_MAX) {
         $this_defense = MMRPG_SETTINGS_STATS_MAX;
     }
     if ($this_speed > MMRPG_SETTINGS_STATS_MAX) {
         $this_speed = MMRPG_SETTINGS_STATS_MAX;
     }
     // -- UPDATE ROBOT OBJECT -- //
     // Update this robot's stats with any changes
     $this_robot->set_energy($this_energy);
     $this_robot->set_base_energy($this_energy);
     $this_robot->set_attack($this_attack);
     $this_robot->set_base_attack($this_attack);
     $this_robot->set_defense($this_defense);
     $this_robot->set_base_defense($this_defense);
     $this_robot->set_speed($this_speed);
     $this_robot->set_base_speed($this_speed);
     // Create the stat boost flag
     $this_robot->set_flag('apply_stat_bonuses', true);
     // Return true on success
     return true;
 }
Esempio n. 2
0
function MMRPG_SETTINGS_STATS_GET_ROBOTMAX($base, $level)
{
    $temp_base = $base;
    $level_boost = MMRPG_SETTINGS_STATS_GET_LEVELBOOST($base, $level);
    $robot_boost = MMRPG_SETTINGS_STATS_ROBOTMAX;
    return round(($temp_base + $level_boost) * $robot_boost);
}