From eedaa63f5f6936b79f80908e3b1c604b3cd6bb75 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Tue, 17 Oct 2023 16:35:34 +0300 Subject: [PATCH] Hnadling of Shrine messages now matches H3 --- config/objects/rewardableShrine.json | 9 +++----- lib/mapObjects/CRewardableObject.cpp | 34 +++++++++++++++++++++++----- lib/mapObjects/CRewardableObject.h | 3 +++ lib/rewardable/Configuration.h | 10 ++++---- lib/rewardable/Info.cpp | 28 +++++++++++++++++++++-- 5 files changed, 66 insertions(+), 18 deletions(-) diff --git a/config/objects/rewardableShrine.json b/config/objects/rewardableShrine.json index 1cec9655a..5bfc9de26 100644 --- a/config/objects/rewardableShrine.json +++ b/config/objects/rewardableShrine.json @@ -20,7 +20,6 @@ "visitMode" : "limiter", "visitedTooltip" : 354, - "description" : "(Learn 1st level spell)", "variables" : { "spell" : { @@ -54,7 +53,7 @@ "limiter" : { "artifacts" : [ { - "type" : "spellbook" + "type" : "spellBook" } ] }, @@ -88,7 +87,6 @@ "visitMode" : "limiter", "visitedTooltip" : 354, - "description" : "(Learn 2nd level spell)", "variables" : { "spell" : { @@ -122,7 +120,7 @@ "limiter" : { "artifacts" : [ { - "type" : "spellbook" + "type" : "spellBook" } ] }, @@ -156,7 +154,6 @@ "visitMode" : "limiter", "visitedTooltip" : 354, - "description" : "(Learn 3rd level spell)", "variables" : { "spell" : { @@ -190,7 +187,7 @@ "limiter" : { "artifacts" : [ { - "type" : "spellbook" + "type" : "spellBook" } ] }, diff --git a/lib/mapObjects/CRewardableObject.cpp b/lib/mapObjects/CRewardableObject.cpp index f59a0ac68..2780e0d2d 100644 --- a/lib/mapObjects/CRewardableObject.cpp +++ b/lib/mapObjects/CRewardableObject.cpp @@ -242,8 +242,8 @@ std::string CRewardableObject::getHoverText(PlayerColor player) const { std::string result = getObjectName(); - if (!configuration.description.empty()) - result += "\n" + configuration.description.toString(); + if (!getDescriptionMessage(player).empty()) + result += "\n" + getDescriptionMessage(player); if(configuration.visitMode == Rewardable::VISIT_PLAYER || configuration.visitMode == Rewardable::VISIT_ONCE) { @@ -259,8 +259,8 @@ std::string CRewardableObject::getHoverText(const CGHeroInstance * hero) const { std::string result = getObjectName(); - if (!configuration.description.empty()) - result += "\n" + configuration.description.toString(); + if (!getDescriptionMessage(hero).empty()) + result += "\n" + getDescriptionMessage(hero); if(configuration.visitMode != Rewardable::VISIT_UNLIMITED) { @@ -272,13 +272,36 @@ std::string CRewardableObject::getHoverText(const CGHeroInstance * hero) const return result; } +std::string CRewardableObject::getDescriptionMessage(PlayerColor player) const +{ + if (!wasScouted(player) || configuration.info.empty()) + return configuration.description.toString(); + + auto rewardIndices = getAvailableRewards(nullptr, Rewardable::EEventType::EVENT_FIRST_VISIT); + if (rewardIndices.empty()) + return configuration.info[0].description.toString(); + + return configuration.info[rewardIndices.front()].description.toString(); +} + +std::string CRewardableObject::getDescriptionMessage(const CGHeroInstance * hero) const +{ + if (!wasScouted(hero->getOwner()) || configuration.info.empty()) + return configuration.description.toString(); + + auto rewardIndices = getAvailableRewards(hero, Rewardable::EEventType::EVENT_FIRST_VISIT); + if (rewardIndices.empty()) + return configuration.info[0].description.toString(); + + return configuration.info[rewardIndices.front()].description.toString(); +} + std::vector CRewardableObject::getPopupComponents(PlayerColor player) const { if (!wasScouted(player)) return {}; auto rewardIndices = getAvailableRewards(nullptr, Rewardable::EEventType::EVENT_FIRST_VISIT); - if (rewardIndices.empty() && !configuration.info.empty()) rewardIndices.push_back(0); @@ -294,7 +317,6 @@ std::vector CRewardableObject::getPopupComponents(const CGHeroInstanc return {}; auto rewardIndices = getAvailableRewards(hero, Rewardable::EEventType::EVENT_FIRST_VISIT); - if (rewardIndices.empty() && !configuration.info.empty()) rewardIndices.push_back(0); diff --git a/lib/mapObjects/CRewardableObject.h b/lib/mapObjects/CRewardableObject.h index 725b869ef..45134a125 100644 --- a/lib/mapObjects/CRewardableObject.h +++ b/lib/mapObjects/CRewardableObject.h @@ -68,6 +68,9 @@ public: std::string getHoverText(PlayerColor player) const override; std::string getHoverText(const CGHeroInstance * hero) const override; + std::string getDescriptionMessage(PlayerColor player) const; + std::string getDescriptionMessage(const CGHeroInstance * hero) const; + std::vector getPopupComponents(PlayerColor player) const override; std::vector getPopupComponents(const CGHeroInstance * hero) const override; diff --git a/lib/rewardable/Configuration.h b/lib/rewardable/Configuration.h index 3d80591ba..2fb901651 100644 --- a/lib/rewardable/Configuration.h +++ b/lib/rewardable/Configuration.h @@ -172,15 +172,17 @@ struct DLL_LINKAGE Configuration template void serialize(Handler &h, const int version) { - h & info; - h & canRefuse; - h & resetParameters; h & onSelect; h & description; h & notVisitedTooltip; h & visitedTooltip; - h & visitMode; + h & info; h & selectMode; + h & visitMode; + h & resetParameters; + h & variables; + h & visitLimiter; + h & canRefuse; h & infoWindowType; } }; diff --git a/lib/rewardable/Info.cpp b/lib/rewardable/Info.cpp index 979c89405..bd1b73de2 100644 --- a/lib/rewardable/Info.cpp +++ b/lib/rewardable/Info.cpp @@ -293,13 +293,28 @@ void Rewardable::Info::configureRewards( info.visitType = event; info.message = loadMessage(reward["message"], TextIdentifier(objectTextID, modeName, i)); - info.description = loadMessage(reward["description"], TextIdentifier(objectTextID, "description", modeName, i)); + info.description = loadMessage(reward["description"], TextIdentifier(objectTextID, "description", modeName, i), EMetaText::GENERAL_TXT); for (const auto & artifact : info.reward.artifacts ) + { info.message.replaceLocalString(EMetaText::ART_NAMES, artifact.getNum()); + info.description.replaceLocalString(EMetaText::ART_NAMES, artifact.getNum()); + } for (const auto & artifact : info.reward.spells ) + { info.message.replaceLocalString(EMetaText::SPELL_NAME, artifact.getNum()); + info.description.replaceLocalString(EMetaText::SPELL_NAME, artifact.getNum()); + } + + for (const auto & variable : object.variables.values ) + { + if( boost::algorithm::starts_with(variable.first, "spell")) + { + info.message.replaceLocalString(EMetaText::SPELL_NAME, variable.second); + info.description.replaceLocalString(EMetaText::SPELL_NAME, variable.second); + } + } object.info.push_back(info); } @@ -331,6 +346,10 @@ void Rewardable::Info::configureObject(Rewardable::Configuration & object, CRand Rewardable::VisitInfo onVisited; onVisited.visitType = Rewardable::EEventType::EVENT_ALREADY_VISITED; onVisited.message = loadMessage(parameters["onVisitedMessage"], TextIdentifier(objectTextID, "onVisited")); + for (const auto & variable : object.variables.values ) + if( boost::algorithm::starts_with(variable.first, "spell")) + onVisited.message.replaceLocalString(EMetaText::SPELL_NAME, variable.second); + object.info.push_back(onVisited); } @@ -339,6 +358,10 @@ void Rewardable::Info::configureObject(Rewardable::Configuration & object, CRand Rewardable::VisitInfo onEmpty; onEmpty.visitType = Rewardable::EEventType::EVENT_NOT_AVAILABLE; onEmpty.message = loadMessage(parameters["onEmptyMessage"], TextIdentifier(objectTextID, "onEmpty")); + for (const auto & variable : object.variables.values ) + if( boost::algorithm::starts_with(variable.first, "spell")) + onEmpty.message.replaceLocalString(EMetaText::SPELL_NAME, variable.second); + object.info.push_back(onEmpty); } @@ -371,7 +394,8 @@ void Rewardable::Info::configureObject(Rewardable::Configuration & object, CRand } } - configureLimiter(object, rng, object.visitLimiter, parameters["visitLimiter"]); + if (object.visitMode == Rewardable::VISIT_LIMITER) + configureLimiter(object, rng, object.visitLimiter, parameters["visitLimiter"]); }