CreatureLib/CInterface/Library/AttackData.cpp

56 lines
2.6 KiB
C++

#include "../../src/Library/Attacks/AttackData.hpp"
#include "../Core.hpp"
using namespace CreatureLib::Library;
export uint8_t CreatureLib_AttackData_Construct(AttackData*& out, const char* name, uint8_t type,
AttackCategory category, uint8_t power, uint8_t accuracy,
uint8_t baseUsage, AttackTarget target, int8_t priority,
float effectChance, const char* effectName, void* effectParameters[],
size_t effectParameterCount, const char* flags[], size_t flagsCount) {
Try({
std::unordered_set<uint32_t> conversedFlags(flagsCount);
for (size_t i = 0; i < flagsCount; i++) {
conversedFlags.insert(ConstString::GetHash(flags[i]));
}
Arbutils::Collections::List<void*> effectParameterList(effectParameterCount);
for (size_t i = 0; i < effectParameterCount; i++) {
effectParameterList[i] = effectParameters[i];
}
auto effect =
SecondaryEffect(effectChance, Arbutils::CaseInsensitiveConstString(effectName), effectParameterList);
out = new AttackData(ConstString(name), type, category, power, accuracy, baseUsage, target, priority, effect,
conversedFlags);
})
};
export void CreatureLib_AttackData_Destruct(const AttackData* p) { delete p; }
#define SIMPLE_GET_FUNC(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const type* p) { return p->name(); }
export const char* CreatureLib_AttackData_GetName(const AttackData* p) { return p->GetName().c_str(); }
SIMPLE_GET_FUNC(AttackData, GetType, uint8_t);
SIMPLE_GET_FUNC(AttackData, GetCategory, AttackCategory);
SIMPLE_GET_FUNC(AttackData, GetBasePower, uint8_t);
SIMPLE_GET_FUNC(AttackData, GetAccuracy, uint8_t);
SIMPLE_GET_FUNC(AttackData, GetBaseUsages, uint8_t);
SIMPLE_GET_FUNC(AttackData, GetTarget, AttackTarget);
SIMPLE_GET_FUNC(AttackData, GetPriority, int8_t);
export bool CreatureLib_AttackData_HasSecondaryEffect(const AttackData* p) { return p->HasSecondaryEffect(); }
export float CreatureLib_AttackData_GetSecondaryEffectChance(const AttackData* p) {
return p->GetSecondaryEffect().GetChance();
}
export const char* CreatureLib_AttackData_GetSecondaryEffectName(const AttackData* p) {
return p->GetSecondaryEffect().GetEffectName().c_str();
}
export bool CreatureLib_AttackData_HasFlag(const AttackData* p, const char* key) {
return p->HasFlag(ConstString::GetHash(key));
}
#undef SIMPLE_GET_FUNC