Anomalies (#13371)
This commit is contained in:
@@ -7,16 +7,19 @@ using Content.Server.Projectiles;
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Server.Weapons.Ranged.Systems;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Projectiles;
|
||||
using Content.Shared.Singularity.Components;
|
||||
using Content.Shared.Singularity.EntitySystems;
|
||||
using Content.Shared.Verbs;
|
||||
using Content.Shared.Weapons.Ranged.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Utility;
|
||||
using Timer = Robust.Shared.Timing.Timer;
|
||||
@@ -27,6 +30,7 @@ namespace Content.Server.Singularity.EntitySystems
|
||||
public sealed class EmitterSystem : SharedEmitterSystem
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
||||
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
@@ -38,14 +42,28 @@ namespace Content.Server.Singularity.EntitySystems
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<EmitterComponent, PowerConsumerReceivedChanged>(ReceivedChanged);
|
||||
SubscribeLocalEvent<EmitterComponent, PowerChangedEvent>(OnApcChanged);
|
||||
SubscribeLocalEvent<EmitterComponent, InteractHandEvent>(OnInteractHand);
|
||||
SubscribeLocalEvent<EmitterComponent, GetVerbsEvent<Verb>>(OnGetVerb);
|
||||
SubscribeLocalEvent<EmitterComponent, ExaminedEvent>(OnExamined);
|
||||
SubscribeLocalEvent<EmitterComponent, RefreshPartsEvent>(OnRefreshParts);
|
||||
SubscribeLocalEvent<EmitterComponent, UpgradeExamineEvent>(OnUpgradeExamine);
|
||||
SubscribeLocalEvent<EmitterComponent, AnchorStateChangedEvent>(OnAnchorStateChanged);
|
||||
}
|
||||
|
||||
private void OnAnchorStateChanged(EntityUid uid, EmitterComponent component, ref AnchorStateChangedEvent args)
|
||||
{
|
||||
if (args.Anchored)
|
||||
return;
|
||||
|
||||
SwitchOff(component);
|
||||
}
|
||||
|
||||
private void OnInteractHand(EntityUid uid, EmitterComponent component, InteractHandEvent args)
|
||||
{
|
||||
args.Handled = true;
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if (EntityManager.TryGetComponent(uid, out LockComponent? lockComp) && lockComp.Locked)
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString("comp-emitter-access-locked",
|
||||
@@ -71,6 +89,7 @@ namespace Content.Server.Singularity.EntitySystems
|
||||
_adminLogger.Add(LogType.Emitter,
|
||||
component.IsOn ? LogImpact.Medium : LogImpact.High,
|
||||
$"{ToPrettyString(args.User):player} toggled {ToPrettyString(uid):emitter}");
|
||||
args.Handled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -79,6 +98,47 @@ namespace Content.Server.Singularity.EntitySystems
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGetVerb(EntityUid uid, EmitterComponent component, GetVerbsEvent<Verb> args)
|
||||
{
|
||||
if (!args.CanAccess || !args.CanInteract || args.Hands == null)
|
||||
return;
|
||||
|
||||
if (TryComp<LockComponent>(uid, out var lockComp) && lockComp.Locked)
|
||||
return;
|
||||
|
||||
if (component.SelectableTypes.Count < 2)
|
||||
return;
|
||||
|
||||
foreach (var type in component.SelectableTypes)
|
||||
{
|
||||
var proto = _prototype.Index<EntityPrototype>(type);
|
||||
|
||||
var v = new Verb
|
||||
{
|
||||
Priority = 1,
|
||||
Category = VerbCategory.SelectType,
|
||||
Text = proto.Name,
|
||||
Disabled = type == component.BoltType,
|
||||
Impact = LogImpact.Medium,
|
||||
DoContactInteraction = true,
|
||||
Act = () =>
|
||||
{
|
||||
component.BoltType = type;
|
||||
_popup.PopupEntity(Loc.GetString("emitter-component-type-set", ("type", proto.Name)), uid);
|
||||
}
|
||||
};
|
||||
args.Verbs.Add(v);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnExamined(EntityUid uid, EmitterComponent component, ExaminedEvent args)
|
||||
{
|
||||
if (component.SelectableTypes.Count < 2)
|
||||
return;
|
||||
var proto = _prototype.Index<EntityPrototype>(component.BoltType);
|
||||
args.Message.AddText(Loc.GetString("emitter-component-current-type", ("type", proto.Name)));
|
||||
}
|
||||
|
||||
private void ReceivedChanged(
|
||||
EntityUid uid,
|
||||
EmitterComponent component,
|
||||
@@ -99,6 +159,23 @@ namespace Content.Server.Singularity.EntitySystems
|
||||
}
|
||||
}
|
||||
|
||||
private void OnApcChanged(EntityUid uid, EmitterComponent component, ref PowerChangedEvent args)
|
||||
{
|
||||
if (!component.IsOn)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!args.Powered)
|
||||
{
|
||||
PowerOff(component);
|
||||
}
|
||||
else
|
||||
{
|
||||
PowerOn(component);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRefreshParts(EntityUid uid, EmitterComponent component, RefreshPartsEvent args)
|
||||
{
|
||||
var powerUseRating = args.PartRatings[component.MachinePartPowerUse];
|
||||
@@ -122,7 +199,9 @@ namespace Content.Server.Singularity.EntitySystems
|
||||
{
|
||||
component.IsOn = false;
|
||||
if (TryComp<PowerConsumerComponent>(component.Owner, out var powerConsumer))
|
||||
powerConsumer.DrawRate = 0;
|
||||
powerConsumer.DrawRate = 1; // this needs to be not 0 so that the visuals still work.
|
||||
if (TryComp<ApcPowerReceiverComponent>(component.Owner, out var apcReceiever))
|
||||
apcReceiever.Load = 1;
|
||||
PowerOff(component);
|
||||
UpdateAppearance(component);
|
||||
}
|
||||
@@ -132,6 +211,11 @@ namespace Content.Server.Singularity.EntitySystems
|
||||
component.IsOn = true;
|
||||
if (TryComp<PowerConsumerComponent>(component.Owner, out var powerConsumer))
|
||||
powerConsumer.DrawRate = component.PowerUseActive;
|
||||
if (TryComp<ApcPowerReceiverComponent>(component.Owner, out var apcReceiever))
|
||||
{
|
||||
apcReceiever.Load = component.PowerUseActive;
|
||||
PowerOn(component);
|
||||
}
|
||||
// Do not directly PowerOn().
|
||||
// OnReceivedPowerChanged will get fired due to DrawRate change which will turn it on.
|
||||
UpdateAppearance(component);
|
||||
@@ -179,9 +263,6 @@ namespace Content.Server.Singularity.EntitySystems
|
||||
// and thus not firing
|
||||
DebugTools.Assert(component.IsPowered);
|
||||
DebugTools.Assert(component.IsOn);
|
||||
DebugTools.Assert(TryComp<PowerConsumerComponent>(component.Owner, out var powerConsumer) &&
|
||||
(powerConsumer.DrawRate <= powerConsumer.ReceivedPower ||
|
||||
MathHelper.CloseTo(powerConsumer.DrawRate, powerConsumer.ReceivedPower, 0.0001f)));
|
||||
|
||||
Fire(component);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user