| 15 | namespace Star { |
| 16 | |
| 17 | NpcDatabase::NpcDatabase() { |
| 18 | auto assets = Root::singleton().assets(); |
| 19 | |
| 20 | auto& files = assets->scanExtension("npctype"); |
| 21 | assets->queueJsons(files); |
| 22 | for (auto& file : files) { |
| 23 | try { |
| 24 | auto config = assets->json(file); |
| 25 | String typeName = config.getString("type"); |
| 26 | |
| 27 | if (m_npcTypes.contains(typeName)) |
| 28 | throw NpcException(strf("Repeat npc type name '{}'", typeName)); |
| 29 | |
| 30 | m_npcTypes[typeName] = config; |
| 31 | |
| 32 | } catch (StarException const& e) { |
| 33 | throw NpcException(strf("Error loading npc type '{}'", file), e); |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | NpcVariant NpcDatabase::generateNpcVariant(String const& species, String const& typeName, float level) const { |
| 39 | return generateNpcVariant(species, typeName, level, Random::randu64(), {}); |