CreatureLib/CInterface/Battling/Creature.cpp

150 lines
8.8 KiB
C++
Raw Normal View History

#include "../../src/Battling/Models/Creature.hpp"
#include "../Core.hpp"
using namespace CreatureLib::Battling;
2022-04-02 10:33:26 +00:00
export_func u8 CreatureLib_Creature_Construct(Creature*& out, const BattleLibrary* library,
const CreatureLib::Library::CreatureSpecies* species,
const CreatureLib::Library::SpeciesVariant* variant, level_int_t level,
u32 experience, u32 uid, CreatureLib::Library::Gender gender, u8 coloring,
const CreatureLib::Library::Item* heldItem, const char* nickname,
bool secretTalent, u8 talent, LearnedAttack* attacks[], size_t attacksNum,
bool allowedExperienceGain) {
Try(auto attacksVec = std::vector<LearnedAttack*>(attacks, attacks + (attacksNum * sizeof(LearnedAttack*)));
out =
new Creature(library, ArbUt::BorrowedPtr<const CreatureLib::Library::CreatureSpecies>(species), variant,
level, experience, uid, gender, coloring,
ArbUt::OptionalBorrowedPtr<const CreatureLib::Library::Item>(heldItem), std::string(nickname),
CreatureLib::Library::TalentIndex(secretTalent, talent), attacksVec, allowedExperienceGain);)
};
2022-04-02 10:33:26 +00:00
export_func void CreatureLib_Creature_Destruct(const Creature* p) { delete p; }
2022-04-02 10:33:26 +00:00
export_func u8 CreatureLib_Creature_Initialize(Creature* p) { Try(p->Initialize();) }
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
2022-04-02 10:33:26 +00:00
export_func u8 CreatureLib_Creature_ChangeSpecies(Creature* p, const CreatureLib::Library::CreatureSpecies* species,
const CreatureLib::Library::SpeciesVariant* variant) {
Try(p->ChangeSpecies(species, variant);)
}
2022-04-02 10:33:26 +00:00
export_func u8 CreatureLib_Creature_ChangeVariant(Creature* p, const CreatureLib::Library::SpeciesVariant* variant) {
2020-06-10 12:39:20 +00:00
Try(p->ChangeVariant(variant);)
}
SIMPLE_GET_FUNC(Creature, GetLevel, level_int_t);
SIMPLE_GET_FUNC(Creature, GetExperience, u32);
SIMPLE_GET_FUNC(Creature, GetUniqueIdentifier, u32);
SIMPLE_GET_FUNC(Creature, GetGender, CreatureLib::Library::Gender);
SIMPLE_GET_FUNC(Creature, GetColoring, u8);
2022-04-02 10:33:26 +00:00
export_func bool CreatureLib_Creature_HasHeldItem(const Creature* p, const char* name) {
2020-06-26 15:08:23 +00:00
return p->HasHeldItem(ArbUt::StringView(name));
}
2022-04-02 10:33:26 +00:00
export_func bool CreatureLib_Creature_HasHeldItemWithHash(const Creature* p, u32 hash) { return p->HasHeldItem(hash); }
OPTIONAL_GET_FUNC(Creature, GetHeldItem, const CreatureLib::Library::Item*);
2022-04-02 10:33:26 +00:00
export_func u8 CreatureLib_Creature_SetHeldItem(Creature* p, const char* name) {
2020-06-26 15:08:23 +00:00
Try(p->SetHeldItem(ArbUt::StringView(name));)
}
export_func u8 CreatureLib_Creature_SetHeldItemWithHash(Creature* p, u32 hash) { Try(p->SetHeldItemByHash(hash);) }
2022-04-02 10:33:26 +00:00
export_func 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, u32);
OPTIONAL_GET_FUNC(Creature, GetBattle, Battle*);
OPTIONAL_GET_FUNC(Creature, GetBattleSide, BattleSide*);
SIMPLE_GET_FUNC(Creature, IsOnBattleField, bool);
2022-04-02 10:33:26 +00:00
export_func const char* CreatureLib_Creature_GetNickname(Creature* p) {
auto s = p->GetNickname();
if (s.has_value()) {
return p->GetNickname().value().data();
}
return "";
}
2022-04-02 10:33:26 +00:00
export_func void CreatureLib_Creature_SetNickname(Creature* p, const char* nickname) { p->SetNickname(nickname); }
export_func bool CreatureLib_Creature_HasType(Creature* p, u8 type) { return p->HasType(type); }
export_func size_t CreatureLib_Creature_GetTypeCount(Creature* p) { return p->GetTypes().size(); }
export_func const u8* CreatureLib_Creature_GetTypes(Creature* p) { return p->GetTypes().data(); }
SIMPLE_GET_FUNC(Creature, GetMaxHealth, u32);
2022-04-02 10:33:26 +00:00
export_func u8 CreatureLib_Creature_ChangeLevelBy(Creature* p, i8 level) { Try(p->ChangeLevelBy(level);) }
export_func u8 CreatureLib_Creature_Damage(Creature* p, u32 damage, DamageSource source) {
Try(p->Damage(damage, source);)
}
export_func u8 CreatureLib_Creature_Heal(Creature* p, u32 health, bool canRevive) { Try(p->Heal(health, canRevive);) }
export_func u8 CreatureLib_Creature_RestoreAllAttackUses(Creature* p) { Try(p->RestoreAllAttackUses();) }
2022-04-02 10:33:26 +00:00
export_func bool CreatureLib_Creature_GetRealTalentIsSecret(const Creature* p) { return p->GetRealTalent().IsSecret(); }
export_func bool CreatureLib_Creature_GetRealTalentIndex(const Creature* p) { return p->GetRealTalent().GetIndex(); }
2022-04-02 10:33:26 +00:00
export_func u8 CreatureLib_Creature_GetActiveTalent(const Creature* p, const CreatureLib::Library::Talent*& out) {
2021-11-15 11:04:45 +00:00
Try(out = p->GetActiveTalent().GetRaw();)
}
2022-04-02 10:33:26 +00:00
export_func u8 CreatureLib_Creature_OverrideActiveTalent(Creature* p, const char* talent) {
2020-06-26 15:08:23 +00:00
Try(p->OverrideActiveTalent(ArbUt::StringView(talent));)
}
2022-04-02 10:33:26 +00:00
export_func u8 CreatureLib_Creature_AddExperience(Creature* p, u32 experience) { Try(p->AddExperience(experience);) }
export_func u8 CreatureLib_Creature_ClearVolatileScripts(Creature* p) { Try(p->ClearVolatileScripts();) }
export_func u8 CreatureLib_Creature_AddVolatileScriptByName(Creature* p, const char* scriptName) {
2020-06-26 15:08:23 +00:00
Try(p->AddVolatileScript(ArbUt::StringView(scriptName));)
}
2022-04-02 10:33:26 +00:00
export_func u8 CreatureLib_Creature_AddVolatileScript(Creature* p, BattleScript* script) {
Try(p->AddVolatileScript(script);)
}
2022-04-02 10:33:26 +00:00
export_func u8 CreatureLib_Creature_RemoveVolatileScriptByName(Creature* p, const char* scriptName) {
2020-06-26 15:08:23 +00:00
Try(p->RemoveVolatileScript(ArbUt::StringView(scriptName));)
}
2022-04-02 10:33:26 +00:00
export_func u8 CreatureLib_Creature_RemoveVolatileScript(Creature* p, BattleScript* script) {
Try(p->RemoveVolatileScript(script);)
}
2022-04-02 10:33:26 +00:00
export_func bool CreatureLib_Creature_HasVolatileScript(Creature* p, const char* scriptName) {
2020-06-26 15:08:23 +00:00
return p->HasVolatileScript(ArbUt::StringView(scriptName));
}
2022-04-02 10:33:26 +00:00
export_func size_t CreatureLib_Creature_GetAttacksCount(Creature* p) { return p->GetAttacks().Count(); }
export_func LearnedAttack* const* CreatureLib_Creature_GetAttacks(Creature* p) { return p->GetAttacks().RawData(); }
export_func bool CreatureLib_Creature_HasAttack(Creature* p, const char* scriptName) {
return p->HasAttack(ArbUt::StringView(scriptName));
}
OPTIONAL_GET_FUNC(Creature, GetDisplaySpecies, const CreatureLib::Library::CreatureSpecies*);
OPTIONAL_GET_FUNC(Creature, GetDisplayVariant, const CreatureLib::Library::SpeciesVariant*);
2022-04-02 10:33:26 +00:00
export_func 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));
}
2022-04-02 10:33:26 +00:00
export_func void CreatureLib_Creature_SetDisplayVariant(Creature* p,
const CreatureLib::Library::SpeciesVariant* variant) {
return p->SetDisplayVariant(variant);
}
2022-04-02 10:33:26 +00:00
export_func bool CreatureLib_Creature_AllowedExperienceGain(Creature* p) { return p->AllowedExperienceGain(); }
export_func void CreatureLib_Creature_SetAllowedExperienceGain(Creature* p, bool b) { p->SetAllowedExperienceGain(b); }
2022-04-02 10:33:26 +00:00
export_func void CreatureLib_Creature_ChangeStatBoost(Creature* p, CreatureLib::Library::Statistic stat,
i8 diffAmount) {
p->ChangeStatBoost(stat, diffAmount);
}
2022-04-02 10:33:26 +00:00
export_func u32 CreatureLib_Creature_GetFlatStat(Creature* p, CreatureLib::Library::Statistic stat) {
return p->GetFlatStat(stat);
}
2022-04-02 10:33:26 +00:00
export_func u32 CreatureLib_Creature_GetBoostedStat(Creature* p, CreatureLib::Library::Statistic stat) {
return p->GetBoostedStat(stat);
}
2022-04-02 10:33:26 +00:00
export_func u32 CreatureLib_Creature_GetBaseStat(Creature* p, CreatureLib::Library::Statistic stat) {
return p->GetBaseStat(stat);
}
2022-04-02 10:33:26 +00:00
export_func i8 CreatureLib_Creature_GetStatBoost(Creature* p, CreatureLib::Library::Statistic stat) {
return p->GetStatBoost(stat);
}
SIMPLE_GET_FUNC(Creature, GetAvailableAttackSlot, u8);
2022-04-02 10:33:26 +00:00
export_func u8 CreatureLib_Creature_AddAttack(Creature* p, LearnedAttack* attack) { Try(p->AddAttack(attack);) }
export_func u8 CreatureLib_Creature_ReplaceAttack(Creature* p, size_t index, LearnedAttack* attack) {
Try(p->ReplaceAttack(index, attack);)
}
2022-04-02 10:33:26 +00:00
export_func u8 CreatureLib_Creature_SwapAttack(Creature* p, size_t a, size_t b) { Try(p->SwapAttacks(a, b);) }
2022-04-02 10:33:26 +00:00
export_func u8 CreatureLib_Creature_SetStatus(Creature* p, const char* name) {
Try(p->SetStatus(ArbUt::StringView(name)));
};
export_func u8 CreatureLib_Creature_ClearStatus(Creature* p) { Try(p->ClearStatus()); };
export_func const char* CreatureLib_Creature_GetStatusName(Creature* p) { return p->GetStatusName().c_str(); }