74 lines
2.9 KiB
C++
74 lines
2.9 KiB
C++
#include "Battle.hpp"
|
|
#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)
|
|
return;
|
|
_weatherScript->OnRemove();
|
|
_weatherScript = nullptr;
|
|
_eventHook.Trigger<WeatherChangeEvent>(""_cnc);
|
|
}
|
|
PkmnLib::Battling::Battle* PkmnLib::Battling::Battle::Clone() const {
|
|
auto parties = ArbUt::List<CreatureLib::Battling::BattleParty*>(_parties.Count());
|
|
for (auto* party : _parties) {
|
|
auto* partyClone = party->Clone();
|
|
parties.Append(partyClone);
|
|
for (auto* m : partyClone->GetParty()->GetParty()) {
|
|
if (m != nullptr) {
|
|
m->ClearBattleData();
|
|
}
|
|
}
|
|
}
|
|
|
|
auto* battle =
|
|
new Battle(_library.ForceAs<const BattleLibrary>(), parties, _canFlee, _numberOfSides, _creaturesPerSide);
|
|
|
|
for (int i = 0; i < _numberOfSides; ++i) {
|
|
battle->_sides.Set(i, _sides[i]->CloneWithoutCreatures(battle));
|
|
// FIXME: This is horrible code to translate the creature from the old battle into the same creature in the
|
|
// new battle. This needs to be cleaned up, as it's ugly and slow.
|
|
for (int creatureIndex = 0; creatureIndex < _creaturesPerSide; ++creatureIndex) {
|
|
auto creature = _sides[i]->GetCreature(creatureIndex);
|
|
if (!creature.HasValue()) {
|
|
continue;
|
|
}
|
|
for (size_t j = 0; j < _parties.Count(); ++j) {
|
|
auto party = _parties[j];
|
|
if (!party->IsResponsibleForIndex(i, creatureIndex)) {
|
|
continue;
|
|
}
|
|
auto partyIndex = party->GetParty()->GetParty().IndexOf(creature.GetValue());
|
|
if (partyIndex.has_value()) {
|
|
auto c = battle->_parties.At(j)->GetParty()->GetParty()[partyIndex.value()];
|
|
battle->_sides.At(i)->SetCreature(c, creatureIndex);
|
|
j = _parties.Count();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
battle->_random = _random;
|
|
battle->_hasEnded = _hasEnded;
|
|
battle->_battleResult = _battleResult;
|
|
battle->_currentTurn = _currentTurn;
|
|
_volatile.Clone(battle, battle->_volatile);
|
|
if (_weatherScript != nullptr) {
|
|
battle->_weatherScript = std::unique_ptr<CreatureLib::Battling::BattleScript>(_weatherScript->Clone(battle));
|
|
}
|
|
|
|
return battle;
|
|
}
|