From 2e860192c7f555acf56bd24e0fa41c5759d55618 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Wed, 20 May 2020 15:18:27 +0200 Subject: [PATCH] Support for blocking a creature from gaining experience, don't give experience when a creature is fainted. --- CInterface/Battling/Creature.cpp | 4 ++-- src/Battling/Library/ExperienceLibrary.cpp | 4 ++++ src/Battling/Models/Creature.cpp | 5 +++-- src/Battling/Models/Creature.hpp | 11 ++++++++--- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CInterface/Battling/Creature.cpp b/CInterface/Battling/Creature.cpp index 146673a..2d0697c 100644 --- a/CInterface/Battling/Creature.cpp +++ b/CInterface/Battling/Creature.cpp @@ -9,10 +9,10 @@ export uint8_t CreatureLib_Creature_Construct(Creature*& out, const BattleLibrar uint32_t experience, uint32_t uid, CreatureLib::Library::Gender gender, uint8_t coloring, const CreatureLib::Library::Item* heldItem, const char* nickname, bool secretTalent, uint8_t talent, - LearnedAttack* attacks[], size_t attacksNum) { + LearnedAttack* attacks[], size_t attacksNum, bool allowedExperienceGain) { Try(auto attacksVec = List(attacks, attacks + attacksNum); out = new Creature(library, species, variant, level, experience, uid, gender, coloring, heldItem, nickname, - CreatureLib::Library::TalentIndex(secretTalent, talent), attacksVec);) + CreatureLib::Library::TalentIndex(secretTalent, talent), attacksVec, allowedExperienceGain);) }; export void CreatureLib_Creature_Destruct(const Creature* p) { delete p; } diff --git a/src/Battling/Library/ExperienceLibrary.cpp b/src/Battling/Library/ExperienceLibrary.cpp index 4dec0ea..0f5637a 100644 --- a/src/Battling/Library/ExperienceLibrary.cpp +++ b/src/Battling/Library/ExperienceLibrary.cpp @@ -6,6 +6,10 @@ void CreatureLib::Battling::ExperienceLibrary::HandleExperienceGain( for (auto opponent : opponents) { if (opponent == nullptr) continue; + if (opponent->IsFainted()) + continue; + if (!opponent->AllowedExperienceGain()) + continue; auto levelDiff = faintedMon->GetLevel() - opponent->GetLevel() + 10; if (levelDiff <= 0) continue; diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index 3c64adc..25d6874 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -10,10 +10,11 @@ Battling::Creature::Creature(const BattleLibrary* library, const Library::Creatu const Library::SpeciesVariant* variant, uint8_t level, uint32_t experience, uint32_t uid, Library::Gender gender, uint8_t coloring, const Library::Item* heldItem, std::string nickname, const Library::TalentIndex& talent, - const List& attacks) + const List& attacks, bool allowedExperienceGain) : _library(library), _species(species), _variant(variant), _level(level), _experience(experience), _uniqueIdentifier(uid), _gender(gender), _coloring(coloring), _heldItem(heldItem), _nickname(std::move(nickname)), - _talentIndex(talent), _hasOverridenTalent(false), _attacks(attacks) { + _talentIndex(talent), _hasOverridenTalent(false), _attacks(attacks), + _allowedExperienceGain(allowedExperienceGain) { AssertNotNull(library) AssertNotNull(species) AssertNotNull(variant) diff --git a/src/Battling/Models/Creature.hpp b/src/Battling/Models/Creature.hpp index 03bd054..fb16db5 100644 --- a/src/Battling/Models/Creature.hpp +++ b/src/Battling/Models/Creature.hpp @@ -54,6 +54,7 @@ namespace CreatureLib::Battling { std::unordered_set _seenOpponents = {}; List _attacks; + bool _allowedExperienceGain; Script* _status = nullptr; ScriptSet _volatile = {}; @@ -65,7 +66,8 @@ namespace CreatureLib::Battling { Creature(const BattleLibrary* library, const Library::CreatureSpecies* species, const Library::SpeciesVariant* variant, uint8_t level, uint32_t experience, uint32_t uid, Library::Gender gender, uint8_t coloring, const Library::Item* heldItem, std::string nickname, - const Library::TalentIndex& talent, const List& attacks); + const Library::TalentIndex& talent, const List& attacks, + bool allowedExperienceGain = true); virtual ~Creature() { for (auto attack : _attacks) { @@ -136,8 +138,11 @@ namespace CreatureLib::Battling { const Library::CreatureSpecies* GetDisplaySpecies() const noexcept; const Library::SpeciesVariant* GetDisplayVariant() const noexcept; - const void SetDisplaySpecies(const Library::CreatureSpecies* species) noexcept { _displaySpecies = species; } - const void SetDisplayVariant(const Library::SpeciesVariant* variant) noexcept { _displayVariant = variant; }; + void SetDisplaySpecies(const Library::CreatureSpecies* species) noexcept { _displaySpecies = species; } + void SetDisplayVariant(const Library::SpeciesVariant* variant) noexcept { _displayVariant = variant; }; + + inline bool AllowedExperienceGain() const noexcept { return _allowedExperienceGain; } + inline void SetAllowedExperienceGain(bool allowed) noexcept { _allowedExperienceGain = allowed; } // region Stat APIs