|
@@ -336,7 +336,7 @@ void PutArtifact::visitTyped(ICPackVisitor & visitor)
|
|
|
visitor.visitPutArtifact(*this);
|
|
|
}
|
|
|
|
|
|
-void EraseArtifact::visitTyped(ICPackVisitor & visitor)
|
|
|
+void BulkEraseArtifacts::visitTyped(ICPackVisitor & visitor)
|
|
|
{
|
|
|
visitor.visitEraseArtifact(*this);
|
|
|
}
|
|
@@ -1611,9 +1611,10 @@ void RebalanceStacks::applyGs(CGameState *gs)
|
|
|
//else - artifact can be lost :/
|
|
|
else
|
|
|
{
|
|
|
- EraseArtifact ea;
|
|
|
- ea.al = ArtifactLocation(dstHero->id, ArtifactPosition::CREATURE_SLOT);
|
|
|
- ea.al.creature = dst.slot;
|
|
|
+ BulkEraseArtifacts ea;
|
|
|
+ ea.artHolder = dstHero->id;
|
|
|
+ ea.posPack.emplace_back(ArtifactPosition::CREATURE_SLOT);
|
|
|
+ ea.creature = dst.slot;
|
|
|
ea.applyGs(gs);
|
|
|
logNetwork->warn("Cannot move artifact! No free slots");
|
|
|
}
|
|
@@ -1701,37 +1702,46 @@ void PutArtifact::applyGs(CGameState *gs)
|
|
|
art->putAt(*hero, al.slot);
|
|
|
}
|
|
|
|
|
|
-void EraseArtifact::applyGs(CGameState *gs)
|
|
|
+void BulkEraseArtifacts::applyGs(CGameState *gs)
|
|
|
{
|
|
|
- const auto artSet = gs->getArtSet(al.artHolder);
|
|
|
+ const auto artSet = gs->getArtSet(artHolder);
|
|
|
assert(artSet);
|
|
|
- const auto slot = artSet->getSlot(al.slot);
|
|
|
- if(slot->locked)
|
|
|
- {
|
|
|
- logGlobal->debug("Erasing locked artifact: %s", slot->artifact->artType->getNameTranslated());
|
|
|
- DisassembledArtifact dis;
|
|
|
- dis.al.artHolder = al.artHolder;
|
|
|
-
|
|
|
- for(auto & slotInfo : artSet->artifactsWorn)
|
|
|
+
|
|
|
+ std::sort(posPack.begin(), posPack.end(), [](const ArtifactPosition & slot0, const ArtifactPosition & slot1) -> bool
|
|
|
+ {
|
|
|
+ return slot0.num > slot1.num;
|
|
|
+ });
|
|
|
+
|
|
|
+ for(const auto & slot : posPack)
|
|
|
+ {
|
|
|
+ const auto slotInfo = artSet->getSlot(slot);
|
|
|
+ if(slotInfo->locked)
|
|
|
{
|
|
|
- auto art = slotInfo.second.artifact;
|
|
|
- if(art->isCombined() && art->isPart(slot->artifact))
|
|
|
+ logGlobal->debug("Erasing locked artifact: %s", slotInfo->artifact->artType->getNameTranslated());
|
|
|
+ DisassembledArtifact dis;
|
|
|
+ dis.al.artHolder = artHolder;
|
|
|
+
|
|
|
+ for(auto & slotInfoWorn : artSet->artifactsWorn)
|
|
|
{
|
|
|
- dis.al.slot = artSet->getArtPos(art);
|
|
|
- break;
|
|
|
+ auto art = slotInfoWorn.second.artifact;
|
|
|
+ if(art->isCombined() && art->isPart(slotInfo->getArt()))
|
|
|
+ {
|
|
|
+ dis.al.slot = artSet->getArtPos(art);
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
+ assert((dis.al.slot != ArtifactPosition::PRE_FIRST) && "Failed to determine the assembly this locked artifact belongs to");
|
|
|
+ logGlobal->debug("Found the corresponding assembly: %s", artSet->getArt(dis.al.slot)->artType->getNameTranslated());
|
|
|
+ dis.applyGs(gs);
|
|
|
}
|
|
|
- assert((dis.al.slot != ArtifactPosition::PRE_FIRST) && "Failed to determine the assembly this locked artifact belongs to");
|
|
|
- logGlobal->debug("Found the corresponding assembly: %s", artSet->getArt(dis.al.slot)->artType->getNameTranslated());
|
|
|
- dis.applyGs(gs);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- logGlobal->debug("Erasing artifact %s", slot->artifact->artType->getNameTranslated());
|
|
|
+ else
|
|
|
+ {
|
|
|
+ logGlobal->debug("Erasing artifact %s", slotInfo->artifact->artType->getNameTranslated());
|
|
|
+ }
|
|
|
+ auto art = artSet->getArt(slot);
|
|
|
+ assert(art);
|
|
|
+ art->removeFrom(*artSet, slot);
|
|
|
}
|
|
|
- auto art = artSet->getArt(al.slot);
|
|
|
- assert(art);
|
|
|
- art->removeFrom(*artSet, al.slot);
|
|
|
}
|
|
|
|
|
|
void BulkMoveArtifacts::applyGs(CGameState *gs)
|