Added C Interface for Script.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-03-25 19:47:37 +01:00
parent 7ce3e6940d
commit b5894ea8f2
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
6 changed files with 104 additions and 8 deletions

View File

@ -0,0 +1,97 @@
#include "../../src/Battling/ScriptHandling/Script.hpp"
#include "../Core.hpp"
using namespace CreatureLib::Battling;
export void CreatureLib_Script_Destruct(Script* p) { delete p; }
export uint8_t CreatureLib_Script_Stack(Script* p) { Try(p->Stack()); }
export uint8_t CreatureLib_Script_OnRemove(Script* p) { Try(p->OnRemove()); }
export const char* CreatureLib_Script_GetName(Script* p) { return p->GetName().c_str(); }
export uint8_t CreatureLib_Script_OnBeforeTurn(Script* p, const BaseTurnChoice* choice) {
Try(p->OnBeforeTurn(choice));
}
export uint8_t CreatureLib_Script_ChangeAttack(Script* p, AttackTurnChoice* choice, ConstString* outAttack) {
Try(p->ChangeAttack(choice, outAttack));
}
export uint8_t CreatureLib_Script_PreventAttack(Script* p, ExecutingAttack* attack, bool* outResult) {
Try(p->PreventAttack(attack, outResult));
}
export uint8_t CreatureLib_Script_FailAttack(Script* p, ExecutingAttack* attack, bool* outResult) {
Try(p->FailAttack(attack, outResult));
}
export uint8_t CreatureLib_Script_StopBeforeAttack(Script* p, ExecutingAttack* attack, bool* outResult) {
Try(p->StopBeforeAttack(attack, outResult));
}
export uint8_t CreatureLib_Script_OnBeforeAttack(Script* p, ExecutingAttack* attack) { Try(p->OnBeforeAttack(attack)); }
export uint8_t CreatureLib_Script_FailIncomingAttack(Script* p, ExecutingAttack* attack, Creature* target,
bool* outResult) {
Try(p->FailIncomingAttack(attack, target, outResult));
}
export uint8_t CreatureLib_Script_IsInvulnerable(Script* p, ExecutingAttack* attack, Creature* target,
bool* outResult) {
Try(p->IsInvulnerable(attack, target, outResult));
}
export uint8_t CreatureLib_Script_OnAttackMiss(Script* p, ExecutingAttack* attack, Creature* target) {
Try(p->OnAttackMiss(attack, target));
}
export uint8_t CreatureLib_Script_ChangeAttackType(Script* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, uint8_t* outType) {
Try(p->ChangeAttackType(attack, target, hitNumber, outType))
}
export uint8_t CreatureLib_Script_OverrideBasePower(Script* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, uint8_t* basePower) {
Try(p->OverrideBasePower(attack, target, hitNumber, basePower));
}
export uint8_t CreatureLib_Script_ChangeDamageStatsUser(Script* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, Creature** statsUser) {
Try(p->ChangeDamageStatsUser(attack, target, hitNumber, statsUser));
}
export uint8_t CreatureLib_Script_BypassDefensiveStat(Script* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, bool* bypass) {
Try(p->BypassDefensiveStat(attack, target, hitNumber, bypass));
}
export uint8_t CreatureLib_Script_BypassOffensiveStat(Script* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, bool* bypass) {
Try(p->BypassOffensiveStat(attack, target, hitNumber, bypass));
}
export uint8_t CreatureLib_Script_ModifyStatModifier(Script* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, float* modifier) {
Try(p->ModifyStatModifier(attack, target, hitNumber, modifier));
}
export uint8_t CreatureLib_Script_ModifyDamageModifier(Script* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, float* modifier) {
Try(p->ModifyDamageModifier(attack, target, hitNumber, modifier));
}
export uint8_t CreatureLib_Script_OverrideDamage(Script* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, uint32_t* damage) {
Try(p->OverrideDamage(attack, target, hitNumber, damage));
}
export uint8_t CreatureLib_Script_OnStatusMove(Script* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber) {
Try(p->OnStatusMove(attack, target, hitNumber));
}
export uint8_t CreatureLib_Script_PreventSecondaryEffects(Script* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber, bool* outResult) {
Try(p->PreventSecondaryEffects(attack, target, hitNumber, outResult));
}
export uint8_t CreatureLib_Script_OnSecondaryEffect(Script* p, ExecutingAttack* attack, Creature* target,
uint8_t hitNumber) {
Try(p->OnSecondaryEffect(attack, target, hitNumber));
}
export uint8_t CreatureLib_Script_OnAfterHits(Script* p, ExecutingAttack* attack, Creature* target) {
Try(p->OnAfterHits(attack, target));
}
export uint8_t CreatureLib_Script_PreventSelfSwitch(Script* p, const SwitchTurnChoice* choice, bool* outResult) {
Try(p->PreventSelfSwitch(choice, outResult));
}
export uint8_t CreatureLib_Script_ModifyEffectChance(Script* p, const ExecutingAttack* attack, Creature* target,
float* chance) {
Try(p->ModifyEffectChance(attack, target, chance));
}
export uint8_t CreatureLib_Script_ModifyIncomingEffectChance(Script* p, const ExecutingAttack* attack, Creature* target,
float* chance) {
Try(p->ModifyIncomingEffectChance(attack, target, chance));
}

