More xeno artifacts effects (#6282)

This commit is contained in:
Alex Evgrashin
2022-02-07 05:26:10 +03:00
committed by GitHub
parent be7a770b78
commit 617f92df65
15 changed files with 299 additions and 23 deletions

View File

@@ -119,6 +119,9 @@ namespace Content.Client.Entry
"RCDAmmo", "RCDAmmo",
"CursedEntityStorage", "CursedEntityStorage",
"Radio", "Radio",
"GasArtifact",
"RadiateArtifact",
"TemperatureArtifact",
"DisposalHolder", "DisposalHolder",
"DisposalTagger", "DisposalTagger",
"DisposalRouter", "DisposalRouter",

View File

@@ -36,6 +36,7 @@ public class ArtifactSystem : EntitySystem
trigger.Owner = uid; trigger.Owner = uid;
EntityManager.AddComponent(uid, trigger); EntityManager.AddComponent(uid, trigger);
RaiseLocalEvent(uid, new RandomizeTriggerEvent());
} }
public bool TryActivateArtifact(EntityUid uid, EntityUid? user = null, public bool TryActivateArtifact(EntityUid uid, EntityUid? user = null,

View File

@@ -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;
/// <summary>
/// Spawn a random gas with random temperature when artifact activated.
/// </summary>
[RegisterComponent]
public class GasArtifactComponent : Component
{
public override string Name => "GasArtifact";
/// <summary>
/// Gas that will be spawned when artifact activated.
/// If null it will be picked on startup from <see cref="PossibleGases"/>.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("spawnGas")]
public Gas? SpawnGas;
/// <summary>
/// List of possible activation gases to pick on startup.
/// </summary>
[DataField("possibleGas")]
public Gas[] PossibleGases =
{
Gas.Oxygen,
Gas.Plasma,
Gas.Nitrogen,
Gas.CarbonDioxide,
Gas.Tritium
};
/// <summary>
/// Temperature of spawned gas. If null it will be picked on startup from range from
/// <see cref="MinRandomTemperature"/> to <see cref="MaxRandomTemperature"/>.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("spawnTemperature")]
public float? SpawnTemperature;
[DataField("minRandomTemp")]
public float MinRandomTemperature = 100;
[DataField("maxRandomTemp")]
public float MaxRandomTemperature = 400;
/// <summary>
/// Max allowed external atmospheric pressure.
/// Artifact will stop spawn gas.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("maxExternalPressure")]
public float MaxExternalPressure = Atmospherics.GasMinerDefaultMaxExternalPressure;
/// <summary>
/// Moles of gas to spawn each time when artifact activated.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("spawnAmount")]
public float SpawnAmount = Atmospherics.MolesCellStandard * 3;
}

View File

@@ -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;
/// <summary>
/// Spawn RadiationPulse when artifact activated.
/// </summary>
[RegisterComponent]
public class RadiateArtifactComponent : Component
{
public override string Name => "RadiateArtifact";
/// <summary>
/// Radiation pulse prototype to spawn.
/// Should has <see cref="RadiationPulseComponent"/>.
/// </summary>
[DataField("pulsePrototype", customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
public string PulsePrototype = "RadiationPulse";
}

View File

@@ -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;
/// <summary>
/// Change atmospherics temperature until it reach target.
/// </summary>
[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;
}

View File

@@ -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<GasArtifactComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<GasArtifactComponent, ArtifactActivatedEvent>(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);
}
}

View File

@@ -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<RadiateArtifactComponent, ArtifactActivatedEvent>(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();
}
}

View File

@@ -16,10 +16,10 @@ public class SpawnArtifactSystem : EntitySystem
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<SpawnArtifactComponent, ComponentInit>(OnInit); SubscribeLocalEvent<SpawnArtifactComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<SpawnArtifactComponent, ArtifactActivatedEvent>(OnActivate); SubscribeLocalEvent<SpawnArtifactComponent, ArtifactActivatedEvent>(OnActivate);
} }
private void OnInit(EntityUid uid, SpawnArtifactComponent component, ComponentInit args) private void OnMapInit(EntityUid uid, SpawnArtifactComponent component, MapInitEvent args)
{ {
ChooseRandomPrototype(uid, component); ChooseRandomPrototype(uid, component);
} }

View File

@@ -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<TemperatureArtifactComponent, ArtifactActivatedEvent>(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;
}
}

View File

@@ -0,0 +1,11 @@
using Robust.Shared.GameObjects;
namespace Content.Server.Xenoarchaeology.XenoArtifacts.Events;
/// <summary>
/// Force to randomize artifact triggers.
/// </summary>
public class RandomizeTriggerEvent : EntityEventArgs
{
}

View File

@@ -16,7 +16,7 @@ public class RandomArtifactSpriteSystem : EntitySystem
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<RandomArtifactSpriteComponent, ComponentInit>(OnInit); SubscribeLocalEvent<RandomArtifactSpriteComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<RandomArtifactSpriteComponent, ArtifactActivatedEvent>(OnActivated); SubscribeLocalEvent<RandomArtifactSpriteComponent, ArtifactActivatedEvent>(OnActivated);
} }
@@ -27,7 +27,7 @@ public class RandomArtifactSpriteSystem : EntitySystem
foreach (var (component, appearance) in query) foreach (var (component, appearance) in query)
{ {
if (component.ActivationStart == null) if (component.ActivationStart == null)
return; continue;
var timeDif = _time.CurTime - component.ActivationStart.Value; var timeDif = _time.CurTime - component.ActivationStart.Value;
if (timeDif.Seconds >= component.ActivationTime) 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)) if (!TryComp(uid, out AppearanceComponent? appearance))
return; return;

View File

@@ -1,4 +1,5 @@
using Content.Server.Atmos.EntitySystems; using Content.Server.Atmos.EntitySystems;
using Content.Server.Xenoarchaeology.XenoArtifacts.Events;
using Content.Server.Xenoarchaeology.XenoArtifacts.Triggers.Components; using Content.Server.Xenoarchaeology.XenoArtifacts.Triggers.Components;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
@@ -15,7 +16,16 @@ public class ArtifactGasTriggerSystem : EntitySystem
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<ArtifactGasTriggerComponent, ComponentInit>(OnInit); SubscribeLocalEvent<ArtifactGasTriggerComponent, RandomizeTriggerEvent>(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) public override void Update(float frameTime)
@@ -25,27 +35,18 @@ public class ArtifactGasTriggerSystem : EntitySystem
foreach (var (trigger, transform) in query) foreach (var (trigger, transform) in query)
{ {
if (trigger.ActivationGas == null) if (trigger.ActivationGas == null)
return; continue;
var environment = _atmosphereSystem.GetTileMixture(transform.Coordinates, true); var environment = _atmosphereSystem.GetTileMixture(transform.Coordinates, true);
if (environment == null) if (environment == null)
return; continue;
// check if outside there is enough moles to activate artifact // check if outside there is enough moles to activate artifact
var moles = environment.GetMoles(trigger.ActivationGas.Value); var moles = environment.GetMoles(trigger.ActivationGas.Value);
if (moles < trigger.ActivationMoles) if (moles < trigger.ActivationMoles)
return; continue;
_artifactSystem.TryActivateArtifact(trigger.Owner); _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;
}
}
} }

View File

@@ -14,6 +14,10 @@
- AngryMobsSpawnArtifact - AngryMobsSpawnArtifact
- JunkSpawnArtifact - JunkSpawnArtifact
- BananaSpawnArtifact - BananaSpawnArtifact
- HeatArtifact
- ColdArtifact
- RadiateArtifact
- GasArtifact
chance: 1 chance: 1
- type: entity - type: entity

View File

@@ -122,3 +122,33 @@
maxSpawns: 20 maxSpawns: 20
possiblePrototypes: possiblePrototypes:
- FoodBanana - 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

View File

@@ -219,11 +219,7 @@
0.1, 0.1,
0.1, 0.1,
0.1, 0.1,
0.1, 0.1
0.1,
0.1,
0.1,
0.1
] ]
] ]
}, },