Browse Source

convert spec format in afterLoadFinalization

Henning Koehler 8 năm trước cách đây
mục cha
commit
c31950612c
3 tập tin đã thay đổi với 27 bổ sung12 xóa
  1. 25 10
      lib/CHeroHandler.cpp
  2. 1 0
      lib/CHeroHandler.h
  3. 1 2
      lib/HeroBonus.cpp

+ 25 - 10
lib/CHeroHandler.cpp

@@ -548,24 +548,17 @@ void CHeroHandler::loadHeroSpecialty(CHero * hero, const JsonNode & node)
 	const JsonNode & specialties = node["specialties"];
 	if (!specialties.isNull())
 	{
-		logMod->warn("Hero %s has deprecated specialties format. New format:", hero->identifier);
-		JsonNode specVec(JsonNode::JsonType::DATA_VECTOR);
+		logMod->warn("Hero %s has deprecated specialties format.", hero->identifier);
 		for(const JsonNode &specialty : node["specialties"].Vector())
 		{
 			SSpecialtyInfo spec;
-
 			spec.type = specialty["type"].Float();
 			spec.val = specialty["val"].Float();
 			spec.subtype = specialty["subtype"].Float();
 			spec.additionalinfo = specialty["info"].Float();
-
-			for(std::shared_ptr<Bonus> bonus : SpecialtyInfoToBonuses(spec, sid))
-			{
-				hero->specialty.push_back(bonus);
-				specVec.Vector().push_back(bonus->toJsonNode());
-			}
+			//we convert after loading completes, to have all identifiers for json logging
+			hero->specDeprecated.push_back(spec);
 		}
-		logMod->info("\"specialty\" = %s", specVec.toJson());
 	}
 	//new format, using bonus system
 	for(const JsonNode & specialty : node["specialty"].Vector())
@@ -737,6 +730,28 @@ void CHeroHandler::loadObject(std::string scope, std::string name, const JsonNod
 	VLC->modh->identifiers.registerObject(scope, "hero", name, object->ID.getNum());
 }
 
+void CHeroHandler::afterLoadFinalization()
+{
+	for(ConstTransitivePtr<CHero> hero : heroes)
+	{
+		if(hero->specDeprecated.size() > 0)
+		{
+			logMod->debug("Converting specialties format for hero %s(%s)", hero->identifier, VLC->townh->encodeFaction(hero->heroClass->faction));
+			JsonNode specVec(JsonNode::JsonType::DATA_VECTOR);
+			for(const SSpecialtyInfo & spec : hero->specDeprecated)
+			{
+				for(std::shared_ptr<Bonus> bonus : SpecialtyInfoToBonuses(spec, hero->ID.getNum()))
+				{
+					hero->specialty.push_back(bonus);
+					specVec.Vector().push_back(bonus->toJsonNode());
+				}
+			}
+			hero->specDeprecated.clear();
+			logMod->trace("\"specialty\" = %s", specVec.toJson());
+		}
+	}
+}
+
 ui32 CHeroHandler::level (ui64 experience) const
 {
 	return boost::range::upper_bound(expPerLevel, experience) - std::begin(expPerLevel);

+ 1 - 0
lib/CHeroHandler.h

@@ -302,6 +302,7 @@ public:
 
 	void loadObject(std::string scope, std::string name, const JsonNode & data) override;
 	void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override;
+	void afterLoadFinalization() override;
 
 	CHeroHandler();
 	~CHeroHandler();

+ 1 - 2
lib/HeroBonus.cpp

@@ -1177,8 +1177,7 @@ JsonNode subtypeToJson(Bonus::BonusType type, int subtype)
 	case Bonus::SPECIAL_BLESS_DAMAGE:
 	case Bonus::MAXED_SPELL:
 	case Bonus::SPECIAL_PECULIAR_ENCHANT:
-		//return JsonUtils::stringNode((*VLC->spellh)[SpellID::ESpellID(subtype)]->identifier);
-		return JsonUtils::intNode(subtype); //Issue 2790
+		return JsonUtils::stringNode((*VLC->spellh)[SpellID::ESpellID(subtype)]->identifier);
 	case Bonus::SPECIAL_UPGRADE:
 		return JsonUtils::stringNode(CreatureID::encode(subtype));
 	case Bonus::GENERATE_RESOURCE: