From 6859ab7c36a534b5172fed05805a3cbc1e0a9780 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Fri, 9 May 2025 17:26:23 +0300 Subject: [PATCH] Fix discovered issues, remove not implemented ideas --- lib/mapObjects/CRewardableObject.cpp | 5 +++-- lib/rewardable/Configuration.h | 5 ----- lib/rewardable/Info.cpp | 8 +++++++- lib/rewardable/Interface.cpp | 13 ++++++------- lib/rewardable/Limiter.cpp | 21 +++++++++++++-------- lib/rewardable/Limiter.h | 4 ++++ 6 files changed, 33 insertions(+), 23 deletions(-) diff --git a/lib/mapObjects/CRewardableObject.cpp b/lib/mapObjects/CRewardableObject.cpp index a61df96be..8450ef3a9 100644 --- a/lib/mapObjects/CRewardableObject.cpp +++ b/lib/mapObjects/CRewardableObject.cpp @@ -53,9 +53,10 @@ void CRewardableObject::onHeroVisit(const CGHeroInstance *hero) const } if (!isGuarded()) + { doHeroVisit(hero); - - if (configuration.forceCombat) + } + else if (configuration.forceCombat) { doStartBattle(hero); } diff --git a/lib/rewardable/Configuration.h b/lib/rewardable/Configuration.h index 6d4586505..59d065356 100644 --- a/lib/rewardable/Configuration.h +++ b/lib/rewardable/Configuration.h @@ -71,9 +71,6 @@ struct DLL_LINKAGE ResetInfo /// if true - re-randomize rewards on a new week bool rewards; - /// Reset object after visit by a hero, whether hero accepted reward or not - bool resetAfterVisit = false; - void serializeJson(JsonSerializeFormat & handler); template void serialize(Handler &h) @@ -81,8 +78,6 @@ struct DLL_LINKAGE ResetInfo h & period; h & visitors; h & rewards; - if (h.version >= Handler::Version::REWARDABLE_EXTENSIONS) - h & resetAfterVisit; } }; diff --git a/lib/rewardable/Info.cpp b/lib/rewardable/Info.cpp index c0516125d..57332ef6f 100644 --- a/lib/rewardable/Info.cpp +++ b/lib/rewardable/Info.cpp @@ -134,6 +134,8 @@ void Rewardable::Info::configureLimiter(Rewardable::Configuration & object, vstd limiter.heroExperience = randomizer.loadValue(source["heroExperience"], rng, variables); limiter.heroLevel = randomizer.loadValue(source["heroLevel"], rng, variables); limiter.canLearnSkills = source["canLearnSkills"].Bool(); + limiter.commanderAlive = source["commanderAlive"].Bool(); + limiter.hasExtraCreatures = source["hasExtraCreatures"].Bool(); limiter.manaPercentage = randomizer.loadValue(source["manaPercentage"], rng, variables); limiter.manaPoints = randomizer.loadValue(source["manaPoints"], rng, variables); @@ -143,9 +145,12 @@ void Rewardable::Info::configureLimiter(Rewardable::Configuration & object, vstd limiter.primary = randomizer.loadPrimaries(source["primary"], rng, variables); limiter.secondary = randomizer.loadSecondaries(source["secondary"], rng, variables); limiter.artifacts = randomizer.loadArtifacts(source["artifacts"], rng, variables); + limiter.availableSlots = randomizer.loadArtifactSlots(source["availableSlots"], rng, variables); limiter.spells = randomizer.loadSpells(source["spells"], rng, variables); + limiter.scrolls = randomizer.loadSpells(source["scrolls"], rng, variables); limiter.canLearnSpells = randomizer.loadSpells(source["canLearnSpells"], rng, variables); limiter.creatures = randomizer.loadCreatures(source["creatures"], rng, variables); + limiter.canReceiveCreatures = randomizer.loadCreatures(source["canReceiveCreatures"], rng, variables); limiter.players = randomizer.loadColors(source["colors"], rng, variables); limiter.heroes = randomizer.loadHeroes(source["heroes"], rng); @@ -185,11 +190,12 @@ void Rewardable::Info::configureReward(Rewardable::Configuration & object, vstd: reward.grantedArtifacts = randomizer.loadArtifacts(source["artifacts"], rng, variables); reward.takenArtifacts = randomizer.loadArtifacts(source["takenArtifacts"], rng, variables); - reward.takenArtifactSlots = randomizer.loadArtifactSlots(source["takenArtifactsSlots"], rng, variables); + reward.takenArtifactSlots = randomizer.loadArtifactSlots(source["takenArtifactSlots"], rng, variables); reward.grantedScrolls = randomizer.loadSpells(source["scrolls"], rng, variables); reward.takenScrolls = randomizer.loadSpells(source["takenScrolls"], rng, variables); reward.spells = randomizer.loadSpells(source["spells"], rng, variables); reward.creatures = randomizer.loadCreatures(source["creatures"], rng, variables); + reward.takenCreatures = randomizer.loadCreatures(source["takenCreatures"], rng, variables); if(!source["spellCast"].isNull() && source["spellCast"].isStruct()) { reward.spellCast.first = randomizer.loadSpell(source["spellCast"]["spell"], rng, variables); diff --git a/lib/rewardable/Interface.cpp b/lib/rewardable/Interface.cpp index d9ebbb691..8dd77da1e 100644 --- a/lib/rewardable/Interface.cpp +++ b/lib/rewardable/Interface.cpp @@ -172,9 +172,6 @@ void Rewardable::Interface::grantRewardAfterLevelup(const Rewardable::VisitInfo cb->giveHeroBonus(&gb); } - for(const ArtifactID & art : info.reward.grantedArtifacts) - cb->giveHeroNewArtifact(hero, art, ArtifactPosition::FIRST_AVAILABLE); - for(const ArtifactID & art : info.reward.takenArtifacts) { // hero does not have such artifact alone, but he might have it as part of assembled artifact @@ -203,16 +200,18 @@ void Rewardable::Interface::grantRewardAfterLevelup(const Rewardable::VisitInfo // TODO: handle locked slots? } - for(const SpellID & spell : info.reward.grantedScrolls) - cb->giveHeroNewScroll(hero, spell, ArtifactPosition::FIRST_AVAILABLE); - - for(const SpellID & spell : info.reward.takenScrolls) { if(hero->hasScroll(spell, false)) cb->removeArtifact(ArtifactLocation(hero->id, hero->getScrollPos(spell, false))); } + for(const ArtifactID & art : info.reward.grantedArtifacts) + cb->giveHeroNewArtifact(hero, art, ArtifactPosition::FIRST_AVAILABLE); + + for(const SpellID & spell : info.reward.grantedScrolls) + cb->giveHeroNewScroll(hero, spell, ArtifactPosition::FIRST_AVAILABLE); + if(!info.reward.spells.empty()) { std::set spellsToGive; diff --git a/lib/rewardable/Limiter.cpp b/lib/rewardable/Limiter.cpp index 429f2ced1..7a4886201 100644 --- a/lib/rewardable/Limiter.cpp +++ b/lib/rewardable/Limiter.cpp @@ -42,20 +42,25 @@ bool operator==(const Rewardable::Limiter & l, const Rewardable::Limiter & r) { return l.dayOfWeek == r.dayOfWeek && l.daysPassed == r.daysPassed - && l.heroLevel == r.heroLevel && l.heroExperience == r.heroExperience + && l.heroLevel == r.heroLevel && l.manaPoints == r.manaPoints && l.manaPercentage == r.manaPercentage - && l.secondary == r.secondary && l.canLearnSkills == r.canLearnSkills - && l.creatures == r.creatures - && l.spells == r.spells - && l.artifacts == r.artifacts - && l.players == r.players - && l.heroes == r.heroes - && l.heroClasses == r.heroClasses + && l.commanderAlive == r.commanderAlive + && l.hasExtraCreatures == r.hasExtraCreatures && l.resources == r.resources && l.primary == r.primary + && l.secondary == r.secondary + && l.artifacts == r.artifacts + && l.availableSlots == r.availableSlots + && l.scrolls == r.scrolls + && l.spells == r.spells + && l.canLearnSpells == r.canLearnSpells + && l.creatures == r.creatures + && l.heroes == r.heroes + && l.heroClasses == r.heroClasses + && l.players == r.players && l.noneOf == r.noneOf && l.allOf == r.allOf && l.anyOf == r.anyOf; diff --git a/lib/rewardable/Limiter.h b/lib/rewardable/Limiter.h index 8948a0202..9e1682aa6 100644 --- a/lib/rewardable/Limiter.h +++ b/lib/rewardable/Limiter.h @@ -135,6 +135,10 @@ struct DLL_LINKAGE Limiter final : public Serializeable h & spells; h & canLearnSpells; h & creatures; + if (h.version >= Handler::Version::REWARDABLE_EXTENSIONS) + { + h & canReceiveCreatures; + } h & heroes; h & heroClasses; h & players;