View File

@ -11,8 +11,8 @@ uint32_t DamageLibrary::GetDamage(ExecutingAttack* attack, Creature* target, uin
auto bp = hit->GetBasePower(); auto bp = hit->GetBasePower();
auto statMod = GetStatModifier(attack, target, hitIndex); auto statMod = GetStatModifier(attack, target, hitIndex);
HOOK(ModifyStatModifier, attack, attack, target, hitIndex, &statMod); HOOK(ModifyStatModifier, attack, attack, target, hitIndex, &statMod);
int32_t damage = static_cast<int32_t>((((levelMod * static_cast<float>(bp) * statMod) / 50) + 2) * uint32_t damage = static_cast<uint32_t>((((levelMod * static_cast<float>(bp) * statMod) / 50) + 2) *
GetDamageModifier(attack, target, hitIndex)); GetDamageModifier(attack, target, hitIndex));
HOOK(OverrideDamage, attack, attack, target, hitIndex, &damage); HOOK(OverrideDamage, attack, attack, target, hitIndex, &damage);
return damage; return damage;
} }

View File

@ -16,13 +16,12 @@ namespace CreatureLib::Battling {
class Script { class Script {
public: public:
explicit Script() {}
virtual ~Script() = default; virtual ~Script() = default;
virtual void Stack(){}; virtual void Stack(){};
virtual void OnRemove(){}; virtual void OnRemove(){};
virtual const ConstString& GetName() const = 0; virtual const ConstString& GetName() const noexcept = 0;
virtual void OnBeforeTurn(const BaseTurnChoice* choice){}; virtual void OnBeforeTurn(const BaseTurnChoice* choice){};
@ -47,7 +46,7 @@ namespace CreatureLib::Battling {
virtual void ModifyStatModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex, float* modifier){}; virtual void ModifyStatModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex, float* modifier){};
virtual void ModifyDamageModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex, virtual void ModifyDamageModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex,
float* modifier){}; float* modifier){};
virtual void OverrideDamage(ExecutingAttack* attack, Creature* target, uint8_t hitIndex, int32_t* damage){}; virtual void OverrideDamage(ExecutingAttack* attack, Creature* target, uint8_t hitIndex, uint32_t* damage){};
virtual void OnStatusMove(const ExecutingAttack* attack, Creature* target, uint8_t hitNumber){}; virtual void OnStatusMove(const ExecutingAttack* attack, Creature* target, uint8_t hitNumber){};
virtual void PreventSecondaryEffects(const ExecutingAttack* attack, Creature* target, uint8_t hitNumber, virtual void PreventSecondaryEffects(const ExecutingAttack* attack, Creature* target, uint8_t hitNumber,

View File

@ -13,7 +13,7 @@ private:
public: public:
explicit TestScript(std::string name) : _name(std::move(name)){}; explicit TestScript(std::string name) : _name(std::move(name)){};
const ConstString& GetName() const override { return _name; } const ConstString& GetName() const noexcept override { return _name; }
void TestMethod(int& runCount) { runCount++; } void TestMethod(int& runCount) { runCount++; }
}; };

View File

@ -13,7 +13,7 @@ private:
public: public:
explicit TestScript(std::string name) : _name(std::move(name)){}; explicit TestScript(std::string name) : _name(std::move(name)){};
const ConstString& GetName() const override { return _name; } const ConstString& GetName() const noexcept override { return _name; }
}; };
TEST_CASE("Empty script set count == 0", "[Battling, Scripting]") { TEST_CASE("Empty script set count == 0", "[Battling, Scripting]") {

View File

@ -14,7 +14,7 @@ private:
public: public:
explicit TestScript(std::string name) : _name(std::move(name)){}; explicit TestScript(std::string name) : _name(std::move(name)){};
const ConstString& GetName() const override { return _name; } const ConstString& GetName() const noexcept override { return _name; }
void TestMethod(int& runCount) { runCount++; } void TestMethod(int& runCount) { runCount++; }
}; };