2019-10-29 10:19:25 +00:00
|
|
|
#ifndef CREATURELIB_ATTACKTURNCHOICE_HPP
|
|
|
|
#define CREATURELIB_ATTACKTURNCHOICE_HPP
|
|
|
|
|
2020-03-12 10:15:00 +00:00
|
|
|
#include "../Models/Battle.hpp"
|
2019-12-05 08:53:48 +00:00
|
|
|
#include "../Models/CreatureIndex.hpp"
|
2019-10-29 10:19:25 +00:00
|
|
|
#include "../Models/LearnedAttack.hpp"
|
2020-03-12 10:15:00 +00:00
|
|
|
#include "../ScriptHandling/ScriptCategory.hpp"
|
2019-11-28 11:55:22 +00:00
|
|
|
#include "BaseTurnChoice.hpp"
|
2019-10-29 10:19:25 +00:00
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
namespace CreatureLib::Battling {
|
2019-10-29 10:19:25 +00:00
|
|
|
class AttackTurnChoice : public BaseTurnChoice {
|
|
|
|
LearnedAttack* _attack;
|
2019-12-05 08:53:48 +00:00
|
|
|
CreatureIndex _target;
|
2019-12-05 11:56:41 +00:00
|
|
|
Script* _attackScript = nullptr;
|
2019-11-28 11:55:22 +00:00
|
|
|
|
2020-03-12 10:15:00 +00:00
|
|
|
void ResolveScript() {
|
|
|
|
if (_attackScript != nullptr)
|
|
|
|
return;
|
|
|
|
auto user = GetUser();
|
|
|
|
if (user == nullptr)
|
|
|
|
return;
|
|
|
|
auto battle = user->GetBattle();
|
|
|
|
if (battle != nullptr) {
|
2020-04-06 10:02:29 +00:00
|
|
|
if (_attack->GetAttack()->HasSecondaryEffect()) {
|
|
|
|
auto library = battle->GetLibrary();
|
2020-04-10 20:17:48 +00:00
|
|
|
auto effect = _attack->GetAttack()->GetSecondaryEffect();
|
|
|
|
_attackScript = library->LoadScript(ScriptCategory::Attack, effect->GetEffectName());
|
2020-04-10 15:18:19 +00:00
|
|
|
if (_attackScript != nullptr) {
|
2020-04-10 20:17:48 +00:00
|
|
|
_attackScript->OnInitialize(effect->GetParameters());
|
2020-04-10 15:18:19 +00:00
|
|
|
}
|
2020-04-06 10:02:29 +00:00
|
|
|
}
|
2020-03-12 10:15:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-29 10:19:25 +00:00
|
|
|
public:
|
2019-12-05 08:53:48 +00:00
|
|
|
AttackTurnChoice(Creature* user, LearnedAttack* attack, const CreatureIndex& target)
|
2020-03-12 10:15:00 +00:00
|
|
|
: BaseTurnChoice(user), _attack(attack), _target(target) {
|
2020-03-22 12:42:26 +00:00
|
|
|
AssertNotNull(attack)
|
2020-03-12 10:15:00 +00:00
|
|
|
ResolveScript();
|
|
|
|
}
|
2020-03-25 18:07:36 +00:00
|
|
|
AttackTurnChoice(Creature* user, LearnedAttack* attack, const CreatureIndex& target, Script* script) noexcept
|
2020-03-12 10:15:00 +00:00
|
|
|
: BaseTurnChoice(user), _attack(attack), _target(target), _attackScript(script) {}
|
2019-10-29 10:19:25 +00:00
|
|
|
|
2020-03-25 18:07:36 +00:00
|
|
|
inline LearnedAttack* GetAttack() const noexcept { return _attack; }
|
2019-10-31 11:02:23 +00:00
|
|
|
|
2020-03-25 18:07:36 +00:00
|
|
|
TurnChoiceKind GetKind() const noexcept override { return TurnChoiceKind ::Attack; }
|
2019-10-31 11:31:31 +00:00
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
int8_t GetPriority() const {
|
|
|
|
// HOOK: Change priority
|
2019-10-31 11:31:31 +00:00
|
|
|
return _attack->GetAttack()->GetPriority();
|
|
|
|
}
|
2019-11-02 12:57:43 +00:00
|
|
|
|
2020-03-25 18:07:36 +00:00
|
|
|
const CreatureIndex& GetTarget() const noexcept { return _target; }
|
2019-11-10 13:32:05 +00:00
|
|
|
|
2020-03-25 18:07:36 +00:00
|
|
|
Script* GetAttackScript() const noexcept { return _attackScript; }
|
2019-11-24 10:06:51 +00:00
|
|
|
|
2019-11-10 16:08:42 +00:00
|
|
|
protected:
|
2020-03-22 18:21:40 +00:00
|
|
|
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
2020-04-23 21:23:58 +00:00
|
|
|
scripts.Append(ScriptWrapper::FromScript(&_attackScript));
|
2019-11-10 16:08:42 +00:00
|
|
|
GetUser()->GetActiveScripts(scripts);
|
2019-11-10 13:32:05 +00:00
|
|
|
}
|
2019-10-29 10:19:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
#endif // CREATURELIB_ATTACKTURNCHOICE_HPP
|