Change script when ChangeAttack script hook changes the used attack.
continuous-integration/drone/push Build is passing Details

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2021-05-14 10:42:05 +02:00
parent 13153b3119
commit b48353822c
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 11 additions and 4 deletions

View File

@ -89,6 +89,7 @@ void TurnHandler::ExecuteAttackChoice(const ArbUt::BorrowedPtr<AttackTurnChoice>
HOOK(ChangeAttack, choice, choice.GetRaw(), &attackName);
if (attackName != choice->GetAttack()->GetAttack()->GetName()) {
attackData = battle.GetValue()->GetLibrary()->GetAttackLibrary()->Get(attackName);
choice->ChangeAttackScript(attackData);
}
auto targetType = attackData->GetTarget();

View File

@ -15,15 +15,15 @@ namespace CreatureLib::Battling {
std::unique_ptr<BattleScript> _attackScript = nullptr;
int8_t _priority = 0;
void ResolveScript() {
void ResolveScript(ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData> attack) {
if (_attackScript != nullptr)
return;
auto user = GetUser();
auto battle = user->GetBattle();
if (battle.HasValue()) {
if (_attack->GetAttack()->HasSecondaryEffect()) {
if (attack->HasSecondaryEffect()) {
auto library = battle.GetValue()->GetLibrary();
auto& effect = _attack->GetAttack()->GetSecondaryEffect();
auto& effect = attack->GetSecondaryEffect();
_attackScript = std::unique_ptr<BattleScript>(
library->LoadScript(ScriptCategory::Attack, effect->GetEffectName()));
if (_attackScript != nullptr) {
@ -37,7 +37,7 @@ namespace CreatureLib::Battling {
AttackTurnChoice(Creature* user, const ArbUt::BorrowedPtr<LearnedAttack>& attack, const CreatureIndex& target)
: BaseTurnChoice(user), _attack(attack), _target(target) {
EnsureNotNull(user)
ResolveScript();
ResolveScript(attack->GetAttack());
_priority = _attack->GetAttack()->GetPriority();
}
AttackTurnChoice(Creature* user, const ArbUt::BorrowedPtr<LearnedAttack>& attack, const CreatureIndex& target,
@ -50,6 +50,12 @@ namespace CreatureLib::Battling {
inline const ArbUt::BorrowedPtr<LearnedAttack>& GetAttack() const noexcept { return _attack; }
void ChangeAttackScript(ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData> attack) {
_attackScript = nullptr;
ResolveScript(attack);
ResetActiveScripts();
}
TurnChoiceKind GetKind() const noexcept override { return TurnChoiceKind ::Attack; }
inline int8_t GetPriority() const noexcept { return _priority; }