From f4dbc52b9a45ea3e4dcd7190cc8cb1f72d84d08a Mon Sep 17 00:00:00 2001 From: Pyetrek Date: Fri, 26 Aug 2022 08:38:23 -0400 Subject: [PATCH] feat: spawn configs can now rotate the prefab. --- .../ConfigTypes/RaidEventConfigurationFile.cs | 5 +++ .../General/SpawnModifierRotatePrefab.cs | 32 +++++++++++++++++++ .../Spawns/SpawnModificationManager.cs | 1 + 3 files changed, 38 insertions(+) create mode 100755 Valheim.CustomRaids/Valheim.CustomRaids/Spawns/Modifiers/General/SpawnModifierRotatePrefab.cs diff --git a/Valheim.CustomRaids/Valheim.CustomRaids/Configuration/ConfigTypes/RaidEventConfigurationFile.cs b/Valheim.CustomRaids/Valheim.CustomRaids/Configuration/ConfigTypes/RaidEventConfigurationFile.cs index 32973eb..2b3b9a9 100644 --- a/Valheim.CustomRaids/Valheim.CustomRaids/Configuration/ConfigTypes/RaidEventConfigurationFile.cs +++ b/Valheim.CustomRaids/Valheim.CustomRaids/Configuration/ConfigTypes/RaidEventConfigurationFile.cs @@ -223,6 +223,11 @@ public int Index public ConfigurationEntry OceanDepthMax = new(0, "Maximum ocean depth to spawn in. Ignored if min == max."); + public ConfigurationEntry RotationX = new(0, "Rotate the spawned object on the x axis. Defaults to 0"); + + public ConfigurationEntry RotationY = new(0, "Rotate the spawned object on the y axis. Defaults to 0"); + + public ConfigurationEntry RotationZ = new(0, "Rotate the spawned object on the z axis. Defaults to 0"); #endregion } diff --git a/Valheim.CustomRaids/Valheim.CustomRaids/Spawns/Modifiers/General/SpawnModifierRotatePrefab.cs b/Valheim.CustomRaids/Valheim.CustomRaids/Spawns/Modifiers/General/SpawnModifierRotatePrefab.cs new file mode 100755 index 0000000..0152be2 --- /dev/null +++ b/Valheim.CustomRaids/Valheim.CustomRaids/Spawns/Modifiers/General/SpawnModifierRotatePrefab.cs @@ -0,0 +1,32 @@ +using Valheim.CustomRaids.Core; + +namespace Valheim.CustomRaids.Spawns.Modifiers.General; + +public class SpawnModifierRotatePrefab : ISpawnModifier +{ + private static SpawnModifierRotatePrefab _instance; + + public static SpawnModifierRotatePrefab Instance + { + get + { + return _instance ??= new SpawnModifierRotatePrefab(); + } + } + + public void Modify(SpawnContext context) + { + if (context.Spawn is null) + { + return; + } + + float rotationX = context.Config.RotationX.Value; + float rotationY = context.Config.RotationY.Value; + float rotationZ = context.Config.RotationZ.Value; +#if DEBUG + Log.LogDebug($"Rotating object: x{rotationX}, y{rotationY}, z{rotationZ}"); +#endif + context.Spawn.transform.Rotate(rotationX, rotationY, rotationZ); + } +} diff --git a/Valheim.CustomRaids/Valheim.CustomRaids/Spawns/SpawnModificationManager.cs b/Valheim.CustomRaids/Valheim.CustomRaids/Spawns/SpawnModificationManager.cs index 60d9687..9fda9ed 100644 --- a/Valheim.CustomRaids/Valheim.CustomRaids/Spawns/SpawnModificationManager.cs +++ b/Valheim.CustomRaids/Valheim.CustomRaids/Spawns/SpawnModificationManager.cs @@ -15,6 +15,7 @@ public static class SpawnModificationManager static SpawnModificationManager() { SpawnModifiers.Add(SpawnModifierSetFaction.Instance); + SpawnModifiers.Add(SpawnModifierRotatePrefab.Instance); SpawnModifiers.Add(SpawnModifierLoaderCLLC.BossAffix); SpawnModifiers.Add(SpawnModifierLoaderCLLC.ExtraEffect);