Adds a bunch of script hooks to the damage library calculations
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
d1efde4328
commit
48da191dfb
|
@ -1,11 +1,8 @@
|
|||
#include "DamageLibrary.hpp"
|
||||
#include <CreatureLib/Battling/Models/Battle.hpp>
|
||||
#include "../PkmnScriptHook.hpp"
|
||||
#include "../Pokemon/Pokemon.hpp"
|
||||
|
||||
using HitData = const CreatureLib::Battling::ExecutingAttack::HitData;
|
||||
|
||||
inline constexpr float to_f(i32 a) { return static_cast<float>(a); }
|
||||
inline constexpr float fl(float a) { return std::floor(a); }
|
||||
|
||||
uint32_t PkmnLib::Battling::DamageLibrary::GetDamage(CreatureLib::Battling::ExecutingAttack* attack,
|
||||
|
@ -14,8 +11,8 @@ uint32_t PkmnLib::Battling::DamageLibrary::GetDamage(CreatureLib::Battling::Exec
|
|||
auto levelMod = fl((2 * attack->GetUser()->GetLevel()) / 5.0f) + 2;
|
||||
auto bp = hitData.GetBasePower();
|
||||
auto statMod = GetStatModifier(attack, target, hitIndex, hitData);
|
||||
PKMN_HOOK(ModifyStatModifier, attack, attack, target, hitIndex, &statMod);
|
||||
auto damageMod = GetDamageModifier(attack, target, hitIndex, hitData);
|
||||
// HOOK: Modify stat modifier
|
||||
|
||||
auto floatDamage = fl(levelMod * bp);
|
||||
floatDamage = fl(floatDamage * statMod);
|
||||
|
@ -70,10 +67,10 @@ uint8_t PkmnLib::Battling::DamageLibrary::GetBasePower(CreatureLib::Battling::Ex
|
|||
return bp;
|
||||
}
|
||||
float PkmnLib::Battling::DamageLibrary::GetStatModifier(CreatureLib::Battling::ExecutingAttack* attack,
|
||||
CreatureLib::Battling::Creature* target, uint8_t,
|
||||
CreatureLib::Battling::Creature* target, uint8_t hit,
|
||||
const HitData& hitData) const {
|
||||
auto user = attack->GetUser();
|
||||
// HOOK: allow overriding for which users stat we use.
|
||||
auto* user = attack->GetUser().GetRaw();
|
||||
PKMN_HOOK(ChangeDamageStatsUser, attack, attack, target, hit, &user);
|
||||
CreatureLib::Library::Statistic offensiveStat;
|
||||
CreatureLib::Library::Statistic defensiveStat;
|
||||
auto moveData = attack->GetUseAttack().ForceAs<const Library::MoveData>();
|
||||
|
@ -86,23 +83,18 @@ float PkmnLib::Battling::DamageLibrary::GetStatModifier(CreatureLib::Battling::E
|
|||
}
|
||||
|
||||
auto bypassDefensive = hitData.IsCritical() && target->GetStatBoost(defensiveStat) > 0;
|
||||
// HOOK: allow bypassing defensive stat modifiers.
|
||||
PKMN_HOOK(BypassDefensiveStat, attack, attack, target, hit, &bypassDefensive);
|
||||
auto bypassOffensive = hitData.IsCritical() && user->GetStatBoost(offensiveStat) < 0;
|
||||
// HOOK: Allow bypassing offensive stat modifiers.
|
||||
PKMN_HOOK(BypassOffensiveStat, attack, attack, target, hit, &bypassOffensive);
|
||||
|
||||
float offensiveValue;
|
||||
float defensiveValue;
|
||||
float offensiveValue =
|
||||
bypassOffensive ? (float)user->GetFlatStat(offensiveStat) : (float)user->GetBoostedStat(offensiveStat);
|
||||
float defensiveValue =
|
||||
bypassDefensive ? (float)target->GetFlatStat(defensiveStat) : (float)target->GetBoostedStat(defensiveStat);
|
||||
|
||||
PKMN_HOOK(ModifyOffensiveStatValue, attack, attack, target, hit, &offensiveValue);
|
||||
PKMN_HOOK(ModifyDefensiveStatValue, attack, attack, target, hit, &defensiveValue);
|
||||
|
||||
if (bypassOffensive) {
|
||||
offensiveValue = user->GetFlatStat(offensiveStat);
|
||||
} else {
|
||||
offensiveValue = user->GetBoostedStat(offensiveStat);
|
||||
}
|
||||
if (bypassDefensive) {
|
||||
defensiveValue = target->GetFlatStat(defensiveStat);
|
||||
} else {
|
||||
defensiveValue = target->GetBoostedStat(defensiveStat);
|
||||
}
|
||||
|
||||
return offensiveValue / defensiveValue;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace PkmnLib::Battling {
|
|||
PkmnScript(const ArbUt::OptionalBorrowedPtr<void>& owner) : CreatureLib::Battling::BattleScript(owner) {}
|
||||
|
||||
virtual void PreventIncomingCritical(CreatureLib::Battling::ExecutingAttack* attack,
|
||||
CreatureLib::Battling::Creature* target, uint8_t hit, bool* preventCrit){};
|
||||
CreatureLib::Battling::Creature* target, uint8_t hit, bool* preventCrit){};
|
||||
virtual void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack,
|
||||
CreatureLib::Battling::Creature* target, uint8_t hit, uint8_t* critStage){};
|
||||
virtual void OverrideCriticalModifier(CreatureLib::Battling::ExecutingAttack* attack,
|
||||
|
@ -31,6 +31,11 @@ namespace PkmnLib::Battling {
|
|||
virtual void DoesShareExperience(CreatureLib::Battling::Creature* faintedMon,
|
||||
CreatureLib::Battling::Creature* winningMon, bool* shareExperience){};
|
||||
virtual void BlockWeather(CreatureLib::Battling::Battle* battle, bool* blockWeather){};
|
||||
|
||||
virtual void ModifyOffensiveStatValue(CreatureLib::Battling::ExecutingAttack* attack,
|
||||
CreatureLib::Battling::Creature* target, u8 hitIndex, float* modifier){};
|
||||
virtual void ModifyDefensiveStatValue(CreatureLib::Battling::ExecutingAttack* attack,
|
||||
CreatureLib::Battling::Creature* target, u8 hitIndex, float* modifier){};
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -411,3 +411,24 @@ void AngelScriptScript::OnFaintingOpponent(const CreatureLib::Battling::Executin
|
|||
ctx->SetArgByte(2, hitNumber);
|
||||
})
|
||||
}
|
||||
void AngelScriptScript::ModifyOffensiveStatValue(CreatureLib::Battling::ExecutingAttack* attack,
|
||||
CreatureLib::Battling::Creature* target, u8 hitIndex,
|
||||
float* modifier) {
|
||||
CALL_HOOK(ModifyOffensiveStatValue, {
|
||||
ctx->SetArgObject(0, (void*)attack);
|
||||
ctx->SetArgObject(1, (void*)target);
|
||||
ctx->SetArgByte(2, hitIndex);
|
||||
ctx->SetArgAddress(3, modifier);
|
||||
})
|
||||
|
||||
}
|
||||
void AngelScriptScript::ModifyDefensiveStatValue(CreatureLib::Battling::ExecutingAttack* attack,
|
||||
CreatureLib::Battling::Creature* target, u8 hitIndex,
|
||||
float* modifier) {
|
||||
CALL_HOOK(ModifyDefensiveStatValue, {
|
||||
ctx->SetArgObject(0, (void*)attack);
|
||||
ctx->SetArgObject(1, (void*)target);
|
||||
ctx->SetArgByte(2, hitIndex);
|
||||
ctx->SetArgAddress(3, modifier);
|
||||
})
|
||||
}
|
||||
|
|
|
@ -152,6 +152,11 @@ public:
|
|||
bool* shareExperience) override;
|
||||
|
||||
void BlockWeather(CreatureLib::Battling::Battle* battle, bool* blockWeather) override;
|
||||
|
||||
void ModifyOffensiveStatValue(CreatureLib::Battling::ExecutingAttack* attack,
|
||||
CreatureLib::Battling::Creature* target, u8 hitIndex, float* modifier) override;
|
||||
void ModifyDefensiveStatValue(CreatureLib::Battling::ExecutingAttack* attack,
|
||||
CreatureLib::Battling::Creature* target, u8 hitIndex, float* modifier) override;
|
||||
};
|
||||
|
||||
#undef CALL_HOOK
|
||||
|
|
|
@ -182,6 +182,13 @@ public:
|
|||
SCRIPT_HOOK_FUNCTION(OnFaint, "void OnFaint(Pokemon@ pokemon, DamageSource damageSource)");
|
||||
SCRIPT_HOOK_FUNCTION(BlockWeather, "void BlockWeather(Battle@ battle, bool& result)");
|
||||
SCRIPT_HOOK_FUNCTION(OnSwitchIn, "void OnSwitchIn(Pokemon@ pokemon)");
|
||||
|
||||
SCRIPT_HOOK_FUNCTION(
|
||||
ModifyOffensiveStatValue,
|
||||
"void ModifyOffensiveStatValue(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& offensiveStatValue)");
|
||||
SCRIPT_HOOK_FUNCTION(
|
||||
ModifyDefensiveStatValue,
|
||||
"void ModifyDefensiveStatValue(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& defensiveStatValue)");
|
||||
};
|
||||
|
||||
#undef SCRIPT_HOOK_FUNCTION
|
||||
|
|
|
@ -69,6 +69,9 @@ shared abstract class PkmnScript {
|
|||
void DoesShareExperience(Pokemon@ faintedMon, Pokemon@ winningMon, bool& shareExperience){};
|
||||
void BlockWeather(Battle@ battle, bool& blockWeather){};
|
||||
void OnSwitchIn(Pokemon@ pokemon){};
|
||||
|
||||
void ModifyOffensiveStatValue(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& offensiveStatValue){};
|
||||
void ModifyDefensiveStatValue(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& defensiveStatValue){};
|
||||
}
|
||||
)");
|
||||
Ensure(r >= 0);
|
||||
|
|
Loading…
Reference in New Issue