浏览代码

Implement placeholders for creature banks messages

Ivan Savenko 1 年之前
父节点
当前提交
2ee4e42348
共有 4 个文件被更改,包括 54 次插入8 次删除
  1. 1 1
      config/objects/creatureBanks.json
  2. 1 1
      lib/battle/BattleInfo.cpp
  3. 5 0
      lib/mapObjects/CRewardableObject.cpp
  4. 47 6
      lib/rewardable/Info.cpp

+ 1 - 1
config/objects/creatureBanks.json

@@ -477,7 +477,7 @@
 					},
 					{
 						"message" : 34,
-						"appearChance" : { "min" : 30, "max" : 60 },
+						"appearChance" : { "min" : 60, "max" : 90 },
 						"guards" : [
 							{ "amount" : 4, "type" : "naga" },
 							{ "amount" : 4, "type" : "naga" },

+ 1 - 1
lib/battle/BattleInfo.cpp

@@ -481,11 +481,11 @@ BattleInfo::BattleInfo(const BattleLayout & layout):
 }
 
 BattleInfo::BattleInfo():
+	layout(std::make_unique<BattleLayout>()),
 	round(-1),
 	activeStack(-1),
 	town(nullptr),
 	tile(-1,-1,-1),
-	layout(std::make_unique<BattleLayout>()),
 	battlefieldType(BattleField::NONE),
 	tacticsSide(BattleSide::NONE),
 	tacticDistance(0)

+ 5 - 0
lib/mapObjects/CRewardableObject.cpp

@@ -508,6 +508,11 @@ void CRewardableObject::initializeGuards()
 {
 	clearSlots();
 
+	// Workaround for default creature banks strings that has placeholder for object name
+	// TODO: find better location for this code
+	for (auto & visitInfo : configuration.info)
+		visitInfo.message.replaceRawString(getObjectName());
+
 	for (auto const & visitInfo : configuration.info)
 	{
 		for (auto const & guard : visitInfo.reward.guards)

+ 47 - 6
lib/rewardable/Info.cpp

@@ -266,14 +266,55 @@ void Rewardable::Info::replaceTextPlaceholders(MetaString & target, const Variab
 
 void Rewardable::Info::replaceTextPlaceholders(MetaString & target, const Variables & variables, const VisitInfo & info) const
 {
-	for (const auto & artifact : info.reward.artifacts )
-		target.replaceName(artifact);
+	if (!info.reward.guards.empty())
+	{
+		CreatureID strongest = info.reward.guards.at(0).getId();
+
+		for (const auto & guard : info.reward.guards )
+		{
+			if (strongest.toEntity(VLC)->getFightValue() < guard.getId().toEntity(VLC)->getFightValue())
+				strongest = guard.getId();
+		}
+		target.replaceNamePlural(strongest); // FIXME: use singular if only 1 such unit is in guards
+
+		MetaString loot;
+
+		for (GameResID it : GameResID::ALL_RESOURCES())
+		{
+			if (info.reward.resources[it] != 0)
+			{
+				loot.appendRawString("%d %s");
+				loot.replaceNumber(info.reward.resources[it]);
+				loot.replaceName(it);
+			}
+		}
+
+		for (const auto & artifact : info.reward.artifacts )
+		{
+			loot.appendRawString("%s");
+			loot.replaceName(artifact);
+		}
 
-	for (const auto & spell : info.reward.spells )
-		target.replaceName(spell);
+		for (const auto & spell : info.reward.spells )
+		{
+			target.replaceName(spell);
+		}
 
-	for (const auto & secondary : info.reward.secondary )
-		target.replaceName(secondary.first);
+		for (const auto & secondary : info.reward.secondary )
+			target.replaceName(secondary.first);
+	}
+	else
+	{
+
+		for (const auto & artifact : info.reward.artifacts )
+			target.replaceName(artifact);
+
+		for (const auto & spell : info.reward.spells )
+			target.replaceName(spell);
+
+		for (const auto & secondary : info.reward.secondary )
+			target.replaceName(secondary.first);
+	}
 
 	replaceTextPlaceholders(target, variables);
 }