浏览代码

Merge pull request #1569 from SoundSSGood/contitutient-swap

combined arts swap
Andrii Danylchenko 2 年之前
父节点
当前提交
71b1d77613
共有 2 个文件被更改,包括 33 次插入29 次删除
  1. 4 3
      client/widgets/CArtifactHolder.cpp
  2. 29 26
      lib/CArtHandler.cpp

+ 4 - 3
client/widgets/CArtifactHolder.cpp

@@ -752,9 +752,10 @@ void CArtifactsOfHero::artifactMoved(const ArtifactLocation & src, const Artifac
 			assert(commonInfo->src.AOH);
 			assert(commonInfo->src.AOH);
 			CCS->curh->dragAndDropCursor("artifact", dst.getArt()->artType->getIconIndex());
 			CCS->curh->dragAndDropCursor("artifact", dst.getArt()->artType->getIconIndex());
 		}
 		}
-		auto art = dst.getArt();
-		if(art && dst.slot == ArtifactPosition::TRANSITION_POS)
-			markPossibleSlots(art);
+		if(!curHero->artifactsTransitionPos.empty())
+		{
+			markPossibleSlots(curHero->getArt(ArtifactPosition::TRANSITION_POS));
+		}
 	}
 	}
 
 
 	updateParentWindow();
 	updateParentWindow();

+ 29 - 26
lib/CArtHandler.cpp

@@ -1023,43 +1023,46 @@ bool CArtifactInstance::isPart(const CArtifactInstance *supposedPart) const
 	return supposedPart == this;
 	return supposedPart == this;
 }
 }
 
 
-bool CCombinedArtifactInstance::canBePutAt(const CArtifactSet *artSet, ArtifactPosition slot, bool assumeDestRemoved) const
+bool CCombinedArtifactInstance::canBePutAt(const CArtifactSet * artSet, ArtifactPosition slot, bool assumeDestRemoved) const
 {
 {
 	if(slot == ArtifactPosition::TRANSITION_POS)
 	if(slot == ArtifactPosition::TRANSITION_POS)
 		return true;
 		return true;
-	bool canMainArtifactBePlaced = CArtifactInstance::canBePutAt(artSet, slot, assumeDestRemoved);
-	if(!canMainArtifactBePlaced)
-		return false; //no is no...
+	if(!CArtifactInstance::canBePutAt(artSet, slot, assumeDestRemoved))
+		return false;
 	if(ArtifactUtils::isSlotBackpack(slot))
 	if(ArtifactUtils::isSlotBackpack(slot))
 		return true; //we can always remove combined art to the backapck
 		return true; //we can always remove combined art to the backapck
 
 
-
-	assert(artType->constituents);
-	std::vector<ConstituentInfo> constituentsToBePlaced = constituentsInfo; //we'll remove constituents from that list, as we find a suitable slot for them
-
-	//it may be that we picked a combined artifact in hero screen (though technically it's still there) to move it
-	//so we remove from the list all constituents that are already present on dst hero in the form of locks
-	for(const ConstituentInfo &constituent : constituentsInfo)
-	{
-		if(constituent.art == artSet->getArt(constituent.slot, false)) //no need to worry about locked constituent
-			constituentsToBePlaced -= constituent;
-	}
-
-	//we iterate over all active slots and check if constituents fits them
-	for(const auto pos : ArtifactUtils::constituentWornSlots())
+	CArtifactFittingSet fittingSet(artSet->bearerType());
+	fittingSet.artifactsWorn = artSet->artifactsWorn;
+	auto artToRemove = fittingSet.getArt(slot);
+	if(assumeDestRemoved && artToRemove)
 	{
 	{
-		for(auto art = constituentsToBePlaced.begin(); art != constituentsToBePlaced.end(); art++)
+		if(artToRemove->canBeDisassembled())
 		{
 		{
-			// pos == slot because we can remove already worn artifact only from that slot. That is our main destination
-			if(art->art->canBePutAt(artSet, pos, pos == slot))
+			auto combinedArtToRemove = dynamic_cast<CCombinedArtifactInstance*>(artToRemove);
+			for(auto & part : combinedArtToRemove->constituentsInfo)
 			{
 			{
-				constituentsToBePlaced.erase(art);
-				break;
+				if(ArtifactUtils::isSlotEquipment(part.slot))
+				{
+					fittingSet.eraseArtSlot(part.slot);
+				}
 			}
 			}
 		}
 		}
+		fittingSet.eraseArtSlot(slot);
 	}
 	}
-
-	return constituentsToBePlaced.empty();
+	for(auto & art : constituentsInfo)
+	{
+		auto possibleSlot = art.art->firstAvailableSlot(&fittingSet);
+		if(ArtifactUtils::isSlotEquipment(possibleSlot))
+		{
+			fittingSet.setNewArtSlot(possibleSlot, nullptr, true);
+		}
+		else
+		{
+			return false;
+		}
+	}
+	return true;
 }
 }
 
 
 bool CCombinedArtifactInstance::canBeDisassembled() const
 bool CCombinedArtifactInstance::canBeDisassembled() const
@@ -1565,7 +1568,7 @@ void CArtifactFittingSet::setNewArtSlot(ArtifactPosition slot, CArtifactInstance
 
 
 void CArtifactFittingSet::putArtifact(ArtifactPosition pos, CArtifactInstance * art)
 void CArtifactFittingSet::putArtifact(ArtifactPosition pos, CArtifactInstance * art)
 {
 {
-	if(art && art->canBeDisassembled() && (pos < ArtifactPosition::AFTER_LAST))
+	if(art && art->canBeDisassembled() && ArtifactUtils::isSlotEquipment(pos))
 	{
 	{
 		for(auto & part : dynamic_cast<CCombinedArtifactInstance*>(art)->constituentsInfo)
 		for(auto & part : dynamic_cast<CCombinedArtifactInstance*>(art)->constituentsInfo)
 		{
 		{