item toggling giga rework + full ninja refactor (#28039)
* item toggle refactoring and some new systems * add ToggleClothing component/system * unhardcode magboots gravity logic * make magboots and speedboots use ItemToggle and stuff * remove now useless clothing components * update client/server magboots systems * add note to use ItemToggledEvent in ToggleActionEvent doc * refactor PowerCellDraw to use ItemToggle for ui open/close control * add TryUseCharges, refactor charges system * update magboot trigger code * make borg use ItemToggle, network SelectedModule instead of now removed Activated * add AccessToggle for borg * the giga ninja refactor * update ninja yml * update ItemToggle usage for some stuff * fix activatableui requires power * random fixing * yaml fixing * nuke ItemToggleDisarmMalus * make defib use ItemToggle * make things that use power not turn on if missing use charge * pro * fix sound prediction * bruh * proximity detector use ItemToggle * oop * big idiot syndrome * fix ninja spawn rule and make it generic * fix ninja spawn rule yml * move loading profiles into AntagLoadProfileRule * more ninja refactor * ninja yml fixes * the dreaded copy paste ops * remove useless NinjaRuleComponent and ue AntagSelection for greeting * fix invisibility * move IsCompleted to SharedObjectivesSystem * ability fixes * oop fix powercell instantly draining itself * sentient speedboots gaming * make reflect use ItemToggle * fix other test * loadprofilerule moved into its own pr * remove conflict with dragon refactor * remove all GenericAntag code from ninja * ) * probably * remove old enabled * great language bravo vince * GREAT LANGUAGE * who made this language * because it stinks * reparent blood-red magboots to magboots probbbly works * most of the review stuff * hasGrav doesnt mean what i thought it did * make health analyzer use itemtoggle, not fail test * fix mag/speed boots being wacky * UNTROLL * add ItemToggle to the random health analyzers * a * remove unused obsolete borg func * untrolling * :trollface: * fix test * fix * g * untroll --------- Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using Content.Shared.ProximityDetection.Components;
|
||||
using Content.Shared.Item.ItemToggle;
|
||||
using Content.Shared.Item.ItemToggle.Components;
|
||||
using Content.Shared.ProximityDetection.Components;
|
||||
using Content.Shared.Tag;
|
||||
using Robust.Shared.Network;
|
||||
|
||||
@@ -9,6 +11,7 @@ namespace Content.Shared.ProximityDetection.Systems;
|
||||
public sealed class ProximityDetectionSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly EntityLookupSystem _entityLookup = default!;
|
||||
[Dependency] private readonly ItemToggleSystem _toggle = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
[Dependency] private readonly TagSystem _tagSystem = default!;
|
||||
[Dependency] private readonly INetManager _net = default!;
|
||||
@@ -17,10 +20,10 @@ public sealed class ProximityDetectionSystem : EntitySystem
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<ProximityDetectorComponent, EntityPausedEvent>(OnPaused);
|
||||
SubscribeLocalEvent<ProximityDetectorComponent, EntityUnpausedEvent>(OnUnpaused);
|
||||
SubscribeLocalEvent<ProximityDetectorComponent, ComponentInit>(OnCompInit);
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ProximityDetectorComponent, ComponentInit>(OnCompInit);
|
||||
SubscribeLocalEvent<ProximityDetectorComponent, ItemToggledEvent>(OnToggled);
|
||||
}
|
||||
|
||||
private void OnCompInit(EntityUid uid, ProximityDetectorComponent component, ComponentInit args)
|
||||
@@ -30,57 +33,39 @@ public sealed class ProximityDetectionSystem : EntitySystem
|
||||
Log.Debug("DetectorComponent only supports requireAll = false for tags. All components are required for a match!");
|
||||
}
|
||||
|
||||
private void OnPaused(EntityUid owner, ProximityDetectorComponent component, EntityPausedEvent args)
|
||||
{
|
||||
SetEnable_Internal(owner,component,false);
|
||||
}
|
||||
|
||||
private void OnUnpaused(EntityUid owner, ProximityDetectorComponent detector, ref EntityUnpausedEvent args)
|
||||
{
|
||||
SetEnable_Internal(owner, detector,true);
|
||||
}
|
||||
public void SetEnable(EntityUid owner, bool enabled, ProximityDetectorComponent? detector = null)
|
||||
{
|
||||
if (!Resolve(owner, ref detector) || detector.Enabled == enabled)
|
||||
return;
|
||||
SetEnable_Internal(owner ,detector, enabled);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
if (_net.IsClient)
|
||||
return;
|
||||
|
||||
var query = EntityQueryEnumerator<ProximityDetectorComponent>();
|
||||
while (query.MoveNext(out var owner, out var detector))
|
||||
{
|
||||
if (!detector.Enabled)
|
||||
if (!_toggle.IsActivated(owner))
|
||||
continue;
|
||||
|
||||
detector.AccumulatedFrameTime += frameTime;
|
||||
if (detector.AccumulatedFrameTime < detector.UpdateRate)
|
||||
continue;
|
||||
|
||||
detector.AccumulatedFrameTime -= detector.UpdateRate;
|
||||
RunUpdate_Internal(owner, detector);
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetEnable(EntityUid owner, ProximityDetectorComponent? detector = null)
|
||||
private void OnToggled(Entity<ProximityDetectorComponent> ent, ref ItemToggledEvent args)
|
||||
{
|
||||
return Resolve(owner, ref detector, false) && detector.Enabled;
|
||||
}
|
||||
|
||||
private void SetEnable_Internal(EntityUid owner,ProximityDetectorComponent detector, bool enabled)
|
||||
{
|
||||
detector.Enabled = enabled;
|
||||
var noDetectEvent = new ProximityTargetUpdatedEvent(detector, detector.TargetEnt, detector.Distance);
|
||||
RaiseLocalEvent(owner, ref noDetectEvent);
|
||||
if (!enabled)
|
||||
if (args.Activated)
|
||||
{
|
||||
detector.AccumulatedFrameTime = 0;
|
||||
RunUpdate_Internal(owner, detector);
|
||||
Dirty(owner, detector);
|
||||
RunUpdate_Internal(ent, ent.Comp);
|
||||
return;
|
||||
}
|
||||
RunUpdate_Internal(owner, detector);
|
||||
|
||||
var noDetectEvent = new ProximityTargetUpdatedEvent(ent.Comp, Target: null, ent.Comp.Distance);
|
||||
RaiseLocalEvent(ent, ref noDetectEvent);
|
||||
|
||||
ent.Comp.AccumulatedFrameTime = 0;
|
||||
Dirty(ent, ent.Comp);
|
||||
}
|
||||
|
||||
public void ForceUpdate(EntityUid owner, ProximityDetectorComponent? detector = null)
|
||||
@@ -90,11 +75,31 @@ public sealed class ProximityDetectionSystem : EntitySystem
|
||||
RunUpdate_Internal(owner, detector);
|
||||
}
|
||||
|
||||
private void ClearTarget(Entity<ProximityDetectorComponent> ent)
|
||||
{
|
||||
var (uid, comp) = ent;
|
||||
if (comp.TargetEnt == null)
|
||||
return;
|
||||
|
||||
comp.Distance = -1;
|
||||
comp.TargetEnt = null;
|
||||
var noDetectEvent = new ProximityTargetUpdatedEvent(comp, null, -1);
|
||||
RaiseLocalEvent(uid, ref noDetectEvent);
|
||||
var newTargetEvent = new NewProximityTargetEvent(comp, null);
|
||||
RaiseLocalEvent(uid, ref newTargetEvent);
|
||||
Dirty(uid, comp);
|
||||
}
|
||||
|
||||
private void RunUpdate_Internal(EntityUid owner,ProximityDetectorComponent detector)
|
||||
{
|
||||
if (!_net.IsServer) //only run detection checks on the server!
|
||||
return;
|
||||
|
||||
if (Deleted(detector.TargetEnt))
|
||||
{
|
||||
ClearTarget((owner, detector));
|
||||
}
|
||||
|
||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||
var xform = xformQuery.GetComponent(owner);
|
||||
List<(EntityUid TargetEnt, float Distance)> detections = new();
|
||||
@@ -173,15 +178,7 @@ public sealed class ProximityDetectionSystem : EntitySystem
|
||||
{
|
||||
if (detections.Count == 0)
|
||||
{
|
||||
if (detector.TargetEnt == null)
|
||||
return;
|
||||
detector.Distance = -1;
|
||||
detector.TargetEnt = null;
|
||||
var noDetectEvent = new ProximityTargetUpdatedEvent(detector, null, -1);
|
||||
RaiseLocalEvent(owner, ref noDetectEvent);
|
||||
var newTargetEvent = new NewProximityTargetEvent(detector, null);
|
||||
RaiseLocalEvent(owner, ref newTargetEvent);
|
||||
Dirty(owner, detector);
|
||||
ClearTarget((owner, detector));
|
||||
return;
|
||||
}
|
||||
var closestDistance = detections[0].Distance;
|
||||
@@ -198,6 +195,7 @@ public sealed class ProximityDetectionSystem : EntitySystem
|
||||
var newData = newTarget || detector.Distance != closestDistance;
|
||||
detector.TargetEnt = closestEnt;
|
||||
detector.Distance = closestDistance;
|
||||
Dirty(owner, detector);
|
||||
if (newTarget)
|
||||
{
|
||||
var newTargetEvent = new NewProximityTargetEvent(detector, closestEnt);
|
||||
|
||||
Reference in New Issue
Block a user