mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
added TimesStackLevelUpdater
This commit is contained in:
parent
af00c29858
commit
95e2b44319
@ -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");
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user