CreatureLib/CInterface/Battling/Creature.cpp

110 lines
6.5 KiB
C++
Raw Normal View History

#include "../../src/Battling/Models/Creature.hpp"
#include "../Core.hpp"
using namespace CreatureLib::Battling;
export uint8_t CreatureLib_Creature_Construct(Creature*& out, const BattleLibrary* library,
const CreatureLib::Library::CreatureSpecies* species,
const CreatureLib::Library::SpeciesVariant* variant, uint8_t level,
uint32_t experience, uint32_t uid, CreatureLib::Library::Gender gender,
uint8_t coloring, const CreatureLib::Library::Item* heldItem,
const char* nickname, bool secretTalent, uint8_t talent,
LearnedAttack* attacks[], size_t attacksNum, bool allowedExperienceGain) {
Try(auto attacksVec = std::vector<LearnedAttack*>(attacks, attacks + (attacksNum * sizeof(LearnedAttack*)));
2020-05-26 16:31:06 +00:00
out = new Creature(library, ArbUt::BorrowedPtr<const CreatureLib::Library::CreatureSpecies>(species), variant,
level, experience, uid, gender, coloring,
ArbUt::BorrowedPtr<const CreatureLib::Library::Item>(heldItem), std::string(nickname),
2020-05-26 16:31:06 +00:00
CreatureLib::Library::TalentIndex(secretTalent, talent), attacksVec, allowedExperienceGain);)
};
export void CreatureLib_Creature_Destruct(const Creature* p) { delete p; }
2020-07-25 13:02:11 +00:00
BORROWED_GET_FUNC(Creature, GetLibrary, const CreatureLib::Battling::BattleLibrary*);
BORROWED_GET_FUNC(Creature, GetSpecies, const CreatureLib::Library::CreatureSpecies*);
BORROWED_GET_FUNC(Creature, GetVariant, const CreatureLib::Library::SpeciesVariant*);
2020-06-10 12:39:20 +00:00
export uint8_t CreatureLib_Creature_ChangeVariant(Creature* p, const CreatureLib::Library::SpeciesVariant* variant) {
Try(p->ChangeVariant(variant);)
}
SIMPLE_GET_FUNC(Creature, GetLevel, uint8_t);
SIMPLE_GET_FUNC(Creature, GetExperience, uint32_t);
SIMPLE_GET_FUNC(Creature, GetGender, CreatureLib::Library::Gender);
SIMPLE_GET_FUNC(Creature, GetColoring, uint8_t);
export bool CreatureLib_Creature_HasHeldItem(const Creature* p, const char* name) {
2020-06-26 15:08:23 +00:00
return p->HasHeldItem(ArbUt::StringView(name));
}
export bool CreatureLib_Creature_HasHeldItemWithHash(const Creature* p, uint32_t hash) { return p->HasHeldItem(hash); }
BORROWED_GET_FUNC(Creature, GetHeldItem, const CreatureLib::Library::Item*);
export uint8_t CreatureLib_Creature_SetHeldItem(Creature* p, const char* name) {
2020-06-26 15:08:23 +00:00
Try(p->SetHeldItem(ArbUt::StringView(name));)
}
export uint8_t CreatureLib_Creature_SetHeldItemWithHash(Creature* p, uint32_t hash) { Try(p->SetHeldItem(hash);) }
export void CreatureLib_Creature_SetHeldItemFromItem(Creature* p, const CreatureLib::Library::Item* item) {
2020-05-26 16:31:06 +00:00
return p->SetHeldItem(ArbUt::BorrowedPtr<const CreatureLib::Library::Item>(item));
}
SIMPLE_GET_FUNC(Creature, GetCurrentHealth, uint32_t);
BORROWED_GET_FUNC(Creature, GetBattle, Battle*);
BORROWED_GET_FUNC(Creature, GetBattleSide, BattleSide*);
SIMPLE_GET_FUNC(Creature, IsOnBattleField, bool);
2020-06-26 15:08:23 +00:00
export const char* CreatureLib_Creature_GetNickname(Creature* p) { return p->GetNickname().data(); }
export bool CreatureLib_Creature_HasType(Creature* p, uint8_t type) { return p->HasType(type); }
SIMPLE_GET_FUNC(Creature, GetMaxHealth, uint32_t);
export uint8_t CreatureLib_Creature_ChangeLevelBy(Creature* p, int8_t level) { Try(p->ChangeLevelBy(level);) }
export uint8_t CreatureLib_Creature_Damage(Creature* p, uint32_t damage, DamageSource source) {
Try(p->Damage(damage, source);)
}
export uint8_t CreatureLib_Creature_Heal(Creature* p, uint32_t health, bool canRevive) {
Try(p->Heal(health, canRevive);)
}
export uint8_t CreatureLib_Creature_RestoreAllAttackUses(Creature* p) { Try(p->RestoreAllAttackUses();) }
export uint8_t CreatureLib_Creature_GetActiveTalent(const Creature* p, const char*& out) {
Try(out = p->GetActiveTalent().c_str();)
}
export uint8_t CreatureLib_Creature_OverrideActiveTalent(Creature* p, const char* talent) {
2020-06-26 15:08:23 +00:00
Try(p->OverrideActiveTalent(ArbUt::StringView(talent));)
}
export uint8_t CreatureLib_Creature_AddExperience(Creature* p, uint32_t experience) {
Try(p->AddExperience(experience);)
}
export uint8_t CreatureLib_Creature_ClearVolatileScripts(Creature* p) { Try(p->ClearVolatileScripts();) }
export uint8_t CreatureLib_Creature_AddVolatileScriptByName(Creature* p, const char* scriptName) {
2020-06-26 15:08:23 +00:00
Try(p->AddVolatileScript(ArbUt::StringView(scriptName));)
}
export uint8_t CreatureLib_Creature_AddVolatileScript(Creature* p, Script* script) {
Try(p->AddVolatileScript(script);)
}
export uint8_t CreatureLib_Creature_RemoveVolatileScriptByName(Creature* p, const char* scriptName) {
2020-06-26 15:08:23 +00:00
Try(p->RemoveVolatileScript(ArbUt::StringView(scriptName));)
}
export uint8_t CreatureLib_Creature_RemoveVolatileScript(Creature* p, Script* script) {
Try(p->RemoveVolatileScript(script);)
}
export bool CreatureLib_Creature_HasVolatileScript(Creature* p, const char* scriptName) {
2020-06-26 15:08:23 +00:00
return p->HasVolatileScript(ArbUt::StringView(scriptName));
}
export size_t CreatureLib_Creature_GetAttacksCount(Creature* p) { return p->GetAttacks().Count(); }
2020-07-17 11:12:21 +00:00
export LearnedAttack* const* CreatureLib_Creature_GetAttacks(Creature* p) { return p->GetAttacks().RawData(); }
BORROWED_GET_FUNC(Creature, GetDisplaySpecies, const CreatureLib::Library::CreatureSpecies*);
BORROWED_GET_FUNC(Creature, GetDisplayVariant, const CreatureLib::Library::SpeciesVariant*);
export void CreatureLib_Creature_SetDisplaySpecies(Creature* p, const CreatureLib::Library::CreatureSpecies* species) {
2020-05-26 16:31:06 +00:00
return p->SetDisplaySpecies(ArbUt::BorrowedPtr<const CreatureLib::Library::CreatureSpecies>(species));
}
export void CreatureLib_Creature_SetDisplayVariant(Creature* p, const CreatureLib::Library::SpeciesVariant* variant) {
return p->SetDisplayVariant(variant);
}
export void CreatureLib_Creature_ChangeStatBoost(Creature* p, CreatureLib::Library::Statistic stat, int8_t diffAmount) {
p->ChangeStatBoost(stat, diffAmount);
}
export uint32_t CreatureLib_Creature_GetFlatStat(Creature* p, CreatureLib::Library::Statistic stat) {
return p->GetFlatStat(stat);
}
export uint32_t CreatureLib_Creature_GetBoostedStat(Creature* p, CreatureLib::Library::Statistic stat) {
return p->GetBoostedStat(stat);
}
export uint32_t CreatureLib_Creature_GetBaseStat(Creature* p, CreatureLib::Library::Statistic stat) {
return p->GetBaseStat(stat);
}
export int8_t CreatureLib_Creature_GetStatBoost(Creature* p, CreatureLib::Library::Statistic stat) {
return p->GetStatBoost(stat);
}