diff --git a/lib/CHeroHandler.cpp b/lib/CHeroHandler.cpp index b4549de37..57b14265a 100644 --- a/lib/CHeroHandler.cpp +++ b/lib/CHeroHandler.cpp @@ -559,7 +559,7 @@ std::vector> SpecialtyBonusToBonuses(const SSpecialtyBonu if(creatureLimiter) { const CCreature * cre = creatureLimiter->creature; - int creStat = newBonus->subtype == PrimarySkill::ATTACK ? cre->Attack() : cre->Defense(); + int creStat = newBonus->subtype == PrimarySkill::ATTACK ? cre->getAttack(false) : cre->getDefence(false); int creLevel = cre->level ? cre->level : 5; newBonus->updater = std::make_shared(creStat, creLevel); } @@ -823,7 +823,7 @@ void CHeroHandler::afterLoadFinalization() hero->specialty.push_back(bonus); specVec.push_back(bonus->toJsonNode()); // find fitting & unique bonus name - std::string bonusName = nameForBonus(*bonus); + std::string bonusName = bonus->nameForBonus(); if(vstd::contains(specNames, bonusName)) { int suffix = 2; diff --git a/lib/HeroBonus.cpp b/lib/HeroBonus.cpp index d1065d071..410158d9a 100644 --- a/lib/HeroBonus.cpp +++ b/lib/HeroBonus.cpp @@ -1218,6 +1218,31 @@ JsonNode Bonus::toJsonNode() const return root; } +std::string Bonus::nameForBonus() const +{ + switch(type) + { + case Bonus::PRIMARY_SKILL: + return PrimarySkill::names[subtype]; + case Bonus::SECONDARY_SKILL_PREMY: + return NSecondarySkill::names[subtype]; + case Bonus::SPECIAL_SPELL_LEV: + case Bonus::SPECIFIC_SPELL_DAMAGE: + case Bonus::SPECIAL_BLESS_DAMAGE: + case Bonus::MAXED_SPELL: + case Bonus::SPECIAL_PECULIAR_ENCHANT: + return (*VLC->spellh)[SpellID::ESpellID(subtype)]->identifier; + case Bonus::SPECIAL_UPGRADE: + return CreatureID::encode(subtype) + "2" + CreatureID::encode(additionalInfo); + case Bonus::GENERATE_RESOURCE: + return GameConstants::RESOURCE_NAMES[subtype]; + case Bonus::STACKS_SPEED: + return "speed"; + default: + return vstd::findKey(bonusNameMap, type); + } +} + Bonus::Bonus(ui16 Dur, BonusType Type, BonusSource Src, si32 Val, ui32 ID, std::string Desc, si32 Subtype) : duration(Dur), type(Type), subtype(Subtype), source(Src), val(Val), sid(ID), description(Desc) { @@ -1717,28 +1742,3 @@ JsonNode ScalingUpdater::toJsonNode() const return root; } - -std::string nameForBonus(const Bonus & bonus) -{ - switch(bonus.type) - { - case Bonus::PRIMARY_SKILL: - return PrimarySkill::names[bonus.subtype]; - case Bonus::SECONDARY_SKILL_PREMY: - return NSecondarySkill::names[bonus.subtype]; - case Bonus::SPECIAL_SPELL_LEV: - case Bonus::SPECIFIC_SPELL_DAMAGE: - case Bonus::SPECIAL_BLESS_DAMAGE: - case Bonus::MAXED_SPELL: - case Bonus::SPECIAL_PECULIAR_ENCHANT: - return (*VLC->spellh)[SpellID::ESpellID(bonus.subtype)]->identifier; - case Bonus::SPECIAL_UPGRADE: - return CreatureID::encode(bonus.subtype) + "2" + CreatureID::encode(bonus.additionalInfo); - case Bonus::GENERATE_RESOURCE: - return GameConstants::RESOURCE_NAMES[bonus.subtype]; - case Bonus::STACKS_SPEED: - return "speed"; - default: - return vstd::findKey(bonusNameMap, bonus.type); - } -} diff --git a/lib/HeroBonus.h b/lib/HeroBonus.h index 664441c20..5a4ea3314 100644 --- a/lib/HeroBonus.h +++ b/lib/HeroBonus.h @@ -426,6 +426,7 @@ struct DLL_LINKAGE Bonus : public std::enable_shared_from_this std::string Description() const; JsonNode toJsonNode() const; + std::string nameForBonus() const; // generate suitable name for bonus - e.g. for storing in json struct std::shared_ptr addLimiter(TLimiterPtr Limiter); //returns this for convenient chain-calls std::shared_ptr addPropagator(TPropagatorPtr Propagator); //returns this for convenient chain-calls @@ -1057,6 +1058,3 @@ struct DLL_LINKAGE ScalingUpdater : public IUpdater virtual std::string toString() const override; virtual JsonNode toJsonNode() const override; }; - -// generate suitable name for bonus - e.g. for storing in json struct -DLL_LINKAGE std::string nameForBonus(const Bonus & bonus);