Allow sound to play at the start of anomaly supercritical animation (#36260)
* Add datafield to AnomalyComponent to play a sound when an anomaly enters supercriticality * use Entity<T> pattern * use implicit default for nullable * don't forget to resolve the AnomalyComponent... * Add comment for StartSupercriticalEvent "ent" parameter * use implicit casts from Entity<T> to EntityUid * StartSupercriticalEvent requires AnomalyComponent to resolve
This commit is contained in:
@@ -44,10 +44,10 @@ public sealed partial class AnomalySystem
|
||||
if (!NetEntity.TryParse(args[0], out var uidNet) || !TryGetEntity(uidNet, out var uid))
|
||||
return;
|
||||
|
||||
if (!HasComp<AnomalyComponent>(uid))
|
||||
if (!TryComp<AnomalyComponent>(uid, out var anomaly))
|
||||
return;
|
||||
|
||||
StartSupercriticalEvent(uid.Value);
|
||||
StartSupercriticalEvent((uid.Value, anomaly));
|
||||
}
|
||||
|
||||
private CompletionResult GetAnomalyCompletion(IConsoleShell shell, string[] args)
|
||||
|
||||
@@ -129,6 +129,12 @@ public sealed partial class AnomalyComponent : Component
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public SoundSpecifier? SupercriticalSound = new SoundCollectionSpecifier("Explosion");
|
||||
|
||||
/// <summary>
|
||||
/// The sound plays at the start of the animation when an anomaly goes supercritical
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public SoundSpecifier? SupercriticalSoundAtAnimationStart;
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -116,21 +116,26 @@ public abstract class SharedAnomalySystem : EntitySystem
|
||||
/// <summary>
|
||||
/// Begins the animation for going supercritical
|
||||
/// </summary>
|
||||
/// <param name="uid"></param>
|
||||
public void StartSupercriticalEvent(EntityUid uid)
|
||||
/// <param name="ent">Entity to go supercritical</param>
|
||||
public void StartSupercriticalEvent(Entity<AnomalyComponent?> ent)
|
||||
{
|
||||
// don't restart it if it's already begun
|
||||
if (HasComp<AnomalySupercriticalComponent>(uid))
|
||||
if (HasComp<AnomalySupercriticalComponent>(ent))
|
||||
return;
|
||||
|
||||
AdminLog.Add(LogType.Anomaly, LogImpact.High, $"Anomaly {ToPrettyString(uid)} began to go supercritical.");
|
||||
if (_net.IsServer)
|
||||
Log.Info($"Anomaly is going supercritical. Entity: {ToPrettyString(uid)}");
|
||||
if(!Resolve(ent, ref ent.Comp))
|
||||
return;
|
||||
|
||||
var super = AddComp<AnomalySupercriticalComponent>(uid);
|
||||
AdminLog.Add(LogType.Anomaly, LogImpact.High, $"Anomaly {ToPrettyString(ent.Owner)} began to go supercritical.");
|
||||
if (_net.IsServer)
|
||||
Log.Info($"Anomaly is going supercritical. Entity: {ToPrettyString(ent.Owner)}");
|
||||
|
||||
Audio.PlayPvs(ent.Comp.SupercriticalSoundAtAnimationStart, Transform(ent).Coordinates);
|
||||
|
||||
var super = AddComp<AnomalySupercriticalComponent>(ent);
|
||||
super.EndTime = Timing.CurTime + super.SupercriticalDuration;
|
||||
Appearance.SetData(uid, AnomalyVisuals.Supercritical, true);
|
||||
Dirty(uid, super);
|
||||
Appearance.SetData(ent, AnomalyVisuals.Supercritical, true);
|
||||
Dirty(ent, super);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -240,7 +245,7 @@ public abstract class SharedAnomalySystem : EntitySystem
|
||||
var newVal = component.Severity + change;
|
||||
|
||||
if (newVal >= 1)
|
||||
StartSupercriticalEvent(uid);
|
||||
StartSupercriticalEvent((uid, component));
|
||||
|
||||
component.Severity = Math.Clamp(newVal, 0, 1);
|
||||
Dirty(uid, component);
|
||||
|
||||
Reference in New Issue
Block a user