mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
vcmi: fix mana points displayed
This commit is contained in:
parent
f2167904ed
commit
d503c875a4
@ -297,19 +297,7 @@ void CRewardableObject::grantRewardBeforeLevelup(const CRewardVisitInfo & info,
|
||||
void CRewardableObject::grantRewardAfterLevelup(const CRewardVisitInfo & info, const CGHeroInstance * hero) const
|
||||
{
|
||||
if(info.reward.manaDiff || info.reward.manaPercentage >= 0)
|
||||
{
|
||||
si32 manaScaled = hero->mana;
|
||||
if (info.reward.manaPercentage >= 0)
|
||||
manaScaled = hero->manaLimit() * info.reward.manaPercentage / 100;
|
||||
|
||||
si32 manaMissing = std::max(0, hero->manaLimit() - manaScaled);
|
||||
si32 manaGranted = std::min(manaMissing, info.reward.manaDiff);
|
||||
si32 manaOverflow = info.reward.manaDiff - manaGranted;
|
||||
si32 manaOverLimit = manaOverflow * info.reward.manaOverflowFactor / 100;
|
||||
si32 manaOutput = manaScaled + manaGranted + manaOverLimit;
|
||||
|
||||
cb->setManaPoints(hero->id, manaOutput);
|
||||
}
|
||||
cb->setManaPoints(hero->id, info.reward.calculateManaPoints(hero));
|
||||
|
||||
if(info.reward.movePoints || info.reward.movePercentage >= 0)
|
||||
{
|
||||
@ -448,7 +436,7 @@ void CRewardInfo::loadComponents(std::vector<Component> & comps,
|
||||
comps.emplace_back(Component::EXPERIENCE, 1, heroLevel, 0);
|
||||
|
||||
if (manaDiff || manaPercentage >= 0)
|
||||
comps.emplace_back(Component::PRIM_SKILL, 5, manaDiff, 0);
|
||||
comps.emplace_back(Component::PRIM_SKILL, 5, calculateManaPoints(h) - h->mana, 0);
|
||||
|
||||
for (size_t i=0; i<primary.size(); i++)
|
||||
{
|
||||
@ -475,6 +463,21 @@ void CRewardInfo::loadComponents(std::vector<Component> & comps,
|
||||
}
|
||||
}
|
||||
|
||||
si32 CRewardInfo::calculateManaPoints(const CGHeroInstance * hero) const
|
||||
{
|
||||
si32 manaScaled = hero->mana;
|
||||
if (manaPercentage >= 0)
|
||||
manaScaled = hero->manaLimit() * manaPercentage / 100;
|
||||
|
||||
si32 manaMissing = std::max(0, hero->manaLimit() - manaScaled);
|
||||
si32 manaGranted = std::min(manaMissing, manaDiff);
|
||||
si32 manaOverflow = manaDiff - manaGranted;
|
||||
si32 manaOverLimit = manaOverflow * manaOverflowFactor / 100;
|
||||
si32 manaOutput = manaScaled + manaGranted + manaOverLimit;
|
||||
|
||||
return manaOutput;
|
||||
}
|
||||
|
||||
Component CRewardInfo::getDisplayedComponent(const CGHeroInstance * h) const
|
||||
{
|
||||
std::vector<Component> comps;
|
||||
|
@ -178,6 +178,8 @@ public:
|
||||
const CGHeroInstance * h) const;
|
||||
Component getDisplayedComponent(const CGHeroInstance * h) const;
|
||||
|
||||
si32 calculateManaPoints(const CGHeroInstance * h) const;
|
||||
|
||||
CRewardInfo() :
|
||||
heroExperience(0),
|
||||
heroLevel(0),
|
||||
|
Loading…
Reference in New Issue
Block a user