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

BattleResultAccepted fixed

This commit is contained in:
SoundSSGood 2023-06-30 18:59:45 +03:00
parent 060aecc61c
commit 670999d40e
3 changed files with 50 additions and 43 deletions

View File

@ -1491,20 +1491,30 @@ struct DLL_LINKAGE BattleSetActiveStack : public CPackForClient
struct DLL_LINKAGE BattleResultAccepted : public CPackForClient
{
void applyGs(CGameState * gs) const;
CGHeroInstance * hero1 = nullptr;
CGHeroInstance * hero2 = nullptr;
CArmedInstance * army1 = nullptr;
CArmedInstance * army2 = nullptr;
TExpType exp[2];
template <typename Handler> void serialize(Handler &h, const int version)
struct HeroBattleResults
{
h & hero1;
h & hero2;
h & army1;
h & army2;
h & exp;
HeroBattleResults()
: hero(nullptr), army(nullptr), exp(0) {}
CGHeroInstance * hero;
CArmedInstance * army;
TExpType exp;
template <typename Handler> void serialize(Handler & h, const int version)
{
h & hero;
h & army;
h & exp;
}
};
std::array<HeroBattleResults, 2> heroResult;
ui8 winnerSide;
template <typename Handler> void serialize(Handler & h, const int version)
{
h & heroResult;
h & winnerSide;
}
};

View File

@ -2214,36 +2214,32 @@ void BattleUpdateGateState::applyGs(CGameState * gs) const
void BattleResultAccepted::applyGs(CGameState * gs) const
{
for(auto * h : {hero1, hero2})
// Remove any "until next battle" bonuses
for(auto & res : heroResult)
{
if(h)
{
h->removeBonusesRecursive(Bonus::OneBattle); //remove any "until next battle" bonuses
if (h->commander && h->commander->alive)
{
for (auto art : h->commander->artifactsWorn) //increment bonuses for commander artifacts
{
art.second.artifact->growingUp();
}
}
for(auto & art : h->artifactsWorn)
{
art.second.artifact->growingUp();
}
}
if(res.hero)
res.hero->removeBonusesRecursive(Bonus::OneBattle);
}
// Grow up growing artifacts
if(const auto hero = heroResult[winnerSide].hero)
{
if(hero->commander && hero->commander->alive)
{
for(auto & art : hero->commander->artifactsWorn)
art.second.artifact->growingUp();
}
for(auto & art : hero->artifactsWorn)
{
art.second.artifact->growingUp();
}
}
if(VLC->settings()->getBoolean(EGameSettings::MODULE_STACK_EXPERIENCE))
{
for(int i = 0; i < 2; i++)
{
if(exp[i])
{
if(auto * army = (i == 0 ? army1 : army2))
army->giveStackExp(exp[i]);
}
}
if(heroResult[0].army)
heroResult[0].army->giveStackExp(heroResult[0].exp);
if(heroResult[1].army)
heroResult[1].army->giveStackExp(heroResult[1].exp);
CBonusSystemNode::treeHasChanged();
}

View File

@ -807,12 +807,13 @@ void CGameHandler::endBattleConfirm(const BattleInfo * battleInfo)
changePrimSkill(finishingBattle->winnerHero, PrimarySkill::EXPERIENCE, battleResult.data->exp[finishingBattle->winnerSide]);
BattleResultAccepted raccepted;
raccepted.army1 = const_cast<CArmedInstance*>(bEndArmy1);
raccepted.army2 = const_cast<CArmedInstance*>(bEndArmy2);
raccepted.hero1 = const_cast<CGHeroInstance*>(battleInfo->sides.at(0).hero);
raccepted.hero2 = const_cast<CGHeroInstance*>(battleInfo->sides.at(1).hero);
raccepted.exp[0] = battleResult.data->exp[0];
raccepted.exp[1] = battleResult.data->exp[1];
raccepted.heroResult[0].army = const_cast<CArmedInstance*>(bEndArmy1);
raccepted.heroResult[1].army = const_cast<CArmedInstance*>(bEndArmy2);
raccepted.heroResult[0].hero = const_cast<CGHeroInstance*>(battleInfo->sides.at(0).hero);
raccepted.heroResult[1].hero = const_cast<CGHeroInstance*>(battleInfo->sides.at(1).hero);
raccepted.heroResult[0].exp = battleResult.data->exp[0];
raccepted.heroResult[1].exp = battleResult.data->exp[1];
raccepted.winnerSide = finishingBattle->winnerSide;
sendAndApply(&raccepted);
queries.popIfTop(battleQuery);