From 3d693c20c8dd468e33a4c3eef0177fb5e277ffc4 Mon Sep 17 00:00:00 2001 From: Vera Aguilera Puerto <6766154+Zumorica@users.noreply.github.com> Date: Fri, 16 Sep 2022 22:01:31 +0200 Subject: [PATCH] Spawn with Random Offset component (#10969) Adds SpawnRandomOffsetComponent, which can be used to randomly move a component on map init Co-authored-by: wrexbe --- .../Coordinates/SpawnRandomOffsetComponent.cs | 8 ++++++++ .../Coordinates/SpawnRandomOffsetSystem.cs | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 Content.Server/Coordinates/SpawnRandomOffsetComponent.cs create mode 100644 Content.Server/Coordinates/SpawnRandomOffsetSystem.cs diff --git a/Content.Server/Coordinates/SpawnRandomOffsetComponent.cs b/Content.Server/Coordinates/SpawnRandomOffsetComponent.cs new file mode 100644 index 0000000000..6ae9b927ab --- /dev/null +++ b/Content.Server/Coordinates/SpawnRandomOffsetComponent.cs @@ -0,0 +1,8 @@ +namespace Content.Server.Coordinates; + +[RegisterComponent] +public sealed class SpawnRandomOffsetComponent : Component +{ + [ViewVariables(VVAccess.ReadWrite)] + [DataField("offset")] public float Offset = 0.5f; +} diff --git a/Content.Server/Coordinates/SpawnRandomOffsetSystem.cs b/Content.Server/Coordinates/SpawnRandomOffsetSystem.cs new file mode 100644 index 0000000000..f664ec1225 --- /dev/null +++ b/Content.Server/Coordinates/SpawnRandomOffsetSystem.cs @@ -0,0 +1,20 @@ +using Content.Shared.Random.Helpers; + +namespace Content.Server.Coordinates; + +public sealed class SpawnRandomOffsetSystem : EntitySystem +{ + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnMapInit); + } + + private void OnMapInit(EntityUid uid, SpawnRandomOffsetComponent component, MapInitEvent args) + { + // TODO: Kill this extension with fire, thanks + uid.RandomOffset(component.Offset); + EntityManager.RemoveComponentDeferred(uid, component); + } +}