1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-28 23:06:24 +02:00

Fix identifiers resolving for stack experience bonuses

This commit is contained in:
Ivan Savenko 2023-04-04 17:12:40 +03:00
parent 00e9cef19f
commit fc750d0917

View File

@ -963,9 +963,6 @@ void CCreatureHandler::loadStackExperience(CCreature * creature, const JsonNode
{ {
for (const JsonNode &exp : input.Vector()) for (const JsonNode &exp : input.Vector())
{ {
auto bonus = JsonUtils::parseBonus (exp["bonus"]);
bonus->source = Bonus::STACK_EXPERIENCE;
bonus->duration = Bonus::PERMANENT;
const JsonVector &values = exp["values"].Vector(); const JsonVector &values = exp["values"].Vector();
int lowerLimit = 1;//, upperLimit = 255; int lowerLimit = 1;//, upperLimit = 255;
if (values[0].getType() == JsonNode::JsonType::DATA_BOOL) if (values[0].getType() == JsonNode::JsonType::DATA_BOOL)
@ -974,8 +971,14 @@ void CCreatureHandler::loadStackExperience(CCreature * creature, const JsonNode
{ {
if(val.Bool()) if(val.Bool())
{ {
// parse each bonus separately
// we can not create copies since identifiers resolution does not tracks copies
// leading to unset identifier values in copies
auto bonus = JsonUtils::parseBonus (exp["bonus"]);
bonus->source = Bonus::STACK_EXPERIENCE;
bonus->duration = Bonus::PERMANENT;
bonus->limiter = std::make_shared<RankRangeLimiter>(RankRangeLimiter(lowerLimit)); bonus->limiter = std::make_shared<RankRangeLimiter>(RankRangeLimiter(lowerLimit));
creature->addNewBonus (std::make_shared<Bonus>(*bonus)); //bonuses must be unique objects creature->addNewBonus (bonus);
break; //TODO: allow bonuses to turn off? break; //TODO: allow bonuses to turn off?
} }
++lowerLimit; ++lowerLimit;
@ -988,9 +991,14 @@ void CCreatureHandler::loadStackExperience(CCreature * creature, const JsonNode
{ {
if (val.Float() != lastVal) if (val.Float() != lastVal)
{ {
bonus->val = static_cast<int>(val.Float()) - lastVal; JsonNode bonusInput = exp["bonus"];
bonusInput["val"].Float() = static_cast<int>(val.Float()) - lastVal;
auto bonus = JsonUtils::parseBonus (bonusInput);
bonus->source = Bonus::STACK_EXPERIENCE;
bonus->duration = Bonus::PERMANENT;
bonus->limiter.reset (new RankRangeLimiter(lowerLimit)); bonus->limiter.reset (new RankRangeLimiter(lowerLimit));
creature->addNewBonus (std::make_shared<Bonus>(*bonus)); creature->addNewBonus (bonus);
} }
lastVal = static_cast<int>(val.Float()); lastVal = static_cast<int>(val.Float());
++lowerLimit; ++lowerLimit;