Files
crystall-punk-14/Content.Shared/Disposal/Unit/SharedDisposalUnitSystem.cs

812 lines
29 KiB
C#
Raw Normal View History

using System.Linq;
using Content.Shared.ActionBlocker;
using Content.Shared.Administration.Logs;
using Content.Shared.Body.Components;
using Content.Shared.Climbing.Systems;
using Content.Shared.Containers;
2023-01-04 00:45:35 -06:00
using Content.Shared.Database;
using Content.Shared.Disposal.Components;
using Content.Shared.Disposal.Unit.Events;
using Content.Shared.DoAfter;
using Content.Shared.DragDrop;
2023-07-06 13:39:34 +10:00
using Content.Shared.Emag.Systems;
using Content.Shared.Hands.Components;
2022-03-17 20:13:31 +13:00
using Content.Shared.Hands.EntitySystems;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
get that crap outta here (completely rewrites inventorysystem) (#5807) * some work * equip: done unequip: todo * unequipping done & refactored events * workin * movin * reee namespaces * stun * mobstate * fixes * some work on events * removes serverside itemcomp & misc fixes * work * smol merge fix * ports template to prototype & finishes ui * moves relay & adds containerenumerator * actions & cuffs * my god what is actioncode * more fixes * im loosing my grasp on reality * more fixes * more work * explosions * yes * more work * more fixes * merge master & misc fixed because i forgot to commit before merging master * more fixes * fixes * moar * more work * moar fixes * suffixmap * more work on client * motivation low * no. no containers * mirroring client to server * fixes * move serverinvcomp * serverinventorycomponent is dead * gaming * only strippable & ai left... * only ai and richtext left * fixes ai * fixes * fixes sprite layers * more fixes * resolves optional * yes * stable:tm: * fixes * moar fixes * moar * fix some tests * lmao * no comment * good to merge:tm: * fixes build but for real * adresses some reviews * adresses some more reviews * nullables, yo * fixes lobbyscreen * timid refactor to differentiate actor & target * adresses more reviews * more * my god what a mess * removed the rest of duplicates * removed duplicate slotflags and renamed shoes to feet * removes another unused one * yes * fixes lobby & makes tryunequip return unequipped item * fixes * some funny renames * fixes * misc improvements to attemptevents * fixes * merge fixes Co-authored-by: Paul Ritter <ritter.paul1@gmail.com>
2021-12-30 22:56:10 +01:00
using Content.Shared.Item;
using Content.Shared.Movement.Events;
using Content.Shared.Popups;
using Content.Shared.Power;
using Content.Shared.Power.EntitySystems;
using Content.Shared.Storage.Components;
using Content.Shared.Throwing;
using Content.Shared.Verbs;
using Content.Shared.Whitelist;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers;
using Robust.Shared.Map.Components;
using Robust.Shared.Physics.Components;
2023-07-06 13:39:34 +10:00
using Robust.Shared.Physics.Events;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
namespace Content.Shared.Disposal.Unit;
2023-07-06 13:39:34 +10:00
[Serializable, NetSerializable]
public sealed partial class DisposalDoAfterEvent : SimpleDoAfterEvent
{
}
public abstract class SharedDisposalUnitSystem : EntitySystem
{
[Dependency] protected readonly ActionBlockerSystem ActionBlockerSystem = default!;
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
[Dependency] protected readonly MetaDataSystem Metadata = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] protected readonly SharedAudioSystem Audio = default!;
[Dependency] protected readonly IGameTiming GameTiming = default!;
[Dependency] private readonly ISharedAdminLogManager _adminLog = default!;
[Dependency] private readonly ClimbSystem _climb = default!;
[Dependency] protected readonly SharedContainerSystem Containers = default!;
[Dependency] protected readonly SharedJointSystem Joints = default!;
[Dependency] private readonly SharedPowerReceiverSystem _power = default!;
[Dependency] private readonly SharedDisposalTubeSystem _disposalTubeSystem = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] protected readonly SharedTransformSystem TransformSystem = default!;
[Dependency] private readonly SharedUserInterfaceSystem _ui = default!;
[Dependency] private readonly SharedMapSystem _map = default!;
protected static TimeSpan ExitAttemptDelay = TimeSpan.FromSeconds(0.5);
// Percentage
public const float PressurePerSecond = 0.05f;
2023-07-06 13:39:34 +10:00
public override void Initialize()
{
2023-07-06 13:39:34 +10:00
base.Initialize();
2023-07-06 13:39:34 +10:00
SubscribeLocalEvent<DisposalUnitComponent, PreventCollideEvent>(OnPreventCollide);
SubscribeLocalEvent<DisposalUnitComponent, CanDropTargetEvent>(OnCanDragDropOn);
SubscribeLocalEvent<DisposalUnitComponent, GetVerbsEvent<InteractionVerb>>(AddInsertVerb);
SubscribeLocalEvent<DisposalUnitComponent, GetVerbsEvent<AlternativeVerb>>(AddDisposalAltVerbs);
SubscribeLocalEvent<DisposalUnitComponent, GetVerbsEvent<Verb>>(AddClimbInsideVerb);
2023-07-06 13:39:34 +10:00
SubscribeLocalEvent<DisposalUnitComponent, DisposalDoAfterEvent>(OnDoAfter);
ECS verbs and update context menu (#4594) * Functioning ECS verbs Currently only ID card console works. * Changed verb types and allow ID card insertions * Verb GUI sorting and verb networking * More networking, and shared components * Clientside verbs work now. * Verb enums changed to bitmask flags * Verb Categories redo * Fix range check * GasTank Verb * Remove unnecessary bodypart verb * Buckle Verb * buckle & unbuckle verbs * Updated range checks * Item cabinet verbs * Add range user override * construction verb * Chemistry machine verbs * Climb Verb * Generalise pulled entity verbs * ViewVariables Verb * rejuvenate, delete, sentient, control verbs * Outfit verb * inrangeunoccluded and tubedirection verbs * attach-to verbs * remove unused verbs and move VV * Rename DebugVerbSystem * Ghost role and pointing verbs * Remove global verbs * Allow verbs to raise events * Changing categories and simplifying debug verbs * Add rotate and flip verbs * fix rejuvenate test * redo context menu * new Add Gas debug verb * Add Set Temperature debug verb * Uncuff verb * Disposal unit verbs * Add pickup verb * lock/unlock verb * Remove verb type, add specific verb events * rename verb messages -> events * Context menu displays verbs by interaction type * Updated context menu HandleMove previously, checked if entities moved 1 tile from click location. Now checks if entities moved out of view. Now you can actually right-click interact with yourself while walking! * Misc Verb menu GUI changes * Fix non-human/ghost verbs * Update types and categories * Allow non-ghost/human to open context menu * configuration verb * tagger verb * Morgue Verbs * Medical Scanner Verbs * Fix solution refactor merge issues * Fix context menu in-view check * Remove prepare GUI * Redo verb restrictions * Fix context menu UI * Disposal Verbs * Spill verb * Light verb * Hand Held light verb * power cell verbs * storage verbs and adding names to insert/eject * Pulling verb * Close context menu on verb execution * Strip verb * AmmoBox verb * fix pull verb * gun barrel verbs revolver verb energy weapon verbs Bolt action verb * Magazine gun barrel verbs * Add charger verbs * PDA verbs * Transfer amount verb * Add reagent verb * make alt-click use ECS verbs * Delete old verb files * Magboot verb * finalising tweaks * context menu visibility changes * code cleanup * Update AdminAddReagentUI.cs * Remove HasFlag * Consistent verb keys * Remove Linq, add comment * Fix in-inventory check * Update GUI text alignment and padding * Added close-menu option * Changed some "interaction" verbs to "activation" * Remove verb keys, use sorted sets * fix master merge * update some verb text * Undo Changes Remove some new verbs that can be added later undid some .ftl bugfixes, can and should be done separately * fix merge * Undo file rename * fix merge * Misc Cleanup * remove contraction * Fix keybinding issue * fix comment * merge fix * fix merge * fix merge * fix merge * fix merge * fix open-close verbs * adjust uncuff verb * fix merge and undo the renaming of SharedPullableComponent to PullableComponent. I'm tired of all of those merge conflicts
2021-10-05 14:29:03 +11:00
SubscribeLocalEvent<DisposalUnitComponent, BeforeThrowInsertEvent>(OnThrowInsert);
SubscribeLocalEvent<DisposalUnitComponent, DisposalUnitComponent.UiButtonPressedMessage>(OnUiButtonPressed);
SubscribeLocalEvent<DisposalUnitComponent, GotEmaggedEvent>(OnEmagged);
SubscribeLocalEvent<DisposalUnitComponent, AnchorStateChangedEvent>(OnAnchorChanged);
SubscribeLocalEvent<DisposalUnitComponent, PowerChangedEvent>(OnPowerChange);
SubscribeLocalEvent<DisposalUnitComponent, ComponentInit>(OnDisposalInit);
SubscribeLocalEvent<DisposalUnitComponent, ActivateInWorldEvent>(OnActivate);
SubscribeLocalEvent<DisposalUnitComponent, AfterInteractUsingEvent>(OnAfterInteractUsing);
SubscribeLocalEvent<DisposalUnitComponent, DragDropTargetEvent>(OnDragDropOn);
SubscribeLocalEvent<DisposalUnitComponent, ContainerRelayMovementEntityEvent>(OnMovement);
SubscribeLocalEvent<DisposalUnitComponent, GetDumpableVerbEvent>(OnGetDumpableVerb);
SubscribeLocalEvent<DisposalUnitComponent, DumpEvent>(OnDump);
2023-07-06 13:39:34 +10:00
}
private void AddDisposalAltVerbs(Entity<DisposalUnitComponent> ent, ref GetVerbsEvent<AlternativeVerb> args)
2023-07-06 13:39:34 +10:00
{
if (!args.CanAccess || !args.CanInteract)
return;
ECS verbs and update context menu (#4594) * Functioning ECS verbs Currently only ID card console works. * Changed verb types and allow ID card insertions * Verb GUI sorting and verb networking * More networking, and shared components * Clientside verbs work now. * Verb enums changed to bitmask flags * Verb Categories redo * Fix range check * GasTank Verb * Remove unnecessary bodypart verb * Buckle Verb * buckle & unbuckle verbs * Updated range checks * Item cabinet verbs * Add range user override * construction verb * Chemistry machine verbs * Climb Verb * Generalise pulled entity verbs * ViewVariables Verb * rejuvenate, delete, sentient, control verbs * Outfit verb * inrangeunoccluded and tubedirection verbs * attach-to verbs * remove unused verbs and move VV * Rename DebugVerbSystem * Ghost role and pointing verbs * Remove global verbs * Allow verbs to raise events * Changing categories and simplifying debug verbs * Add rotate and flip verbs * fix rejuvenate test * redo context menu * new Add Gas debug verb * Add Set Temperature debug verb * Uncuff verb * Disposal unit verbs * Add pickup verb * lock/unlock verb * Remove verb type, add specific verb events * rename verb messages -> events * Context menu displays verbs by interaction type * Updated context menu HandleMove previously, checked if entities moved 1 tile from click location. Now checks if entities moved out of view. Now you can actually right-click interact with yourself while walking! * Misc Verb menu GUI changes * Fix non-human/ghost verbs * Update types and categories * Allow non-ghost/human to open context menu * configuration verb * tagger verb * Morgue Verbs * Medical Scanner Verbs * Fix solution refactor merge issues * Fix context menu in-view check * Remove prepare GUI * Redo verb restrictions * Fix context menu UI * Disposal Verbs * Spill verb * Light verb * Hand Held light verb * power cell verbs * storage verbs and adding names to insert/eject * Pulling verb * Close context menu on verb execution * Strip verb * AmmoBox verb * fix pull verb * gun barrel verbs revolver verb energy weapon verbs Bolt action verb * Magazine gun barrel verbs * Add charger verbs * PDA verbs * Transfer amount verb * Add reagent verb * make alt-click use ECS verbs * Delete old verb files * Magboot verb * finalising tweaks * context menu visibility changes * code cleanup * Update AdminAddReagentUI.cs * Remove HasFlag * Consistent verb keys * Remove Linq, add comment * Fix in-inventory check * Update GUI text alignment and padding * Added close-menu option * Changed some "interaction" verbs to "activation" * Remove verb keys, use sorted sets * fix master merge * update some verb text * Undo Changes Remove some new verbs that can be added later undid some .ftl bugfixes, can and should be done separately * fix merge * Undo file rename * fix merge * Misc Cleanup * remove contraction * Fix keybinding issue * fix comment * merge fix * fix merge * fix merge * fix merge * fix merge * fix open-close verbs * adjust uncuff verb * fix merge and undo the renaming of SharedPullableComponent to PullableComponent. I'm tired of all of those merge conflicts
2021-10-05 14:29:03 +11:00
var uid = ent.Owner;
var component = ent.Comp;
2023-07-06 13:39:34 +10:00
// Behavior for if the disposals bin has items in it
if (component.Container.ContainedEntities.Count > 0)
ECS verbs and update context menu (#4594) * Functioning ECS verbs Currently only ID card console works. * Changed verb types and allow ID card insertions * Verb GUI sorting and verb networking * More networking, and shared components * Clientside verbs work now. * Verb enums changed to bitmask flags * Verb Categories redo * Fix range check * GasTank Verb * Remove unnecessary bodypart verb * Buckle Verb * buckle & unbuckle verbs * Updated range checks * Item cabinet verbs * Add range user override * construction verb * Chemistry machine verbs * Climb Verb * Generalise pulled entity verbs * ViewVariables Verb * rejuvenate, delete, sentient, control verbs * Outfit verb * inrangeunoccluded and tubedirection verbs * attach-to verbs * remove unused verbs and move VV * Rename DebugVerbSystem * Ghost role and pointing verbs * Remove global verbs * Allow verbs to raise events * Changing categories and simplifying debug verbs * Add rotate and flip verbs * fix rejuvenate test * redo context menu * new Add Gas debug verb * Add Set Temperature debug verb * Uncuff verb * Disposal unit verbs * Add pickup verb * lock/unlock verb * Remove verb type, add specific verb events * rename verb messages -> events * Context menu displays verbs by interaction type * Updated context menu HandleMove previously, checked if entities moved 1 tile from click location. Now checks if entities moved out of view. Now you can actually right-click interact with yourself while walking! * Misc Verb menu GUI changes * Fix non-human/ghost verbs * Update types and categories * Allow non-ghost/human to open context menu * configuration verb * tagger verb * Morgue Verbs * Medical Scanner Verbs * Fix solution refactor merge issues * Fix context menu in-view check * Remove prepare GUI * Redo verb restrictions * Fix context menu UI * Disposal Verbs * Spill verb * Light verb * Hand Held light verb * power cell verbs * storage verbs and adding names to insert/eject * Pulling verb * Close context menu on verb execution * Strip verb * AmmoBox verb * fix pull verb * gun barrel verbs revolver verb energy weapon verbs Bolt action verb * Magazine gun barrel verbs * Add charger verbs * PDA verbs * Transfer amount verb * Add reagent verb * make alt-click use ECS verbs * Delete old verb files * Magboot verb * finalising tweaks * context menu visibility changes * code cleanup * Update AdminAddReagentUI.cs * Remove HasFlag * Consistent verb keys * Remove Linq, add comment * Fix in-inventory check * Update GUI text alignment and padding * Added close-menu option * Changed some "interaction" verbs to "activation" * Remove verb keys, use sorted sets * fix master merge * update some verb text * Undo Changes Remove some new verbs that can be added later undid some .ftl bugfixes, can and should be done separately * fix merge * Undo file rename * fix merge * Misc Cleanup * remove contraction * Fix keybinding issue * fix comment * merge fix * fix merge * fix merge * fix merge * fix merge * fix open-close verbs * adjust uncuff verb * fix merge and undo the renaming of SharedPullableComponent to PullableComponent. I'm tired of all of those merge conflicts
2021-10-05 14:29:03 +11:00
{
2023-07-06 13:39:34 +10:00
// Verbs to flush the unit
AlternativeVerb flushVerb = new()
{
Act = () => ManualEngage(uid, component),
Text = Loc.GetString("disposal-flush-verb-get-data-text"),
Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/delete_transparent.svg.192dpi.png")),
Priority = 1,
};
args.Verbs.Add(flushVerb);
ECS verbs and update context menu (#4594) * Functioning ECS verbs Currently only ID card console works. * Changed verb types and allow ID card insertions * Verb GUI sorting and verb networking * More networking, and shared components * Clientside verbs work now. * Verb enums changed to bitmask flags * Verb Categories redo * Fix range check * GasTank Verb * Remove unnecessary bodypart verb * Buckle Verb * buckle & unbuckle verbs * Updated range checks * Item cabinet verbs * Add range user override * construction verb * Chemistry machine verbs * Climb Verb * Generalise pulled entity verbs * ViewVariables Verb * rejuvenate, delete, sentient, control verbs * Outfit verb * inrangeunoccluded and tubedirection verbs * attach-to verbs * remove unused verbs and move VV * Rename DebugVerbSystem * Ghost role and pointing verbs * Remove global verbs * Allow verbs to raise events * Changing categories and simplifying debug verbs * Add rotate and flip verbs * fix rejuvenate test * redo context menu * new Add Gas debug verb * Add Set Temperature debug verb * Uncuff verb * Disposal unit verbs * Add pickup verb * lock/unlock verb * Remove verb type, add specific verb events * rename verb messages -> events * Context menu displays verbs by interaction type * Updated context menu HandleMove previously, checked if entities moved 1 tile from click location. Now checks if entities moved out of view. Now you can actually right-click interact with yourself while walking! * Misc Verb menu GUI changes * Fix non-human/ghost verbs * Update types and categories * Allow non-ghost/human to open context menu * configuration verb * tagger verb * Morgue Verbs * Medical Scanner Verbs * Fix solution refactor merge issues * Fix context menu in-view check * Remove prepare GUI * Redo verb restrictions * Fix context menu UI * Disposal Verbs * Spill verb * Light verb * Hand Held light verb * power cell verbs * storage verbs and adding names to insert/eject * Pulling verb * Close context menu on verb execution * Strip verb * AmmoBox verb * fix pull verb * gun barrel verbs revolver verb energy weapon verbs Bolt action verb * Magazine gun barrel verbs * Add charger verbs * PDA verbs * Transfer amount verb * Add reagent verb * make alt-click use ECS verbs * Delete old verb files * Magboot verb * finalising tweaks * context menu visibility changes * code cleanup * Update AdminAddReagentUI.cs * Remove HasFlag * Consistent verb keys * Remove Linq, add comment * Fix in-inventory check * Update GUI text alignment and padding * Added close-menu option * Changed some "interaction" verbs to "activation" * Remove verb keys, use sorted sets * fix master merge * update some verb text * Undo Changes Remove some new verbs that can be added later undid some .ftl bugfixes, can and should be done separately * fix merge * Undo file rename * fix merge * Misc Cleanup * remove contraction * Fix keybinding issue * fix comment * merge fix * fix merge * fix merge * fix merge * fix merge * fix open-close verbs * adjust uncuff verb * fix merge and undo the renaming of SharedPullableComponent to PullableComponent. I'm tired of all of those merge conflicts
2021-10-05 14:29:03 +11:00
2023-07-06 13:39:34 +10:00
// Verb to eject the contents
AlternativeVerb ejectVerb = new()
{
2023-07-06 13:39:34 +10:00
Act = () => TryEjectContents(uid, component),
Category = VerbCategory.Eject,
Text = Loc.GetString("disposal-eject-verb-get-data-text")
};
2023-07-06 13:39:34 +10:00
args.Verbs.Add(ejectVerb);
}
2023-07-06 13:39:34 +10:00
}
private void AddInsertVerb(EntityUid uid, DisposalUnitComponent component, GetVerbsEvent<InteractionVerb> args)
2023-07-06 13:39:34 +10:00
{
if (!args.CanAccess || !args.CanInteract || args.Hands == null || args.Using == null)
return;
if (!ActionBlockerSystem.CanDrop(args.User))
2023-07-06 13:39:34 +10:00
return;
2023-07-06 13:39:34 +10:00
if (!CanInsert(uid, component, args.Using.Value))
return;
2023-07-06 13:39:34 +10:00
InteractionVerb insertVerb = new()
{
2023-07-06 13:39:34 +10:00
Text = Name(args.Using.Value),
Category = VerbCategory.Insert,
Act = () =>
{
_handsSystem.TryDropIntoContainer((args.User, args.Hands), args.Using.Value, component.Container, checkActionBlocker: false);
_adminLog.Add(LogType.Action, LogImpact.Medium, $"{ToPrettyString(args.User):player} inserted {ToPrettyString(args.Using.Value)} into {ToPrettyString(uid)}");
2023-07-06 13:39:34 +10:00
AfterInsert(uid, component, args.Using.Value, args.User);
}
};
2023-07-06 13:39:34 +10:00
args.Verbs.Add(insertVerb);
}
private void OnDoAfter(EntityUid uid, DisposalUnitComponent component, DoAfterEvent args)
2023-07-06 13:39:34 +10:00
{
if (args.Handled || args.Cancelled || args.Args.Target == null || args.Args.Used == null)
return;
AfterInsert(uid, component, args.Args.Target.Value, args.Args.User, doInsert: true);
2023-07-06 13:39:34 +10:00
args.Handled = true;
}
private void OnThrowInsert(Entity<DisposalUnitComponent> ent, ref BeforeThrowInsertEvent args)
{
if (!CanInsert(ent, ent, args.ThrownEntity))
args.Cancelled = true;
}
2023-07-06 13:39:34 +10:00
public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<DisposalUnitComponent, MetaDataComponent>();
2023-07-06 13:39:34 +10:00
while (query.MoveNext(out var uid, out var unit, out var metadata))
{
Update(uid, unit, metadata);
}
2023-07-06 13:39:34 +10:00
}
// TODO: This should just use the same thing as entity storage?
private void OnMovement(EntityUid uid, DisposalUnitComponent component, ref ContainerRelayMovementEntityEvent args)
2023-07-06 13:39:34 +10:00
{
var currentTime = GameTiming.CurTime;
if (!ActionBlockerSystem.CanMove(args.Entity))
return;
if (!TryComp(args.Entity, out HandsComponent? hands) ||
hands.Count == 0 ||
currentTime < component.LastExitAttempt + ExitAttemptDelay)
return;
Dirty(uid, component);
component.LastExitAttempt = currentTime;
Remove(uid, component, args.Entity);
UpdateUI((uid, component));
2023-07-06 13:39:34 +10:00
}
private void OnActivate(EntityUid uid, DisposalUnitComponent component, ActivateInWorldEvent args)
2023-07-06 13:39:34 +10:00
{
if (args.Handled || !args.Complex)
return;
2023-07-06 13:39:34 +10:00
args.Handled = true;
_ui.TryToggleUi(uid, DisposalUnitComponent.DisposalUnitUiKey.Key, args.User);
2023-07-06 13:39:34 +10:00
}
private void OnAfterInteractUsing(EntityUid uid, DisposalUnitComponent component, AfterInteractUsingEvent args)
2023-07-06 13:39:34 +10:00
{
if (args.Handled || !args.CanReach)
return;
2023-07-06 13:39:34 +10:00
if (!HasComp<HandsComponent>(args.User))
{
return;
}
2023-07-06 13:39:34 +10:00
if (!CanInsert(uid, component, args.Used) || !_handsSystem.TryDropIntoContainer(args.User, args.Used, component.Container))
{
2023-07-06 13:39:34 +10:00
return;
}
_adminLog.Add(LogType.Action, LogImpact.Medium, $"{ToPrettyString(args.User):player} inserted {ToPrettyString(args.Used)} into {ToPrettyString(uid)}");
2023-07-06 13:39:34 +10:00
AfterInsert(uid, component, args.Used, args.User);
args.Handled = true;
}
protected virtual void OnDisposalInit(Entity<DisposalUnitComponent> ent, ref ComponentInit args)
2023-07-06 13:39:34 +10:00
{
ent.Comp.Container = Containers.EnsureContainer<Container>(ent, DisposalUnitComponent.ContainerId);
2023-07-06 13:39:34 +10:00
}
private void OnPowerChange(EntityUid uid, DisposalUnitComponent component, ref PowerChangedEvent args)
2023-07-06 13:39:34 +10:00
{
if (!component.Running)
2023-07-06 13:39:34 +10:00
return;
UpdateUI((uid, component));
2023-07-06 13:39:34 +10:00
UpdateVisualState(uid, component);
if (!args.Powered)
{
2023-07-06 13:39:34 +10:00
component.NextFlush = null;
Dirty(uid, component);
2023-07-06 13:39:34 +10:00
return;
}
if (component.Engaged)
{
// Run ManualEngage to recalculate a new flush time
ManualEngage(uid, component);
2023-07-06 13:39:34 +10:00
}
}
private void OnAnchorChanged(EntityUid uid, DisposalUnitComponent component, ref AnchorStateChangedEvent args)
2023-07-06 13:39:34 +10:00
{
if (Terminating(uid))
return;
2023-07-06 13:39:34 +10:00
UpdateVisualState(uid, component);
if (!args.Anchored)
TryEjectContents(uid, component);
2023-07-06 13:39:34 +10:00
}
private void OnDragDropOn(EntityUid uid, DisposalUnitComponent component, ref DragDropTargetEvent args)
2023-07-06 13:39:34 +10:00
{
args.Handled = TryInsert(uid, args.Dragged, args.User);
2023-07-06 13:39:34 +10:00
}
protected virtual void UpdateUI(Entity<DisposalUnitComponent> entity)
2023-07-06 13:39:34 +10:00
{
2023-07-06 13:39:34 +10:00
}
/// <summary>
/// Returns the estimated time when the disposal unit will be back to full pressure.
/// </summary>
public TimeSpan EstimatedFullPressure(EntityUid uid, DisposalUnitComponent component)
{
if (component.NextPressurized < GameTiming.CurTime)
return TimeSpan.Zero;
return component.NextPressurized;
}
public bool CanFlush(EntityUid unit, DisposalUnitComponent component)
2023-07-06 13:39:34 +10:00
{
return GetState(unit, component) == DisposalsPressureState.Ready
&& _power.IsPowered(unit)
&& Comp<TransformComponent>(unit).Anchored;
}
public void Remove(EntityUid uid, DisposalUnitComponent component, EntityUid toRemove)
{
if (GameTiming.ApplyingState)
2023-07-06 13:39:34 +10:00
return;
if (!Containers.Remove(toRemove, component.Container))
return;
if (component.Container.ContainedEntities.Count == 0)
2023-07-06 13:39:34 +10:00
{
// If not manually engaged then reset the flushing entirely.
if (!component.Engaged)
{
2023-07-06 13:39:34 +10:00
component.NextFlush = null;
Dirty(uid, component);
UpdateUI((uid, component));
}
2023-07-06 13:39:34 +10:00
}
_climb.Climb(toRemove, toRemove, uid, silent: true);
UpdateVisualState(uid, component);
2023-07-06 13:39:34 +10:00
}
public void UpdateVisualState(EntityUid uid, DisposalUnitComponent component, bool flush = false)
2023-07-06 13:39:34 +10:00
{
if (!TryComp(uid, out AppearanceComponent? appearance))
{
return;
}
if (!Transform(uid).Anchored)
2023-07-06 13:39:34 +10:00
{
_appearance.SetData(uid, DisposalUnitComponent.Visuals.VisualState, DisposalUnitComponent.VisualState.UnAnchored, appearance);
_appearance.SetData(uid, DisposalUnitComponent.Visuals.Handle, DisposalUnitComponent.HandleState.Normal, appearance);
_appearance.SetData(uid, DisposalUnitComponent.Visuals.Light, DisposalUnitComponent.LightStates.Off, appearance);
2023-07-06 13:39:34 +10:00
return;
}
var state = GetState(uid, component);
switch (state)
{
case DisposalsPressureState.Flushed:
_appearance.SetData(uid, DisposalUnitComponent.Visuals.VisualState, DisposalUnitComponent.VisualState.OverlayFlushing, appearance);
break;
case DisposalsPressureState.Pressurizing:
_appearance.SetData(uid, DisposalUnitComponent.Visuals.VisualState, DisposalUnitComponent.VisualState.OverlayCharging, appearance);
break;
case DisposalsPressureState.Ready:
_appearance.SetData(uid, DisposalUnitComponent.Visuals.VisualState, DisposalUnitComponent.VisualState.Anchored, appearance);
break;
2023-07-06 13:39:34 +10:00
}
_appearance.SetData(uid, DisposalUnitComponent.Visuals.Handle, component.Engaged
? DisposalUnitComponent.HandleState.Engaged
: DisposalUnitComponent.HandleState.Normal, appearance);
if (!_power.IsPowered(uid))
{
_appearance.SetData(uid, DisposalUnitComponent.Visuals.Light, DisposalUnitComponent.LightStates.Off, appearance);
return;
}
var lightState = DisposalUnitComponent.LightStates.Off;
if (component.Container.ContainedEntities.Count > 0)
2023-07-06 13:39:34 +10:00
{
lightState |= DisposalUnitComponent.LightStates.Full;
}
if (state is DisposalsPressureState.Pressurizing or DisposalsPressureState.Flushed)
{
lightState |= DisposalUnitComponent.LightStates.Charging;
}
else
{
lightState |= DisposalUnitComponent.LightStates.Ready;
}
_appearance.SetData(uid, DisposalUnitComponent.Visuals.Light, lightState, appearance);
}
/// <summary>
/// Gets the current pressure state of a disposals unit.
/// </summary>
/// <param name="uid"></param>
/// <param name="component"></param>
/// <param name="metadata"></param>
/// <returns></returns>
public DisposalsPressureState GetState(EntityUid uid, DisposalUnitComponent component, MetaDataComponent? metadata = null)
{
var nextPressure = Metadata.GetPauseTime(uid, metadata) + component.NextPressurized - GameTiming.CurTime;
var pressurizeTime = 1f / PressurePerSecond;
var pressurizeDuration = pressurizeTime - component.FlushDelay.TotalSeconds;
if (nextPressure.TotalSeconds > pressurizeDuration)
{
return DisposalsPressureState.Flushed;
}
if (nextPressure > TimeSpan.Zero)
{
return DisposalsPressureState.Pressurizing;
}
return DisposalsPressureState.Ready;
}
public float GetPressure(EntityUid uid, DisposalUnitComponent component, MetaDataComponent? metadata = null)
{
if (!Resolve(uid, ref metadata))
return 0f;
var pauseTime = Metadata.GetPauseTime(uid, metadata);
return MathF.Min(1f,
(float)(GameTiming.CurTime - pauseTime - component.NextPressurized).TotalSeconds / PressurePerSecond);
}
protected void OnPreventCollide(EntityUid uid, DisposalUnitComponent component,
ref PreventCollideEvent args)
{
var otherBody = args.OtherEntity;
// Items dropped shouldn't collide but items thrown should
if (HasComp<ItemComponent>(otherBody) && !HasComp<ThrownItemComponent>(otherBody))
{
args.Cancelled = true;
2023-07-06 13:39:34 +10:00
}
}
protected void OnCanDragDropOn(EntityUid uid, DisposalUnitComponent component, ref CanDropTargetEvent args)
{
if (args.Handled)
return;
args.CanDrop = CanInsert(uid, component, args.Dragged);
args.Handled = true;
}
protected void OnEmagged(EntityUid uid, DisposalUnitComponent component, ref GotEmaggedEvent args)
{
component.DisablePressure = true;
args.Handled = true;
}
public virtual bool CanInsert(EntityUid uid, DisposalUnitComponent component, EntityUid entity)
{
// TODO: All of the below should be using the EXISTING EVENT
if (!Containers.CanInsert(entity, component.Container))
return false;
if (!Transform(uid).Anchored)
return false;
var storable = HasComp<ItemComponent>(entity);
if (!storable && !HasComp<BodyComponent>(entity))
return false;
if (_whitelistSystem.IsBlacklistPass(component.Blacklist, entity) ||
_whitelistSystem.IsWhitelistFail(component.Whitelist, entity))
return false;
if (TryComp<PhysicsComponent>(entity, out var physics) && (physics.CanCollide) || storable)
return true;
else
return false;
}
public void DoInsertDisposalUnit(EntityUid uid,
EntityUid toInsert,
EntityUid user,
DisposalUnitComponent? disposal = null)
{
if (!Resolve(uid, ref disposal))
return;
if (!Containers.Insert(toInsert, disposal.Container))
return;
_adminLog.Add(LogType.Action, LogImpact.Medium, $"{ToPrettyString(user):player} inserted {ToPrettyString(toInsert)} into {ToPrettyString(uid)}");
AfterInsert(uid, disposal, toInsert, user);
}
public virtual void AfterInsert(EntityUid uid,
DisposalUnitComponent component,
EntityUid inserted,
EntityUid? user = null,
bool doInsert = false)
{
Audio.PlayPredicted(component.InsertSound, uid, user: user);
if (doInsert && !Containers.Insert(inserted, component.Container))
return;
if (user != inserted && user != null)
_adminLog.Add(LogType.Action, LogImpact.Medium, $"{ToPrettyString(user.Value):player} inserted {ToPrettyString(inserted)} into {ToPrettyString(uid)}");
QueueAutomaticEngage(uid, component);
_ui.CloseUi(uid, DisposalUnitComponent.DisposalUnitUiKey.Key, inserted);
// Maybe do pullable instead? Eh still fine.
Joints.RecursiveClearJoints(inserted);
UpdateVisualState(uid, component);
2023-07-06 13:39:34 +10:00
}
2023-07-06 13:39:34 +10:00
public bool TryInsert(EntityUid unitId, EntityUid toInsertId, EntityUid? userId, DisposalUnitComponent? unit = null)
{
if (!Resolve(unitId, ref unit))
return false;
2023-07-06 13:39:34 +10:00
if (userId.HasValue && !HasComp<HandsComponent>(userId) && toInsertId != userId) // Mobs like mouse can Jump inside even with no hands
{
_popupSystem.PopupEntity(Loc.GetString("disposal-unit-no-hands"), userId.Value, userId.Value, PopupType.SmallCaution);
return false;
}
2023-07-06 13:39:34 +10:00
if (!CanInsert(unitId, unit, toInsertId))
return false;
bool insertingSelf = userId == toInsertId;
var delay = insertingSelf ? unit.EntryDelay : unit.DraggedEntryDelay;
if (userId != null && !insertingSelf)
_popupSystem.PopupEntity(Loc.GetString("disposal-unit-being-inserted", ("user", Identity.Entity((EntityUid)userId, EntityManager))), toInsertId, toInsertId, PopupType.Large);
2023-07-06 13:39:34 +10:00
if (delay <= 0 || userId == null)
{
AfterInsert(unitId, unit, toInsertId, userId, doInsert: true);
2023-07-06 13:39:34 +10:00
return true;
}
2023-07-06 13:39:34 +10:00
// 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 DoAfterArgs(EntityManager, userId.Value, delay, new DisposalDoAfterEvent(), unitId, target: toInsertId, used: unitId)
2023-07-06 13:39:34 +10:00
{
BreakOnDamage = true,
BreakOnMove = true,
NeedHand = false,
2023-07-06 13:39:34 +10:00
};
2023-07-06 13:39:34 +10:00
_doAfterSystem.TryStartDoAfter(doAfterArgs);
return true;
}
private void UpdateState(EntityUid uid, DisposalsPressureState state, DisposalUnitComponent component, MetaDataComponent metadata)
{
if (component.State == state)
return;
component.State = state;
UpdateVisualState(uid, component);
Dirty(uid, component, metadata);
if (state == DisposalsPressureState.Ready)
{
component.NextPressurized = TimeSpan.Zero;
// Manually engaged
if (component.Engaged)
{
component.NextFlush = GameTiming.CurTime + component.ManualFlushTime;
}
else if (component.Container.ContainedEntities.Count > 0)
{
component.NextFlush = GameTiming.CurTime + component.AutomaticEngageTime;
}
else
{
component.NextFlush = null;
}
}
}
/// <summary>
/// Work out if we can stop updating this disposals component i.e. full pressure and nothing colliding.
/// </summary>
private void Update(EntityUid uid, DisposalUnitComponent component, MetaDataComponent metadata)
{
var state = GetState(uid, component, metadata);
// Pressurizing, just check if we need a state update.
if (component.NextPressurized > GameTiming.CurTime)
{
UpdateState(uid, state, component, metadata);
return;
}
if (component.NextFlush != null)
{
if (component.NextFlush.Value < GameTiming.CurTime)
{
TryFlush(uid, component);
}
}
UpdateState(uid, state, component, metadata);
}
public bool TryFlush(EntityUid uid, DisposalUnitComponent component)
2023-07-06 13:39:34 +10:00
{
if (!CanFlush(uid, component))
{
return false;
}
2023-07-06 13:39:34 +10:00
if (component.NextFlush != null)
component.NextFlush = component.NextFlush.Value + component.AutomaticEngageTime;
2023-07-06 13:39:34 +10:00
var beforeFlushArgs = new BeforeDisposalFlushEvent();
RaiseLocalEvent(uid, beforeFlushArgs);
2023-07-06 13:39:34 +10:00
if (beforeFlushArgs.Cancelled)
{
2023-07-06 13:39:34 +10:00
Disengage(uid, component);
return false;
}
2023-07-06 13:39:34 +10:00
var xform = Transform(uid);
if (!TryComp(xform.GridUid, out MapGridComponent? grid))
return false;
2023-07-06 13:39:34 +10:00
var coords = xform.Coordinates;
var entry = _map.GetLocal(xform.GridUid.Value, grid, coords)
.FirstOrDefault(HasComp<Tube.DisposalEntryComponent>);
2023-07-06 13:39:34 +10:00
if (entry == default || component is not DisposalUnitComponent sDisposals)
{
2023-07-06 13:39:34 +10:00
component.Engaged = false;
UpdateUI((uid, component));
Dirty(uid, component);
2023-07-06 13:39:34 +10:00
return false;
}
2023-07-06 13:39:34 +10:00
HandleAir(uid, sDisposals, xform);
2023-07-06 13:39:34 +10:00
_disposalTubeSystem.TryInsert(entry, sDisposals, beforeFlushArgs.Tags);
component.NextPressurized = GameTiming.CurTime;
if (!component.DisablePressure)
component.NextPressurized += TimeSpan.FromSeconds(1f / PressurePerSecond);
2023-07-06 13:39:34 +10:00
component.Engaged = false;
// stop queuing NOW
component.NextFlush = null;
2023-07-06 13:39:34 +10:00
UpdateVisualState(uid, component, true);
Dirty(uid, component);
UpdateUI((uid, component));
2023-07-06 13:39:34 +10:00
return true;
}
protected virtual void HandleAir(EntityUid uid, DisposalUnitComponent component, TransformComponent xform)
2023-07-06 13:39:34 +10:00
{
2023-07-06 13:39:34 +10:00
}
public void ManualEngage(EntityUid uid, DisposalUnitComponent component, MetaDataComponent? metadata = null)
2023-07-06 13:39:34 +10:00
{
component.Engaged = true;
UpdateVisualState(uid, component);
Dirty(uid, component);
UpdateUI((uid, component));
2023-07-06 13:39:34 +10:00
if (!CanFlush(uid, component))
return;
2023-07-06 13:39:34 +10:00
if (!Resolve(uid, ref metadata))
return;
2023-07-06 13:39:34 +10:00
var pauseTime = Metadata.GetPauseTime(uid, metadata);
var nextEngage = GameTiming.CurTime - pauseTime + component.ManualFlushTime;
component.NextFlush = TimeSpan.FromSeconds(Math.Min((component.NextFlush ?? TimeSpan.MaxValue).TotalSeconds, nextEngage.TotalSeconds));
}
public void Disengage(EntityUid uid, DisposalUnitComponent component)
2023-07-06 13:39:34 +10:00
{
component.Engaged = false;
2023-07-06 13:39:34 +10:00
if (component.Container.ContainedEntities.Count == 0)
{
component.NextFlush = null;
}
2023-07-06 13:39:34 +10:00
UpdateVisualState(uid, component);
Dirty(uid, component);
UpdateUI((uid, component));
}
/// <summary>
2023-07-06 13:39:34 +10:00
/// Remove all entities currently in the disposal unit.
/// </summary>
public void TryEjectContents(EntityUid uid, DisposalUnitComponent component)
{
2023-07-06 13:39:34 +10:00
foreach (var entity in component.Container.ContainedEntities.ToArray())
{
Remove(uid, component, entity);
}
2023-07-06 13:39:34 +10:00
if (!component.Engaged)
{
2023-07-06 13:39:34 +10:00
component.NextFlush = null;
Dirty(uid, component);
UpdateUI((uid, component));
}
}
/// <summary>
2023-07-06 13:39:34 +10:00
/// If something is inserted (or the likes) then we'll queue up an automatic flush in the future.
/// </summary>
public void QueueAutomaticEngage(EntityUid uid, DisposalUnitComponent component, MetaDataComponent? metadata = null)
{
if (component.Deleted || !component.AutomaticEngage || !_power.IsPowered(uid) && component.Container.ContainedEntities.Count == 0)
2023-07-06 13:39:34 +10:00
{
return;
}
var pauseTime = Metadata.GetPauseTime(uid, metadata);
var automaticTime = GameTiming.CurTime + component.AutomaticEngageTime - pauseTime;
var flushTime = TimeSpan.FromSeconds(Math.Min((component.NextFlush ?? TimeSpan.MaxValue).TotalSeconds, automaticTime.TotalSeconds));
component.NextFlush = flushTime;
Dirty(uid, component);
UpdateUI((uid, component));
}
2023-07-06 13:39:34 +10:00
private void OnUiButtonPressed(EntityUid uid, DisposalUnitComponent component, DisposalUnitComponent.UiButtonPressedMessage args)
2023-07-06 13:39:34 +10:00
{
if (args.Actor is not { Valid: true } player)
{
2023-07-06 13:39:34 +10:00
return;
}
2023-07-06 13:39:34 +10:00
switch (args.Button)
{
case DisposalUnitComponent.UiButton.Eject:
TryEjectContents(uid, component);
_adminLog.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(player):player} hit eject button on {ToPrettyString(uid)}");
break;
case DisposalUnitComponent.UiButton.Engage:
ToggleEngage(uid, component);
_adminLog.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(player):player} hit flush button on {ToPrettyString(uid)}, it's now {(component.Engaged ? "on" : "off")}");
break;
case DisposalUnitComponent.UiButton.Power:
_power.TogglePower(uid, user: args.Actor);
break;
default:
throw new ArgumentOutOfRangeException($"{ToPrettyString(player):player} attempted to hit a nonexistant button on {ToPrettyString(uid)}");
}
2023-07-06 13:39:34 +10:00
}
public void ToggleEngage(EntityUid uid, DisposalUnitComponent component)
{
component.Engaged ^= true;
if (component.Engaged)
{
ManualEngage(uid, component);
}
else
{
Disengage(uid, component);
}
}
private void AddClimbInsideVerb(EntityUid uid, DisposalUnitComponent component, GetVerbsEvent<Verb> args)
{
// This is not an interaction, activation, or alternative verb type because unfortunately most users are
// unwilling to accept that this is where they belong and don't want to accidentally climb inside.
if (!args.CanAccess ||
!args.CanInteract ||
component.Container.ContainedEntities.Contains(args.User) ||
!ActionBlockerSystem.CanMove(args.User))
{
return;
}
2023-07-06 13:39:34 +10:00
if (!CanInsert(uid, component, args.User))
return;
2023-07-06 13:39:34 +10:00
// Add verb to climb inside of the unit,
Verb verb = new()
{
Act = () => TryInsert(uid, args.User, args.User),
DoContactInteraction = true,
Text = Loc.GetString("disposal-self-insert-verb-get-data-text")
};
// TODO VERB ICON
// TODO VERB CATEGORY
// create a verb category for "enter"?
// See also, medical scanner. Also maybe add verbs for entering lockers/body bags?
args.Verbs.Add(verb);
2023-07-06 13:39:34 +10:00
}
private void OnGetDumpableVerb(Entity<DisposalUnitComponent> ent, ref GetDumpableVerbEvent args)
{
args.Verb = Loc.GetString("dump-disposal-verb-name", ("unit", ent));
}
private void OnDump(Entity<DisposalUnitComponent> ent, ref DumpEvent args)
{
if (args.Handled)
return;
args.Handled = true;
args.PlaySound = true;
foreach (var entity in args.DumpQueue)
{
DoInsertDisposalUnit(ent, entity, args.User);
}
}
2023-07-06 13:39:34 +10:00
}