Adds script hook to change choice speed when determining turn order
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2022-02-19 16:11:25 +01:00
parent c078d91b0d
commit 5fce541ffb
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
3 changed files with 11 additions and 6 deletions

View File

@ -22,12 +22,8 @@ public:
if (aPriority != bPriority)
return aPriority > bPriority;
}
auto aUser = a->GetUser();
auto bUser = b->GetUser();
auto aSpeed = aUser->GetBoostedStat(Library::Statistic::Speed);
auto bSpeed = bUser->GetBoostedStat(Library::Statistic::Speed);
if (aSpeed != bSpeed)
return aSpeed > bSpeed;
if (a->__GetSpeed() != b->__GetSpeed())
return a->__GetSpeed() > b->__GetSpeed();
return a->__GetRandomValue() > b->__GetRandomValue();
}
@ -43,6 +39,10 @@ void TurnOrdering::OrderChoices(std::vector<std::shared_ptr<BaseTurnChoice>>& ve
HOOK(ChangePriority, attackChoice, attackChoice.get(), &priority);
attackChoice->SetPriority(priority);
}
auto speed = item->GetUser()->GetBoostedStat(Library::Statistic::Speed);
HOOK(ChangeSpeed, item, item.get(), &speed);
item->__SetSpeed(speed);
}
std::sort(vec.begin(), vec.end(), ChoiceCompare());
}

View File

@ -49,6 +49,7 @@ namespace CreatureLib::Battling {
_par_ const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters){};
virtual void OnBeforeTurn(_par_ const BaseTurnChoice* choice){};
virtual void ChangeSpeed(_par_ BaseTurnChoice* choice, _par_ uint32_t* speed){};
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){};

View File

@ -9,6 +9,7 @@ namespace CreatureLib::Battling {
class BaseTurnChoice : public ScriptSource {
int32_t _randomValue;
uint32_t _speed;
protected:
ArbUt::BorrowedPtr<Creature> _user;
@ -21,6 +22,9 @@ namespace CreatureLib::Battling {
inline void __SetRandomValue(int32_t val) noexcept { _randomValue = val; }
inline int32_t __GetRandomValue() const noexcept { return _randomValue; }
inline void __SetSpeed(uint32_t val) noexcept { _speed = val; }
inline uint32_t __GetSpeed() const noexcept { return _speed; }
};
}