浏览代码

Backpack limit part3 finishQuest

SoundSSGood 2 年之前
父节点
当前提交
ca5c9910a4
共有 3 个文件被更改,包括 28 次插入11 次删除
  1. 2 1
      lib/mapObjects/CBank.cpp
  2. 2 1
      lib/mapObjects/CGPandoraBox.cpp
  3. 24 9
      lib/mapObjects/CQuest.cpp

+ 2 - 1
lib/mapObjects/CBank.cpp

@@ -238,7 +238,8 @@ void CBank::doVisit(const CGHeroInstance * hero) const
 			iw.components.emplace_back(Component::EComponentType::ARTIFACT, elem, 0, 0);
 			loot << "%s";
 			loot.addReplacement(MetaString::ART_NAMES, elem);
-			cb->giveHeroNewArtifact(hero, VLC->arth->objects[elem], ArtifactPosition::FIRST_AVAILABLE);
+			if(ArtifactUtils::isPossibleToGetArt(hero, elem))
+				cb->giveHeroNewArtifact(hero, VLC->arth->objects[elem], ArtifactPosition::FIRST_AVAILABLE);
 		}
 		//display loot
 		if (!iw.components.empty())

+ 2 - 1
lib/mapObjects/CGPandoraBox.cpp

@@ -248,7 +248,8 @@ void CGPandoraBox::giveContentsAfterExp(const CGHeroInstance *h) const
 	cb->giveResources(h->getOwner(), resources);
 
 	for(const auto & elem : artifacts)
-		cb->giveHeroNewArtifact(h, VLC->arth->objects[elem],ArtifactPosition::FIRST_AVAILABLE);
+		if(ArtifactUtils::isPossibleToGetArt(h, elem))
+			cb->giveHeroNewArtifact(h, VLC->arth->objects[elem],ArtifactPosition::FIRST_AVAILABLE);
 
 	iw.components.clear();
 	iw.text.clear();

+ 24 - 9
lib/mapObjects/CQuest.cpp

@@ -140,18 +140,26 @@ bool CQuest::checkQuest(const CGHeroInstance * h) const
 				return true;
 			return false;
 		case MISSION_ART:
+		{
 			// if the object was deserialized
 			if(artifactsRequirements.empty())
 				for(const auto & id : m5arts)
 					++artifactsRequirements[id];
 
+			size_t reqSlots = 0;
 			for(const auto & elem : artifactsRequirements)
 			{
 				// check required amount of artifacts
 				if(h->getArtPosCount(elem.first, false, true, true) < elem.second)
 					return false;
+				if(!h->hasArt(elem.first))
+					reqSlots += h->getAssemblyByConstituent(elem.first)->constituentsInfo.size() - 2;
 			}
-			return true;
+			if(ArtifactUtils::isBackpackFreeSlots(h, reqSlots))
+				return true;
+			else
+				return false;
+		}
 		case MISSION_ARMY:
 			return checkMissionArmy(this, h);
 		case MISSION_RESOURCES:
@@ -786,21 +794,28 @@ void CGSeerHut::finishQuest(const CGHeroInstance * h, ui32 accept) const
 		switch (quest->missionType)
 		{
 			case CQuest::MISSION_ART:
-				for (auto & elem : quest->m5arts)
+				for(auto & elem : quest->m5arts)
 				{
-					if(!h->hasArt(elem))
+					if(h->hasArt(elem))
+					{
+						cb->removeArtifact(ArtifactLocation(h, h->getArtPos(elem, false)));
+					}
+					else
 					{
-						// first we need to disassemble this backpack artifact
 						const auto * assembly = h->getAssemblyByConstituent(elem);
 						assert(assembly);
-						for(const auto & ci : assembly->constituentsInfo)
+						auto parts = assembly->constituentsInfo;
+
+						// Remove the assembly
+						cb->removeArtifact(ArtifactLocation(h, h->getArtPos(assembly)));
+
+						// Disassemble this backpack artifact
+						for(const auto & ci : parts)
 						{
-							cb->giveHeroNewArtifact(h, ci.art->artType, ArtifactPosition::PRE_FIRST);
+							if(ci.art->artType->getId() != elem)
+								cb->giveHeroNewArtifact(h, ci.art->artType, GameConstants::BACKPACK_START);
 						}
-						// remove the assembly
-						cb->removeArtifact(ArtifactLocation(h, h->getArtPos(assembly)));
 					}
-					cb->removeArtifact(ArtifactLocation(h, h->getArtPos(elem, false)));
 				}
 				break;
 			case CQuest::MISSION_ARMY: