mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Check for artifacts copies in limiter
This commit is contained in:
@@ -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))
|
||||||
|
@@ -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
|
||||||
|
Reference in New Issue
Block a user