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"
|
||||
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) {
|
||||
_weatherScript->OnRemove();
|
||||
}
|
||||
_weatherScript = std::unique_ptr<CreatureLib::Battling::BattleScript>(
|
||||
_library->LoadScript(this, static_cast<ScriptCategory>(PkmnScriptCategory::Weather), name));
|
||||
_eventHook.Trigger<WeatherChangeEvent>(name);
|
||||
return true;
|
||||
}
|
||||
void PkmnLib::Battling::Battle::ClearWeather() {
|
||||
if (_weatherScript == nullptr)
|
||||
|
|
|
@ -22,8 +22,19 @@ namespace PkmnLib::Battling {
|
|||
|
||||
virtual ~Battle() = default;
|
||||
|
||||
void SetWeather(const ArbUt::StringView& name);
|
||||
bool SetWeather(const ArbUt::StringView& name);
|
||||
void ClearWeather();
|
||||
void SuppressWeather() {
|
||||
if (_weatherScript != nullptr) {
|
||||
_weatherScript->Suppress();
|
||||
}
|
||||
}
|
||||
void UnsuppressWeather() {
|
||||
if (_weatherScript != nullptr) {
|
||||
_weatherScript->Unsuppress();
|
||||
}
|
||||
}
|
||||
|
||||
const ArbUt::StringView& GetWeatherName() noexcept {
|
||||
if (_weatherScript == nullptr)
|
||||
return ArbUt::StringView::EmptyString();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef PKMNLIB_PKMNSCRIPT_HPP
|
||||
#define PKMNLIB_PKMNSCRIPT_HPP
|
||||
#include <CreatureLib/Battling/ScriptHandling/BattleScript.hpp>
|
||||
#include "Battle/Battle.hpp"
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
|
@ -27,6 +28,7 @@ namespace PkmnLib::Battling {
|
|||
CreatureLib::Battling::Creature* winningMon, uint32_t* experienceGain){};
|
||||
virtual void DoesShareExperience(CreatureLib::Battling::Creature* faintedMon,
|
||||
CreatureLib::Battling::Creature* winningMon, bool* shareExperience){};
|
||||
virtual void BlockWeather(CreatureLib::Battling::Battle* battle, bool* blockWeather){};
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
auto aggregator = source->GetScriptIterator(); \
|
||||
ArbUt::BorrowedPtr<CreatureLib::Battling::BattleScript> next = (CreatureLib::Battling::BattleScript*)1; \
|
||||
while (aggregator.GetNext(next)) { \
|
||||
if (next->IsSuppressed()) { \
|
||||
continue; \
|
||||
} \
|
||||
auto castNext = next.ForceAs<PkmnLib::Battling::PkmnScript>(); \
|
||||
castNext->hookName(__VA_ARGS__); \
|
||||
} \
|
||||
|
|
|
@ -191,8 +191,8 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) {
|
|||
asCALL_THISCALL);
|
||||
Ensure(r >= 0);
|
||||
r = engine->RegisterObjectMethod(
|
||||
"Battle", "void SetWeather(const constString &in name) const",
|
||||
asMETHODPR(PkmnLib::Battling::Battle, SetWeather, (const ArbUt::StringView&), void), asCALL_THISCALL);
|
||||
"Battle", "bool SetWeather(const constString &in name) const",
|
||||
asMETHODPR(PkmnLib::Battling::Battle, SetWeather, (const ArbUt::StringView&), bool), asCALL_THISCALL);
|
||||
Ensure(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Battle", "void ClearWeather(const constString &in name) const",
|
||||
asMETHODPR(PkmnLib::Battling::Battle, ClearWeather, (), void), asCALL_THISCALL);
|
||||
|
@ -201,6 +201,12 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) {
|
|||
"Battle", "const constString& GetWeatherName() const",
|
||||
asMETHODPR(PkmnLib::Battling::Battle, GetWeatherName, (), const ArbUt::StringView&), asCALL_THISCALL);
|
||||
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)",
|
||||
asFUNCTION(GetBattleSideWrapper), asCALL_CDECL_OBJFIRST);
|
||||
Ensure(r >= 0);
|
||||
|
|
Loading…
Reference in New Issue