Script hook for changing priority.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
f55ae5a809
commit
b3366f7b58
|
@ -24,6 +24,7 @@ namespace CreatureLib::Battling {
|
||||||
virtual void OnInitialize(const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters){};
|
virtual void OnInitialize(const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters){};
|
||||||
virtual void OnBeforeTurn(const BaseTurnChoice* choice){};
|
virtual void OnBeforeTurn(const BaseTurnChoice* choice){};
|
||||||
|
|
||||||
|
virtual void ChangePriority(AttackTurnChoice* choice, int8_t* priority){};
|
||||||
virtual void ChangeAttack(AttackTurnChoice* choice, ArbUt::CaseInsensitiveConstString* outAttack){};
|
virtual void ChangeAttack(AttackTurnChoice* choice, ArbUt::CaseInsensitiveConstString* outAttack){};
|
||||||
virtual void PreventAttack(ExecutingAttack* attack, bool* outResult){};
|
virtual void PreventAttack(ExecutingAttack* attack, bool* outResult){};
|
||||||
virtual void FailAttack(ExecutingAttack* attack, bool* outFailed){};
|
virtual void FailAttack(ExecutingAttack* attack, bool* outFailed){};
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "../Models/CreatureIndex.hpp"
|
#include "../Models/CreatureIndex.hpp"
|
||||||
#include "../Models/LearnedAttack.hpp"
|
#include "../Models/LearnedAttack.hpp"
|
||||||
#include "../ScriptHandling/ScriptCategory.hpp"
|
#include "../ScriptHandling/ScriptCategory.hpp"
|
||||||
|
#include "../ScriptHandling/ScriptMacros.hpp"
|
||||||
#include "BaseTurnChoice.hpp"
|
#include "BaseTurnChoice.hpp"
|
||||||
|
|
||||||
namespace CreatureLib::Battling {
|
namespace CreatureLib::Battling {
|
||||||
|
@ -12,7 +13,7 @@ namespace CreatureLib::Battling {
|
||||||
ArbUt::BorrowedPtr<LearnedAttack> _attack;
|
ArbUt::BorrowedPtr<LearnedAttack> _attack;
|
||||||
CreatureIndex _target;
|
CreatureIndex _target;
|
||||||
std::unique_ptr<Script> _attackScript = nullptr;
|
std::unique_ptr<Script> _attackScript = nullptr;
|
||||||
bool _scriptIsTaken = false;
|
int8_t _priority = 0;
|
||||||
|
|
||||||
void ResolveScript() {
|
void ResolveScript() {
|
||||||
if (_attackScript != nullptr)
|
if (_attackScript != nullptr)
|
||||||
|
@ -37,37 +38,48 @@ namespace CreatureLib::Battling {
|
||||||
public:
|
public:
|
||||||
AttackTurnChoice(Creature* user, const ArbUt::BorrowedPtr<LearnedAttack>& attack, const CreatureIndex& target)
|
AttackTurnChoice(Creature* user, const ArbUt::BorrowedPtr<LearnedAttack>& attack, const CreatureIndex& target)
|
||||||
: BaseTurnChoice(user), _attack(attack), _target(target) {
|
: BaseTurnChoice(user), _attack(attack), _target(target) {
|
||||||
|
#ifndef TESTS_BUILD
|
||||||
|
AssertNotNull(user)
|
||||||
AssertNotNull(attack)
|
AssertNotNull(attack)
|
||||||
|
#endif
|
||||||
ResolveScript();
|
ResolveScript();
|
||||||
|
HOOK(ChangePriority, this, this, &_priority);
|
||||||
}
|
}
|
||||||
AttackTurnChoice(Creature* user, const ArbUt::BorrowedPtr<LearnedAttack>& attack, const CreatureIndex& target,
|
AttackTurnChoice(Creature* user, const ArbUt::BorrowedPtr<LearnedAttack>& attack, const CreatureIndex& target,
|
||||||
Script* script) noexcept
|
Script* script)
|
||||||
: BaseTurnChoice(user), _attack(attack), _target(target), _attackScript(script) {}
|
: BaseTurnChoice(user), _attack(attack), _target(target), _attackScript(script) {
|
||||||
|
#ifndef TESTS_BUILD
|
||||||
|
AssertNotNull(user)
|
||||||
|
AssertNotNull(attack)
|
||||||
|
#endif
|
||||||
|
HOOK(ChangePriority, this, this, &_priority);
|
||||||
|
}
|
||||||
|
|
||||||
~AttackTurnChoice() {
|
~AttackTurnChoice() = default;
|
||||||
if (!_scriptIsTaken) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const ArbUt::BorrowedPtr<LearnedAttack>& GetAttack() const noexcept { return _attack; }
|
inline const ArbUt::BorrowedPtr<LearnedAttack>& GetAttack() const noexcept { return _attack; }
|
||||||
|
|
||||||
TurnChoiceKind GetKind() const noexcept override { return TurnChoiceKind ::Attack; }
|
TurnChoiceKind GetKind() const noexcept override { return TurnChoiceKind ::Attack; }
|
||||||
|
|
||||||
int8_t GetPriority() const {
|
inline int8_t GetPriority() const { return _attack->GetAttack()->GetPriority(); }
|
||||||
// HOOK: Change priority
|
|
||||||
return _attack->GetAttack()->GetPriority();
|
|
||||||
}
|
|
||||||
|
|
||||||
const CreatureIndex& GetTarget() const noexcept { return _target; }
|
const CreatureIndex& GetTarget() const noexcept { return _target; }
|
||||||
|
|
||||||
const std::unique_ptr<Script>& GetAttackScript() const noexcept { return _attackScript; }
|
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:
|
protected:
|
||||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override {
|
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override {
|
||||||
scripts.Append(ScriptWrapper::FromScript(&_attackScript));
|
scripts.Append(ScriptWrapper::FromScript(&_attackScript));
|
||||||
|
if (_user != nullptr) {
|
||||||
GetUser()->GetActiveScripts(scripts);
|
GetUser()->GetActiveScripts(scripts);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,10 @@ namespace CreatureLib::Battling {
|
||||||
class Creature;
|
class Creature;
|
||||||
|
|
||||||
class BaseTurnChoice : public ScriptSource {
|
class BaseTurnChoice : public ScriptSource {
|
||||||
ArbUt::BorrowedPtr<Creature> _user;
|
|
||||||
int32_t _randomValue;
|
int32_t _randomValue;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
ArbUt::BorrowedPtr<Creature> _user;
|
||||||
BaseTurnChoice(ArbUt::BorrowedPtr<Creature> user) noexcept : _user(user){};
|
BaseTurnChoice(ArbUt::BorrowedPtr<Creature> user) noexcept : _user(user){};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue