Browse Source

Check for artifacts copies in limiter

nordsoft 2 years ago
parent
commit
937a8d63c7
2 changed files with 17 additions and 4 deletions
  1. 16 3
      lib/rewardable/Limiter.cpp
  2. 1 1
      lib/rewardable/Limiter.h

+ 16 - 3
lib/rewardable/Limiter.cpp

@@ -17,6 +17,7 @@
 #include "../serializer/JsonSerializeFormat.h"
 #include "../serializer/JsonSerializeFormat.h"
 #include "../constants/StringConstants.h"
 #include "../constants/StringConstants.h"
 #include "../CSkillHandler.h"
 #include "../CSkillHandler.h"
+#include "../ArtifactUtils.h"
 
 
 VCMI_LIB_NAMESPACE_BEGIN
 VCMI_LIB_NAMESPACE_BEGIN
 
 
@@ -93,12 +94,24 @@ bool Rewardable::Limiter::heroAllowed(const CGHeroInstance * hero) const
 			return false;
 			return false;
 	}
 	}
 
 
-	for(const auto & art : artifacts)
 	{
 	{
-		if (!hero->hasArt(art))
+		std::unordered_map<ArtifactID, unsigned, ArtifactID::hash> artifactsRequirements; // artifact ID -> required count
+		for(const auto & art : artifacts)
+			++artifactsRequirements[art];
+		
+		size_t reqSlots = 0;
+		for(const auto & elem : artifactsRequirements)
+		{
+			// check required amount of artifacts
+			if(hero->getArtPosCount(elem.first, false, true, true) < elem.second)
+				return false;
+			if(!hero->hasArt(elem.first))
+				reqSlots += hero->getAssemblyByConstituent(elem.first)->getPartsInfo().size() - 2;
+		}
+		if(!ArtifactUtils::isBackpackFreeSlots(hero, reqSlots))
 			return false;
 			return false;
 	}
 	}
-
+	
 	for(const auto & sublimiter : noneOf)
 	for(const auto & sublimiter : noneOf)
 	{
 	{
 		if (sublimiter->heroAllowed(hero))
 		if (sublimiter->heroAllowed(hero))

+ 1 - 1
lib/rewardable/Limiter.h

@@ -52,7 +52,7 @@ struct DLL_LINKAGE Limiter
 	std::map<SecondarySkill, si32> secondary;
 	std::map<SecondarySkill, si32> secondary;
 
 
 	/// artifacts that hero needs to have (equipped or in backpack) to trigger this
 	/// artifacts that hero needs to have (equipped or in backpack) to trigger this
-	/// Note: does not checks for multiple copies of the same arts
+	/// checks for artifacts copies if same artifact id is included multiple times
 	std::vector<ArtifactID> artifacts;
 	std::vector<ArtifactID> artifacts;
 
 
 	/// Spells that hero must have in the spellbook
 	/// Spells that hero must have in the spellbook