Support for failing an AttackTurnChoice.
continuous-integration/drone/push Build is passing Details

This is handled before the actual ExecutingAttack is created, so allows for failing a move a lot earlier than before.
This commit is contained in:
Deukhoofd 2021-11-12 12:54:05 +01:00
parent 1a3b7fe50a
commit 33d384c464
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 9 additions and 0 deletions

View File

@ -134,6 +134,11 @@ void TurnHandler::ExecuteAttackChoice(const ArbUt::BorrowedPtr<AttackTurnChoice>
return;
}
if (choice->HasFailed()) {
FAIL_HANDLING_NO_TARGET(choice, choice->GetUser());
return;
}
auto* attack = attackScoped.TakeOwnership();
battle.GetValue()->TriggerEventListener<AttackUseEvent>(attack);
battle.GetValue()->RegisterHistoryElement<AttackUseHistory>(attack);

View File

@ -14,6 +14,7 @@ namespace CreatureLib::Battling {
CreatureIndex _target;
std::unique_ptr<BattleScript> _attackScript = nullptr;
int8_t _priority = 0;
bool _hasFailed = false;
void ResolveScript(ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData> attack) {
if (_attackScript != nullptr)
@ -73,6 +74,9 @@ namespace CreatureLib::Battling {
void GetOwnScripts(ArbUt::List<ScriptWrapper>& scripts) override {
scripts.Append(ScriptWrapper::FromScript(&_attackScript));
}
inline bool HasFailed() const noexcept { return _hasFailed; }
inline void Fail() noexcept { _hasFailed = true; }
};
}