1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00

Random selection for secondary skills

This commit is contained in:
nordsoft 2023-04-07 20:34:11 +04:00
parent ea0d8f292c
commit 6e538dab30

View File

@ -20,6 +20,7 @@
#include "../CCreatureHandler.h"
#include "../CCreatureSet.h"
#include "../spells/CSpellHandler.h"
#include "../CSkillHandler.h"
VCMI_LIB_NAMESPACE_BEGIN
@ -136,11 +137,40 @@ namespace JsonRandom
std::map<SecondarySkill, si32> loadSecondary(const JsonNode & value, CRandomGenerator & rng)
{
std::map<SecondarySkill, si32> ret;
std::vector<SecondarySkill> except;
for(const auto & pair : value.Struct())
{
std::string skillName = pair.first;
if(skillName == "random")
{
if(pair.second.isNumber())
skillName = RandomGeneratorUtil::nextItem(VLC->skillh->objects, rng)->get()->getNameTextID();
else
{
auto skill = *RandomGeneratorUtil::nextItem(loadSecondary(pair.second, rng), rng);
ret[skill.first] = skill.second;
}
}
else if(skillName == "except")
{
for(auto & i : pair.second.Vector())
{
SecondarySkill id(VLC->modh->identifiers.getIdentifier(pair.second.meta, "skill", i.String()).get());
except.push_back(id);
}
}
else
{
SecondarySkill id(VLC->modh->identifiers.getIdentifier(pair.second.meta, "skill", pair.first).get());
ret[id] = loadValue(pair.second, rng);
}
}
for(auto & i : except)
ret.erase(i);
return ret;
}