Add C interface for ExecutingAttack.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
9ff5df1b70
commit
70fc8d2d5f
|
@ -0,0 +1,52 @@
|
||||||
|
#include "../../src/Battling/Models/ExecutingAttack.hpp"
|
||||||
|
#include "../Core.hpp"
|
||||||
|
using namespace CreatureLib::Battling;
|
||||||
|
|
||||||
|
export uint8_t CreatureLib_ExecutingAttack_Construct(ExecutingAttack*& out, Creature* const* targets,
|
||||||
|
size_t targetCount, uint8_t numberHits, Creature* user,
|
||||||
|
LearnedAttack* attack, Script* script) {
|
||||||
|
Try(auto ls = List<Creature*>(targets, targets + targetCount);
|
||||||
|
out = new ExecutingAttack(ls, numberHits, user, attack, script);)
|
||||||
|
}
|
||||||
|
|
||||||
|
export void CreatureLib_ExecutingAttack_Destruct(ExecutingAttack* p) { delete p; }
|
||||||
|
|
||||||
|
export uint8_t CreatureLib_ExecutingAttack_GetAttackDataForTarget(ExecutingAttack::TargetData*& out, ExecutingAttack* p,
|
||||||
|
Creature* target) {
|
||||||
|
Try(out = p->GetAttackDataForTarget(target);)
|
||||||
|
}
|
||||||
|
|
||||||
|
export bool CreatureLib_ExecutingAttack_IsCreatureTarget(ExecutingAttack* p, Creature* target) {
|
||||||
|
return p->IsCreatureTarget(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
export Creature* CreatureLib_ExecutingAttack_GetUser(ExecutingAttack* p) { return p->GetUser(); }
|
||||||
|
export LearnedAttack* CreatureLib_ExecutingAttack_GetAttack(ExecutingAttack* p) { return p->GetAttack(); }
|
||||||
|
|
||||||
|
export uint8_t CreatureLib_TargetData_GetHit(ExecutingAttack::HitData*& out, ExecutingAttack::TargetData* p,
|
||||||
|
uint8_t hit) {
|
||||||
|
Try(out = p->GetHit(hit);)
|
||||||
|
}
|
||||||
|
export uint8_t CreatureLib_TargetData_GetNumberOfHits(ExecutingAttack::TargetData* p) { return p->GetNumberOfHits(); }
|
||||||
|
export bool CreatureLib_TargetData_IsHit(ExecutingAttack::TargetData* p) { return p->IsHit(); }
|
||||||
|
|
||||||
|
#define HITDATA_GET_FUNC(name, returnType) \
|
||||||
|
export returnType CreatureLib_HitData##_##name(const ExecutingAttack::HitData* p) { return p->name(); }
|
||||||
|
|
||||||
|
HITDATA_GET_FUNC(IsCritical, bool);
|
||||||
|
HITDATA_GET_FUNC(GetBasePower, uint8_t);
|
||||||
|
HITDATA_GET_FUNC(GetEffectiveness, float);
|
||||||
|
HITDATA_GET_FUNC(GetDamage, uint32_t);
|
||||||
|
HITDATA_GET_FUNC(GetType, uint8_t);
|
||||||
|
|
||||||
|
#define HITDATA_SET_FUNC(name, type) \
|
||||||
|
export void CreatureLib_HitData##_##name(ExecutingAttack::HitData* p, type val) { p->name(val); }
|
||||||
|
|
||||||
|
HITDATA_SET_FUNC(SetCritical, bool);
|
||||||
|
HITDATA_SET_FUNC(SetBasePower, uint8_t);
|
||||||
|
HITDATA_SET_FUNC(SetEffectiveness, float);
|
||||||
|
HITDATA_SET_FUNC(SetDamage, uint32_t);
|
||||||
|
HITDATA_SET_FUNC(SetType, uint8_t);
|
||||||
|
|
||||||
|
#undef HITDATA_GET_FUNC
|
||||||
|
#undef HITDATA_SET_FUNC
|
|
@ -5,7 +5,7 @@ using namespace CreatureLib::Library;
|
||||||
export uint8_t CreatureLib_AttackData_Construct(AttackData*& out, const char* name, uint8_t type,
|
export uint8_t CreatureLib_AttackData_Construct(AttackData*& out, const char* name, uint8_t type,
|
||||||
AttackCategory category, uint8_t power, uint8_t accuracy,
|
AttackCategory category, uint8_t power, uint8_t accuracy,
|
||||||
uint8_t baseUsage, AttackTarget target, int8_t priority,
|
uint8_t baseUsage, AttackTarget target, int8_t priority,
|
||||||
int8_t effectChance, const char* effectName, const char* flags[],
|
float effectChance, const char* effectName, const char* flags[],
|
||||||
size_t flagsCount) {
|
size_t flagsCount) {
|
||||||
Try(std::unordered_set<uint32_t> conversedFlags(flagsCount); for (size_t i = 0; i < flagsCount; i++) {
|
Try(std::unordered_set<uint32_t> conversedFlags(flagsCount); for (size_t i = 0; i < flagsCount; i++) {
|
||||||
conversedFlags.insert(ConstString::GetHash(flags[i]));
|
conversedFlags.insert(ConstString::GetHash(flags[i]));
|
||||||
|
@ -31,7 +31,7 @@ SIMPLE_GET_FUNC(AttackData, GetPriority, int8_t);
|
||||||
|
|
||||||
export bool CreatureLib_AttackData_HasSecondaryEffect(const AttackData* p) { return p->HasSecondaryEffect(); }
|
export bool CreatureLib_AttackData_HasSecondaryEffect(const AttackData* p) { return p->HasSecondaryEffect(); }
|
||||||
|
|
||||||
export uint8_t CreatureLib_AttackData_GetSecondaryEffectChance(const AttackData* p) {
|
export float CreatureLib_AttackData_GetSecondaryEffectChance(const AttackData* p) {
|
||||||
return p->GetSecondaryEffect().GetChance();
|
return p->GetSecondaryEffect().GetChance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ export bool CreatureLib_CreatureSpecies_TryGetVariant(const CreatureSpecies* p,
|
||||||
return p->TryGetVariant(Arbutils::CaseInsensitiveConstString::GetHash(name), out);
|
return p->TryGetVariant(Arbutils::CaseInsensitiveConstString::GetHash(name), out);
|
||||||
}
|
}
|
||||||
export bool CreatureLib_CreatureSpecies_TryGetVariantWithHash(const CreatureSpecies* p, uint32_t hash,
|
export bool CreatureLib_CreatureSpecies_TryGetVariantWithHash(const CreatureSpecies* p, uint32_t hash,
|
||||||
const SpeciesVariant* out) {
|
const SpeciesVariant*& out) {
|
||||||
return p->TryGetVariant(hash, out);
|
return p->TryGetVariant(hash, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,19 +22,19 @@ namespace CreatureLib::Battling {
|
||||||
uint8_t _type = 0;
|
uint8_t _type = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HitData() {}
|
HitData() noexcept {}
|
||||||
|
|
||||||
[[nodiscard]] inline bool IsCritical() const { return _critical; }
|
[[nodiscard]] inline bool IsCritical() const noexcept { return _critical; }
|
||||||
[[nodiscard]] inline uint8_t GetBasePower() const { return _basePower; }
|
[[nodiscard]] inline uint8_t GetBasePower() const noexcept { return _basePower; }
|
||||||
[[nodiscard]] inline float GetEffectiveness() const { return _effectiveness; }
|
[[nodiscard]] inline float GetEffectiveness() const noexcept { return _effectiveness; }
|
||||||
[[nodiscard]] inline uint32_t GetDamage() const { return _damage; }
|
[[nodiscard]] inline uint32_t GetDamage() const noexcept { return _damage; }
|
||||||
[[nodiscard]] inline uint8_t GetType() const { return _type; }
|
[[nodiscard]] inline uint8_t GetType() const noexcept { return _type; }
|
||||||
|
|
||||||
inline void SetCritical(bool value) { _critical = value; }
|
inline void SetCritical(bool value) noexcept { _critical = value; }
|
||||||
inline void SetBasePower(uint8_t value) { _basePower = value; }
|
inline void SetBasePower(uint8_t value) noexcept { _basePower = value; }
|
||||||
inline void SetEffectiveness(float value) { _effectiveness = value; }
|
inline void SetEffectiveness(float value) noexcept { _effectiveness = value; }
|
||||||
inline void SetDamage(uint32_t value) { _damage = value; }
|
inline void SetDamage(uint32_t value) noexcept { _damage = value; }
|
||||||
inline void SetType(uint8_t value) { _type = value; }
|
inline void SetType(uint8_t value) noexcept { _type = value; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class TargetData {
|
class TargetData {
|
||||||
|
@ -51,9 +51,9 @@ namespace CreatureLib::Battling {
|
||||||
|
|
||||||
HitData* GetHit(uint8_t index) { return &_hits[index]; }
|
HitData* GetHit(uint8_t index) { return &_hits[index]; }
|
||||||
|
|
||||||
uint8_t GetNumberOfHits() const { return _hits.Count(); }
|
uint8_t GetNumberOfHits() const noexcept { return _hits.Count(); }
|
||||||
|
|
||||||
bool IsHit() const { return _isHit; }
|
bool IsHit() const noexcept { return _isHit; }
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -73,17 +73,17 @@ namespace CreatureLib::Battling {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~ExecutingAttack() { delete _script; };
|
virtual ~ExecutingAttack() noexcept { delete _script; };
|
||||||
|
|
||||||
TargetData* GetAttackDataForTarget(Creature* creature) { return &_targets[creature]; }
|
TargetData* GetAttackDataForTarget(Creature* creature) { return &_targets[creature]; }
|
||||||
|
|
||||||
bool IsCreatureTarget(Creature* creature) { return _targets.Has(creature); }
|
bool IsCreatureTarget(Creature* creature) noexcept { return _targets.Has(creature); }
|
||||||
|
|
||||||
Dictionary<Creature*, TargetData>& GetTargets() { return _targets; }
|
Dictionary<Creature*, TargetData>& GetTargets() noexcept { return _targets; }
|
||||||
|
|
||||||
Creature* GetUser() { return _user; }
|
Creature* GetUser() noexcept { return _user; }
|
||||||
|
|
||||||
LearnedAttack* GetAttack() { return _attack; }
|
LearnedAttack* GetAttack() noexcept { return _attack; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
|
||||||
|
|
Loading…
Reference in New Issue