Support for attack when other attacks can't be used in MiscLibrary.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2020-03-12 11:15:00 +01:00
parent 7435a2a678
commit 5672f2d2a7
4 changed files with 60 additions and 4 deletions

View File

@@ -1,8 +1,10 @@
#ifndef CREATURELIB_ATTACKTURNCHOICE_HPP
#define CREATURELIB_ATTACKTURNCHOICE_HPP
#include "../Models/Battle.hpp"
#include "../Models/CreatureIndex.hpp"
#include "../Models/LearnedAttack.hpp"
#include "../ScriptHandling/ScriptCategory.hpp"
#include "BaseTurnChoice.hpp"
namespace CreatureLib::Battling {
@@ -11,9 +13,26 @@ namespace CreatureLib::Battling {
CreatureIndex _target;
Script* _attackScript = nullptr;
void ResolveScript() {
if (_attackScript != nullptr)
return;
auto user = GetUser();
if (user == nullptr)
return;
auto battle = user->GetBattle();
if (battle != nullptr) {
auto library = battle->GetLibrary();
_attackScript = library->LoadScript(ScriptCategory::Attack, _attack->GetAttack()->GetName());
}
}
public:
AttackTurnChoice(Creature* user, LearnedAttack* attack, const CreatureIndex& target)
: BaseTurnChoice(user), _attack(attack), _target(target) {}
: BaseTurnChoice(user), _attack(attack), _target(target) {
ResolveScript();
}
AttackTurnChoice(Creature* user, LearnedAttack* attack, const CreatureIndex& target, Script* script)
: BaseTurnChoice(user), _attack(attack), _target(target), _attackScript(script) {}
inline LearnedAttack* GetAttack() const { return _attack; }