Battle C Interface.

This commit is contained in:
2020-04-26 20:01:11 +02:00
parent ec1685aa14
commit 718c146ebe
4 changed files with 45 additions and 26 deletions

View File

@@ -1 +1,15 @@
#include "Battle.hpp"
void PkmnLib::Battling::Battle::SetWeather(const Arbutils::CaseInsensitiveConstString& name) {
if (_weatherScript != nullptr) {
_weatherScript->OnRemove();
delete _weatherScript;
}
_weatherScript = _library->LoadScript(static_cast<ScriptCategory>(PkmnScriptCategory::Weather), name);
_eventHook.TriggerEvent(new WeatherChangeEvent(name));
}
void PkmnLib::Battling::Battle::ClearWeather() {
_weatherScript->OnRemove();
delete _weatherScript;
_weatherScript = nullptr;
_eventHook.TriggerEvent(new WeatherChangeEvent(""_cnc));
}

View File

@@ -16,20 +16,8 @@ namespace PkmnLib::Battling {
bool canFlee = true, uint8_t numberOfSides = 2, uint8_t creaturesPerSide = 1)
: CreatureLib::Battling::Battle(library, parties, canFlee, numberOfSides, creaturesPerSide) {}
void SetWeather(const Arbutils::CaseInsensitiveConstString& name) {
if (_weatherScript != nullptr) {
_weatherScript->OnRemove();
delete _weatherScript;
}
_weatherScript = _library->LoadScript(static_cast<ScriptCategory>(PkmnScriptCategory::Weather), name);
_eventHook.TriggerEvent(new WeatherChangeEvent(name));
}
void ClearWeather() {
_weatherScript->OnRemove();
delete _weatherScript;
_weatherScript = nullptr;
_eventHook.TriggerEvent(new WeatherChangeEvent(""_cnc));
}
void SetWeather(const Arbutils::CaseInsensitiveConstString& name);
void ClearWeather();
const Arbutils::CaseInsensitiveConstString& GetWeatherName() noexcept { return _weatherScript->GetName(); }
size_t ScriptCount() const override { return CreatureLib::Battling::Battle::ScriptCount() + 1; }

View File

@@ -1,6 +1,6 @@
#include "RegisterExecutingAttack.hpp"
#include <CreatureLib/Battling/Models/ExecutingAttack.hpp>
#include <cassert>
#include <Arbutils/Assert.hpp>
void RegisterExecutingAttack::Register(asIScriptEngine* engine) {
RegisterHitData(engine);
@@ -8,46 +8,46 @@ void RegisterExecutingAttack::Register(asIScriptEngine* engine) {
}
void RegisterExecutingAttack::RegisterHitData(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("HitData", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("HitData", "bool get_IsCritical() const property",
asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, IsCritical),
asCALL_THISCALL);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("HitData", "uint8 get_BasePower() const property",
asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetBasePower),
asCALL_THISCALL);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("HitData", "float get_Effectiveness() const property",
asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetEffectiveness),
asCALL_THISCALL);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("HitData", "uint get_Damage() const property",
asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetDamage),
asCALL_THISCALL);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("HitData", "uint8 get_Type() const property",
asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetType),
asCALL_THISCALL);
assert(r >= 0);
Assert(r >= 0);
}
void RegisterExecutingAttack::RegisterExecutingAttackType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("ExecutingMove", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("ExecutingMove", "HitData@ GetHitData(Pokemon@ target, uint8 hit) const",
asMETHOD(CreatureLib::Battling::ExecutingAttack, GetHitData),
asCALL_THISCALL);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("ExecutingMove", "bool IsPokemonTarget(Pokemon@ pkmn) const",
asMETHOD(CreatureLib::Battling::ExecutingAttack, IsCreatureTarget),
asCALL_THISCALL);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("ExecutingMove", "Pokemon@ get_User() const property",
asMETHOD(CreatureLib::Battling::ExecutingAttack, GetUser),
asCALL_THISCALL);
assert(r >= 0);
Assert(r >= 0);
r = engine->RegisterObjectMethod("ExecutingMove", "LearnedMove@ get_Move() const property",
asMETHOD(CreatureLib::Battling::ExecutingAttack, GetAttack),
asCALL_THISCALL);
assert(r >= 0);
Assert(r >= 0);
}