Beispiel #1
0
    private static void ApplyWorldSpawnerTemplates(List <SpawnSystemList> spawnLists)
    {
        var templates = WorldSpawnTemplateManager
                        .GetTemplates()
                        .Where(x => x.template.TemplateEnabled)
                        .OrderBy(x => x.id)
                        .ToList();

        Log.LogTrace($"Found {templates.Count} world spawner templates to apply.");

        if (templates.Count == 0)
        {
            return;
        }

        var spawners = spawnLists
                       .SelectMany(x => x.m_spawners)
                       .ToList();

        var mainSpawnList = spawnLists.FirstOrDefault();

        if (mainSpawnList.IsNull())
        {
            Log.LogWarning("Something is really wrong. No SpawnSystemLists found. Skipping configuration of world spawners.");
            return;
        }

        foreach ((int id, WorldSpawnTemplate template) in templates)
        {
            // Validate
            if (!template.TemplateEnabled)
            {
                continue;
            }

            SpawnSystem.SpawnData entry;

            if (ConfigurationManager.GeneralConfig?.AlwaysAppend?.Value == true ||
                id >= spawners.Count)
            {
                entry = new SpawnSystem.SpawnData();
                mainSpawnList.m_spawners.Add(entry);

                Log.LogTrace($"Creating spawner entry for template [{id}:{template.PrefabName}]");

                ConfigureNewEntry(entry, template);
            }
            else
            {
                Log.LogTrace($"Overriding spawner entry [{id}:{spawners[id].m_prefab.name}] with template '{template.TemplateName}'");
                entry = spawners[id];

                ConfigureExistingEntry(entry, template);
            }

            WorldSpawnerManager.SetTemplate(entry, template);
        }
    }