Adds Script Hook to change stat boost changes
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2022-02-12 15:05:42 +01:00
parent 6da591dd92
commit 34f1e43269
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
3 changed files with 80 additions and 81 deletions

View File

@ -141,6 +141,7 @@ namespace CreatureLib::Battling {
}
bool Creature::ChangeStatBoost(Library::Statistic stat, int8_t diffAmount) {
HOOK(ModifyStatBoostChange, this, this, stat, &diffAmount);
bool changed = false;
auto oldValue = this->_statBoost.GetStat(stat);
if (diffAmount > 0) {
@ -148,11 +149,14 @@ namespace CreatureLib::Battling {
} else if (diffAmount < 0) {
changed = this->_statBoost.DecreaseStatBy(stat, -diffAmount);
}
if (changed) {
if (this->GetBattle().HasValue()) {
auto newValue = this->_statBoost.GetStat(stat);
this->GetBattle().GetValue()->TriggerEventListener<ChangeStatBoostEvent>(this, stat, oldValue, newValue);
this->GetBattle().GetValue()->TriggerEventListener<ChangeStatBoostEvent>(this, stat, oldValue,
newValue);
}
this->RecalculateBoostedStat(stat);
}
return changed;
}

View File

@ -5,6 +5,7 @@
#include <Arbutils/Memory/Memory.hpp>
#include <Arbutils/Misc.hpp>
#include "../../Library/EffectParameter.hpp"
#include "../../Library/Statistic.hpp"
#include "../Models/DamageSource.hpp"
namespace CreatureLib::Battling {
@ -40,82 +41,76 @@ namespace CreatureLib::Battling {
[[nodiscard]] virtual const ArbUt::StringView& GetName() const noexcept = 0;
virtual void
OnInitialize([[maybe_unused]] const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters){};
virtual void OnBeforeTurn([[maybe_unused]] const BaseTurnChoice* choice){};
#define _par_ [[maybe_unused]]
virtual void ChangePriority([[maybe_unused]] AttackTurnChoice* choice, [[maybe_unused]] int8_t* priority){};
virtual void ChangeAttack([[maybe_unused]] AttackTurnChoice* choice,
[[maybe_unused]] ArbUt::StringView* outAttack){};
virtual void ModifyNumberOfHits([[maybe_unused]] AttackTurnChoice* choice, [[maybe_unused]] u8* numberOfHits){};
virtual void PreventAttack([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] bool* outResult){};
virtual void FailAttack([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] bool* outFailed){};
virtual void StopBeforeAttack([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] bool* outResult){};
virtual void OnBeforeAttack([[maybe_unused]] ExecutingAttack* attack){};
virtual void OnInitialize(_par_ const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters){};
virtual void OnBeforeTurn(_par_ const BaseTurnChoice* choice){};
virtual void FailIncomingAttack([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target,
[[maybe_unused]] bool* outResult){};
virtual void IsInvulnerable([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target,
[[maybe_unused]] bool* outResult){};
virtual void OnAttackMiss([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target){};
virtual void ChangeAttackType([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target,
[[maybe_unused]] u8 hitNumber, [[maybe_unused]] u8* outType){};
virtual void ChangeEffectiveness([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target,
[[maybe_unused]] u8 hitNumber, [[maybe_unused]] float* effectiveness){};
virtual void BlockCritical([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target,
[[maybe_unused]] u8 hitNumber, [[maybe_unused]] bool* blockCritical){};
virtual void ChangePriority(_par_ AttackTurnChoice* choice, _par_ int8_t* priority){};
virtual void ChangeAttack(_par_ AttackTurnChoice* choice, _par_ ArbUt::StringView* outAttack){};
virtual void ModifyNumberOfHits(_par_ AttackTurnChoice* choice, _par_ u8* numberOfHits){};
virtual void PreventAttack(_par_ ExecutingAttack* attack, _par_ bool* outResult){};
virtual void FailAttack(_par_ ExecutingAttack* attack, _par_ bool* outFailed){};
virtual void StopBeforeAttack(_par_ ExecutingAttack* attack, _par_ bool* outResult){};
virtual void OnBeforeAttack(_par_ ExecutingAttack* attack){};
virtual void OverrideBasePower([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target,
[[maybe_unused]] u8 hitIndex, [[maybe_unused]] u8* basePower){};
virtual void ChangeDamageStatsUser([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target,
[[maybe_unused]] u8 hitIndex, [[maybe_unused]] Creature** statsUser){};
virtual void FailIncomingAttack(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ bool* outResult){};
virtual void IsInvulnerable(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ bool* outResult){};
virtual void OnAttackMiss(_par_ ExecutingAttack* attack, _par_ Creature* target){};
virtual void ChangeAttackType(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitNumber,
_par_ u8* outType){};
virtual void ChangeEffectiveness(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitNumber,
_par_ float* effectiveness){};
virtual void BlockCritical(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitNumber,
_par_ bool* blockCritical){};
virtual void BypassDefensiveStat([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target,
[[maybe_unused]] u8 hitIndex, [[maybe_unused]] bool* bypass){};
virtual void BypassOffensiveStat([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target,
[[maybe_unused]] u8 hitIndex, [[maybe_unused]] bool* bypass){};
virtual void ModifyStatModifier([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target,
[[maybe_unused]] u8 hitIndex, [[maybe_unused]] float* modifier){};
virtual void ModifyDamageModifier([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target,
[[maybe_unused]] u8 hitIndex, [[maybe_unused]] float* modifier){};
virtual void OverrideDamage([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target,
[[maybe_unused]] u8 hitIndex, [[maybe_unused]] u32* damage){};
virtual void OverrideIncomingDamage([[maybe_unused]] ExecutingAttack* attack, [[maybe_unused]] Creature* target,
[[maybe_unused]] u8 hitIndex, [[maybe_unused]] u32* damage){};
virtual void OverrideBasePower(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitIndex,
_par_ u8* basePower){};
virtual void ChangeDamageStatsUser(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitIndex,
_par_ Creature** statsUser){};
virtual void OnIncomingHit([[maybe_unused]] const ExecutingAttack* attack, [[maybe_unused]] Creature* target,
[[maybe_unused]] u8 hitNumber){};
virtual void OnFaintingOpponent([[maybe_unused]] const ExecutingAttack* attack,
[[maybe_unused]] Creature* target, [[maybe_unused]] u8 hitNumber){};
virtual void BypassDefensiveStat(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitIndex,
_par_ bool* bypass){};
virtual void BypassOffensiveStat(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitIndex,
_par_ bool* bypass){};
virtual void ModifyStatModifier(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitIndex,
_par_ float* modifier){};
virtual void ModifyDamageModifier(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitIndex,
_par_ float* modifier){};
virtual void OverrideDamage(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitIndex,
_par_ u32* damage){};
virtual void OverrideIncomingDamage(_par_ ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitIndex,
_par_ u32* damage){};
virtual void PreventSecondaryEffects([[maybe_unused]] const ExecutingAttack* attack,
[[maybe_unused]] Creature* target, [[maybe_unused]] u8 hitNumber,
[[maybe_unused]] bool* outResult){};
virtual void OnSecondaryEffect([[maybe_unused]] const ExecutingAttack* attack,
[[maybe_unused]] Creature* target, [[maybe_unused]] u8 hitNumber){};
virtual void OnIncomingHit(_par_ const ExecutingAttack* attack, _par_ Creature* target, _par_ u8 hitNumber){};
virtual void OnFaintingOpponent(_par_ const ExecutingAttack* attack, _par_ Creature* target,
_par_ u8 hitNumber){};
virtual void OnAfterHits([[maybe_unused]] const ExecutingAttack* attack, [[maybe_unused]] Creature* target){};
virtual void ModifyStatBoostChange(_par_ Creature* target, _par_ Library::Statistic stat,
_par_ int8_t* diffAmount){};
virtual void PreventSecondaryEffects(_par_ const ExecutingAttack* attack, _par_ Creature* target,
_par_ u8 hitNumber, _par_ bool* outResult){};
virtual void OnSecondaryEffect(_par_ const ExecutingAttack* attack, _par_ Creature* target,
_par_ u8 hitNumber){};
virtual void PreventSelfSwitch([[maybe_unused]] const SwitchTurnChoice* choice,
[[maybe_unused]] bool* outResult){};
virtual void PreventOpponentSwitch([[maybe_unused]] const SwitchTurnChoice* choice,
[[maybe_unused]] bool* outResult){};
virtual void OnAfterHits(_par_ const ExecutingAttack* attack, _par_ Creature* target){};
virtual void ModifyEffectChance([[maybe_unused]] const ExecutingAttack* attack,
[[maybe_unused]] Creature* target, [[maybe_unused]] float* chance){};
virtual void ModifyIncomingEffectChance([[maybe_unused]] const ExecutingAttack* attack,
[[maybe_unused]] Creature* target, [[maybe_unused]] float* chance){};
virtual void PreventSelfSwitch(_par_ const SwitchTurnChoice* choice, _par_ bool* outResult){};
virtual void PreventOpponentSwitch(_par_ const SwitchTurnChoice* choice, _par_ bool* outResult){};
virtual void OnFail([[maybe_unused]] Creature* target){};
virtual void OnOpponentFail([[maybe_unused]] Creature* target){};
virtual void ModifyEffectChance(_par_ const ExecutingAttack* attack, _par_ Creature* target,
_par_ float* chance){};
virtual void ModifyIncomingEffectChance(_par_ const ExecutingAttack* attack, _par_ Creature* target,
_par_ float* chance){};
virtual void PreventRunAway([[maybe_unused]] const FleeTurnChoice* choice, [[maybe_unused]] bool* result){};
virtual void PreventOpponentRunAway([[maybe_unused]] const FleeTurnChoice* choice,
[[maybe_unused]] bool* result){};
virtual void OnFail(_par_ Creature* target){};
virtual void OnOpponentFail(_par_ Creature* target){};
virtual void PreventRunAway(_par_ const FleeTurnChoice* choice, _par_ bool* result){};
virtual void PreventOpponentRunAway(_par_ const FleeTurnChoice* choice, _par_ bool* result){};
virtual void OnEndTurn(){};
virtual void OnDamage(Creature*, DamageSource, [[maybe_unused]] u32 oldHealth,
[[maybe_unused]] u32 newHealth){};
virtual void OnDamage(Creature*, DamageSource, _par_ u32 oldHealth, _par_ u32 newHealth){};
virtual void OnFaint(Creature*, DamageSource){};
virtual void OnSwitchIn(Creature*){};
};

View File

@ -74,24 +74,24 @@ namespace CreatureLib::Library {
inline bool IncreaseStatBy(Statistic stat, T amount) {
switch (stat) {
case CreatureLib::Library::Statistic::Health: ModifyStat(_health, +) break;
case CreatureLib::Library::Statistic::PhysicalAttack: ModifyStat(_physicalAttack, +) break;
case CreatureLib::Library::Statistic::PhysicalDefense: ModifyStat(_physicalDefense, +) break;
case CreatureLib::Library::Statistic::MagicalAttack: ModifyStat(_magicalAttack, +) break;
case CreatureLib::Library::Statistic::MagicalDefense: ModifyStat(_magicalDefense, +) break;
case CreatureLib::Library::Statistic::Speed: ModifyStat(_speed, +) break;
default: NOT_REACHABLE;
case CreatureLib::Library::Statistic::Health:
ModifyStat(_health, +) case CreatureLib::Library::Statistic::PhysicalAttack
: ModifyStat(_physicalAttack, +) case CreatureLib::Library::Statistic::PhysicalDefense
: ModifyStat(_physicalDefense, +) case CreatureLib::Library::Statistic::MagicalAttack
: ModifyStat(_magicalAttack, +) case CreatureLib::Library::Statistic::MagicalDefense
: ModifyStat(_magicalDefense, +) case CreatureLib::Library::Statistic::Speed
: ModifyStat(_speed, +) default : NOT_REACHABLE;
}
}
inline bool DecreaseStatBy(Statistic stat, T amount) {
switch (stat) {
case CreatureLib::Library::Statistic::Health: ModifyStat(_health, -) break;
case CreatureLib::Library::Statistic::PhysicalAttack: ModifyStat(_physicalAttack, -) break;
case CreatureLib::Library::Statistic::PhysicalDefense: ModifyStat(_physicalDefense, -) break;
case CreatureLib::Library::Statistic::MagicalAttack: ModifyStat(_magicalAttack, -) break;
case CreatureLib::Library::Statistic::MagicalDefense: ModifyStat(_magicalDefense, -) break;
case CreatureLib::Library::Statistic::Speed: ModifyStat(_speed, -) break;
default: NOT_REACHABLE;
case CreatureLib::Library::Statistic::Health:
ModifyStat(_health, -) case CreatureLib::Library::Statistic::PhysicalAttack
: ModifyStat(_physicalAttack, -) case CreatureLib::Library::Statistic::PhysicalDefense
: ModifyStat(_physicalDefense, -) case CreatureLib::Library::Statistic::MagicalAttack
: ModifyStat(_magicalAttack, -) case CreatureLib::Library::Statistic::MagicalDefense
: ModifyStat(_magicalDefense, -) case CreatureLib::Library::Statistic::Speed
: ModifyStat(_speed, -) default : NOT_REACHABLE;
}
}
};