Script hook for changing priority.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-06-20 19:44:41 +02:00
parent f55ae5a809
commit b3366f7b58
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
3 changed files with 27 additions and 14 deletions

View File

@ -24,6 +24,7 @@ namespace CreatureLib::Battling {
virtual void OnInitialize(const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters){};
virtual void OnBeforeTurn(const BaseTurnChoice* choice){};
virtual void ChangePriority(AttackTurnChoice* choice, int8_t* priority){};
virtual void ChangeAttack(AttackTurnChoice* choice, ArbUt::CaseInsensitiveConstString* outAttack){};
virtual void PreventAttack(ExecutingAttack* attack, bool* outResult){};
virtual void FailAttack(ExecutingAttack* attack, bool* outFailed){};

View File

@ -5,6 +5,7 @@
#include "../Models/CreatureIndex.hpp"
#include "../Models/LearnedAttack.hpp"
#include "../ScriptHandling/ScriptCategory.hpp"
#include "../ScriptHandling/ScriptMacros.hpp"
#include "BaseTurnChoice.hpp"
namespace CreatureLib::Battling {
@ -12,7 +13,7 @@ namespace CreatureLib::Battling {
ArbUt::BorrowedPtr<LearnedAttack> _attack;
CreatureIndex _target;
std::unique_ptr<Script> _attackScript = nullptr;
bool _scriptIsTaken = false;
int8_t _priority = 0;
void ResolveScript() {
if (_attackScript != nullptr)
@ -37,36 +38,47 @@ namespace CreatureLib::Battling {
public:
AttackTurnChoice(Creature* user, const ArbUt::BorrowedPtr<LearnedAttack>& attack, const CreatureIndex& target)
: BaseTurnChoice(user), _attack(attack), _target(target) {
#ifndef TESTS_BUILD
AssertNotNull(user)
AssertNotNull(attack)
#endif
ResolveScript();
HOOK(ChangePriority, this, this, &_priority);
}
AttackTurnChoice(Creature* user, const ArbUt::BorrowedPtr<LearnedAttack>& attack, const CreatureIndex& target,
Script* script) noexcept
: BaseTurnChoice(user), _attack(attack), _target(target), _attackScript(script) {}
~AttackTurnChoice() {
if (!_scriptIsTaken) {
}
Script* script)
: BaseTurnChoice(user), _attack(attack), _target(target), _attackScript(script) {
#ifndef TESTS_BUILD
AssertNotNull(user)
AssertNotNull(attack)
#endif
HOOK(ChangePriority, this, this, &_priority);
}
~AttackTurnChoice() = default;
inline const ArbUt::BorrowedPtr<LearnedAttack>& GetAttack() const noexcept { return _attack; }
TurnChoiceKind GetKind() const noexcept override { return TurnChoiceKind ::Attack; }
int8_t GetPriority() const {
// HOOK: Change priority
return _attack->GetAttack()->GetPriority();
}
inline int8_t GetPriority() const { return _attack->GetAttack()->GetPriority(); }
const CreatureIndex& GetTarget() const noexcept { return _target; }
const std::unique_ptr<Script>& GetAttackScript() const noexcept { return _attackScript; }
size_t ScriptCount() const override { return 1 + GetUser()->ScriptCount(); }
size_t ScriptCount() const override {
if (_user == nullptr) {
return 1;
}
return 1 + GetUser()->ScriptCount();
}
protected:
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override {
scripts.Append(ScriptWrapper::FromScript(&_attackScript));
GetUser()->GetActiveScripts(scripts);
if (_user != nullptr) {
GetUser()->GetActiveScripts(scripts);
}
}
};
}

View File

@ -9,10 +9,10 @@ namespace CreatureLib::Battling {
class Creature;
class BaseTurnChoice : public ScriptSource {
ArbUt::BorrowedPtr<Creature> _user;
int32_t _randomValue;
protected:
ArbUt::BorrowedPtr<Creature> _user;
BaseTurnChoice(ArbUt::BorrowedPtr<Creature> user) noexcept : _user(user){};
public: