diff --git a/lib/rewardable/Limiter.cpp b/lib/rewardable/Limiter.cpp index bf3fb2911..9611f67aa 100644 --- a/lib/rewardable/Limiter.cpp +++ b/lib/rewardable/Limiter.cpp @@ -17,6 +17,7 @@ #include "../serializer/JsonSerializeFormat.h" #include "../constants/StringConstants.h" #include "../CSkillHandler.h" +#include "../ArtifactUtils.h" VCMI_LIB_NAMESPACE_BEGIN @@ -93,12 +94,24 @@ bool Rewardable::Limiter::heroAllowed(const CGHeroInstance * hero) const return false; } - for(const auto & art : artifacts) { - if (!hero->hasArt(art)) + std::unordered_map 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; } - + for(const auto & sublimiter : noneOf) { if (sublimiter->heroAllowed(hero)) diff --git a/lib/rewardable/Limiter.h b/lib/rewardable/Limiter.h index 68639bb68..1f92cf4f0 100644 --- a/lib/rewardable/Limiter.h +++ b/lib/rewardable/Limiter.h @@ -52,7 +52,7 @@ struct DLL_LINKAGE Limiter std::map secondary; /// 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 artifacts; /// Spells that hero must have in the spellbook