Make DisposalUnitComponent.TryInsert ECS (#4959)
This commit is contained in:
committed by
GitHub
parent
ecbcab4824
commit
3e5a856948
@@ -3,9 +3,10 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Server.Disposal.Unit.Components;
|
||||
using Content.Server.Construction.Components;
|
||||
using Content.Server.Disposal.Tube.Components;
|
||||
using Content.Server.Disposal.Unit.Components;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Items;
|
||||
using Content.Server.Power.Components;
|
||||
@@ -17,6 +18,7 @@ using Content.Shared.Interaction;
|
||||
using Content.Shared.Movement;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Throwing;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -26,7 +28,6 @@ using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Random;
|
||||
using Content.Shared.Verbs;
|
||||
|
||||
namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
{
|
||||
@@ -36,6 +37,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||
[Dependency] private readonly AtmosphereSystem _atmosSystem = default!;
|
||||
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
|
||||
|
||||
private readonly List<DisposalUnitComponent> _activeDisposals = new();
|
||||
|
||||
@@ -63,7 +65,11 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
// Verbs
|
||||
SubscribeLocalEvent<DisposalUnitComponent, GetAlternativeVerbsEvent>(AddFlushEjectVerbs);
|
||||
SubscribeLocalEvent<DisposalUnitComponent, GetOtherVerbsEvent>(AddClimbInsideVerb);
|
||||
|
||||
// Units
|
||||
SubscribeLocalEvent<DoInsertDisposalUnitEvent>(DoInsertDisposalUnit);
|
||||
}
|
||||
|
||||
private void AddFlushEjectVerbs(EntityUid uid, DisposalUnitComponent component, GetAlternativeVerbsEvent args)
|
||||
{
|
||||
if (!args.CanAccess || !args.CanInteract || component.ContainedEntities.Count == 0)
|
||||
@@ -95,10 +101,12 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
!_actionBlockerSystem.CanMove(args.User))
|
||||
return;
|
||||
|
||||
// Add verb to climb inside of the unit,
|
||||
Verb verb = new();
|
||||
verb.Act = () => component.TryInsert(args.User, args.User);
|
||||
verb.Text = Loc.GetString("disposal-self-insert-verb-get-data-text");
|
||||
// Add verb to climb inside of the unit,
|
||||
Verb verb = new()
|
||||
{
|
||||
Act = () => TryInsert(component.Owner.Uid, args.User.Uid, args.User.Uid),
|
||||
Text = Loc.GetString("disposal-self-insert-verb-get-data-text")
|
||||
};
|
||||
// TODO VERN ICON
|
||||
// TODO VERB CATEGORY
|
||||
// create a verb category for "enter"?
|
||||
@@ -106,6 +114,23 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
private void DoInsertDisposalUnit(DoInsertDisposalUnitEvent ev)
|
||||
{
|
||||
var toInsert = EntityManager.GetEntity(ev.ToInsert);
|
||||
|
||||
if (!EntityManager.TryGetComponent(ev.Unit, out DisposalUnitComponent? unit))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!unit.Container.Insert(toInsert))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AfterInsert(unit, toInsert);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
@@ -376,6 +401,39 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
return true;
|
||||
}
|
||||
|
||||
public void TryInsert(EntityUid unitId, EntityUid toInsertId, EntityUid userId, DisposalUnitComponent? unit = null)
|
||||
{
|
||||
if (!Resolve(unitId, ref unit))
|
||||
return;
|
||||
|
||||
if (!CanInsert(unit, toInsertId))
|
||||
return;
|
||||
|
||||
var delay = userId == toInsertId ? unit.EntryDelay : unit.DraggedEntryDelay;
|
||||
var ev = new DoInsertDisposalUnitEvent(userId, toInsertId, unitId);
|
||||
|
||||
if (delay <= 0)
|
||||
{
|
||||
DoInsertDisposalUnit(ev);
|
||||
return;
|
||||
}
|
||||
|
||||
// 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, delay, default, toInsertId)
|
||||
{
|
||||
BreakOnDamage = true,
|
||||
BreakOnStun = true,
|
||||
BreakOnTargetMove = true,
|
||||
BreakOnUserMove = true,
|
||||
NeedHand = false,
|
||||
BroadcastFinishedEvent = ev
|
||||
};
|
||||
|
||||
_doAfterSystem.DoAfter(doAfterArgs);
|
||||
}
|
||||
|
||||
|
||||
public bool TryFlush(DisposalUnitComponent component)
|
||||
{
|
||||
if (component.Deleted || !CanFlush(component))
|
||||
|
||||
Reference in New Issue
Block a user