Răsfoiți Sursa

added TimesStackLevelUpdater

Henning Koehler 8 ani în urmă
părinte
comite
95e2b44319
3 a modificat fișierele cu 57 adăugiri și 1 ștergeri
  1. 41 1
      lib/HeroBonus.cpp
  2. 15 0
      lib/HeroBonus.h
  3. 1 0
      lib/registerTypes/RegisterTypes.h

+ 41 - 1
lib/HeroBonus.cpp

@@ -83,7 +83,8 @@ const std::map<std::string, TPropagatorPtr> bonusPropagatorMap =
 
 const std::map<std::string, TUpdaterPtr> bonusUpdaterMap =
 {
-	{"TIMES_HERO_LEVEL", std::make_shared<TimesHeroLevelUpdater>()}
+	{"TIMES_HERO_LEVEL", std::make_shared<TimesHeroLevelUpdater>()},
+	{"TIMES_STACK_LEVEL", std::make_shared<TimesStackLevelUpdater>()}
 };
 
 ///CBonusProxy
@@ -1800,3 +1801,42 @@ JsonNode TimesHeroLevelUpdater::toJsonNode() const
 {
 	return JsonUtils::stringNode("TIMES_HERO_LEVEL");
 }
+
+TimesStackLevelUpdater::TimesStackLevelUpdater()
+{
+}
+
+const std::shared_ptr<Bonus> TimesStackLevelUpdater::update(const std::shared_ptr<Bonus> b, const CBonusSystemNode & context) const
+{
+	if(context.getNodeType() == CBonusSystemNode::STACK_INSTANCE)
+	{
+		int level = static_cast<const CStackInstance &>(context).getLevel();
+		std::shared_ptr<Bonus> newBonus = std::make_shared<Bonus>(*b);
+		newBonus->val *= level;
+		return newBonus;
+	}
+	else if(context.getNodeType() == CBonusSystemNode::STACK_BATTLE)
+	{
+		const CStack & stack = static_cast<const CStack &>(context);
+		//only update if stack doesn't have an instance (summons, war machines)
+		//otherwise we'd end up multiplying twice
+		if(stack.base == nullptr)
+		{
+			int level = stack.type->level;
+			std::shared_ptr<Bonus> newBonus = std::make_shared<Bonus>(*b);
+			newBonus->val *= level;
+			return newBonus;
+		}
+	}
+	return b;
+}
+
+std::string TimesStackLevelUpdater::toString() const
+{
+	return "TimesStackLevelUpdater";
+}
+
+JsonNode TimesStackLevelUpdater::toJsonNode() const
+{
+	return JsonUtils::stringNode("TIMES_STACK_LEVEL");
+}

+ 15 - 0
lib/HeroBonus.h

@@ -1074,3 +1074,18 @@ public:
 	virtual std::string toString() const override;
 	virtual JsonNode toJsonNode() const override;
 };
+
+class DLL_LINKAGE TimesStackLevelUpdater : public IUpdater
+{
+public:
+	TimesStackLevelUpdater();
+
+	template <typename Handler> void serialize(Handler & h, const int version)
+	{
+		h & static_cast<IUpdater &>(*this);
+	}
+
+	const std::shared_ptr<Bonus> update(const std::shared_ptr<Bonus> b, const CBonusSystemNode & context) const override;
+	virtual std::string toString() const override;
+	virtual JsonNode toJsonNode() const override;
+};

+ 1 - 0
lib/registerTypes/RegisterTypes.h

@@ -138,6 +138,7 @@ void registerTypesMapObjectTypes(Serializer &s)
 
 	s.template registerType<IUpdater, GrowsWithLevelUpdater>();
 	s.template registerType<IUpdater, TimesHeroLevelUpdater>();
+	s.template registerType<IUpdater, TimesStackLevelUpdater>();
 	//new types (other than netpacks) must register here
 	//order of type registration is critical for loading old savegames
 }