Support for blocking a creature from gaining experience, don't give experience when a creature is fainted.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-05-20 15:18:27 +02:00
parent 6c40f4291d
commit 2e860192c7
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
4 changed files with 17 additions and 7 deletions

View File

@ -9,10 +9,10 @@ export uint8_t CreatureLib_Creature_Construct(Creature*& out, const BattleLibrar
uint32_t experience, uint32_t uid, CreatureLib::Library::Gender gender, uint32_t experience, uint32_t uid, CreatureLib::Library::Gender gender,
uint8_t coloring, const CreatureLib::Library::Item* heldItem, uint8_t coloring, const CreatureLib::Library::Item* heldItem,
const char* nickname, bool secretTalent, uint8_t talent, const char* nickname, bool secretTalent, uint8_t talent,
LearnedAttack* attacks[], size_t attacksNum) { LearnedAttack* attacks[], size_t attacksNum, bool allowedExperienceGain) {
Try(auto attacksVec = List<LearnedAttack*>(attacks, attacks + attacksNum); Try(auto attacksVec = List<LearnedAttack*>(attacks, attacks + attacksNum);
out = new Creature(library, species, variant, level, experience, uid, gender, coloring, heldItem, nickname, 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; } export void CreatureLib_Creature_Destruct(const Creature* p) { delete p; }

View File

@ -6,6 +6,10 @@ void CreatureLib::Battling::ExperienceLibrary::HandleExperienceGain(
for (auto opponent : opponents) { for (auto opponent : opponents) {
if (opponent == nullptr) if (opponent == nullptr)
continue; continue;
if (opponent->IsFainted())
continue;
if (!opponent->AllowedExperienceGain())
continue;
auto levelDiff = faintedMon->GetLevel() - opponent->GetLevel() + 10; auto levelDiff = faintedMon->GetLevel() - opponent->GetLevel() + 10;
if (levelDiff <= 0) if (levelDiff <= 0)
continue; continue;

View File

@ -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, const Library::SpeciesVariant* variant, uint8_t level, uint32_t experience, uint32_t uid,
Library::Gender gender, uint8_t coloring, const Library::Item* heldItem, Library::Gender gender, uint8_t coloring, const Library::Item* heldItem,
std::string nickname, const Library::TalentIndex& talent, std::string nickname, const Library::TalentIndex& talent,
const List<LearnedAttack*>& attacks) const List<LearnedAttack*>& attacks, bool allowedExperienceGain)
: _library(library), _species(species), _variant(variant), _level(level), _experience(experience), : _library(library), _species(species), _variant(variant), _level(level), _experience(experience),
_uniqueIdentifier(uid), _gender(gender), _coloring(coloring), _heldItem(heldItem), _nickname(std::move(nickname)), _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(library)
AssertNotNull(species) AssertNotNull(species)
AssertNotNull(variant) AssertNotNull(variant)

View File

@ -54,6 +54,7 @@ namespace CreatureLib::Battling {
std::unordered_set<Creature*> _seenOpponents = {}; std::unordered_set<Creature*> _seenOpponents = {};
List<LearnedAttack*> _attacks; List<LearnedAttack*> _attacks;
bool _allowedExperienceGain;
Script* _status = nullptr; Script* _status = nullptr;
ScriptSet _volatile = {}; ScriptSet _volatile = {};
@ -65,7 +66,8 @@ namespace CreatureLib::Battling {
Creature(const BattleLibrary* library, const Library::CreatureSpecies* species, Creature(const BattleLibrary* library, const Library::CreatureSpecies* species,
const Library::SpeciesVariant* variant, uint8_t level, uint32_t experience, uint32_t uid, 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, Library::Gender gender, uint8_t coloring, const Library::Item* heldItem, std::string nickname,
const Library::TalentIndex& talent, const List<LearnedAttack*>& attacks); const Library::TalentIndex& talent, const List<LearnedAttack*>& attacks,
bool allowedExperienceGain = true);
virtual ~Creature() { virtual ~Creature() {
for (auto attack : _attacks) { for (auto attack : _attacks) {
@ -136,8 +138,11 @@ namespace CreatureLib::Battling {
const Library::CreatureSpecies* GetDisplaySpecies() const noexcept; const Library::CreatureSpecies* GetDisplaySpecies() const noexcept;
const Library::SpeciesVariant* GetDisplayVariant() const noexcept; const Library::SpeciesVariant* GetDisplayVariant() const noexcept;
const void SetDisplaySpecies(const Library::CreatureSpecies* species) noexcept { _displaySpecies = species; } void SetDisplaySpecies(const Library::CreatureSpecies* species) noexcept { _displaySpecies = species; }
const void SetDisplayVariant(const Library::SpeciesVariant* variant) noexcept { _displayVariant = variant; }; 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 // region Stat APIs