mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-23 12:08:45 +02:00
Merge pull request #2357 from SoundSSGood/picked-art-fix
Fixed hero skills if artifact picked
This commit is contained in:
commit
ab6a4be105
@ -38,53 +38,6 @@
|
|||||||
#include "../lib/mapObjects/CGHeroInstance.h"
|
#include "../lib/mapObjects/CGHeroInstance.h"
|
||||||
#include "../lib/NetPacksBase.h"
|
#include "../lib/NetPacksBase.h"
|
||||||
|
|
||||||
TConstBonusListPtr CHeroWithMaybePickedArtifact::getAllBonuses(const CSelector & selector, const CSelector & limit, const CBonusSystemNode * root, const std::string & cachingStr) const
|
|
||||||
{
|
|
||||||
TBonusListPtr out(new BonusList());
|
|
||||||
TConstBonusListPtr heroBonuses = hero->getAllBonuses(selector, limit, hero, cachingStr);
|
|
||||||
TConstBonusListPtr bonusesFromPickedUpArtifact;
|
|
||||||
|
|
||||||
const auto pickedArtInst = cww->getPickedArtifact();
|
|
||||||
|
|
||||||
if(pickedArtInst)
|
|
||||||
bonusesFromPickedUpArtifact = pickedArtInst->getAllBonuses(selector, limit, hero);
|
|
||||||
else
|
|
||||||
bonusesFromPickedUpArtifact = TBonusListPtr(new BonusList());
|
|
||||||
|
|
||||||
for(const auto & b : *heroBonuses)
|
|
||||||
out->push_back(b);
|
|
||||||
|
|
||||||
for(const auto & b : *bonusesFromPickedUpArtifact)
|
|
||||||
*out -= b;
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t CHeroWithMaybePickedArtifact::getTreeVersion() const
|
|
||||||
{
|
|
||||||
return hero->getTreeVersion(); //this assumes that hero and artifact belongs to main bonus tree
|
|
||||||
}
|
|
||||||
|
|
||||||
si32 CHeroWithMaybePickedArtifact::manaLimit() const
|
|
||||||
{
|
|
||||||
//TODO: reduplicate code with CGHeroInstance
|
|
||||||
return si32(getPrimSkillLevel(PrimarySkill::KNOWLEDGE) * (valOfBonuses(BonusType::MANA_PER_KNOWLEDGE)));
|
|
||||||
}
|
|
||||||
|
|
||||||
const IBonusBearer * CHeroWithMaybePickedArtifact::getBonusBearer() const
|
|
||||||
{
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
FactionID CHeroWithMaybePickedArtifact::getFaction() const
|
|
||||||
{
|
|
||||||
return hero->getFaction();
|
|
||||||
}
|
|
||||||
|
|
||||||
CHeroWithMaybePickedArtifact::CHeroWithMaybePickedArtifact(CWindowWithArtifacts * Cww, const CGHeroInstance * Hero)
|
|
||||||
: hero(Hero), cww(Cww)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void CHeroSwitcher::clickPressed(const Point & cursorPosition)
|
void CHeroSwitcher::clickPressed(const Point & cursorPosition)
|
||||||
{
|
{
|
||||||
//TODO: do not recreate window
|
//TODO: do not recreate window
|
||||||
@ -114,8 +67,7 @@ CHeroSwitcher::CHeroSwitcher(CHeroWindow * owner_, Point pos_, const CGHeroInsta
|
|||||||
}
|
}
|
||||||
|
|
||||||
CHeroWindow::CHeroWindow(const CGHeroInstance * hero)
|
CHeroWindow::CHeroWindow(const CGHeroInstance * hero)
|
||||||
: CStatusbarWindow(PLAYER_COLORED, "HeroScr4"),
|
: CStatusbarWindow(PLAYER_COLORED, "HeroScr4")
|
||||||
heroWArt(this, hero)
|
|
||||||
{
|
{
|
||||||
auto & heroscrn = CGI->generaltexth->heroscrn;
|
auto & heroscrn = CGI->generaltexth->heroscrn;
|
||||||
|
|
||||||
@ -268,7 +220,7 @@ void CHeroWindow::update(const CGHeroInstance * hero, bool redrawNeeded)
|
|||||||
//primary skills support
|
//primary skills support
|
||||||
for(size_t g=0; g<primSkillAreas.size(); ++g)
|
for(size_t g=0; g<primSkillAreas.size(); ++g)
|
||||||
{
|
{
|
||||||
primSkillAreas[g]->bonusValue = heroWArt.getPrimSkillLevel(static_cast<PrimarySkill::PrimarySkill>(g));
|
primSkillAreas[g]->bonusValue = curHero->getPrimSkillLevel(static_cast<PrimarySkill::PrimarySkill>(g));
|
||||||
primSkillValues[g]->setText(std::to_string(primSkillAreas[g]->bonusValue));
|
primSkillValues[g]->setText(std::to_string(primSkillAreas[g]->bonusValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,7 +246,7 @@ void CHeroWindow::update(const CGHeroInstance * hero, bool redrawNeeded)
|
|||||||
expValue->setText(expstr.str());
|
expValue->setText(expstr.str());
|
||||||
|
|
||||||
std::ostringstream manastr;
|
std::ostringstream manastr;
|
||||||
manastr << curHero->mana << '/' << heroWArt.manaLimit();
|
manastr << curHero->mana << '/' << curHero->manaLimit();
|
||||||
manaValue->setText(manastr.str());
|
manaValue->setText(manastr.str());
|
||||||
|
|
||||||
//printing experience - original format does not support ui64
|
//printing experience - original format does not support ui64
|
||||||
@ -307,7 +259,7 @@ void CHeroWindow::update(const CGHeroInstance * hero, bool redrawNeeded)
|
|||||||
spellPointsArea->text = CGI->generaltexth->allTexts[205];
|
spellPointsArea->text = CGI->generaltexth->allTexts[205];
|
||||||
boost::replace_first(spellPointsArea->text, "%s", curHero->getNameTranslated());
|
boost::replace_first(spellPointsArea->text, "%s", curHero->getNameTranslated());
|
||||||
boost::replace_first(spellPointsArea->text, "%d", std::to_string(curHero->mana));
|
boost::replace_first(spellPointsArea->text, "%d", std::to_string(curHero->mana));
|
||||||
boost::replace_first(spellPointsArea->text, "%d", std::to_string(heroWArt.manaLimit()));
|
boost::replace_first(spellPointsArea->text, "%d", std::to_string(curHero->manaLimit()));
|
||||||
|
|
||||||
//if we have exchange window with this curHero open
|
//if we have exchange window with this curHero open
|
||||||
bool noDismiss=false;
|
bool noDismiss=false;
|
||||||
@ -343,8 +295,8 @@ void CHeroWindow::update(const CGHeroInstance * hero, bool redrawNeeded)
|
|||||||
formations->setSelected(curHero->formation == EArmyFormation::TIGHT ? 1 : 0);
|
formations->setSelected(curHero->formation == EArmyFormation::TIGHT ? 1 : 0);
|
||||||
formations->addCallback([=](int value){ LOCPLINT->cb->setFormation(curHero, value);});
|
formations->addCallback([=](int value){ LOCPLINT->cb->setFormation(curHero, value);});
|
||||||
|
|
||||||
morale->set(&heroWArt);
|
morale->set(curHero);
|
||||||
luck->set(&heroWArt);
|
luck->set(curHero);
|
||||||
|
|
||||||
if(redrawNeeded)
|
if(redrawNeeded)
|
||||||
redraw();
|
redraw();
|
||||||
@ -390,5 +342,5 @@ void CHeroWindow::commanderWindow()
|
|||||||
void CHeroWindow::updateGarrisons()
|
void CHeroWindow::updateGarrisons()
|
||||||
{
|
{
|
||||||
garr->recreateSlots();
|
garr->recreateSlots();
|
||||||
morale->set(&heroWArt);
|
morale->set(curHero);
|
||||||
}
|
}
|
||||||
|
@ -46,24 +46,6 @@ public:
|
|||||||
CHeroSwitcher(CHeroWindow * owner_, Point pos_, const CGHeroInstance * hero_);
|
CHeroSwitcher(CHeroWindow * owner_, Point pos_, const CGHeroInstance * hero_);
|
||||||
};
|
};
|
||||||
|
|
||||||
//helper class for calculating values of hero bonuses without bonuses from picked up artifact
|
|
||||||
class CHeroWithMaybePickedArtifact : public IBonusBearer, public AFactionMember
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
const CGHeroInstance * hero;
|
|
||||||
CWindowWithArtifacts * cww;
|
|
||||||
|
|
||||||
CHeroWithMaybePickedArtifact(CWindowWithArtifacts * Cww, const CGHeroInstance * Hero);
|
|
||||||
TConstBonusListPtr getAllBonuses(const CSelector & selector, const CSelector & limit, const CBonusSystemNode * root = nullptr, const std::string & cachingStr = "") const override;
|
|
||||||
|
|
||||||
const IBonusBearer * getBonusBearer() const override;
|
|
||||||
FactionID getFaction() const override;
|
|
||||||
|
|
||||||
int64_t getTreeVersion() const override;
|
|
||||||
|
|
||||||
si32 manaLimit() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CHeroWindow : public CStatusbarWindow, public CGarrisonHolder, public CWindowWithArtifacts
|
class CHeroWindow : public CStatusbarWindow, public CGarrisonHolder, public CWindowWithArtifacts
|
||||||
{
|
{
|
||||||
std::shared_ptr<CLabel> name;
|
std::shared_ptr<CLabel> name;
|
||||||
@ -97,8 +79,6 @@ class CHeroWindow : public CStatusbarWindow, public CGarrisonHolder, public CWin
|
|||||||
std::vector<std::shared_ptr<CLabel>> secSkillNames;
|
std::vector<std::shared_ptr<CLabel>> secSkillNames;
|
||||||
std::vector<std::shared_ptr<CLabel>> secSkillValues;
|
std::vector<std::shared_ptr<CLabel>> secSkillValues;
|
||||||
|
|
||||||
CHeroWithMaybePickedArtifact heroWArt;
|
|
||||||
|
|
||||||
std::shared_ptr<CButton> quitButton;
|
std::shared_ptr<CButton> quitButton;
|
||||||
std::shared_ptr<CTextBox> dismissLabel;
|
std::shared_ptr<CTextBox> dismissLabel;
|
||||||
std::shared_ptr<CButton> dismissButton;
|
std::shared_ptr<CButton> dismissButton;
|
||||||
|
@ -912,8 +912,6 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
|
|||||||
{
|
{
|
||||||
const CGHeroInstance * hero = heroInst.at(leftRight);
|
const CGHeroInstance * hero = heroInst.at(leftRight);
|
||||||
|
|
||||||
herosWArt[leftRight] = std::make_shared<CHeroWithMaybePickedArtifact>(this, hero);
|
|
||||||
|
|
||||||
for(int m=0; m<GameConstants::PRIMARY_SKILLS; ++m)
|
for(int m=0; m<GameConstants::PRIMARY_SKILLS; ++m)
|
||||||
primSkillValues[leftRight].push_back(std::make_shared<CLabel>(352 + (qeLayout ? 96 : 93) * leftRight, (qeLayout ? 22 : 35) + (qeLayout ? 26 : 36) * m, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE));
|
primSkillValues[leftRight].push_back(std::make_shared<CLabel>(352 + (qeLayout ? 96 : 93) * leftRight, (qeLayout ? 22 : 35) + (qeLayout ? 26 : 36) * m, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE));
|
||||||
|
|
||||||
@ -1079,7 +1077,7 @@ void CExchangeWindow::updateWidgets()
|
|||||||
|
|
||||||
for(int m=0; m<GameConstants::PRIMARY_SKILLS; ++m)
|
for(int m=0; m<GameConstants::PRIMARY_SKILLS; ++m)
|
||||||
{
|
{
|
||||||
auto value = herosWArt[leftRight]->getPrimSkillLevel(static_cast<PrimarySkill::PrimarySkill>(m));
|
auto value = heroInst[leftRight]->getPrimSkillLevel(static_cast<PrimarySkill::PrimarySkill>(m));
|
||||||
primSkillValues[leftRight][m]->setText(std::to_string(value));
|
primSkillValues[leftRight][m]->setText(std::to_string(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,6 @@ class CToggleButton;
|
|||||||
class CGStatusBar;
|
class CGStatusBar;
|
||||||
class CTextBox;
|
class CTextBox;
|
||||||
class CResDataBar;
|
class CResDataBar;
|
||||||
class CHeroWithMaybePickedArtifact;
|
|
||||||
|
|
||||||
enum class EUserEvent;
|
enum class EUserEvent;
|
||||||
|
|
||||||
@ -248,18 +247,6 @@ public:
|
|||||||
class CCallback;
|
class CCallback;
|
||||||
class CExchangeWindow;
|
class CExchangeWindow;
|
||||||
|
|
||||||
struct HeroArtifact
|
|
||||||
{
|
|
||||||
const CGHeroInstance * hero;
|
|
||||||
const CArtifactInstance * artifact;
|
|
||||||
ArtifactPosition artPosition;
|
|
||||||
|
|
||||||
HeroArtifact(const CGHeroInstance * hero, const CArtifactInstance * artifact, ArtifactPosition artPosition)
|
|
||||||
:hero(hero), artifact(artifact), artPosition(artPosition)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class CExchangeController
|
class CExchangeController
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@ -288,8 +275,6 @@ private:
|
|||||||
|
|
||||||
class CExchangeWindow : public CStatusbarWindow, public CGarrisonHolder, public CWindowWithArtifacts
|
class CExchangeWindow : public CStatusbarWindow, public CGarrisonHolder, public CWindowWithArtifacts
|
||||||
{
|
{
|
||||||
std::array<std::shared_ptr<CHeroWithMaybePickedArtifact>, 2> herosWArt;
|
|
||||||
|
|
||||||
std::array<std::shared_ptr<CLabel>, 2> titles;
|
std::array<std::shared_ptr<CLabel>, 2> titles;
|
||||||
std::vector<std::shared_ptr<CAnimImage>> primSkillImages;//shared for both heroes
|
std::vector<std::shared_ptr<CAnimImage>> primSkillImages;//shared for both heroes
|
||||||
std::array<std::vector<std::shared_ptr<CLabel>>, 2> primSkillValues;
|
std::array<std::vector<std::shared_ptr<CLabel>>, 2> primSkillValues;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user