Anomaly Generator Tweaks (#13856)
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
using Content.Server.Anomaly.Components;
|
||||
using Content.Server.Anomaly.Components;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Content.Shared.Anomaly;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Materials;
|
||||
using Content.Shared.Radio;
|
||||
using Robust.Shared.Audio;
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Physics;
|
||||
@@ -24,6 +26,9 @@ public sealed partial class AnomalySystem
|
||||
SubscribeLocalEvent<AnomalyGeneratorComponent, MaterialAmountChangedEvent>(OnGeneratorMaterialAmountChanged);
|
||||
SubscribeLocalEvent<AnomalyGeneratorComponent, AnomalyGeneratorGenerateButtonPressedEvent>(OnGenerateButtonPressed);
|
||||
SubscribeLocalEvent<AnomalyGeneratorComponent, PowerChangedEvent>(OnGeneratorPowerChanged);
|
||||
SubscribeLocalEvent<AnomalyGeneratorComponent, EntityUnpausedEvent>(OnGeneratorUnpaused);
|
||||
SubscribeLocalEvent<GeneratingAnomalyGeneratorComponent, ComponentStartup>(OnGeneratingStartup);
|
||||
SubscribeLocalEvent<GeneratingAnomalyGeneratorComponent, EntityUnpausedEvent>(OnGeneratingUnpaused);
|
||||
}
|
||||
|
||||
private void OnGeneratorPowerChanged(EntityUid uid, AnomalyGeneratorComponent component, ref PowerChangedEvent args)
|
||||
@@ -46,6 +51,11 @@ public sealed partial class AnomalySystem
|
||||
TryGeneratorCreateAnomaly(uid, component);
|
||||
}
|
||||
|
||||
private void OnGeneratorUnpaused(EntityUid uid, AnomalyGeneratorComponent component, ref EntityUnpausedEvent args)
|
||||
{
|
||||
component.CooldownEndTime += args.PausedTime;
|
||||
}
|
||||
|
||||
public void UpdateGeneratorUi(EntityUid uid, AnomalyGeneratorComponent component)
|
||||
{
|
||||
var materialAmount = _material.GetMaterialAmount(uid, component.RequiredMaterial);
|
||||
@@ -65,14 +75,12 @@ public sealed partial class AnomalySystem
|
||||
if (Timing.CurTime < component.CooldownEndTime)
|
||||
return;
|
||||
|
||||
var grid = Transform(uid).GridUid;
|
||||
if (grid == null)
|
||||
return;
|
||||
|
||||
if (!_material.TryChangeMaterialAmount(uid, component.RequiredMaterial, -component.MaterialPerAnomaly))
|
||||
return;
|
||||
|
||||
SpawnOnRandomGridLocation(grid.Value, component.SpawnerPrototype);
|
||||
var generating = EnsureComp<GeneratingAnomalyGeneratorComponent>(uid);
|
||||
generating.EndTime = Timing.CurTime + component.GenerationLength;
|
||||
generating.AudioStream = Audio.PlayPvs(component.GeneratingSound, uid, AudioParams.Default.WithLoop(true));
|
||||
component.CooldownEndTime = Timing.CurTime + component.CooldownLength;
|
||||
UpdateGeneratorUi(uid, component);
|
||||
}
|
||||
@@ -126,4 +134,42 @@ public sealed partial class AnomalySystem
|
||||
|
||||
Spawn(toSpawn, targetCoords);
|
||||
}
|
||||
|
||||
private void OnGeneratingStartup(EntityUid uid, GeneratingAnomalyGeneratorComponent component, ComponentStartup args)
|
||||
{
|
||||
Appearance.SetData(uid, AnomalyGeneratorVisuals.Generating, true);
|
||||
}
|
||||
|
||||
private void OnGeneratingUnpaused(EntityUid uid, GeneratingAnomalyGeneratorComponent component, ref EntityUnpausedEvent args)
|
||||
{
|
||||
component.EndTime += args.PausedTime;
|
||||
}
|
||||
|
||||
private void OnGeneratingFinished(EntityUid uid, AnomalyGeneratorComponent component)
|
||||
{
|
||||
var grid = Transform(uid).GridUid;
|
||||
if (grid == null)
|
||||
return;
|
||||
|
||||
SpawnOnRandomGridLocation(grid.Value, component.SpawnerPrototype);
|
||||
RemComp<GeneratingAnomalyGeneratorComponent>(uid);
|
||||
Appearance.SetData(uid, AnomalyGeneratorVisuals.Generating, false);
|
||||
Audio.PlayPvs(component.GeneratingFinishedSound, uid);
|
||||
|
||||
var message = Loc.GetString("anomaly-generator-announcement");
|
||||
_radio.SendRadioMessage(uid, message, _prototype.Index<RadioChannelPrototype>(component.ScienceChannel));
|
||||
}
|
||||
|
||||
private void UpdateGenerator()
|
||||
{
|
||||
foreach (var (active, gen) in EntityQuery<GeneratingAnomalyGeneratorComponent, AnomalyGeneratorComponent>())
|
||||
{
|
||||
var ent = active.Owner;
|
||||
|
||||
if (Timing.CurTime < active.EndTime)
|
||||
continue;
|
||||
active.AudioStream?.Stop();
|
||||
OnGeneratingFinished(ent, gen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user