Sfoglia il codice sorgente

added updater to Bonus json format

Henning Koehler 8 anni fa
parent
commit
2703b035a6
5 ha cambiato i file con 61 aggiunte e 3 eliminazioni
  1. 10 3
      config/heroes/castle.json
  2. 17 0
      config/schemas/bonus.json
  3. 15 0
      lib/HeroBonus.cpp
  4. 2 0
      lib/HeroBonus.h
  5. 17 0
      lib/JsonNode.cpp

+ 10 - 3
config/heroes/castle.json

@@ -9,9 +9,16 @@
 			{ "skill" : "leadership", "level": "basic" },
 			{ "skill" : "leadership", "level": "basic" },
 			{ "skill" : "archery", "level": "basic" }
 			{ "skill" : "archery", "level": "basic" }
 		],
 		],
-		"specialties":
-		[
-			{ "type":2, "val": 5, "subtype": 1, "info": 0 }
+		"specialty" : [
+			{
+				"type" : "SECONDARY_SKILL_PREMY",
+				"subtype" : "skill.archery",
+				"valueType" : "PERCENT_TO_BASE",
+				"updater" : {
+					"type" : "GROWS_WITH_LEVEL",
+					"parameters" : [100]
+				}
+			}
 		]
 		]
 	},
 	},
 	"valeska":
 	"valeska":

+ 17 - 0
config/schemas/bonus.json

@@ -70,6 +70,23 @@
 				}
 				}
 			]
 			]
 		},
 		},
+		"updater" : {
+			"description" : "updater",
+			"type" : "object",
+			"required" : ["type", "parameters"],
+			"additionalProperties" : false,
+			"properties" : {
+				"type" : {
+					"type" : "string",
+					"description" : "type"
+				},
+				"parameters": {
+					"type" : "array",
+					"description" : "parameters",
+					"additionalItems" : true
+				}
+			}
+		},
 		"sourceID": {
 		"sourceID": {
 			"type":"number",
 			"type":"number",
 			"description": "sourceID"
 			"description": "sourceID"

+ 15 - 0
lib/HeroBonus.cpp

@@ -1327,6 +1327,9 @@ DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const Bonus &bonus)
 	printField(effectRange);
 	printField(effectRange);
 #undef printField
 #undef printField
 
 
+	if(bonus.updater)
+		out << "\tUpdater: " << bonus.updater->toString() << "\n";
+
 	return out;
 	return out;
 }
 }
 
 
@@ -1571,6 +1574,11 @@ IUpdater::~IUpdater()
 {
 {
 }
 }
 
 
+std::string IUpdater::toString() const
+{
+	return typeid(*this).name();
+}
+
 ScalingUpdater::ScalingUpdater() : valPer20(0), stepSize(1)
 ScalingUpdater::ScalingUpdater() : valPer20(0), stepSize(1)
 {
 {
 }
 }
@@ -1596,6 +1604,13 @@ bool ScalingUpdater::update(Bonus & b, const CBonusSystemNode & context) const
 	return false;
 	return false;
 }
 }
 
 
+std::string ScalingUpdater::toString() const
+{
+	char buf[100];
+	sprintf(buf, "ScalingUpdater(valPer20=%d, stepSize=%d)", valPer20, stepSize);
+	return std::string(buf);
+}
+
 std::shared_ptr<Bonus> Bonus::addUpdater(TUpdaterPtr Updater)
 std::shared_ptr<Bonus> Bonus::addUpdater(TUpdaterPtr Updater)
 {
 {
 	updater = Updater;
 	updater = Updater;

+ 2 - 0
lib/HeroBonus.h

@@ -1024,6 +1024,7 @@ public:
 	virtual ~IUpdater();
 	virtual ~IUpdater();
 
 
 	virtual bool update(Bonus & b, const CBonusSystemNode & context) const = 0;
 	virtual bool update(Bonus & b, const CBonusSystemNode & context) const = 0;
+	virtual std::string toString() const;
 
 
 	template <typename Handler> void serialize(Handler &h, const int version)
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{
 	{
@@ -1046,4 +1047,5 @@ struct DLL_LINKAGE ScalingUpdater : public IUpdater
 	}
 	}
 
 
 	bool update(Bonus & b, const CBonusSystemNode & context) const override;
 	bool update(Bonus & b, const CBonusSystemNode & context) const override;
+	virtual std::string toString() const override;
 };
 };

+ 17 - 0
lib/JsonNode.cpp

@@ -603,6 +603,23 @@ bool JsonUtils::parseBonus(const JsonNode &ability, Bonus *b)
 	if (!value->isNull())
 	if (!value->isNull())
 		b->propagator = parseByMap(bonusPropagatorMap, value, "propagator type ");
 		b->propagator = parseByMap(bonusPropagatorMap, value, "propagator type ");
 
 
+	value = &ability["updater"];
+	if (!value->isNull())
+	{
+		const JsonNode & updaterJson = *value;
+		if(updaterJson["type"].String() == "GROWS_WITH_LEVEL")
+		{
+			std::shared_ptr<ScalingUpdater> updater = std::make_shared<ScalingUpdater>();
+			const JsonVector param = updaterJson["parameters"].Vector();
+			updater->valPer20 = param[0].Float();
+			if(param.size() > 1)
+				updater->stepSize = param[1].Float();
+			b->addUpdater(updater);
+		}
+		else
+			logMod->warn("Unknown updater type \"%s\"", updaterJson["type"].String());
+	}
+
 	return true;
 	return true;
 }
 }