mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
cleaned up secondary skill bonus merging
This commit is contained in:
parent
06d2507371
commit
9bbfb57b93
@ -257,7 +257,7 @@ const std::shared_ptr<Bonus> CSkillHandler::defaultBonus(SecondarySkill skill, i
|
||||
case SecondarySkill::FIRST_AID:
|
||||
bonusVal = 25 + 25 * level; break;
|
||||
default:
|
||||
valueType = Bonus::INDEPENDENT_MIN; break;
|
||||
break;
|
||||
}
|
||||
|
||||
return std::make_shared<Bonus>(Bonus::PERMANENT, bonusType, Bonus::SECONDARY_SKILL, bonusVal, skill, skill, valueType);
|
||||
|
@ -1166,6 +1166,11 @@ namespace Selector
|
||||
return CSelectFieldEqual<Bonus::BonusSource>(&Bonus::source)(source);
|
||||
}
|
||||
|
||||
CSelector DLL_LINKAGE valueType(Bonus::ValueType valType)
|
||||
{
|
||||
return CSelectFieldEqual<Bonus::ValueType>(&Bonus::valType)(valType);
|
||||
}
|
||||
|
||||
DLL_LINKAGE CSelector all([](const Bonus * b){return true;});
|
||||
DLL_LINKAGE CSelector none([](const Bonus * b){return false;});
|
||||
|
||||
|
@ -950,6 +950,7 @@ namespace Selector
|
||||
CSelector DLL_LINKAGE typeSubtypeInfo(Bonus::BonusType type, TBonusSubtype subtype, si32 info);
|
||||
CSelector DLL_LINKAGE source(Bonus::BonusSource source, ui32 sourceID);
|
||||
CSelector DLL_LINKAGE sourceTypeSel(Bonus::BonusSource source);
|
||||
CSelector DLL_LINKAGE valueType(Bonus::ValueType valType);
|
||||
|
||||
/**
|
||||
* Selects all bonuses
|
||||
|
@ -769,15 +769,14 @@ void CGHeroInstance::updateSkill(SecondarySkill which, int val)
|
||||
auto skillBonus = (*VLC->skillh)[which]->getBonus(val);
|
||||
for (auto b : skillBonus)
|
||||
{
|
||||
// TODO: add standard method for joining bonuses, should match on valType as well
|
||||
std::shared_ptr<Bonus> existing = getBonusLocalFirst(Selector::typeSubtype(b->type,b->subtype).And(Selector::source(Bonus::SECONDARY_SKILL, b->sid)));
|
||||
// bonuses provided by different levels of a secondary skill are aggregated via max (not + as usual)
|
||||
// different secondary skills providing the same bonus (e.g. ballistics might improve archery as well) are kept separate
|
||||
std::shared_ptr<Bonus> existing = getBonusLocalFirst(
|
||||
Selector::typeSubtype(b->type, b->subtype).And(
|
||||
Selector::source(Bonus::SECONDARY_SKILL, b->sid).And(
|
||||
Selector::valueType(b->valType))));
|
||||
if(existing)
|
||||
{
|
||||
if(b->valType == Bonus::INDEPENDENT_MIN || b->valType == Bonus::BASE_NUMBER)
|
||||
existing->val = b->val;
|
||||
else
|
||||
existing->val += b->val;
|
||||
}
|
||||
vstd::amax(existing->val, b->val);
|
||||
else
|
||||
addNewBonus(std::make_shared<Bonus>(*b));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user