1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

vcmi: fix mana points displayed

This commit is contained in:
Konstantin 2023-03-07 12:49:23 +03:00
parent f2167904ed
commit d503c875a4
2 changed files with 19 additions and 14 deletions

View File

@ -297,19 +297,7 @@ void CRewardableObject::grantRewardBeforeLevelup(const CRewardVisitInfo & info,
void CRewardableObject::grantRewardAfterLevelup(const CRewardVisitInfo & info, const CGHeroInstance * hero) const void CRewardableObject::grantRewardAfterLevelup(const CRewardVisitInfo & info, const CGHeroInstance * hero) const
{ {
if(info.reward.manaDiff || info.reward.manaPercentage >= 0) if(info.reward.manaDiff || info.reward.manaPercentage >= 0)
{ cb->setManaPoints(hero->id, info.reward.calculateManaPoints(hero));
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);
}
if(info.reward.movePoints || info.reward.movePercentage >= 0) 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); comps.emplace_back(Component::EXPERIENCE, 1, heroLevel, 0);
if (manaDiff || manaPercentage >= 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++) 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 Component CRewardInfo::getDisplayedComponent(const CGHeroInstance * h) const
{ {
std::vector<Component> comps; std::vector<Component> comps;

View File

@ -178,6 +178,8 @@ public:
const CGHeroInstance * h) const; const CGHeroInstance * h) const;
Component getDisplayedComponent(const CGHeroInstance * h) const; Component getDisplayedComponent(const CGHeroInstance * h) const;
si32 calculateManaPoints(const CGHeroInstance * h) const;
CRewardInfo() : CRewardInfo() :
heroExperience(0), heroExperience(0),
heroLevel(0), heroLevel(0),