mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
endBattleConfirm
This commit is contained in:
parent
6dd76908bc
commit
f87762bc96
@ -263,12 +263,12 @@ bool ArtifactUtilsClient::askToAssemble(const CGHeroInstance * hero, const Artif
|
|||||||
boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
|
boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
|
||||||
for(const auto combinedArt : assemblyPossibilities)
|
for(const auto combinedArt : assemblyPossibilities)
|
||||||
{
|
{
|
||||||
|
LOCPLINT->waitWhileDialog();
|
||||||
bool assembleConfirmed = false;
|
bool assembleConfirmed = false;
|
||||||
CFunctionList<void()> onYesHandlers([&assembleConfirmed]() -> void {assembleConfirmed = true; });
|
CFunctionList<void()> onYesHandlers([&assembleConfirmed]() -> void {assembleConfirmed = true; });
|
||||||
onYesHandlers += std::bind(&CCallback::assembleArtifacts, LOCPLINT->cb.get(), hero, slot, true, combinedArt->getId());
|
onYesHandlers += std::bind(&CCallback::assembleArtifacts, LOCPLINT->cb.get(), hero, slot, true, combinedArt->getId());
|
||||||
|
|
||||||
LOCPLINT->showArtifactAssemblyDialog(art->artType, combinedArt, onYesHandlers);
|
LOCPLINT->showArtifactAssemblyDialog(art->artType, combinedArt, onYesHandlers);
|
||||||
LOCPLINT->waitWhileDialog();
|
|
||||||
if(assembleConfirmed)
|
if(assembleConfirmed)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -323,81 +323,134 @@ void BattleResultProcessor::endBattleConfirm(const CBattleInfoCallback & battle)
|
|||||||
CasualtiesAfterBattle cab1(battle, BattleSide::ATTACKER);
|
CasualtiesAfterBattle cab1(battle, BattleSide::ATTACKER);
|
||||||
CasualtiesAfterBattle cab2(battle, BattleSide::DEFENDER);
|
CasualtiesAfterBattle cab2(battle, BattleSide::DEFENDER);
|
||||||
|
|
||||||
ChangeSpells cs; //for Eagle Eye
|
cab1.updateArmy(gameHandler);
|
||||||
|
cab2.updateArmy(gameHandler); //take casualties after battle is deleted
|
||||||
|
|
||||||
|
if(battleResult->winner == BattleSide::DEFENDER
|
||||||
|
&& finishingBattle->winnerHero
|
||||||
|
&& finishingBattle->winnerHero->visitedTown
|
||||||
|
&& !finishingBattle->winnerHero->inTownGarrison
|
||||||
|
&& finishingBattle->winnerHero->visitedTown->garrisonHero == finishingBattle->winnerHero)
|
||||||
|
{
|
||||||
|
gameHandler->swapGarrisonOnSiege(finishingBattle->winnerHero->visitedTown->id); //return defending visitor from garrison to its rightful place
|
||||||
|
}
|
||||||
|
//give exp
|
||||||
|
if(!finishingBattle->isDraw() && battleResult->exp[finishingBattle->winnerSide] && finishingBattle->winnerHero)
|
||||||
|
gameHandler->giveExperience(finishingBattle->winnerHero, battleResult->exp[finishingBattle->winnerSide]);
|
||||||
|
|
||||||
|
// Eagle Eye handling
|
||||||
if(!finishingBattle->isDraw() && finishingBattle->winnerHero)
|
if(!finishingBattle->isDraw() && finishingBattle->winnerHero)
|
||||||
{
|
{
|
||||||
if (int eagleEyeLevel = finishingBattle->winnerHero->valOfBonuses(BonusType::LEARN_BATTLE_SPELL_LEVEL_LIMIT))
|
ChangeSpells spells;
|
||||||
|
|
||||||
|
if(auto eagleEyeLevel = finishingBattle->winnerHero->valOfBonuses(BonusType::LEARN_BATTLE_SPELL_LEVEL_LIMIT))
|
||||||
{
|
{
|
||||||
double eagleEyeChance = finishingBattle->winnerHero->valOfBonuses(BonusType::LEARN_BATTLE_SPELL_CHANCE);
|
auto eagleEyeChance = finishingBattle->winnerHero->valOfBonuses(BonusType::LEARN_BATTLE_SPELL_CHANCE);
|
||||||
for(auto & spellId : battle.getBattle()->getUsedSpells(battle.otherSide(battleResult->winner)))
|
for(auto & spellId : battle.getBattle()->getUsedSpells(battle.otherSide(battleResult->winner)))
|
||||||
{
|
{
|
||||||
auto spell = spellId.toEntity(VLC->spells());
|
auto spell = spellId.toEntity(VLC->spells());
|
||||||
if(spell && spell->getLevel() <= eagleEyeLevel && !finishingBattle->winnerHero->spellbookContainsSpell(spell->getId()) && gameHandler->getRandomGenerator().nextInt(99) < eagleEyeChance)
|
if(spell
|
||||||
cs.spells.insert(spell->getId());
|
&& spell->getLevel() <= eagleEyeLevel
|
||||||
|
&& !finishingBattle->winnerHero->spellbookContainsSpell(spell->getId())
|
||||||
|
&& gameHandler->getRandomGenerator().nextInt(99) < eagleEyeChance)
|
||||||
|
{
|
||||||
|
spells.spells.insert(spell->getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::vector<const CArtifactInstance *> arts; //display them in window
|
|
||||||
|
|
||||||
|
if(!spells.spells.empty())
|
||||||
|
{
|
||||||
|
spells.learn = 1;
|
||||||
|
spells.hid = finishingBattle->winnerHero->id;
|
||||||
|
|
||||||
|
InfoWindow iw;
|
||||||
|
iw.player = finishingBattle->winnerHero->tempOwner;
|
||||||
|
iw.text.appendLocalString(EMetaText::GENERAL_TXT, 221); //Through eagle-eyed observation, %s is able to learn %s
|
||||||
|
iw.text.replaceRawString(finishingBattle->winnerHero->getNameTranslated());
|
||||||
|
|
||||||
|
std::ostringstream names;
|
||||||
|
for(int i = 0; i < spells.spells.size(); i++)
|
||||||
|
{
|
||||||
|
names << "%s";
|
||||||
|
if(i < spells.spells.size() - 2)
|
||||||
|
names << ", ";
|
||||||
|
else if(i < spells.spells.size() - 1)
|
||||||
|
names << "%s";
|
||||||
|
}
|
||||||
|
names << ".";
|
||||||
|
|
||||||
|
iw.text.replaceRawString(names.str());
|
||||||
|
|
||||||
|
auto it = spells.spells.begin();
|
||||||
|
for(int i = 0; i < spells.spells.size(); i++, it++)
|
||||||
|
{
|
||||||
|
iw.text.replaceName(*it);
|
||||||
|
if(i == spells.spells.size() - 2) //we just added pre-last name
|
||||||
|
iw.text.replaceLocalString(EMetaText::GENERAL_TXT, 141); // " and "
|
||||||
|
iw.components.emplace_back(ComponentType::SPELL, *it);
|
||||||
|
}
|
||||||
|
gameHandler->sendAndApply(&iw);
|
||||||
|
gameHandler->sendAndApply(&spells);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Artifacts handling
|
||||||
if(result == EBattleResult::NORMAL && !finishingBattle->isDraw() && finishingBattle->winnerHero)
|
if(result == EBattleResult::NORMAL && !finishingBattle->isDraw() && finishingBattle->winnerHero)
|
||||||
{
|
{
|
||||||
BulkMoveArtifacts bma(finishingBattle->winnerHero->getOwner(), finishingBattle->loserHero->id, finishingBattle->winnerHero->id, false);
|
std::vector<const CArtifactInstance*> arts; // display them in window
|
||||||
bma.askAssemble = true;
|
|
||||||
CArtifactFittingSet artFittingSet(*finishingBattle->winnerHero);
|
CArtifactFittingSet artFittingSet(*finishingBattle->winnerHero);
|
||||||
|
|
||||||
const auto addArtifactToTransfer = [&](const ArtifactPosition & srcSlot, const CArtifactInstance * art)
|
const auto addArtifactToTransfer = [&artFittingSet, &arts](BulkMoveArtifacts & pack, const ArtifactPosition & srcSlot, const CArtifactInstance * art)
|
||||||
{
|
{
|
||||||
assert(art);
|
assert(art);
|
||||||
const auto dstSlot = ArtifactUtils::getArtAnyPosition(&artFittingSet, art->getTypeId());
|
const auto dstSlot = ArtifactUtils::getArtAnyPosition(&artFittingSet, art->getTypeId());
|
||||||
if(dstSlot != ArtifactPosition::PRE_FIRST)
|
if(dstSlot != ArtifactPosition::PRE_FIRST)
|
||||||
{
|
{
|
||||||
bma.artsPack0.emplace_back(BulkMoveArtifacts::LinkedSlots(srcSlot, dstSlot));
|
pack.artsPack0.emplace_back(BulkMoveArtifacts::LinkedSlots(srcSlot, dstSlot));
|
||||||
arts.emplace_back(art);
|
arts.emplace_back(art);
|
||||||
artFittingSet.putArtifact(dstSlot, const_cast<CArtifactInstance*>(art));
|
artFittingSet.putArtifact(dstSlot, const_cast<CArtifactInstance*>(art));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const auto sendArtifacts = [&bma, this]()
|
const auto sendArtifacts = [this](BulkMoveArtifacts & bma)
|
||||||
{
|
{
|
||||||
if(!bma.artsPack0.empty())
|
if(!bma.artsPack0.empty())
|
||||||
gameHandler->sendAndApply(&bma);
|
gameHandler->sendAndApply(&bma);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
BulkMoveArtifacts packHero(finishingBattle->winnerHero->getOwner(), ObjectInstanceID::NONE, finishingBattle->winnerHero->id, false);
|
||||||
if(finishingBattle->loserHero)
|
if(finishingBattle->loserHero)
|
||||||
{
|
{
|
||||||
|
packHero.srcArtHolder = finishingBattle->loserHero->id;
|
||||||
|
packHero.askAssemble = true;
|
||||||
for(const auto & artSlot : finishingBattle->loserHero->artifactsWorn)
|
for(const auto & artSlot : finishingBattle->loserHero->artifactsWorn)
|
||||||
{
|
{
|
||||||
if(ArtifactUtils::isArtRemovable(artSlot))
|
if(ArtifactUtils::isArtRemovable(artSlot))
|
||||||
addArtifactToTransfer(artSlot.first, artSlot.second.getArt());
|
addArtifactToTransfer(packHero, artSlot.first, artSlot.second.getArt());
|
||||||
}
|
}
|
||||||
for(const auto & artSlot : finishingBattle->loserHero->artifactsInBackpack)
|
for(const auto & artSlot : finishingBattle->loserHero->artifactsInBackpack)
|
||||||
{
|
{
|
||||||
if(const auto art = artSlot.getArt(); art->getTypeId() != ArtifactID::GRAIL)
|
if(const auto art = artSlot.getArt(); art->getTypeId() != ArtifactID::GRAIL)
|
||||||
addArtifactToTransfer(finishingBattle->loserHero->getArtPos(art), art);
|
addArtifactToTransfer(packHero, finishingBattle->loserHero->getArtPos(art), art);
|
||||||
}
|
}
|
||||||
sendArtifacts();
|
|
||||||
|
|
||||||
bma.askAssemble = false;
|
|
||||||
bma.artsPack0.clear();
|
|
||||||
if(finishingBattle->loserHero->commander)
|
if(finishingBattle->loserHero->commander)
|
||||||
{
|
{
|
||||||
bma.srcCreature = finishingBattle->loserHero->findStack(finishingBattle->loserHero->commander);
|
BulkMoveArtifacts packCommander(finishingBattle->winnerHero->getOwner(), finishingBattle->loserHero->id, finishingBattle->winnerHero->id, false);
|
||||||
|
packCommander.srcCreature = finishingBattle->loserHero->findStack(finishingBattle->loserHero->commander);
|
||||||
for(const auto & artSlot : finishingBattle->loserHero->commander->artifactsWorn)
|
for(const auto & artSlot : finishingBattle->loserHero->commander->artifactsWorn)
|
||||||
addArtifactToTransfer(artSlot.first, artSlot.second.getArt());
|
addArtifactToTransfer(packCommander, artSlot.first, artSlot.second.getArt());
|
||||||
sendArtifacts();
|
sendArtifacts(packCommander);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto armyObj = battle.battleGetArmyObject(battle.otherSide(battleResult->winner));
|
auto armyObj = battle.battleGetArmyObject(battle.otherSide(battleResult->winner));
|
||||||
bma.srcArtHolder = armyObj->id;
|
|
||||||
for(const auto & armySlot : armyObj->stacks)
|
for(const auto & armySlot : armyObj->stacks)
|
||||||
{
|
{
|
||||||
bma.artsPack0.clear();
|
BulkMoveArtifacts packsArmy(finishingBattle->winnerHero->getOwner(), finishingBattle->loserHero->id, finishingBattle->winnerHero->id, false);
|
||||||
bma.interfaceOwner = finishingBattle->winnerHero->getOwner();
|
packsArmy.srcArtHolder = armyObj->id;
|
||||||
bma.srcCreature = armySlot.first;
|
packsArmy.srcCreature = armySlot.first;
|
||||||
for(const auto & artSlot : armySlot.second->artifactsWorn)
|
for(const auto & artSlot : armySlot.second->artifactsWorn)
|
||||||
addArtifactToTransfer(artSlot.first, armySlot.second->getArt(artSlot.first));
|
addArtifactToTransfer(packsArmy, artSlot.first, armySlot.second->getArt(artSlot.first));
|
||||||
sendArtifacts();
|
sendArtifacts(packsArmy);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Display loot
|
// Display loot
|
||||||
if(!arts.empty())
|
if(!arts.empty())
|
||||||
@ -421,67 +474,23 @@ void BattleResultProcessor::endBattleConfirm(const CBattleInfoCallback & battle)
|
|||||||
}
|
}
|
||||||
gameHandler->sendAndApply(&iw);
|
gameHandler->sendAndApply(&iw);
|
||||||
}
|
}
|
||||||
//Eagle Eye secondary skill handling
|
if(!packHero.artsPack0.empty())
|
||||||
if (!cs.spells.empty())
|
sendArtifacts(packHero);
|
||||||
{
|
|
||||||
cs.learn = 1;
|
|
||||||
cs.hid = finishingBattle->winnerHero->id;
|
|
||||||
|
|
||||||
InfoWindow iw;
|
|
||||||
iw.player = finishingBattle->winnerHero->tempOwner;
|
|
||||||
iw.text.appendLocalString(EMetaText::GENERAL_TXT, 221); //Through eagle-eyed observation, %s is able to learn %s
|
|
||||||
iw.text.replaceRawString(finishingBattle->winnerHero->getNameTranslated());
|
|
||||||
|
|
||||||
std::ostringstream names;
|
|
||||||
for (int i = 0; i < cs.spells.size(); i++)
|
|
||||||
{
|
|
||||||
names << "%s";
|
|
||||||
if (i < cs.spells.size() - 2)
|
|
||||||
names << ", ";
|
|
||||||
else if (i < cs.spells.size() - 1)
|
|
||||||
names << "%s";
|
|
||||||
}
|
}
|
||||||
names << ".";
|
|
||||||
|
|
||||||
iw.text.replaceRawString(names.str());
|
// Remove beaten hero
|
||||||
|
if(finishingBattle->loserHero)
|
||||||
auto it = cs.spells.begin();
|
|
||||||
for (int i = 0; i < cs.spells.size(); i++, it++)
|
|
||||||
{
|
|
||||||
iw.text.replaceName(*it);
|
|
||||||
if (i == cs.spells.size() - 2) //we just added pre-last name
|
|
||||||
iw.text.replaceLocalString(EMetaText::GENERAL_TXT, 141); // " and "
|
|
||||||
iw.components.emplace_back(ComponentType::SPELL, *it);
|
|
||||||
}
|
|
||||||
gameHandler->sendAndApply(&iw);
|
|
||||||
gameHandler->sendAndApply(&cs);
|
|
||||||
}
|
|
||||||
cab1.updateArmy(gameHandler);
|
|
||||||
cab2.updateArmy(gameHandler); //take casualties after battle is deleted
|
|
||||||
|
|
||||||
if(finishingBattle->loserHero) //remove beaten hero
|
|
||||||
{
|
{
|
||||||
RemoveObject ro(finishingBattle->loserHero->id, finishingBattle->victor);
|
RemoveObject ro(finishingBattle->loserHero->id, finishingBattle->victor);
|
||||||
gameHandler->sendAndApply(&ro);
|
gameHandler->sendAndApply(&ro);
|
||||||
}
|
}
|
||||||
if(finishingBattle->isDraw() && finishingBattle->winnerHero) //for draw case both heroes should be removed
|
// For draw case both heroes should be removed
|
||||||
|
if(finishingBattle->isDraw() && finishingBattle->winnerHero)
|
||||||
{
|
{
|
||||||
RemoveObject ro(finishingBattle->winnerHero->id, finishingBattle->loser);
|
RemoveObject ro(finishingBattle->winnerHero->id, finishingBattle->loser);
|
||||||
gameHandler->sendAndApply(&ro);
|
gameHandler->sendAndApply(&ro);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(battleResult->winner == BattleSide::DEFENDER
|
|
||||||
&& finishingBattle->winnerHero
|
|
||||||
&& finishingBattle->winnerHero->visitedTown
|
|
||||||
&& !finishingBattle->winnerHero->inTownGarrison
|
|
||||||
&& finishingBattle->winnerHero->visitedTown->garrisonHero == finishingBattle->winnerHero)
|
|
||||||
{
|
|
||||||
gameHandler->swapGarrisonOnSiege(finishingBattle->winnerHero->visitedTown->id); //return defending visitor from garrison to its rightful place
|
|
||||||
}
|
|
||||||
//give exp
|
|
||||||
if(!finishingBattle->isDraw() && battleResult->exp[finishingBattle->winnerSide] && finishingBattle->winnerHero)
|
|
||||||
gameHandler->giveExperience(finishingBattle->winnerHero, battleResult->exp[finishingBattle->winnerSide]);
|
|
||||||
|
|
||||||
BattleResultAccepted raccepted;
|
BattleResultAccepted raccepted;
|
||||||
raccepted.battleID = battle.getBattle()->getBattleID();
|
raccepted.battleID = battle.getBattle()->getBattleID();
|
||||||
raccepted.heroResult[0].army = const_cast<CArmedInstance*>(battle.battleGetArmyObject(BattleSide::ATTACKER));
|
raccepted.heroResult[0].army = const_cast<CArmedInstance*>(battle.battleGetArmyObject(BattleSide::ATTACKER));
|
||||||
|
Loading…
Reference in New Issue
Block a user