Ensure no invalid move pointer is passed to LearnMove.

This commit is contained in:
Deukhoofd 2020-04-22 10:32:28 +02:00
parent a470d11b25
commit 9ac60dfa42
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
1 changed files with 2 additions and 1 deletions

View File

@ -144,13 +144,14 @@ PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithHeldItem
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon*
PkmnLib::Battling::CreatePokemon::LearnMove(const Arbutils::CaseInsensitiveConstString& moveName, PkmnLib::Battling::CreatePokemon::LearnMove(const Arbutils::CaseInsensitiveConstString& moveName,
CreatureLib::Battling::AttackLearnMethod method) { CreatureLib::Battling::AttackLearnMethod method) {
const PkmnLib::Library::MoveData* move; const PkmnLib::Library::MoveData* move = nullptr;
if (!_library->GetMoveLibrary()->TryGet(moveName, move)) { if (!_library->GetMoveLibrary()->TryGet(moveName, move)) {
throw CreatureException("Invalid Move given: " + moveName.std_str()); throw CreatureException("Invalid Move given: " + moveName.std_str());
} }
if (_attacks.size() >= _library->GetSettings()->GetMaximalMoves()) { if (_attacks.size() >= _library->GetSettings()->GetMaximalMoves()) {
throw CreatureException("This pokemon already has the maximal allowed moves."); throw CreatureException("This pokemon already has the maximal allowed moves.");
} }
Assert(move != nullptr);
_attacks.emplace_back(move, method); _attacks.emplace_back(move, method);
return this; return this;
} }