Defensive programming.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -21,7 +21,11 @@ namespace PkmnLib::Battling {
|
||||
|
||||
void SetWeather(const ArbUt::StringView& name);
|
||||
void ClearWeather();
|
||||
const ArbUt::StringView& GetWeatherName() noexcept { return _weatherScript->GetName(); }
|
||||
const ArbUt::StringView& GetWeatherName() noexcept {
|
||||
if (_weatherScript == nullptr)
|
||||
return ArbUt::StringView::EmptyString();
|
||||
return _weatherScript->GetName();
|
||||
}
|
||||
|
||||
size_t ScriptCount() const override { return CreatureLib::Battling::Battle::ScriptCount() + 1; }
|
||||
void GetActiveScripts(ArbUt::List<CreatureLib::Battling::ScriptWrapper>& scripts) override {
|
||||
|
||||
@@ -20,12 +20,15 @@ void PkmnLib::Battling::ExperienceLibrary::HandleExperienceGain(
|
||||
const std::unordered_set<ArbUt::BorrowedPtr<CreatureLib::Battling::Creature>>& opponents) const {
|
||||
|
||||
auto fainted = dynamic_cast<Pokemon*>(faintedMon);
|
||||
auto expGain = fainted->GetForme()->GetBaseExperience();
|
||||
AssertNotNull(fainted);
|
||||
auto& forme = fainted->GetForme();
|
||||
AssertNotNull(forme);
|
||||
auto expGain = forme->GetBaseExperience();
|
||||
auto level = fainted->GetLevel();
|
||||
|
||||
float v1 = (expGain * level) / 5;
|
||||
|
||||
for (auto op : opponents) {
|
||||
for (const auto& op : opponents) {
|
||||
if (!op->AllowedExperienceGain())
|
||||
continue;
|
||||
auto experienceGain = CalculateDynamicExperience(level, v1, op, fainted);
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace PkmnLib::Battling {
|
||||
_friendship(species->GetBaseHappiness()) {}
|
||||
|
||||
const ArbUt::BorrowedPtr<const Library::PokemonForme> GetForme() const {
|
||||
return _variant.As<const Library::PokemonForme>();
|
||||
return _variant.ForceAs<const Library::PokemonForme>();
|
||||
}
|
||||
|
||||
inline bool IsShiny() const noexcept { return _coloring == 1; }
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "../Moves/MoveData.hpp"
|
||||
|
||||
namespace PkmnLib::Library {
|
||||
class LearnableMoves : CreatureLib::Library::LearnableAttacks {
|
||||
class LearnableMoves : public CreatureLib::Library::LearnableAttacks {
|
||||
ArbUt::List<ArbUt::BorrowedPtr<const MoveData>> _eggMoves;
|
||||
|
||||
public:
|
||||
|
||||
@@ -5,7 +5,6 @@ PkmnLib::Library::PokemonForme::PokemonForme(const ArbUt::StringView& name, floa
|
||||
CreatureLib::Library::StatisticSet<uint16_t> baseStats,
|
||||
const ArbUt::List<ArbUt::StringView>& talents,
|
||||
const ArbUt::List<ArbUt::StringView>& secretTalents,
|
||||
const CreatureLib::Library::LearnableAttacks* attacks,
|
||||
std::unordered_set<uint32_t> flags)
|
||||
: SpeciesVariant(name, height, weight, baseExperience, types, baseStats, talents, secretTalents, attacks,
|
||||
const LearnableMoves* moves, std::unordered_set<uint32_t> flags)
|
||||
: SpeciesVariant(name, height, weight, baseExperience, types, baseStats, talents, secretTalents, moves,
|
||||
std::move(flags)) {}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <CreatureLib/Library/CreatureData/SpeciesVariant.hpp>
|
||||
#include <cstdint>
|
||||
#include "LearnableMoves.hpp"
|
||||
|
||||
namespace PkmnLib::Library {
|
||||
class PokemonForme : public CreatureLib::Library::SpeciesVariant {
|
||||
@@ -10,7 +11,7 @@ namespace PkmnLib::Library {
|
||||
PokemonForme(const ArbUt::StringView& name, float height, float weight, uint32_t baseExperience,
|
||||
const ArbUt::List<uint8_t>& types, CreatureLib::Library::StatisticSet<uint16_t> baseStats,
|
||||
const ArbUt::List<ArbUt::StringView>& talents, const ArbUt::List<ArbUt::StringView>& secretTalents,
|
||||
const CreatureLib::Library::LearnableAttacks* attacks, std::unordered_set<uint32_t> flags = {});
|
||||
const LearnableMoves* moves, std::unordered_set<uint32_t> flags = {});
|
||||
|
||||
private:
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user