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

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

View File

@ -6,7 +6,13 @@ export MiscLibrary* CreatureLib_MiscLibrary_Construct() { return new MiscLibrary
export void CreatureLib_MiscLibrary_Destruct(const MiscLibrary* p) { delete p; }
export void CreatureLib_MiscLibrary_IsCritical(MiscLibrary* p, ExecutingAttack* attack, Creature* target, uint8_t hit) {
p->IsCritical(attack, target, hit);
export bool CreatureLib_MiscLibrary_IsCritical(MiscLibrary* p, ExecutingAttack* attack, Creature* target, uint8_t hit) {
return p->IsCritical(attack, target, hit);
};
export bool CreatureLib_MiscLibrary_CanFlee(MiscLibrary* p, FleeTurnChoice* switchChoice) {
return p->CanFlee(switchChoice);
};
export BaseTurnChoice* CreatureLib_MiscLibrary_ReplacementAttack(MiscLibrary* p, Creature* user, uint8_t sideTarget,
uint8_t creatureTarget) {
return p->ReplacementAttack(user, CreatureIndex(sideTarget, creatureTarget));
};
export void CreatureLib_MiscLibrary_CanFlee(MiscLibrary* p, FleeTurnChoice* switchChoice) { p->CanFlee(switchChoice); };

View File

@ -1,9 +1,38 @@
#include "MiscLibrary.hpp"
#include "../Models/Battle.hpp"
#include "../TurnChoices/AttackTurnChoice.hpp"
bool CreatureLib::Battling::MiscLibrary::IsCritical(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target, uint8_t hit) const {
auto rand = target->GetBattle()->GetRandom();
return rand->Get(10) <= 0;
}
static CreatureLib::Battling::LearnedAttack* _replacementAttack = nullptr;
static CreatureLib::Library::AttackData* _replacementAttackData = nullptr;
static CreatureLib::Library::AttackData* GetReplacementAttackData() {
if (_replacementAttackData == nullptr) {
_replacementAttackData =
new CreatureLib::Library::AttackData("replacement"_cnc, 0, CreatureLib::Library::AttackCategory::Physical,
30, 255, 255, CreatureLib::Library::AttackTarget::Any, 0, {});
}
return _replacementAttackData;
}
static CreatureLib::Battling::LearnedAttack* GetReplacementAttack() {
if (_replacementAttack == nullptr) {
_replacementAttack = new CreatureLib::Battling::LearnedAttack(
GetReplacementAttackData(), CreatureLib::Battling::AttackLearnMethod::Unknown);
}
return _replacementAttack;
}
bool CreatureLib::Battling::MiscLibrary::CanFlee(FleeTurnChoice* switchChoice) const { return true; }
CreatureLib::Battling::BaseTurnChoice*
CreatureLib::Battling::MiscLibrary::ReplacementAttack(Creature* user, CreatureIndex target) const {
auto sideTarget = 0;
if (user->GetBattleSide()->GetSideIndex() == 0)
sideTarget = 1;
return new AttackTurnChoice(user, GetReplacementAttack(), target);
}

View File

@ -1,6 +1,7 @@
#ifndef CREATURELIB_MISCLIBRARY_HPP
#define CREATURELIB_MISCLIBRARY_HPP
#include "../Models/CreatureIndex.hpp"
#include "../Models/ExecutingAttack.hpp"
#include "../TurnChoices/FleeTurnChoice.hpp"
@ -10,6 +11,7 @@ namespace CreatureLib::Battling {
virtual ~MiscLibrary() = default;
virtual bool IsCritical(ExecutingAttack* attack, Creature* target, uint8_t hit) const;
virtual bool CanFlee(FleeTurnChoice* switchChoice) const;
virtual BaseTurnChoice* ReplacementAttack(Creature* user, CreatureIndex target) const;
};
}

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; }