Do not hardcode salvage magnet channel (#9633)

This commit is contained in:
Rane
2022-07-11 18:06:56 -04:00
committed by GitHub
parent 955df9a3be
commit 582436d6b5
2 changed files with 21 additions and 12 deletions

View File

@@ -1,3 +1,7 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Content.Shared.Radio;
namespace Content.Server.Salvage namespace Content.Server.Salvage
{ {
/// <summary> /// <summary>
@@ -28,6 +32,11 @@ namespace Content.Server.Salvage
[ViewVariables(VVAccess.ReadOnly)] [ViewVariables(VVAccess.ReadOnly)]
[DataField("magnetState")] [DataField("magnetState")]
public MagnetState MagnetState = MagnetState.Inactive; public MagnetState MagnetState = MagnetState.Inactive;
[ViewVariables]
[DataField("salvageChannel", customTypeSerializer: typeof(PrototypeIdSerializer<RadioChannelPrototype>))]
public string SalvageChannel = "Supply";
} }
public record struct MagnetState(MagnetStateType StateType, TimeSpan Until) public record struct MagnetState(MagnetStateType StateType, TimeSpan Until)
{ {

View File

@@ -69,7 +69,7 @@ namespace Content.Server.Salvage
{ {
var gridUid = _mapManager.GetGridEuid(ev.GridId); var gridUid = _mapManager.GetGridEuid(ev.GridId);
if (EntityManager.TryGetComponent<SalvageGridComponent>(gridUid, out var salvComp) && salvComp.SpawnerMagnet != null) if (EntityManager.TryGetComponent<SalvageGridComponent>(gridUid, out var salvComp) && salvComp.SpawnerMagnet != null)
Report(salvComp.SpawnerMagnet.Owner, "salvage-system-announcement-spawn-magnet-lost"); Report(salvComp.SpawnerMagnet.Owner, salvComp.SpawnerMagnet.SalvageChannel, "salvage-system-announcement-spawn-magnet-lost");
// For the very unlikely possibility that the salvage magnet was on a salvage, we will not return here // For the very unlikely possibility that the salvage magnet was on a salvage, we will not return here
} }
foreach(var gridState in _salvageGridStates) foreach(var gridState in _salvageGridStates)
@@ -96,16 +96,16 @@ namespace Content.Server.Salvage
return; return;
} }
salvageGridState.ActiveMagnets.Remove(component); salvageGridState.ActiveMagnets.Remove(component);
Report(uid, "salvage-system-announcement-spawn-magnet-lost"); Report(uid, component.SalvageChannel, "salvage-system-announcement-spawn-magnet-lost");
if (component.AttachedEntity.HasValue) if (component.AttachedEntity.HasValue)
{ {
SafeDeleteSalvage(component.AttachedEntity.Value); SafeDeleteSalvage(component.AttachedEntity.Value);
component.AttachedEntity = null; component.AttachedEntity = null;
Report(uid, "salvage-system-announcement-lost"); Report(uid, component.SalvageChannel, "salvage-system-announcement-lost");
} }
else if (component.MagnetState is { StateType: MagnetStateType.Attaching }) else if (component.MagnetState is { StateType: MagnetStateType.Attaching })
{ {
Report(uid, "salvage-system-announcement-spawn-no-debris-available"); Report(uid, component.SalvageChannel, "salvage-system-announcement-spawn-no-debris-available");
} }
component.MagnetState = MagnetState.Inactive; component.MagnetState = MagnetState.Inactive;
} }
@@ -168,7 +168,7 @@ namespace Content.Server.Salvage
} }
gridState.ActiveMagnets.Add(component); gridState.ActiveMagnets.Add(component);
component.MagnetState = new MagnetState(MagnetStateType.Attaching, gridState.CurrentTime + AttachingTime); component.MagnetState = new MagnetState(MagnetStateType.Attaching, gridState.CurrentTime + AttachingTime);
Report(component.Owner, "salvage-system-report-activate-success"); Report(component.Owner, component.SalvageChannel, "salvage-system-report-activate-success");
break; break;
case MagnetStateType.Attaching: case MagnetStateType.Attaching:
case MagnetStateType.Holding: case MagnetStateType.Holding:
@@ -279,7 +279,7 @@ namespace Content.Server.Salvage
if (map == null) if (map == null)
{ {
Report(component.Owner, "salvage-system-announcement-spawn-no-debris-available"); Report(component.Owner, component.SalvageChannel, "salvage-system-announcement-spawn-no-debris-available");
return false; return false;
} }
@@ -291,7 +291,7 @@ namespace Content.Server.Salvage
var (_, salvageEntityId) = _mapLoader.LoadBlueprint(spl.MapId, map.MapPath.ToString(), opts); var (_, salvageEntityId) = _mapLoader.LoadBlueprint(spl.MapId, map.MapPath.ToString(), opts);
if (salvageEntityId == null) if (salvageEntityId == null)
{ {
Report(component.Owner, "salvage-system-announcement-spawn-debris-disintegrated"); Report(component.Owner, component.SalvageChannel, "salvage-system-announcement-spawn-debris-disintegrated");
return false; return false;
} }
component.AttachedEntity = salvageEntityId; component.AttachedEntity = salvageEntityId;
@@ -301,16 +301,16 @@ namespace Content.Server.Salvage
var pulledTransform = EntityManager.GetComponent<TransformComponent>(salvageEntityId.Value); var pulledTransform = EntityManager.GetComponent<TransformComponent>(salvageEntityId.Value);
pulledTransform.WorldRotation = spAngle; pulledTransform.WorldRotation = spAngle;
Report(component.Owner, "salvage-system-announcement-arrived", ("timeLeft", HoldTime.TotalSeconds)); Report(component.Owner, component.SalvageChannel, "salvage-system-announcement-arrived", ("timeLeft", HoldTime.TotalSeconds));
return true; return true;
} }
private void Report(EntityUid source, string messageKey, params (string, object)[] args) private void Report(EntityUid source, string channelName, string messageKey, params (string, object)[] args)
{ {
if (!TryComp<IntrinsicRadioComponent>(source, out var radio)) return; if (!TryComp<IntrinsicRadioComponent>(source, out var radio)) return;
var message = args.Length == 0 ? Loc.GetString(messageKey) : Loc.GetString(messageKey, args); var message = args.Length == 0 ? Loc.GetString(messageKey) : Loc.GetString(messageKey, args);
var channel = _prototypeManager.Index<RadioChannelPrototype>("Supply"); var channel = _prototypeManager.Index<RadioChannelPrototype>(channelName);
_radioSystem.SpreadMessage(radio, source, message, channel); _radioSystem.SpreadMessage(radio, source, message, channel);
} }
@@ -329,7 +329,7 @@ namespace Content.Server.Salvage
} }
break; break;
case MagnetStateType.Holding: case MagnetStateType.Holding:
Report(magnet.Owner, "salvage-system-announcement-losing", ("timeLeft", DetachingTime.TotalSeconds)); Report(magnet.Owner, magnet.SalvageChannel, "salvage-system-announcement-losing", ("timeLeft", DetachingTime.TotalSeconds));
magnet.MagnetState = new MagnetState(MagnetStateType.Detaching, currentTime + DetachingTime); magnet.MagnetState = new MagnetState(MagnetStateType.Detaching, currentTime + DetachingTime);
break; break;
case MagnetStateType.Detaching: case MagnetStateType.Detaching:
@@ -341,7 +341,7 @@ namespace Content.Server.Salvage
{ {
Logger.ErrorS("salvage", "Salvage detaching was expecting attached entity but it was null"); Logger.ErrorS("salvage", "Salvage detaching was expecting attached entity but it was null");
} }
Report(magnet.Owner, "salvage-system-announcement-lost"); Report(magnet.Owner, magnet.SalvageChannel, "salvage-system-announcement-lost");
magnet.MagnetState = new MagnetState(MagnetStateType.CoolingDown, currentTime + CooldownTime); magnet.MagnetState = new MagnetState(MagnetStateType.CoolingDown, currentTime + CooldownTime);
break; break;
case MagnetStateType.CoolingDown: case MagnetStateType.CoolingDown: