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 "DamageLibrary.hpp"
|
||||||
#include <CreatureLib/Battling/Models/Battle.hpp>
|
|
||||||
#include "../PkmnScriptHook.hpp"
|
#include "../PkmnScriptHook.hpp"
|
||||||
#include "../Pokemon/Pokemon.hpp"
|
|
||||||
|
|
||||||
using HitData = const CreatureLib::Battling::ExecutingAttack::HitData;
|
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); }
|
inline constexpr float fl(float a) { return std::floor(a); }
|
||||||
|
|
||||||
uint32_t PkmnLib::Battling::DamageLibrary::GetDamage(CreatureLib::Battling::ExecutingAttack* attack,
|
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 levelMod = fl((2 * attack->GetUser()->GetLevel()) / 5.0f) + 2;
|
||||||
auto bp = hitData.GetBasePower();
|
auto bp = hitData.GetBasePower();
|
||||||
auto statMod = GetStatModifier(attack, target, hitIndex, hitData);
|
auto statMod = GetStatModifier(attack, target, hitIndex, hitData);
|
||||||
|
PKMN_HOOK(ModifyStatModifier, attack, attack, target, hitIndex, &statMod);
|
||||||
auto damageMod = GetDamageModifier(attack, target, hitIndex, hitData);
|
auto damageMod = GetDamageModifier(attack, target, hitIndex, hitData);
|
||||||
// HOOK: Modify stat modifier
|
|
||||||
|
|
||||||
auto floatDamage = fl(levelMod * bp);
|
auto floatDamage = fl(levelMod * bp);
|
||||||
floatDamage = fl(floatDamage * statMod);
|
floatDamage = fl(floatDamage * statMod);
|
||||||
|
@ -70,10 +67,10 @@ uint8_t PkmnLib::Battling::DamageLibrary::GetBasePower(CreatureLib::Battling::Ex
|
||||||
return bp;
|
return bp;
|
||||||
}
|
}
|
||||||
float PkmnLib::Battling::DamageLibrary::GetStatModifier(CreatureLib::Battling::ExecutingAttack* attack,
|
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 {
|
const HitData& hitData) const {
|
||||||
auto user = attack->GetUser();
|
auto* user = attack->GetUser().GetRaw();
|
||||||
// HOOK: allow overriding for which users stat we use.
|
PKMN_HOOK(ChangeDamageStatsUser, attack, attack, target, hit, &user);
|
||||||
CreatureLib::Library::Statistic offensiveStat;
|
CreatureLib::Library::Statistic offensiveStat;
|
||||||
CreatureLib::Library::Statistic defensiveStat;
|
CreatureLib::Library::Statistic defensiveStat;
|
||||||
auto moveData = attack->GetUseAttack().ForceAs<const Library::MoveData>();
|
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;
|
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;
|
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 offensiveValue =
|
||||||
float defensiveValue;
|
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;
|
return offensiveValue / defensiveValue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,11 @@ namespace PkmnLib::Battling {
|
||||||
virtual void DoesShareExperience(CreatureLib::Battling::Creature* faintedMon,
|
virtual void DoesShareExperience(CreatureLib::Battling::Creature* faintedMon,
|
||||||
CreatureLib::Battling::Creature* winningMon, bool* shareExperience){};
|
CreatureLib::Battling::Creature* winningMon, bool* shareExperience){};
|
||||||
virtual void BlockWeather(CreatureLib::Battling::Battle* battle, bool* blockWeather){};
|
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);
|
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;
|
bool* shareExperience) override;
|
||||||
|
|
||||||
void BlockWeather(CreatureLib::Battling::Battle* battle, bool* blockWeather) 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
|
#undef CALL_HOOK
|
||||||
|
|
|
@ -182,6 +182,13 @@ public:
|
||||||
SCRIPT_HOOK_FUNCTION(OnFaint, "void OnFaint(Pokemon@ pokemon, DamageSource damageSource)");
|
SCRIPT_HOOK_FUNCTION(OnFaint, "void OnFaint(Pokemon@ pokemon, DamageSource damageSource)");
|
||||||
SCRIPT_HOOK_FUNCTION(BlockWeather, "void BlockWeather(Battle@ battle, bool& result)");
|
SCRIPT_HOOK_FUNCTION(BlockWeather, "void BlockWeather(Battle@ battle, bool& result)");
|
||||||
SCRIPT_HOOK_FUNCTION(OnSwitchIn, "void OnSwitchIn(Pokemon@ pokemon)");
|
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
|
#undef SCRIPT_HOOK_FUNCTION
|
||||||
|
|
|
@ -69,6 +69,9 @@ shared abstract class PkmnScript {
|
||||||
void DoesShareExperience(Pokemon@ faintedMon, Pokemon@ winningMon, bool& shareExperience){};
|
void DoesShareExperience(Pokemon@ faintedMon, Pokemon@ winningMon, bool& shareExperience){};
|
||||||
void BlockWeather(Battle@ battle, bool& blockWeather){};
|
void BlockWeather(Battle@ battle, bool& blockWeather){};
|
||||||
void OnSwitchIn(Pokemon@ pokemon){};
|
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);
|
Ensure(r >= 0);
|
||||||
|
|
Loading…
Reference in New Issue