From c7ade44d0787a65169451526aa38a9045a65a48b Mon Sep 17 00:00:00 2001 From: nordsoft Date: Sat, 29 Apr 2023 17:52:31 +0400 Subject: [PATCH] Fix skills loading from mods --- lib/mapObjects/JsonRandom.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/mapObjects/JsonRandom.cpp b/lib/mapObjects/JsonRandom.cpp index 9df0770ec..a00684cbe 100644 --- a/lib/mapObjects/JsonRandom.cpp +++ b/lib/mapObjects/JsonRandom.cpp @@ -123,7 +123,9 @@ namespace JsonRandom std::set defaultStats(std::begin(PrimarySkill::names), std::end(PrimarySkill::names)); for(const auto & element : value.Vector()) { - int id = vstd::find_pos(PrimarySkill::names, loadKey(element, rng, defaultStats)); + auto key = loadKey(element, rng, defaultStats); + defaultStats.erase(key); + int id = vstd::find_pos(PrimarySkill::names, key); if(id != -1) ret[id] += loadValue(element, rng); } @@ -153,8 +155,13 @@ namespace JsonRandom for(const auto & element : value.Vector()) { - SecondarySkill id(VLC->modh->identifiers.getIdentifier(element.meta, "skill", loadKey(element, rng, defaultSkills)).value()); - ret[id] = loadValue(element, rng); + auto key = loadKey(element, rng, defaultSkills); + defaultSkills.erase(key); //avoid dupicates + if(auto identifier = VLC->modh->identifiers.getIdentifier(CModHandler::scopeGame(), "skill", key)) + { + SecondarySkill id(identifier.value()); + ret[id] = loadValue(element, rng); + } } } return ret;