Support for (un)suppressing weather, adds hook to block weather changes.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
ea3bc7ee33
commit
b2accd720e
|
@ -1,11 +1,18 @@
|
||||||
#include "Battle.hpp"
|
#include "Battle.hpp"
|
||||||
void PkmnLib::Battling::Battle::SetWeather(const ArbUt::StringView& name) {
|
#include "../PkmnScriptHook.hpp"
|
||||||
|
bool PkmnLib::Battling::Battle::SetWeather(const ArbUt::StringView& name) {
|
||||||
|
bool blockWeather = false;
|
||||||
|
PKMN_HOOK(BlockWeather, this, this, &blockWeather);
|
||||||
|
if (blockWeather) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (_weatherScript != nullptr) {
|
if (_weatherScript != nullptr) {
|
||||||
_weatherScript->OnRemove();
|
_weatherScript->OnRemove();
|
||||||
}
|
}
|
||||||
_weatherScript = std::unique_ptr<CreatureLib::Battling::BattleScript>(
|
_weatherScript = std::unique_ptr<CreatureLib::Battling::BattleScript>(
|
||||||
_library->LoadScript(this, static_cast<ScriptCategory>(PkmnScriptCategory::Weather), name));
|
_library->LoadScript(this, static_cast<ScriptCategory>(PkmnScriptCategory::Weather), name));
|
||||||
_eventHook.Trigger<WeatherChangeEvent>(name);
|
_eventHook.Trigger<WeatherChangeEvent>(name);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
void PkmnLib::Battling::Battle::ClearWeather() {
|
void PkmnLib::Battling::Battle::ClearWeather() {
|
||||||
if (_weatherScript == nullptr)
|
if (_weatherScript == nullptr)
|
||||||
|
|
|
@ -22,8 +22,19 @@ namespace PkmnLib::Battling {
|
||||||
|
|
||||||
virtual ~Battle() = default;
|
virtual ~Battle() = default;
|
||||||
|
|
||||||
void SetWeather(const ArbUt::StringView& name);
|
bool SetWeather(const ArbUt::StringView& name);
|
||||||
void ClearWeather();
|
void ClearWeather();
|
||||||
|
void SuppressWeather() {
|
||||||
|
if (_weatherScript != nullptr) {
|
||||||
|
_weatherScript->Suppress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void UnsuppressWeather() {
|
||||||
|
if (_weatherScript != nullptr) {
|
||||||
|
_weatherScript->Unsuppress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const ArbUt::StringView& GetWeatherName() noexcept {
|
const ArbUt::StringView& GetWeatherName() noexcept {
|
||||||
if (_weatherScript == nullptr)
|
if (_weatherScript == nullptr)
|
||||||
return ArbUt::StringView::EmptyString();
|
return ArbUt::StringView::EmptyString();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef PKMNLIB_PKMNSCRIPT_HPP
|
#ifndef PKMNLIB_PKMNSCRIPT_HPP
|
||||||
#define PKMNLIB_PKMNSCRIPT_HPP
|
#define PKMNLIB_PKMNSCRIPT_HPP
|
||||||
#include <CreatureLib/Battling/ScriptHandling/BattleScript.hpp>
|
#include <CreatureLib/Battling/ScriptHandling/BattleScript.hpp>
|
||||||
|
#include "Battle/Battle.hpp"
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
|
@ -27,6 +28,7 @@ namespace PkmnLib::Battling {
|
||||||
CreatureLib::Battling::Creature* winningMon, uint32_t* experienceGain){};
|
CreatureLib::Battling::Creature* winningMon, uint32_t* experienceGain){};
|
||||||
virtual void DoesShareExperience(CreatureLib::Battling::Creature* faintedMon,
|
virtual void DoesShareExperience(CreatureLib::Battling::Creature* faintedMon,
|
||||||
CreatureLib::Battling::Creature* winningMon, bool* shareExperience){};
|
CreatureLib::Battling::Creature* winningMon, bool* shareExperience){};
|
||||||
|
virtual void BlockWeather(CreatureLib::Battling::Battle* battle, bool* blockWeather){};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,9 @@
|
||||||
auto aggregator = source->GetScriptIterator(); \
|
auto aggregator = source->GetScriptIterator(); \
|
||||||
ArbUt::BorrowedPtr<CreatureLib::Battling::BattleScript> next = (CreatureLib::Battling::BattleScript*)1; \
|
ArbUt::BorrowedPtr<CreatureLib::Battling::BattleScript> next = (CreatureLib::Battling::BattleScript*)1; \
|
||||||
while (aggregator.GetNext(next)) { \
|
while (aggregator.GetNext(next)) { \
|
||||||
|
if (next->IsSuppressed()) { \
|
||||||
|
continue; \
|
||||||
|
} \
|
||||||
auto castNext = next.ForceAs<PkmnLib::Battling::PkmnScript>(); \
|
auto castNext = next.ForceAs<PkmnLib::Battling::PkmnScript>(); \
|
||||||
castNext->hookName(__VA_ARGS__); \
|
castNext->hookName(__VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
|
|
|
@ -191,8 +191,8 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) {
|
||||||
asCALL_THISCALL);
|
asCALL_THISCALL);
|
||||||
Ensure(r >= 0);
|
Ensure(r >= 0);
|
||||||
r = engine->RegisterObjectMethod(
|
r = engine->RegisterObjectMethod(
|
||||||
"Battle", "void SetWeather(const constString &in name) const",
|
"Battle", "bool SetWeather(const constString &in name) const",
|
||||||
asMETHODPR(PkmnLib::Battling::Battle, SetWeather, (const ArbUt::StringView&), void), asCALL_THISCALL);
|
asMETHODPR(PkmnLib::Battling::Battle, SetWeather, (const ArbUt::StringView&), bool), asCALL_THISCALL);
|
||||||
Ensure(r >= 0);
|
Ensure(r >= 0);
|
||||||
r = engine->RegisterObjectMethod("Battle", "void ClearWeather(const constString &in name) const",
|
r = engine->RegisterObjectMethod("Battle", "void ClearWeather(const constString &in name) const",
|
||||||
asMETHODPR(PkmnLib::Battling::Battle, ClearWeather, (), void), asCALL_THISCALL);
|
asMETHODPR(PkmnLib::Battling::Battle, ClearWeather, (), void), asCALL_THISCALL);
|
||||||
|
@ -201,6 +201,12 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) {
|
||||||
"Battle", "const constString& GetWeatherName() const",
|
"Battle", "const constString& GetWeatherName() const",
|
||||||
asMETHODPR(PkmnLib::Battling::Battle, GetWeatherName, (), const ArbUt::StringView&), asCALL_THISCALL);
|
asMETHODPR(PkmnLib::Battling::Battle, GetWeatherName, (), const ArbUt::StringView&), asCALL_THISCALL);
|
||||||
Ensure(r >= 0);
|
Ensure(r >= 0);
|
||||||
|
r = engine->RegisterObjectMethod("Battle", "void SuppressWeather() const",
|
||||||
|
asMETHOD(PkmnLib::Battling::Battle, SuppressWeather), asCALL_THISCALL);
|
||||||
|
Ensure(r >= 0);
|
||||||
|
r = engine->RegisterObjectMethod("Battle", "void UnsuppressWeather() const",
|
||||||
|
asMETHOD(PkmnLib::Battling::Battle, UnsuppressWeather), asCALL_THISCALL);
|
||||||
|
Ensure(r >= 0);
|
||||||
r = engine->RegisterObjectMethod("Battle", "BattleSide@ GetBattleSide(uint8 index)",
|
r = engine->RegisterObjectMethod("Battle", "BattleSide@ GetBattleSide(uint8 index)",
|
||||||
asFUNCTION(GetBattleSideWrapper), asCALL_CDECL_OBJFIRST);
|
asFUNCTION(GetBattleSideWrapper), asCALL_CDECL_OBJFIRST);
|
||||||
Ensure(r >= 0);
|
Ensure(r >= 0);
|
||||||
|
|
Loading…
Reference in New Issue