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)
void MapZone::_RandomPosition(float& x, float& y) { // Select a random ZoneSection uint16 i = RandomBoundedInteger(0, _sections.size() - 1); // Select a random x and y position inside that section x = (float)RandomBoundedInteger(_sections[i].left_col, _sections[i].right_col); y = (float)RandomBoundedInteger(_sections[i].top_row, _sections[i].bottom_row); }
uint32_t RndMagicalDamage(BattleActor* attacker, BattleActor* target_actor, GLOBAL_ELEMENTAL element, uint32_t add_atk, float mul_atk, int32_t attack_point) { if(attacker == nullptr) { IF_PRINT_WARNING(BATTLE_DEBUG) << "function received nullptr attacker argument" << std::endl; return 0; } if(target_actor == nullptr) { IF_PRINT_WARNING(BATTLE_DEBUG) << "function received nullptr target_actor argument" << std::endl; return 0; } // Holds the total physical attack of the attacker and modifier int32_t total_mag_atk = attacker->GetTotalMagicalAttack(element) + add_atk; total_mag_atk = static_cast<int32_t>(static_cast<float>(total_mag_atk) * mul_atk); // Randomize the damage a bit. int32_t mag_atk_diff = total_mag_atk / 10; total_mag_atk = RandomBoundedInteger(total_mag_atk - mag_atk_diff, total_mag_atk + mag_atk_diff); if(total_mag_atk < 0) total_mag_atk = 0; // Holds the total physical defense of the target int32_t total_mag_def = 0; if(attack_point > -1) { GlobalAttackPoint* atk_point = target_actor->GetAttackPoint(attack_point); total_mag_def = atk_point ? atk_point->GetTotalMagicalDefense(element) : target_actor->GetAverageMagicalDefense(element); } else { total_mag_def = target_actor->GetAverageMagicalDefense(element); } // Holds the total damage dealt int32_t total_dmg = total_mag_atk - total_mag_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_t>(RandomBoundedInteger(1, 5 + attacker->GetMagAtk() / 10)); return static_cast<uint32_t>(total_dmg); }