2
0
Эх сурвалжийг харах

Hnadling of Shrine messages now matches H3

Ivan Savenko 2 жил өмнө
parent
commit
eedaa63f5f

+ 3 - 6
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"
 								}
 							]
 						},

+ 28 - 6
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<Component> 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<Component> CRewardableObject::getPopupComponents(const CGHeroInstanc
 		return {};
 
 	auto rewardIndices = getAvailableRewards(hero, Rewardable::EEventType::EVENT_FIRST_VISIT);
-
 	if (rewardIndices.empty() && !configuration.info.empty())
 		rewardIndices.push_back(0);
 

+ 3 - 0
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<Component> getPopupComponents(PlayerColor player) const override;
 	std::vector<Component> getPopupComponents(const CGHeroInstance * hero) const override;
 

+ 6 - 4
lib/rewardable/Configuration.h

@@ -172,15 +172,17 @@ struct DLL_LINKAGE Configuration
 	
 	template <typename Handler> 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;
 	}
 };

+ 26 - 2
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"]);
 
 }