From 617f92df65b454fd1c3435a4d42af6441a911d77 Mon Sep 17 00:00:00 2001 From: Alex Evgrashin Date: Mon, 7 Feb 2022 05:26:10 +0300 Subject: [PATCH] More xeno artifacts effects (#6282) --- Content.Client/Entry/IgnoredComponents.cs | 3 + .../XenoArtifacts/ArtifactSystem.cs | 1 + .../Components/GasArtifactComponent.cs | 65 +++++++++++++++++++ .../Components/RadiateArtifactComponent.cs | 23 +++++++ .../TemperatureArtifactComponent.cs | 23 +++++++ .../Effects/Systems/GasArtifactSystem.cs | 57 ++++++++++++++++ .../Effects/Systems/RadiateArtifactSystem.cs | 26 ++++++++ .../Effects/Systems/SpawnArtifactSystem.cs | 4 +- .../Systems/TemperatureArtifactSystem.cs | 36 ++++++++++ .../Events/RandomizeTriggerEvent.cs | 11 ++++ .../RandomArtifactSpriteSystem.cs | 6 +- .../Systems/ArtifactGasTriggerSystem.cs | 27 ++++---- .../Markers/Spawners/Random/artifacts.yml | 4 ++ .../Specific/Xenoarchaeology/artifacts.yml | 30 +++++++++ .../xeno_artifacts.rsi/meta.json | 6 +- 15 files changed, 299 insertions(+), 23 deletions(-) create mode 100644 Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Components/GasArtifactComponent.cs create mode 100644 Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Components/RadiateArtifactComponent.cs create mode 100644 Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Components/TemperatureArtifactComponent.cs create mode 100644 Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Systems/GasArtifactSystem.cs create mode 100644 Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Systems/RadiateArtifactSystem.cs create mode 100644 Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Systems/TemperatureArtifactSystem.cs create mode 100644 Content.Server/Xenoarchaeology/XenoArtifacts/Events/RandomizeTriggerEvent.cs diff --git a/Content.Client/Entry/IgnoredComponents.cs b/Content.Client/Entry/IgnoredComponents.cs index 8e6e1b2673..828dfe6589 100644 --- a/Content.Client/Entry/IgnoredComponents.cs +++ b/Content.Client/Entry/IgnoredComponents.cs @@ -119,6 +119,9 @@ namespace Content.Client.Entry "RCDAmmo", "CursedEntityStorage", "Radio", + "GasArtifact", + "RadiateArtifact", + "TemperatureArtifact", "DisposalHolder", "DisposalTagger", "DisposalRouter", diff --git a/Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.cs b/Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.cs index ca62871709..6ba1800f0d 100644 --- a/Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.cs +++ b/Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.cs @@ -36,6 +36,7 @@ public class ArtifactSystem : EntitySystem trigger.Owner = uid; EntityManager.AddComponent(uid, trigger); + RaiseLocalEvent(uid, new RandomizeTriggerEvent()); } public bool TryActivateArtifact(EntityUid uid, EntityUid? user = null, diff --git a/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Components/GasArtifactComponent.cs b/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Components/GasArtifactComponent.cs new file mode 100644 index 0000000000..dad141f1d3 --- /dev/null +++ b/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Components/GasArtifactComponent.cs @@ -0,0 +1,65 @@ +using Content.Shared.Atmos; +using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; + +namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components; + +/// +/// Spawn a random gas with random temperature when artifact activated. +/// +[RegisterComponent] +public class GasArtifactComponent : Component +{ + public override string Name => "GasArtifact"; + + /// + /// Gas that will be spawned when artifact activated. + /// If null it will be picked on startup from . + /// + [ViewVariables(VVAccess.ReadWrite)] + [DataField("spawnGas")] + public Gas? SpawnGas; + + /// + /// List of possible activation gases to pick on startup. + /// + [DataField("possibleGas")] + public Gas[] PossibleGases = + { + Gas.Oxygen, + Gas.Plasma, + Gas.Nitrogen, + Gas.CarbonDioxide, + Gas.Tritium + }; + + /// + /// Temperature of spawned gas. If null it will be picked on startup from range from + /// to . + /// + [ViewVariables(VVAccess.ReadWrite)] + [DataField("spawnTemperature")] + public float? SpawnTemperature; + + [DataField("minRandomTemp")] + public float MinRandomTemperature = 100; + + [DataField("maxRandomTemp")] + public float MaxRandomTemperature = 400; + + /// + /// Max allowed external atmospheric pressure. + /// Artifact will stop spawn gas. + /// + [ViewVariables(VVAccess.ReadWrite)] + [DataField("maxExternalPressure")] + public float MaxExternalPressure = Atmospherics.GasMinerDefaultMaxExternalPressure; + + /// + /// Moles of gas to spawn each time when artifact activated. + /// + [ViewVariables(VVAccess.ReadWrite)] + [DataField("spawnAmount")] + public float SpawnAmount = Atmospherics.MolesCellStandard * 3; +} diff --git a/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Components/RadiateArtifactComponent.cs b/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Components/RadiateArtifactComponent.cs new file mode 100644 index 0000000000..249e9f4abe --- /dev/null +++ b/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Components/RadiateArtifactComponent.cs @@ -0,0 +1,23 @@ +using Content.Server.Radiation; +using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; + +namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components; + +/// +/// Spawn RadiationPulse when artifact activated. +/// +[RegisterComponent] +public class RadiateArtifactComponent : Component +{ + public override string Name => "RadiateArtifact"; + + /// + /// Radiation pulse prototype to spawn. + /// Should has . + /// + [DataField("pulsePrototype", customTypeSerializer:typeof(PrototypeIdSerializer))] + public string PulsePrototype = "RadiationPulse"; +} diff --git a/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Components/TemperatureArtifactComponent.cs b/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Components/TemperatureArtifactComponent.cs new file mode 100644 index 0000000000..4d62253045 --- /dev/null +++ b/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Components/TemperatureArtifactComponent.cs @@ -0,0 +1,23 @@ +using Content.Shared.Atmos; +using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; + +namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components; + +/// +/// Change atmospherics temperature until it reach target. +/// +[RegisterComponent] +public class TemperatureArtifactComponent : Component +{ + public override string Name => "TemperatureArtifact"; + + [DataField("targetTemp")] + public float TargetTemperature = Atmospherics.T0C; + + [DataField("spawnTemp")] + public float SpawnTemperature = 100; + + [DataField("maxTempDif")] + public float MaxTemperatureDifference = 1; +} diff --git a/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Systems/GasArtifactSystem.cs b/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Systems/GasArtifactSystem.cs new file mode 100644 index 0000000000..bce2a3a5de --- /dev/null +++ b/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Systems/GasArtifactSystem.cs @@ -0,0 +1,57 @@ +using Content.Server.Atmos; +using Content.Server.Atmos.EntitySystems; +using Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components; +using Content.Server.Xenoarchaeology.XenoArtifacts.Events; +using Robust.Shared.GameObjects; +using Robust.Shared.IoC; +using Robust.Shared.Random; + +namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems; + +public class GasArtifactSystem : EntitySystem +{ + [Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!; + [Dependency] private readonly IRobustRandom _random = default!; + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnMapInit); + SubscribeLocalEvent(OnActivate); + } + + private void OnMapInit(EntityUid uid, GasArtifactComponent component, MapInitEvent args) + { + if (component.SpawnGas == null && component.PossibleGases.Length != 0) + { + var gas = _random.Pick(component.PossibleGases); + component.SpawnGas = gas; + } + + if (component.SpawnTemperature == null) + { + var temp = _random.NextFloat(component.MinRandomTemperature, component.MaxRandomTemperature); + component.SpawnTemperature = temp; + } + } + + private void OnActivate(EntityUid uid, GasArtifactComponent component, ArtifactActivatedEvent args) + { + if (component.SpawnGas == null || component.SpawnTemperature == null) + return; + + var transform = Transform(uid); + + var environment = _atmosphereSystem.GetTileMixture(transform.Coordinates, true); + if (environment == null) + return; + + if (environment.Pressure >= component.MaxExternalPressure) + return; + + var merger = new GasMixture(1) { Temperature = component.SpawnTemperature.Value }; + merger.SetMoles(component.SpawnGas.Value, component.SpawnAmount); + + _atmosphereSystem.Merge(environment, merger); + } +} diff --git a/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Systems/RadiateArtifactSystem.cs b/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Systems/RadiateArtifactSystem.cs new file mode 100644 index 0000000000..0e7dc5faf2 --- /dev/null +++ b/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Systems/RadiateArtifactSystem.cs @@ -0,0 +1,26 @@ +using Content.Server.Radiation; +using Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components; +using Content.Server.Xenoarchaeology.XenoArtifacts.Events; +using Robust.Shared.GameObjects; + +namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems; + +public class RadiateArtifactSystem : EntitySystem +{ + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnActivate); + } + + private void OnActivate(EntityUid uid, RadiateArtifactComponent component, ArtifactActivatedEvent args) + { + var transform = Transform(uid); + + var pulseUid = EntityManager.SpawnEntity(component.PulsePrototype, transform.Coordinates); + if (!TryComp(pulseUid, out RadiationPulseComponent? pulse)) + return; + + pulse.DoPulse(); + } +} diff --git a/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Systems/SpawnArtifactSystem.cs b/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Systems/SpawnArtifactSystem.cs index 9dc8559a23..de2fda3ffe 100644 --- a/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Systems/SpawnArtifactSystem.cs +++ b/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Systems/SpawnArtifactSystem.cs @@ -16,10 +16,10 @@ public class SpawnArtifactSystem : EntitySystem public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(OnInit); + SubscribeLocalEvent(OnMapInit); SubscribeLocalEvent(OnActivate); } - private void OnInit(EntityUid uid, SpawnArtifactComponent component, ComponentInit args) + private void OnMapInit(EntityUid uid, SpawnArtifactComponent component, MapInitEvent args) { ChooseRandomPrototype(uid, component); } diff --git a/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Systems/TemperatureArtifactSystem.cs b/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Systems/TemperatureArtifactSystem.cs new file mode 100644 index 0000000000..40c9146bb7 --- /dev/null +++ b/Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Systems/TemperatureArtifactSystem.cs @@ -0,0 +1,36 @@ +using System; +using Content.Server.Atmos.EntitySystems; +using Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components; +using Content.Server.Xenoarchaeology.XenoArtifacts.Events; +using Robust.Shared.GameObjects; +using Robust.Shared.IoC; + +namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems; + +public class TemperatureArtifactSystem : EntitySystem +{ + [Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!; + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnActivate); + } + + private void OnActivate(EntityUid uid, TemperatureArtifactComponent component, ArtifactActivatedEvent args) + { + var transform = Transform(uid); + + var environment = _atmosphereSystem.GetTileMixture(transform.Coordinates, true); + if (environment == null) + return; + + var dif = component.TargetTemperature - environment.Temperature; + var absDif = Math.Abs(dif); + if (absDif < component.MaxTemperatureDifference) + return; + + var step = Math.Min(absDif, component.SpawnTemperature); + environment.Temperature += dif > 0 ? step : -step; + } +} diff --git a/Content.Server/Xenoarchaeology/XenoArtifacts/Events/RandomizeTriggerEvent.cs b/Content.Server/Xenoarchaeology/XenoArtifacts/Events/RandomizeTriggerEvent.cs new file mode 100644 index 0000000000..3aa03fd46d --- /dev/null +++ b/Content.Server/Xenoarchaeology/XenoArtifacts/Events/RandomizeTriggerEvent.cs @@ -0,0 +1,11 @@ +using Robust.Shared.GameObjects; + +namespace Content.Server.Xenoarchaeology.XenoArtifacts.Events; + +/// +/// Force to randomize artifact triggers. +/// +public class RandomizeTriggerEvent : EntityEventArgs +{ + +} diff --git a/Content.Server/Xenoarchaeology/XenoArtifacts/RandomArtifactSpriteSystem.cs b/Content.Server/Xenoarchaeology/XenoArtifacts/RandomArtifactSpriteSystem.cs index 4bbe2a3e67..59cfb94952 100644 --- a/Content.Server/Xenoarchaeology/XenoArtifacts/RandomArtifactSpriteSystem.cs +++ b/Content.Server/Xenoarchaeology/XenoArtifacts/RandomArtifactSpriteSystem.cs @@ -16,7 +16,7 @@ public class RandomArtifactSpriteSystem : EntitySystem public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(OnInit); + SubscribeLocalEvent(OnMapInit); SubscribeLocalEvent(OnActivated); } @@ -27,7 +27,7 @@ public class RandomArtifactSpriteSystem : EntitySystem foreach (var (component, appearance) in query) { if (component.ActivationStart == null) - return; + continue; var timeDif = _time.CurTime - component.ActivationStart.Value; if (timeDif.Seconds >= component.ActivationTime) @@ -38,7 +38,7 @@ public class RandomArtifactSpriteSystem : EntitySystem } } - private void OnInit(EntityUid uid, RandomArtifactSpriteComponent component, ComponentInit args) + private void OnMapInit(EntityUid uid, RandomArtifactSpriteComponent component, MapInitEvent args) { if (!TryComp(uid, out AppearanceComponent? appearance)) return; diff --git a/Content.Server/Xenoarchaeology/XenoArtifacts/Triggers/Systems/ArtifactGasTriggerSystem.cs b/Content.Server/Xenoarchaeology/XenoArtifacts/Triggers/Systems/ArtifactGasTriggerSystem.cs index 1cc7cd331f..0d47f20975 100644 --- a/Content.Server/Xenoarchaeology/XenoArtifacts/Triggers/Systems/ArtifactGasTriggerSystem.cs +++ b/Content.Server/Xenoarchaeology/XenoArtifacts/Triggers/Systems/ArtifactGasTriggerSystem.cs @@ -1,4 +1,5 @@ using Content.Server.Atmos.EntitySystems; +using Content.Server.Xenoarchaeology.XenoArtifacts.Events; using Content.Server.Xenoarchaeology.XenoArtifacts.Triggers.Components; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -15,7 +16,16 @@ public class ArtifactGasTriggerSystem : EntitySystem public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(OnInit); + SubscribeLocalEvent(OnRandomizeTrigger); + } + + private void OnRandomizeTrigger(EntityUid uid, ArtifactGasTriggerComponent component, RandomizeTriggerEvent args) + { + if (component.ActivationGas == null) + { + var gas = _random.Pick(component.PossibleGases); + component.ActivationGas = gas; + } } public override void Update(float frameTime) @@ -25,27 +35,18 @@ public class ArtifactGasTriggerSystem : EntitySystem foreach (var (trigger, transform) in query) { if (trigger.ActivationGas == null) - return; + continue; var environment = _atmosphereSystem.GetTileMixture(transform.Coordinates, true); if (environment == null) - return; + continue; // check if outside there is enough moles to activate artifact var moles = environment.GetMoles(trigger.ActivationGas.Value); if (moles < trigger.ActivationMoles) - return; + continue; _artifactSystem.TryActivateArtifact(trigger.Owner); } } - - private void OnInit(EntityUid uid, ArtifactGasTriggerComponent component, ComponentInit args) - { - if (component.ActivationGas == null) - { - var gas = _random.Pick(component.PossibleGases); - component.ActivationGas = gas; - } - } } diff --git a/Resources/Prototypes/Entities/Markers/Spawners/Random/artifacts.yml b/Resources/Prototypes/Entities/Markers/Spawners/Random/artifacts.yml index 97a4149946..6d277e0625 100644 --- a/Resources/Prototypes/Entities/Markers/Spawners/Random/artifacts.yml +++ b/Resources/Prototypes/Entities/Markers/Spawners/Random/artifacts.yml @@ -14,6 +14,10 @@ - AngryMobsSpawnArtifact - JunkSpawnArtifact - BananaSpawnArtifact + - HeatArtifact + - ColdArtifact + - RadiateArtifact + - GasArtifact chance: 1 - type: entity diff --git a/Resources/Prototypes/Entities/Objects/Specific/Xenoarchaeology/artifacts.yml b/Resources/Prototypes/Entities/Objects/Specific/Xenoarchaeology/artifacts.yml index 75ea5de5da..53c982dfd0 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/Xenoarchaeology/artifacts.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/Xenoarchaeology/artifacts.yml @@ -122,3 +122,33 @@ maxSpawns: 20 possiblePrototypes: - FoodBanana + +- type: entity + parent: BaseXenoArtifact + id: HeatArtifact + suffix: Heat + components: + - type: TemperatureArtifact + targetTemp: 400 # around 125 celsius + +- type: entity + parent: BaseXenoArtifact + id: ColdArtifact + suffix: Cold + components: + - type: TemperatureArtifact + targetTemp: 150 # around -125 celsius + +- type: entity + parent: BaseXenoArtifact + id: RadiateArtifact + suffix: Radiation + components: + - type: RadiateArtifact + +- type: entity + parent: BaseXenoArtifact + id: GasArtifact + suffix: Gas + components: + - type: GasArtifact diff --git a/Resources/Textures/Objects/Specific/Xenoarchaeology/xeno_artifacts.rsi/meta.json b/Resources/Textures/Objects/Specific/Xenoarchaeology/xeno_artifacts.rsi/meta.json index fda4b97b5a..47903ab4b1 100644 --- a/Resources/Textures/Objects/Specific/Xenoarchaeology/xeno_artifacts.rsi/meta.json +++ b/Resources/Textures/Objects/Specific/Xenoarchaeology/xeno_artifacts.rsi/meta.json @@ -219,11 +219,7 @@ 0.1, 0.1, 0.1, - 0.1, - 0.1, - 0.1, - 0.1, - 0.1 + 0.1 ] ] },