bool CalculateStandardEvasionAdder(BattleTarget* target, float add_eva) { if (target == NULL) { IF_PRINT_WARNING(BATTLE_DEBUG) << "function received NULL target argument" << std::endl; return false; } if (IsTargetParty(target->GetType()) == true) { IF_PRINT_WARNING(BATTLE_DEBUG) << "target was a party type: " << target->GetType() << std::endl; return false; } float evasion = 0.0f; if (IsTargetPoint(target->GetType()) == true) { evasion = target->GetActor()->GetAttackPoint(target->GetPoint())->GetTotalEvadeRating(); } else if (IsTargetActor(target->GetType()) == true) { evasion = target->GetActor()->TotalEvadeRating(); } else { IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid target type: " << target->GetType() << std::endl; return false; } evasion += add_eva; // Check for absolute hit/miss conditions if (evasion <= 0.0f) return false; else if (evasion >= 100.0f) return true; if (RandomFloat(0.0f, 100.0f) <= evasion) return true; else return false; } // bool CalculateStandardEvasionAdder(BattleTarget* target, float add_evade)
uint32 CalculateMetaphysicalDamageAdder(BattleActor* attacker, BattleTarget* target, int32 add_atk, float std_dev) { if (attacker == NULL) { IF_PRINT_WARNING(BATTLE_DEBUG) << "function received NULL attacker argument" << std::endl; return 0; } if (target == NULL) { IF_PRINT_WARNING(BATTLE_DEBUG) << "function received NULL target argument" << std::endl; return 0; } if (IsTargetParty(target->GetType()) == true) { IF_PRINT_WARNING(BATTLE_DEBUG) << "target was a party type: " << target->GetType() << std::endl; return 0; } if (std_dev < 0.0f) { IF_PRINT_WARNING(BATTLE_DEBUG) << "function received negative standard deviation argument: " << std_dev << std::endl; std_dev = fabs(std_dev); } // Holds the total physical attack of the attacker and modifier int32 total_meta_atk = 0; total_meta_atk = attacker->GetTotalMetaphysicalAttack() + add_atk; if (total_meta_atk < 0) total_meta_atk = 0; // Holds the total physical defense of the target int32 total_meta_def = 0; if (IsTargetPoint(target->GetType()) == true) { total_meta_def = target->GetActor()->GetAttackPoint(target->GetPoint())->GetTotalMetaphysicalDefense(); } else if (IsTargetActor(target->GetType()) == true) { total_meta_def = target->GetActor()->TotalMetaphysicalDefense(); } else { IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid target type: " << target->GetType() << std::endl; return 0; } // Holds the total damage dealt int32 total_dmg = total_meta_atk - total_meta_def; if (total_dmg < 0) total_dmg = 0; // If the total damage is zero, fall back to causing a small non-zero damage value if (total_dmg <= 0) return static_cast<uint32>(RandomBoundedInteger(1, 5)); // Holds the absolute standard deviation used in the GaussianRandomValue function float abs_std_dev = 0.0f; abs_std_dev = static_cast<float>(total_dmg) * std_dev; total_dmg = GaussianRandomValue(total_dmg, abs_std_dev, false); // If the total damage came to a value less than or equal to zero after the gaussian randomization, // fall back to returning a small non-zero damage value if (total_dmg <= 0) return static_cast<uint32>(RandomBoundedInteger(1, 5)); return static_cast<uint32>(total_dmg); } // uint32 CalculateMetaphysicalDamageAdder(BattleActor* attacker, BattleTarget* target, int32 add_atk, float std_dev)
bool BattleTarget::SelectNextActor(bool direction) { if(!IsTargetPoint(_type) && !IsTargetActor(_type)) { IF_PRINT_WARNING(BATTLE_DEBUG) << "Invalid target type: " << _type << std::endl; return false; } // Check the target party for early exit conditions if(_party_target.empty()) { IF_PRINT_WARNING(BATTLE_DEBUG) << "Actor target's party was empty" << std::endl; return false; } if(_party_target.size() == 1) { return false; // No more actors to select from in the party } // The target died in between events. Let's reset it. if(!_actor_target) { _actor_target = _party_target.at(0); } // Determine the index of the current actor in the target party uint32_t original_target_index = 0xFFFFFFFF; // Initially set to an impossibly high index for error checking for(uint32_t i = 0; i < _party_target.size(); ++i) { if(_party_target.at(i) == _actor_target) { original_target_index = i; break; } } if(original_target_index == 0xFFFFFFFF) { IF_PRINT_WARNING(BATTLE_DEBUG) << "actor target was not found in party" << std::endl; return false; } // Starting from the index of the original actor, select the next available actor BattleActor* original_actor = _actor_target; uint32_t new_target_index = original_target_index; while(true) { // Increment or decrement the target index based on the direction argument if(direction == true) { new_target_index = (new_target_index >= _party_target.size() - 1) ? 0 : new_target_index + 1; } else { new_target_index = (new_target_index == 0) ? _party_target.size() - 1 : new_target_index - 1; } // If we've reached the original target index then we were unable to select another actor target if(new_target_index == original_target_index) { _actor_target = original_actor; return false; } // Set the new actor target and if required, ascertain the new target's validity. If the new target // must be valid and this new actor is not, the loop will continue and will try again with the next actor _actor_target = _party_target.at(new_target_index); if (IsValid()) return true; } }
bool BattleTarget::SetActorTarget(GLOBAL_TARGET type, BattleActor* actor) { if (!IsTargetActor(type)) { IF_PRINT_WARNING(BATTLE_DEBUG) << "function received invalid type argument: " << type << std::endl; return false; } if (!actor) { IF_PRINT_WARNING(BATTLE_DEBUG) << "function received NULL argument" << std::endl; return false; } _type = type; _point = 0; _actor = actor; _party = NULL; return true; }
bool CalculateStandardEvasionMultiplier(BattleTarget* target, float mul_eva) { if (target == NULL) { IF_PRINT_WARNING(BATTLE_DEBUG) << "function received NULL target argument" << std::endl; return false; } if (IsTargetParty(target->GetType()) == true) { IF_PRINT_WARNING(BATTLE_DEBUG) << "target was a party type: " << target->GetType() << std::endl; return false; } if (mul_eva < 0.0f) { IF_PRINT_WARNING(BATTLE_DEBUG) << "function received negative multiplier argument: " << mul_eva << std::endl; mul_eva = fabs(mul_eva); } // Find the base evasion and apply the multiplier float evasion = 0.0f; if (IsTargetPoint(target->GetType()) == true) { evasion = target->GetActor()->GetAttackPoint(target->GetPoint())->GetTotalEvadeRating(); } else if (IsTargetActor(target->GetType()) == true) { evasion = target->GetActor()->TotalEvadeRating(); } else { IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid target type: " << target->GetType() << std::endl; return false; } evasion = evasion * mul_eva; // Check for absolute hit/miss conditions if (evasion <= 0.0f) return false; else if (evasion >= 100.0f) return true; if (RandomFloat(0.0f, 100.0f) > evasion) return false; else return true; } // bool CalculateStandardEvasionMultiplier(BattleTarget* target, float mul_evade)
bool BattleTarget::IsValid(bool permit_dead_targets) { // No dead enemies can be selected here. if (IsTargetPoint(_type)) { if (!_actor) return false; bool enemy_actor = _actor->IsEnemy(); if (_point >= _actor->GetAttackPoints().size()) return false; // We extra check the actor HP since the state might desynced on purpose. else if (!_actor->IsAlive() || _actor->GetHitPoints() == 0) return !enemy_actor && permit_dead_targets; else if (_actor->GetState() == ACTOR_STATE_DYING) return !enemy_actor && permit_dead_targets; else return true; } else if (IsTargetActor(_type) == true) { if (!_actor) return false; bool enemy_actor = _actor->IsEnemy(); if (!_actor->IsAlive() || _actor->GetHitPoints() == 0) return !enemy_actor && permit_dead_targets; else if (_actor->GetState() == ACTOR_STATE_DYING) return !enemy_actor && permit_dead_targets; else return true; } else if (IsTargetParty(_type)) { if (!_party) return false; else return true; } else { IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid target type: " << _type << std::endl; return false; } }
bool BattleTarget::SelectNextActor(BattleActor* user, bool direction, bool valid_criteria, bool permit_dead_targets) { if (!user) { IF_PRINT_WARNING(BATTLE_DEBUG) << "function received NULL argument" << std::endl; return false; } if ((!IsTargetPoint(_type)) && (!IsTargetActor(_type))) { IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid target type: " << _type << std::endl; return false; } if (!_actor) { IF_PRINT_WARNING(BATTLE_DEBUG) << "no valid actor target" << std::endl; return false; } // ----- (1): Retrieve the proper party container that contains the actors we would like to select from std::deque<BattleActor*>* target_party = NULL; if ((_type == GLOBAL_TARGET_SELF_POINT) || (_type == GLOBAL_TARGET_SELF)) { return false; // Self type targets do not have multiple actors to select from } else if ((_type == GLOBAL_TARGET_ALLY_POINT) || (_type == GLOBAL_TARGET_ALLY) || (_type == GLOBAL_TARGET_ALLY_EVEN_DEAD)) { if (user->IsEnemy() == false) target_party = &BattleMode::CurrentInstance()->GetCharacterParty(); else target_party = &BattleMode::CurrentInstance()->GetEnemyParty(); } else if ((_type == GLOBAL_TARGET_FOE_POINT) || (_type == GLOBAL_TARGET_FOE)) { if (user->IsEnemy() == false) target_party = &BattleMode::CurrentInstance()->GetEnemyParty(); else target_party = &BattleMode::CurrentInstance()->GetCharacterParty(); } else { // This should never be reached because the target type was already determined to be a point or actor above IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid target type: " << _type << std::endl; return false; } // ----- (2): Check the target party for early exit conditions if (target_party->empty() == true) { IF_PRINT_WARNING(BATTLE_DEBUG) << "actor target's party was empty" << std::endl; return false; } if (target_party->size() == 1) { return false; // No more actors to select from in the party } // ----- (3): Determine the index of the current actor in the target party uint32 original_target_index = 0xFFFFFFFF; // Initially set to an impossibly high index for error checking for (uint32 i = 0; i < target_party->size(); i++) { if (target_party->at(i) == _actor) { original_target_index = i; break; } } if (original_target_index == 0xFFFFFFFF) { IF_PRINT_WARNING(BATTLE_DEBUG) << "actor target was not found in party" << std::endl; return false; } // ----- (4): Starting from the index of the original actor, select the next available actor BattleActor* original_actor = _actor; uint32 new_target_index = original_target_index; while (true) { // Increment or decrement the target index based on the direction argument if (direction == true) { new_target_index = (new_target_index >= target_party->size() - 1) ? 0 : new_target_index + 1; } else { new_target_index = (new_target_index == 0) ? target_party->size() - 1 : new_target_index - 1; } // If we've reached the original target index then we were unable to select another actor target if (new_target_index == original_target_index) { _actor = original_actor; return false; } // Set the new actor target and if required, ascertain the new target's validity. If the new target // must be valid and this new actor is not, the loop will continue and will try again with the next actor _actor = target_party->at(new_target_index); if (valid_criteria == false) { return true; } else if (IsValid(permit_dead_targets)){ return true; } } } // bool BattleTarget::SelectNextActor(BattleActor* user, bool direction, bool valid_criteria)