internal static void ModifySpawn(CreatureSpawner spawner, GameObject spawn)
    {
        var template = LocalSpawnerManager.GetTemplate(spawner);

        if (template is null)
        {
#if DEBUG
            Log.LogTrace($"Found no config for {spawn}.");
#endif
            return;
        }

        Log.LogTrace($"Applying modifiers to spawn {spawn.name}");

        var spawnZdo = ComponentCache.GetZdo(spawn);

        if (template.Modifiers is not null)
        {
            foreach (var modifier in template.Modifiers)
            {
                try
                {
                    modifier?.Modify(spawn, spawnZdo);
                }
                catch (Exception e)
                {
                    Log.LogError($"Error while attempting to apply modifier '{modifier?.GetType()?.Name}' to local spawner '{spawner.name}'", e);
                }
            }
        }
    }
    private static void SetCommandable(Tameable __instance)
    {
        var zdo = ComponentCache.GetZdo(__instance);

        if (zdo is null)
        {
            return;
        }

        if (zdo.GetBool("spawnthat_tamed_commandable", false))
        {
            __instance.m_commandable = true;
        }
    }
    internal static bool CheckConditionsValid(CreatureSpawner spawner)
    {
#if DEBUG && VERBOSE
        Log.LogTrace($"Testing conditions of spawner '{spawner.name}:{spawner.transform.position}'");
#endif

        var template = LocalSpawnerManager.GetTemplate(spawner);

        if (template is not null && !template.Enabled)
        {
            return(false);
        }

        if (template?.SpawnConditions is null)
        {
            return(true);
        }

        var spawnerZdo = ComponentCache.GetZdo(spawner);

        if (spawnerZdo is null)
        {
            return(true);
        }

        SpawnSessionContext context = new(spawnerZdo);

        foreach (var condition in template.SpawnConditions)
        {
            try
            {
                var validCondition = condition?.IsValid(context) ?? true;

                if (!validCondition)
                {
#if DEBUG && VERBOSE
                    Log.LogTrace($"Local Spawner '{spawner.name}', Invalid condition '{condition.GetType().Name}'");
#endif
                    return(false);
                }
            }
            catch (Exception e)
            {
                Log.LogError($"Error while attempting to check spawn condition '{condition?.GetType()?.Name}' for local spawner '{spawner.name}'. Ignoring condition", e);
            }
        }

        return(true);
    }
Example #4
0
    public static void StartSession(SpawnSystem spawner)
    {
        try
        {
#if FALSE && DEBUG && VERBOSE
            Log.LogDebug("WorldSpawnSessionManager.StartSession");
#endif

            Spawner = spawner;
            Context = new(ComponentCache.GetZdo(Spawner));
        }
        catch (Exception e)
        {
            Log.LogError("Error during initialization of new SpawnSystem session", e);
        }
    }
Example #5
0
    private static void ForceAlert(BaseAI __instance, ref bool alert)
    {
        var zdo = ComponentCache.GetZdo(__instance);

        if (zdo is null)
        {
            return;
        }

        var forceAlert = zdo.GetBool(ModifierSetRelentless.ZdoFeatureHash, false);

        if (!alert && forceAlert)
        {
            __instance.Alert();
            alert = true;
        }
    }
Example #6
0
    private static void StartAlerted(MonsterAI __instance)
    {
        var zdo = ComponentCache.GetZdo(__instance);

        if (zdo is null)
        {
            return;
        }

        var forceAlert = zdo.GetBool(ModifierSetRelentless.ZdoFeatureHash, false);

        if (forceAlert)
        {
            Log.LogTrace($"Initializing forced alertness for {__instance.gameObject.name}");
            __instance.Alert();
        }
    }
Example #7
0
    public static void ModifySpawn(GameObject spawn, bool isEventCreature)
    {
#if DEBUG && VERBOSE
        Log.LogDebug("WorldSpawnSessionManager.ModifySpawn");
#endif
        if (isEventCreature)
        {
            return;
        }

        if (SpawnTemplate?.SpawnModifiers is null)
        {
            return;
        }

        var zdo = ComponentCache.GetZdo(spawn);

        if (zdo is null)
        {
            return;
        }

        foreach (var modifier in SpawnTemplate.SpawnModifiers)
        {
            try
            {
                modifier?.Modify(spawn, zdo);
            }
            catch (Exception e)
            {
                string spawnName = spawn.IsNotNull()
                    ? spawn.name
                    : "";

                Log.LogError($"Error while attempting to apply modifier {modifier.GetType().Name} to entity '{spawnName}' from world spawn template {SpawnTemplate.TemplateName}", e);
            }
        }
    }