1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

added TimesStackLevelUpdater

This commit is contained in:
Henning Koehler 2017-09-19 11:43:13 +12:00
parent af00c29858
commit 95e2b44319
3 changed files with 57 additions and 1 deletions

View File

@ -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");
}

View File

@ -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;
};

View File

@ -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
}