Loads of work on capturing pokemon
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-03-26 16:23:24 +01:00
parent 1b14f31bd7
commit 09638c8d14
12 changed files with 110 additions and 13 deletions

View File

@@ -1,5 +1,6 @@
#include "Pokemon.hpp"
#include <CreatureLib/Battling/Models/Battle.hpp>
#include "../EventHooks/CaptureAttemptEvent.hpp"
#include "../PkmnScriptCategory.hpp"
void PkmnLib::Battling::Pokemon::Evolve(ArbUt::BorrowedPtr<const Library::PokemonSpecies> mon,
@@ -71,5 +72,30 @@ bool PkmnLib::Battling::Pokemon::IsUsable() const noexcept {
if (IsEgg()) {
return false;
}
if (_wasCaught) {
return false;
}
return Creature::IsUsable();
}
void PkmnLib::Battling::Pokemon::AttemptCapture(PkmnLib::Library::Item* catchItem) {
Ensure(_battleData.OnBattleField);
Ensure(_battleData.Battle.HasValue());
Ensure(_battleData.Side.HasValue());
Ensure(!IsFainted());
Ensure(IsUsable());
Ensure(!GetBattleSide().GetValue()->IsSlotUnfillabe(this)) auto captureLibrary =
GetLibrary().ForceAs<const BattleLibrary>()->GetCaptureLibrary();
auto result = captureLibrary->TryCatch(this, catchItem, _battleData.Battle.GetValue()->GetRandom());
_battleData.Battle.GetValue()->TriggerEventListener<CaptureAttemptEvent>(this, result);
if (result.WasCaught) {
// By marking the pokemon as caught, it becomes no longer usable for switch in.
_wasCaught = true;
// As the pokemon is caught now, we replace it with an empty space.
_battleData.Side.GetValue()->SetCreature(nullptr, _battleData.Index.GetCreatureIndex());
}
}
void PkmnLib::Battling::Pokemon::ClearBattleData() noexcept {
Creature::ClearBattleData();
_wasCaught = false;
}

View File

@@ -4,6 +4,7 @@
#include <CreatureLib/Battling/Models/Creature.hpp>
#include "../../Library/Statistic.hpp"
#include "../Library/BattleLibrary.hpp"
#include "../Library/CaptureLibrary.hpp"
#include "../PkmnScript.hpp"
#include "LearnedMove.hpp"
@@ -16,6 +17,7 @@ namespace PkmnLib::Battling {
ArbUt::BorrowedPtr<const PkmnLib::Library::Nature> _nature;
u8 _friendship = 0;
bool _isEgg;
bool _wasCaught = {};
public:
Pokemon(ArbUt::BorrowedPtr<const BattleLibrary> library,
@@ -81,6 +83,15 @@ namespace PkmnLib::Battling {
_friendship = newValue;
}
/// @brief Attempt to capture the Pokemon.
/// @param catchItem The item used to try and catch the Pokemon with (generally a pokeball).
/// @warning This requires the Pokemon to be on the battle field, not fainted, and usable (so not already caught
/// and not an egg).
void AttemptCapture(Library::Item* non_null catchItem);
inline bool WasCaught() const noexcept { return _wasCaught; }
void ClearBattleData() noexcept override;
bool IsUsable() const noexcept override;
Creature* non_null Clone() const override;