Predict EmitterSystem ExamineEvent and GetVerbsEvent (#39318)

* ididathing.exe

* commit

* cleanup

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
This commit is contained in:
Kyle Tyo
2025-08-01 13:40:15 -04:00
committed by GitHub
parent a942ce2193
commit d805704a1f
4 changed files with 81 additions and 68 deletions

View File

@@ -12,6 +12,8 @@ public sealed class EmitterSystem : SharedEmitterSystem
/// <inheritdoc/>
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<EmitterComponent, AppearanceChangeEvent>(OnAppearanceChange);
}

View File

@@ -7,7 +7,6 @@ using Content.Server.Projectiles;
using Content.Server.Weapons.Ranged.Systems;
using Content.Shared.Database;
using Content.Shared.DeviceLinking.Events;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Lock;
using Content.Shared.Popups;
@@ -15,9 +14,7 @@ using Content.Shared.Power;
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;
@@ -28,7 +25,6 @@ using Timer = Robust.Shared.Timing.Timer;
namespace Content.Server.Singularity.EntitySystems
{
[UsedImplicitly]
public sealed class EmitterSystem : SharedEmitterSystem
{
[Dependency] private readonly IRobustRandom _random = default!;
@@ -46,8 +42,6 @@ namespace Content.Server.Singularity.EntitySystems
SubscribeLocalEvent<EmitterComponent, PowerConsumerReceivedChanged>(ReceivedChanged);
SubscribeLocalEvent<EmitterComponent, PowerChangedEvent>(OnApcChanged);
SubscribeLocalEvent<EmitterComponent, ActivateInWorldEvent>(OnActivate);
SubscribeLocalEvent<EmitterComponent, GetVerbsEvent<Verb>>(OnGetVerb);
SubscribeLocalEvent<EmitterComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<EmitterComponent, AnchorStateChangedEvent>(OnAnchorStateChanged);
SubscribeLocalEvent<EmitterComponent, SignalReceivedEvent>(OnSignalReceived);
}
@@ -99,47 +93,6 @@ namespace Content.Server.Singularity.EntitySystems
}
}
private void OnGetVerb(EntityUid uid, EmitterComponent component, GetVerbsEvent<Verb> args)
{
if (!args.CanAccess || !args.CanInteract || !args.CanComplexInteract || 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.PushMarkup(Loc.GetString("emitter-component-current-type", ("type", proto.Name)));
}
private void ReceivedChanged(
EntityUid uid,
EmitterComponent component,

View File

@@ -3,12 +3,10 @@ using Content.Shared.DeviceLinking;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
namespace Content.Shared.Singularity.Components;
[RegisterComponent, NetworkedComponent]
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class EmitterComponent : Component
{
public CancellationTokenSource? TimerCancel;
@@ -27,8 +25,8 @@ public sealed partial class EmitterComponent : Component
/// <summary>
/// The entity that is spawned when the emitter fires.
/// </summary>
[DataField("boltType", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string BoltType = "EmitterBolt";
[DataField, AutoNetworkedField]
public EntProtoId BoltType = "EmitterBolt";
[DataField]
public List<EntProtoId> SelectableTypes = new();
@@ -36,68 +34,68 @@ public sealed partial class EmitterComponent : Component
/// <summary>
/// The current amount of power being used.
/// </summary>
[DataField("powerUseActive")]
[DataField]
public int PowerUseActive = 600;
/// <summary>
/// The amount of shots that are fired in a single "burst"
/// </summary>
[DataField("fireBurstSize")]
[DataField]
public int FireBurstSize = 3;
/// <summary>
/// The time between each shot during a burst.
/// </summary>
[DataField("fireInterval")]
[DataField]
public TimeSpan FireInterval = TimeSpan.FromSeconds(2);
/// <summary>
/// The current minimum delay between bursts.
/// </summary>
[DataField("fireBurstDelayMin")]
[DataField]
public TimeSpan FireBurstDelayMin = TimeSpan.FromSeconds(4);
/// <summary>
/// The current maximum delay between bursts.
/// </summary>
[DataField("fireBurstDelayMax")]
[DataField]
public TimeSpan FireBurstDelayMax = TimeSpan.FromSeconds(10);
/// <summary>
/// The visual state that is set when the emitter is turned on
/// </summary>
[DataField("onState")]
[DataField]
public string? OnState = "beam";
/// <summary>
/// The visual state that is set when the emitter doesn't have enough power.
/// </summary>
[DataField("underpoweredState")]
[DataField]
public string? UnderpoweredState = "underpowered";
/// <summary>
/// Signal port that turns on the emitter.
/// </summary>
[DataField("onPort", customTypeSerializer: typeof(PrototypeIdSerializer<SinkPortPrototype>))]
public string OnPort = "On";
[DataField]
public ProtoId<SinkPortPrototype> OnPort = "On";
/// <summary>
/// Signal port that turns off the emitter.
/// </summary>
[DataField("offPort", customTypeSerializer: typeof(PrototypeIdSerializer<SinkPortPrototype>))]
public string OffPort = "Off";
[DataField]
public ProtoId<SinkPortPrototype> OffPort = "Off";
/// <summary>
/// Signal port that toggles the emitter on or off.
/// </summary>
[DataField("togglePort", customTypeSerializer: typeof(PrototypeIdSerializer<SinkPortPrototype>))]
public string TogglePort = "Toggle";
[DataField]
public ProtoId<SinkPortPrototype> TogglePort = "Toggle";
/// <summary>
/// Map of signal ports to entity prototype IDs of the entity that will be fired.
/// </summary>
[DataField("setTypePorts", customTypeSerializer: typeof(PrototypeIdDictionarySerializer<string, SinkPortPrototype>))]
public Dictionary<string, string> SetTypePorts = new();
[DataField]
public Dictionary<ProtoId<SinkPortPrototype>, EntProtoId> SetTypePorts = new();
}
[NetSerializable, Serializable]

View File

@@ -1,6 +1,66 @@
namespace Content.Shared.Singularity.EntitySystems;
using Content.Shared.Database;
using Content.Shared.Examine;
using Content.Shared.Lock;
using Content.Shared.Popups;
using Content.Shared.Singularity.Components;
using Content.Shared.Verbs;
using Robust.Shared.Prototypes;
namespace Content.Shared.Singularity.EntitySystems;
public abstract class SharedEmitterSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<EmitterComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<EmitterComponent, GetVerbsEvent<Verb>>(OnGetVerb);
}
private void OnGetVerb(Entity<EmitterComponent> ent, ref GetVerbsEvent<Verb> args)
{
if (!args.CanAccess || !args.CanInteract || !args.CanComplexInteract || args.Hands == null)
return;
if (TryComp<LockComponent>(ent.Owner, out var lockComp) && lockComp.Locked)
return;
if (ent.Comp.SelectableTypes.Count < 2)
return;
foreach (var type in ent.Comp.SelectableTypes)
{
var proto = _prototype.Index(type);
var v = new Verb
{
Priority = 1,
Category = VerbCategory.SelectType,
Text = proto.Name,
Disabled = type == ent.Comp.BoltType,
Impact = LogImpact.Medium,
DoContactInteraction = true,
Act = () =>
{
ent.Comp.BoltType = type;
Dirty(ent);
_popup.PopupClient(Loc.GetString("emitter-component-type-set", ("type", proto.Name)), ent.Owner);
},
};
args.Verbs.Add(v);
}
}
private void OnExamined(Entity<EmitterComponent> ent, ref ExaminedEvent args)
{
if (ent.Comp.SelectableTypes.Count < 2)
return;
var proto = _prototype.Index(ent.Comp.BoltType);
args.PushMarkup(Loc.GetString("emitter-component-current-type", ("type", proto.Name)));
}
}