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"
|
2020-06-20 17:44:41 +00:00
|
|
|
#include "../ScriptHandling/ScriptMacros.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 {
|
2020-05-31 15:26:39 +00:00
|
|
|
ArbUt::BorrowedPtr<LearnedAttack> _attack;
|
2019-12-05 08:53:48 +00:00
|
|
|
CreatureIndex _target;
|
2021-03-07 09:26:41 +00:00
|
|
|
std::unique_ptr<BattleScript> _attackScript = nullptr;
|
2020-06-20 17:44:41 +00:00
|
|
|
int8_t _priority = 0;
|
2019-11-28 11:55:22 +00:00
|
|
|
|
2021-05-14 08:42:05 +00:00
|
|
|
void ResolveScript(ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData> attack) {
|
2020-03-12 10:15:00 +00:00
|
|
|
if (_attackScript != nullptr)
|
|
|
|
return;
|
|
|
|
auto user = GetUser();
|
|
|
|
auto battle = user->GetBattle();
|
2020-12-12 11:22:48 +00:00
|
|
|
if (battle.HasValue()) {
|
2021-05-14 08:42:05 +00:00
|
|
|
if (attack->HasSecondaryEffect()) {
|
2020-12-12 11:22:48 +00:00
|
|
|
auto library = battle.GetValue()->GetLibrary();
|
2021-05-14 08:42:05 +00:00
|
|
|
auto& effect = attack->GetSecondaryEffect();
|
2021-03-07 09:26:41 +00:00
|
|
|
_attackScript = std::unique_ptr<BattleScript>(
|
|
|
|
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:
|
2020-05-31 15:26:39 +00:00
|
|
|
AttackTurnChoice(Creature* user, const ArbUt::BorrowedPtr<LearnedAttack>& attack, const CreatureIndex& target)
|
2020-03-12 10:15:00 +00:00
|
|
|
: BaseTurnChoice(user), _attack(attack), _target(target) {
|
2020-12-13 11:15:40 +00:00
|
|
|
EnsureNotNull(user)
|
2021-05-14 08:42:05 +00:00
|
|
|
ResolveScript(attack->GetAttack());
|
2020-06-20 17:51:34 +00:00
|
|
|
_priority = _attack->GetAttack()->GetPriority();
|
2020-03-12 10:15:00 +00:00
|
|
|
}
|
2020-05-31 15:26:39 +00:00
|
|
|
AttackTurnChoice(Creature* user, const ArbUt::BorrowedPtr<LearnedAttack>& attack, const CreatureIndex& target,
|
2021-03-07 09:26:41 +00:00
|
|
|
BattleScript* script)
|
2020-06-20 17:44:41 +00:00
|
|
|
: BaseTurnChoice(user), _attack(attack), _target(target), _attackScript(script) {
|
2020-06-20 17:51:34 +00:00
|
|
|
_priority = _attack->GetAttack()->GetPriority();
|
2020-05-29 18:05:05 +00:00
|
|
|
}
|
|
|
|
|
2020-06-20 17:44:41 +00:00
|
|
|
~AttackTurnChoice() = default;
|
|
|
|
|
2020-05-31 15:26:39 +00:00
|
|
|
inline const ArbUt::BorrowedPtr<LearnedAttack>& GetAttack() const noexcept { return _attack; }
|
2019-10-31 11:02:23 +00:00
|
|
|
|
2021-05-14 08:42:05 +00:00
|
|
|
void ChangeAttackScript(ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData> attack) {
|
|
|
|
_attackScript = nullptr;
|
|
|
|
ResolveScript(attack);
|
|
|
|
ResetActiveScripts();
|
|
|
|
}
|
|
|
|
|
2020-03-25 18:07:36 +00:00
|
|
|
TurnChoiceKind GetKind() const noexcept override { return TurnChoiceKind ::Attack; }
|
2019-10-31 11:31:31 +00:00
|
|
|
|
2020-06-20 17:51:34 +00:00
|
|
|
inline int8_t GetPriority() const noexcept { return _priority; }
|
|
|
|
inline void SetPriority(int8_t priority) noexcept { _priority = priority; }
|
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
|
|
|
|
2021-03-07 09:26:41 +00:00
|
|
|
const std::unique_ptr<BattleScript>& GetAttackScript() const noexcept { return _attackScript; }
|
2020-12-13 11:26:54 +00:00
|
|
|
size_t ScriptCount() const override { return 1 + GetUser()->ScriptCount(); }
|
2019-11-24 10:06:51 +00:00
|
|
|
|
2020-05-26 16:31:06 +00:00
|
|
|
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override {
|
2021-10-29 17:31:08 +00:00
|
|
|
GetOwnScripts(scripts);
|
2020-12-13 11:15:40 +00:00
|
|
|
GetUser()->GetActiveScripts(scripts);
|
2019-11-10 13:32:05 +00:00
|
|
|
}
|
2021-10-29 17:31:08 +00:00
|
|
|
void GetOwnScripts(ArbUt::List<ScriptWrapper>& scripts) override {
|
|
|
|
scripts.Append(ScriptWrapper::FromScript(&_attackScript));
|
|
|
|
}
|
2019-10-29 10:19:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
#endif // CREATURELIB_ATTACKTURNCHOICE_HPP
|