浏览代码

Implemented "changeCreatures" option for Stables

Ivan Savenko 2 年之前
父节点
当前提交
c9dcb921ab

+ 12 - 2
config/objects/rewardableBonusing.json

@@ -313,16 +313,26 @@
 					"rarity"	: 40
 				},
 				
-				"onVisitedMessage" : 136,
+				"onVisitedMessage" : 136, // TODO: alternative message with Cavalier -> Champions upgrade & text ID 139
 				"visitMode" : "bonus",
 				"selectMode" : "selectFirst",
 				"rewards" : [
+					{
+						"limiter" : {
+							"creatures" : [ { "type" : "cavalier", "amount" : 1 } ],
+						},
+						"message" : 138,
+						"movePoints" : 400,
+						"bonuses" : [ { "type" : "LAND_MOVEMENT", "val" : 400, "duration" : "ONE_WEEK"} ],
+						"changeCreatures" : {
+							"cavalier" : "champion"
+						}
+					},
 					{
 						"message" : 137,
 						"movePoints" : 400,
 						"bonuses" : [ { "type" : "LAND_MOVEMENT", "val" : 400, "duration" : "ONE_WEEK"} ]
 					}
-					// TODO: 2nd reward with Cavalier -> Champions upgrade & text ID 138
 				]
 			}
 		}

+ 11 - 0
lib/mapObjects/CRewardableConstructor.cpp

@@ -13,6 +13,7 @@
 #include "../CRandomGenerator.h"
 #include "../StringConstants.h"
 #include "../CCreatureHandler.h"
+#include "../CModHandler.h"
 #include "JsonRandom.h"
 #include "../IGameCallback.h"
 
@@ -117,6 +118,16 @@ void CRandomRewardObjectInfo::configureReward(CRewardableObject * object, CRando
 	reward.artifacts = JsonRandom::loadArtifacts(source["artifacts"], rng);
 	reward.spells = JsonRandom::loadSpells(source["spells"], rng, spells);
 	reward.creatures = JsonRandom::loadCreatures(source["creatures"], rng);
+
+	for ( auto node : source["changeCreatures"].Struct() )
+	{
+		CreatureID from (VLC->modh->identifiers.getIdentifier (node.second.meta, "creature", node.first) .get());
+		CreatureID dest (VLC->modh->identifiers.getIdentifier (node.second.meta, "creature", node.second.String()).get());
+
+		reward.extraComponents.push_back(Component(Component::CREATURE, dest.getNum(), 0, 0));
+
+		reward.creaturesChange[from] = dest;
+	}
 }
 
 void CRandomRewardObjectInfo::configureResetInfo(CRewardableObject * object, CRandomGenerator & rng, CRewardResetInfo & resetParameters, const JsonNode & source) const

+ 18 - 0
lib/mapObjects/CRewardableObject.cpp

@@ -337,6 +337,24 @@ void CRewardableObject::grantRewardAfterLevelup(const CRewardVisitInfo & info, c
 		cb->changeSpells(hero, true, spellsToGive);
 	}
 
+	if(!info.reward.creaturesChange.empty())
+	{
+		for (auto slot : hero->Slots())
+		{
+			const CStackInstance * heroStack = slot.second;
+
+			for (auto & change : info.reward.creaturesChange)
+			{
+				if (heroStack->type->getId() == change.first)
+				{
+					StackLocation location(hero, slot.first);
+					cb->changeStackType(location, change.second.toCreature());
+					break;
+				}
+			}
+		}
+	}
+
 	if(!info.reward.creatures.empty())
 	{
 		CCreatureSet creatures;

+ 4 - 0
lib/mapObjects/CRewardableObject.h

@@ -153,6 +153,9 @@ public:
 	std::vector<si32> primary;
 	std::map<SecondarySkill, si32> secondary;
 
+	/// creatures that will be changed in hero's army
+	std::map<CreatureID, CreatureID> creaturesChange;
+
 	/// objects that hero may receive
 	std::vector<ArtifactID> artifacts;
 	std::vector<SpellID> spells;
@@ -198,6 +201,7 @@ public:
 		h & artifacts;
 		h & spells;
 		h & creatures;
+		h & creaturesChange;
 	}
 };
 

+ 1 - 1
lib/mapObjects/JsonRandom.cpp

@@ -32,7 +32,7 @@ namespace JsonRandom
 		if (value.isNumber())
 			return static_cast<si32>(value.Float());
 		if (!value["amount"].isNull())
-			return static_cast<si32>(loadValue(value, rng, defaultValue));
+			return static_cast<si32>(loadValue(value["amount"], rng, defaultValue));
 		si32 min = static_cast<si32>(value["min"].Float());
 		si32 max = static_cast<si32>(value["max"].Float());
 		return rng.getIntRange(min, max)();