DoAfter Refactor (#13225)
Co-authored-by: DrSmugleaf <drsmugleaf@gmail.com>
This commit is contained in:
@@ -16,6 +16,7 @@ using Content.Shared.Database;
|
||||
using Content.Shared.Destructible;
|
||||
using Content.Shared.Disposal;
|
||||
using Content.Shared.Disposal.Components;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.DragDrop;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
@@ -28,7 +29,6 @@ using Content.Shared.Verbs;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Map.Components;
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
SubscribeLocalEvent<DisposalUnitComponent, GetVerbsEvent<Verb>>(AddClimbInsideVerb);
|
||||
|
||||
// Units
|
||||
SubscribeLocalEvent<DoInsertDisposalUnitEvent>(DoInsertDisposalUnit);
|
||||
SubscribeLocalEvent<DisposalUnitComponent, DoAfterEvent>(OnDoAfter);
|
||||
|
||||
//UI
|
||||
SubscribeLocalEvent<DisposalUnitComponent, SharedDisposalUnitComponent.UiButtonPressedMessage>(OnUiButtonPressed);
|
||||
@@ -155,28 +155,21 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
{
|
||||
_handsSystem.TryDropIntoContainer(args.User, args.Using.Value, component.Container, checkActionBlocker: false, args.Hands);
|
||||
_adminLogger.Add(LogType.Action, LogImpact.Medium, $"{ToPrettyString(args.User):player} inserted {ToPrettyString(args.Using.Value)} into {ToPrettyString(uid)}");
|
||||
AfterInsert(uid, component, args.Using.Value);
|
||||
AfterInsert(uid, component, args.Using.Value, args.User);
|
||||
}
|
||||
};
|
||||
|
||||
args.Verbs.Add(insertVerb);
|
||||
}
|
||||
|
||||
private void DoInsertDisposalUnit(DoInsertDisposalUnitEvent ev)
|
||||
private void OnDoAfter(EntityUid uid, DisposalUnitComponent component, DoAfterEvent args)
|
||||
{
|
||||
var toInsert = ev.ToInsert;
|
||||
|
||||
if (!TryComp(ev.Unit, out DisposalUnitComponent? unit))
|
||||
{
|
||||
if (args.Handled || args.Cancelled || args.Args.Target == null || args.Args.Used == null)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!unit.Container.Insert(toInsert))
|
||||
return;
|
||||
if (ev.User != null)
|
||||
_adminLogger.Add(LogType.Action, LogImpact.Medium,
|
||||
$"{ToPrettyString(ev.User.Value):player} inserted {ToPrettyString(toInsert)} into {ToPrettyString(ev.Unit)}");
|
||||
AfterInsert(ev.Unit, unit, toInsert);
|
||||
AfterInsert(uid, component, args.Args.Target.Value, args.Args.User);
|
||||
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
public void DoInsertDisposalUnit(EntityUid uid, EntityUid toInsert, EntityUid user, DisposalUnitComponent? disposal = null)
|
||||
@@ -188,7 +181,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
return;
|
||||
|
||||
_adminLogger.Add(LogType.Action, LogImpact.Medium, $"{ToPrettyString(user):player} inserted {ToPrettyString(toInsert)} into {ToPrettyString(uid)}");
|
||||
AfterInsert(uid, disposal, toInsert);
|
||||
AfterInsert(uid, disposal, toInsert, user);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
@@ -273,7 +266,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
}
|
||||
|
||||
_adminLogger.Add(LogType.Action, LogImpact.Medium, $"{ToPrettyString(args.User):player} inserted {ToPrettyString(args.Used)} into {ToPrettyString(uid)}");
|
||||
AfterInsert(uid, component, args.Used);
|
||||
AfterInsert(uid, component, args.Used, args.User);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
@@ -454,6 +447,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
TryComp(ejectedId, out PhysicsComponent? body))
|
||||
{
|
||||
// TODO: We need to use a specific collision method (which sloth hasn't coded yet) for actual bounds overlaps.
|
||||
// TODO: Come do this sloth :^)
|
||||
// Check for itemcomp as we won't just block the disposal unit "sleeping" for something it can't collide with anyway.
|
||||
if (!HasComp<ItemComponent>(ejectedId)
|
||||
&& _lookup.GetWorldAABB(ejectedId).Intersects(disposalsBounds!.Value))
|
||||
@@ -485,24 +479,22 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
return false;
|
||||
|
||||
var delay = userId == toInsertId ? unit.EntryDelay : unit.DraggedEntryDelay;
|
||||
var ev = new DoInsertDisposalUnitEvent(userId, toInsertId, unitId);
|
||||
|
||||
if (delay <= 0 || userId == null)
|
||||
{
|
||||
DoInsertDisposalUnit(ev);
|
||||
AfterInsert(unitId, unit, toInsertId, userId);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Can't check if our target AND disposals moves currently so we'll just check target.
|
||||
// if you really want to check if disposals moves then add a predicate.
|
||||
var doAfterArgs = new DoAfterEventArgs(userId.Value, delay, default, toInsertId)
|
||||
var doAfterArgs = new DoAfterEventArgs(userId.Value, delay, target:toInsertId, used:unitId)
|
||||
{
|
||||
BreakOnDamage = true,
|
||||
BreakOnStun = true,
|
||||
BreakOnTargetMove = true,
|
||||
BreakOnUserMove = true,
|
||||
NeedHand = false,
|
||||
BroadcastFinishedEvent = ev
|
||||
};
|
||||
|
||||
_doAfterSystem.DoAfter(doAfterArgs);
|
||||
@@ -727,8 +719,14 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
}, component.AutomaticEngageToken.Token);
|
||||
}
|
||||
|
||||
public void AfterInsert(EntityUid uid, DisposalUnitComponent component, EntityUid inserted)
|
||||
public void AfterInsert(EntityUid uid, DisposalUnitComponent component, EntityUid inserted, EntityUid? user = null)
|
||||
{
|
||||
if (!component.Container.Insert(inserted))
|
||||
return;
|
||||
|
||||
if (user != inserted && user != null)
|
||||
_adminLogger.Add(LogType.Action, LogImpact.Medium, $"{ToPrettyString(user.Value):player} inserted {ToPrettyString(inserted)} into {ToPrettyString(uid)}");
|
||||
|
||||
TryQueueEngage(uid, component);
|
||||
|
||||
if (TryComp(inserted, out ActorComponent? actor))
|
||||
|
||||
Reference in New Issue
Block a user