Work on evolution helpers
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-06-27 17:11:37 +02:00
parent 4633c6beef
commit 3d3bff3772
10 changed files with 85 additions and 9 deletions

View File

@@ -1,7 +1,10 @@
#include "MiscLibrary.hpp"
#include <CreatureLib/Battling/Models/Battle.hpp>
#include <CreatureLib/Battling/Models/LearnedAttack.hpp>
#include <CreatureLib/Battling/TurnChoices/AttackTurnChoice.hpp>
#include "../PkmnScriptHook.hpp"
#include "../Pokemon/LearnedMove.hpp"
#include "../Pokemon/Pokemon.hpp"
bool PkmnLib::Battling::MiscLibrary::IsCritical(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target, uint8_t hit) const {
@@ -26,3 +29,49 @@ PkmnLib::Battling::MiscLibrary::ReplacementAttack(CreatureLib::Battling::Creatur
CreatureLib::Battling::CreatureIndex target) const {
return new CreatureLib::Battling::AttackTurnChoice(user, GetReplacementAttack(), target);
}
using TimeOfDay = PkmnLib::Library::TimeOfDay;
bool PkmnLib::Battling::MiscLibrary::CanEvolveFromLevelUp(
const ArbUt::BorrowedPtr<const PkmnLib::Library::EvolutionData>& evolution,
const ArbUt::BorrowedPtr<const Pokemon>& pokemon) {
auto time = GetTime();
switch (evolution->GetMethod()) {
case Library::EvolutionMethod::Level: return pokemon->GetLevel() >= evolution->GetData(0)->AsInt();
case Library::EvolutionMethod::HighFriendship:
return pokemon->GetFriendship() >= evolution->GetData(0)->AsInt();
case Library::EvolutionMethod::HighFriendshipTime:
return pokemon->GetFriendship() >= evolution->GetData(0)->AsInt() &&
time >= (TimeOfDay)evolution->GetData(1)->AsInt() &&
time <= (TimeOfDay)evolution->GetData(2)->AsInt();
case Library::EvolutionMethod::KnownMove: {
auto v = evolution->GetData(0)->AsString();
return std::any_of(pokemon->GetMoves().begin(), pokemon->GetMoves().end(), [v](const auto& move) {
return move.HasValue() && move.GetValue()->GetMoveData()->GetName() == v;
});
}
case Library::EvolutionMethod::LocationBased:
// TODO: Implement this
return false;
case Library::EvolutionMethod::TimeBased:
return time >= (TimeOfDay)evolution->GetData(0)->AsInt() &&
time <= (TimeOfDay)evolution->GetData(1)->AsInt();
case Library::EvolutionMethod::HoldsItem: return pokemon->HasHeldItem(evolution->GetData(0)->AsString());
case Library::EvolutionMethod::HoldsItemTime:
return pokemon->HasHeldItem(evolution->GetData(0)->AsString()) &&
time >= (TimeOfDay)evolution->GetData(0)->AsInt() &&
time <= (TimeOfDay)evolution->GetData(1)->AsInt();
case Library::EvolutionMethod::IsGenderAndLevel:
return pokemon->GetLevel() >= evolution->GetData(1)->AsInt() &&
pokemon->GetGender() == (CreatureLib::Library::Gender)evolution->GetData(0)->AsInt();
case Library::EvolutionMethod::Custom:
// TODO
case Library::EvolutionMethod::EvolutionItemUse:
case Library::EvolutionMethod::EvolutionItemUseWithGender:
case Library::EvolutionMethod::Trade:
case Library::EvolutionMethod::TradeWithHeldItem:
case Library::EvolutionMethod::TradeWithSpecificPokemon: return false;
}
__builtin_unreachable();
}