mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-29 23:07:48 +02:00
Create separate instance of updater for every bonus
This commit is contained in:
@@ -19,14 +19,6 @@
|
|||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
const std::map<std::string, TUpdaterPtr> bonusUpdaterMap =
|
|
||||||
{
|
|
||||||
{"TIMES_HERO_LEVEL", std::make_shared<TimesHeroLevelUpdater>()},
|
|
||||||
{"TIMES_STACK_LEVEL", std::make_shared<TimesStackLevelUpdater>()},
|
|
||||||
{"ARMY_MOVEMENT", std::make_shared<ArmyMovementUpdater>()},
|
|
||||||
{"BONUS_OWNER_UPDATER", std::make_shared<OwnerUpdater>()}
|
|
||||||
};
|
|
||||||
|
|
||||||
std::shared_ptr<Bonus> IUpdater::createUpdatedBonus(const std::shared_ptr<Bonus> & b, const CBonusSystemNode & context) const
|
std::shared_ptr<Bonus> IUpdater::createUpdatedBonus(const std::shared_ptr<Bonus> & b, const CBonusSystemNode & context) const
|
||||||
{
|
{
|
||||||
return b;
|
return b;
|
||||||
|
|||||||
@@ -13,8 +13,6 @@
|
|||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
extern DLL_LINKAGE const std::map<std::string, TUpdaterPtr> bonusUpdaterMap;
|
|
||||||
|
|
||||||
// observers for updating bonuses based on certain events (e.g. hero gaining level)
|
// observers for updating bonuses based on certain events (e.g. hero gaining level)
|
||||||
|
|
||||||
class DLL_LINKAGE IUpdater
|
class DLL_LINKAGE IUpdater
|
||||||
|
|||||||
@@ -325,11 +325,25 @@ static BonusParams convertDeprecatedBonus(const JsonNode &ability)
|
|||||||
|
|
||||||
static TUpdaterPtr parseUpdater(const JsonNode & updaterJson)
|
static TUpdaterPtr parseUpdater(const JsonNode & updaterJson)
|
||||||
{
|
{
|
||||||
|
const std::map<std::string, std::function<TUpdaterPtr()>> bonusUpdaterMap =
|
||||||
|
{
|
||||||
|
{"TIMES_HERO_LEVEL", std::make_shared<TimesHeroLevelUpdater>},
|
||||||
|
{"TIMES_STACK_LEVEL", std::make_shared<TimesStackLevelUpdater>},
|
||||||
|
{"ARMY_MOVEMENT", std::make_shared<ArmyMovementUpdater>},
|
||||||
|
{"BONUS_OWNER_UPDATER", std::make_shared<OwnerUpdater>}
|
||||||
|
};
|
||||||
|
|
||||||
switch(updaterJson.getType())
|
switch(updaterJson.getType())
|
||||||
{
|
{
|
||||||
case JsonNode::JsonType::DATA_STRING:
|
case JsonNode::JsonType::DATA_STRING:
|
||||||
return parseByMap(bonusUpdaterMap, &updaterJson, "updater type ");
|
{
|
||||||
break;
|
auto it = bonusUpdaterMap.find(updaterJson.String());
|
||||||
|
if (it != bonusUpdaterMap.end())
|
||||||
|
return it->second();
|
||||||
|
|
||||||
|
logGlobal->error("Unknown bonus updater type '%s'", updaterJson.String());
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
case JsonNode::JsonType::DATA_STRUCT:
|
case JsonNode::JsonType::DATA_STRUCT:
|
||||||
if(updaterJson["type"].String() == "GROWS_WITH_LEVEL")
|
if(updaterJson["type"].String() == "GROWS_WITH_LEVEL")
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user