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

CGameHandler::buildStructure: give spells after gs apply. Fix issue 2425

Hero will also immidiately get new spells when Library built in Tower or Grail in Conflux.
This commit is contained in:
Arseniy Shestakov 2016-03-13 11:31:09 +03:00
parent 113bd1b9ea
commit bee0c6d705

View File

@ -2787,8 +2787,8 @@ bool CGameHandler::buildStructure( ObjectInstanceID tid, BuildingID requestedID,
}
}
//Performs stuff that has to be done after new building is built
auto processBuiltStructure = [t, this](const BuildingID buildingID)
//Performs stuff that has to be done before new building is built
auto processBeforeBuiltStructure = [t, this](const BuildingID buildingID)
{
if(buildingID >= BuildingID::DWELL_FIRST) //dwelling
{
@ -2817,8 +2817,14 @@ bool CGameHandler::buildStructure( ObjectInstanceID tid, BuildingID requestedID,
{
setPortalDwelling(t);
}
};
if(buildingID <= BuildingID::MAGES_GUILD_5) //it's mage guild
//Performs stuff that has to be done after new building is built
auto processAfterBuiltStructure = [t, this](const BuildingID buildingID)
{
if(buildingID <= BuildingID::MAGES_GUILD_5 || //it's mage guild
(t->subID == ETownType::TOWER && buildingID == BuildingID::LIBRARY) ||
(t->subID == ETownType::CONFLUX && buildingID == BuildingID::GRAIL))
{
if(t->visitingHero)
giveSpells(t,t->visitingHero);
@ -2869,9 +2875,9 @@ bool CGameHandler::buildStructure( ObjectInstanceID tid, BuildingID requestedID,
}
}
//Other post-built events
// FIXME: it's done before NewStructures applied because otherwise town window wont be properly updated on client. That should be actually fixed on client and not on server.
for(auto builtID : ns.bid)
processBuiltStructure(builtID);
processBeforeBuiltStructure(builtID);
//Take cost
if (!force)
@ -2885,6 +2891,10 @@ bool CGameHandler::buildStructure( ObjectInstanceID tid, BuildingID requestedID,
//We know what has been built, appluy changes. Do this as final step to properly update town window
sendAndApply(&ns);
//Other post-built events. To some logic like giving spells to work gamestate changes for new building must be already in place!
for(auto builtID : ns.bid)
processAfterBuiltStructure(builtID);
// now when everything is built - reveal tiles for lookout tower
FoWChange fw;
fw.player = t->tempOwner;