浏览代码

improved/fixed specialty json encoding

Henning Koehler 8 年之前
父节点
当前提交
26862b4c51
共有 3 个文件被更改,包括 32 次插入15 次删除
  1. 1 1
      lib/CHeroHandler.cpp
  2. 30 13
      lib/HeroBonus.cpp
  3. 1 1
      lib/HeroBonus.h

+ 1 - 1
lib/CHeroHandler.cpp

@@ -549,7 +549,7 @@ void CHeroHandler::loadHeroSpecialty(CHero * hero, const JsonNode & node)
 	if (!specialties.isNull())
 	{
 		logMod->warn("Hero %s has deprecated specialties format. New format:", hero->identifier);
-		JsonNode specVec(JsonNode::DATA_VECTOR);
+		JsonNode specVec(JsonNode::JsonType::DATA_VECTOR);
 		for(const JsonNode &specialty : node["specialties"].Vector())
 		{
 			SSpecialtyInfo spec;

+ 30 - 13
lib/HeroBonus.cpp

@@ -1166,31 +1166,48 @@ std::string Bonus::Description() const
 
 JsonNode subtypeToJson(Bonus::BonusType type, int subtype)
 {
-	JsonNode node;
-
 	switch(type)
 	{
 	case Bonus::PRIMARY_SKILL:
-		node.String() = PrimarySkill::names[subtype];
-		break;
+		return JsonUtils::stringNode(PrimarySkill::names[subtype]);
 	case Bonus::SECONDARY_SKILL_PREMY:
-		node.String() = NSecondarySkill::names[subtype];
-		break;
+		return JsonUtils::stringNode(NSecondarySkill::names[subtype]);
+	case Bonus::SPECIAL_SPELL_LEV:
+	case Bonus::SPECIFIC_SPELL_DAMAGE:
+	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
+	case Bonus::SPECIAL_UPGRADE:
+		return JsonUtils::stringNode(CreatureID::encode(subtype));
+	case Bonus::GENERATE_RESOURCE:
+		return JsonUtils::stringNode(GameConstants::RESOURCE_NAMES[subtype]);
 	default:
-		node.Integer() = subtype;
-		break;
+		return JsonUtils::intNode(subtype);
 	}
+}
 
-	return node;
+JsonNode additionalInfoToJson(Bonus::BonusType type, int addInfo)
+{
+	switch(type)
+	{
+	case Bonus::SPECIAL_UPGRADE:
+		return JsonUtils::stringNode(CreatureID::encode(addInfo));
+	default:
+		return JsonUtils::intNode(addInfo);
+	}
 }
 
 JsonNode Bonus::toJsonNode() const
 {
-	JsonNode root(JsonNode::DATA_STRUCT);
+	JsonNode root(JsonNode::JsonType::DATA_STRUCT);
 
 	root["type"].String() = vstd::findKey(bonusNameMap, type);
 	if(subtype != -1)
 		root["subtype"] = subtypeToJson(type, subtype);
+	if(additionalInfo != -1)
+		root["addInfo"] = additionalInfoToJson(type, additionalInfo);
 	if(val != 0)
 		root["val"].Integer() = val;
 	if(valType != ADDITIVE_VALUE)
@@ -1413,7 +1430,7 @@ std::string ILimiter::toString() const
 
 JsonNode ILimiter::toJsonNode() const
 {
-	JsonNode root(JsonNode::DATA_STRUCT);
+	JsonNode root(JsonNode::JsonType::DATA_STRUCT);
 	root["type"].String() = toString();
 	return root;
 }
@@ -1454,7 +1471,7 @@ std::string CCreatureTypeLimiter::toString() const
 
 JsonNode CCreatureTypeLimiter::toJsonNode() const
 {
-	JsonNode root(JsonNode::DATA_STRUCT);
+	JsonNode root(JsonNode::JsonType::DATA_STRUCT);
 
 	root["type"].String() = "CREATURE_TYPE_LIMITER";
 	root["parameters"].Vector().push_back(JsonUtils::stringNode(creature->identifier));
@@ -1692,7 +1709,7 @@ std::string ScalingUpdater::toString() const
 
 JsonNode ScalingUpdater::toJsonNode() const
 {
-	JsonNode root(JsonNode::DATA_STRUCT);
+	JsonNode root(JsonNode::JsonType::DATA_STRUCT);
 
 	root["type"].String() = "GROWS_WITH_LEVEL";
 	root["parameters"].Vector().push_back(JsonUtils::intNode(valPer20));

+ 1 - 1
lib/HeroBonus.h

@@ -214,7 +214,7 @@ private:
 	BONUS_NAME(SPECIAL_BLESS_DAMAGE) /*val = spell (bless), additionalInfo = value per level in percent*/\
 	BONUS_NAME(MAXED_SPELL) /*val = id*/\
 	BONUS_NAME(SPECIAL_PECULIAR_ENCHANT) /*blesses and curses with id = val dependent on unit's level, subtype = 0 or 1 for Coronius*/\
-	BONUS_NAME(SPECIAL_UPGRADE) /*val = base, additionalInfo = target */\
+	BONUS_NAME(SPECIAL_UPGRADE) /*subtype = base, additionalInfo = target */\
 	BONUS_NAME(DRAGON_NATURE) \
 	BONUS_NAME(CREATURE_DAMAGE)/*subtype 0 = both, 1 = min, 2 = max*/\
 	BONUS_NAME(EXP_MULTIPLIER)/* val - percent of additional exp gained by stack/commander (base value 100)*/\