# Conflicts: # .github/PULL_REQUEST_TEMPLATE.md # Content.Client/Lobby/LobbyUIController.cs # Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs # Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs # Content.Server/Administration/Systems/BwoinkSystem.cs # Content.Server/IoC/ServerContentIoC.cs # Content.Server/Players/PlayTimeTracking/PlayTimeTrackingSystem.cs # Content.Server/Shuttles/Systems/ArrivalsSystem.cs # Content.Shared/Preferences/Loadouts/LoadoutPrototype.cs # Content.Shared/Roles/JobRequirements.cs # Resources/Prototypes/Accents/word_replacements.yml # Resources/Prototypes/Catalog/Fills/Lockers/security.yml # Resources/Prototypes/Entities/Mobs/Species/base.yml # Resources/Prototypes/Loadouts/Jobs/Cargo/cargo_technician.yml # Resources/Prototypes/Loadouts/Jobs/Cargo/quartermaster.yml # Resources/Prototypes/Loadouts/Jobs/Civilian/bartender.yml # Resources/Prototypes/Loadouts/Jobs/Civilian/botanist.yml # Resources/Prototypes/Loadouts/Jobs/Civilian/chaplain.yml # Resources/Prototypes/Loadouts/Jobs/Civilian/chef.yml # Resources/Prototypes/Loadouts/Jobs/Civilian/janitor.yml # Resources/Prototypes/Loadouts/Jobs/Civilian/lawyer.yml # Resources/Prototypes/Loadouts/Jobs/Civilian/librarian.yml # Resources/Prototypes/Loadouts/Jobs/Civilian/mime.yml # Resources/Prototypes/Loadouts/Jobs/Civilian/passenger.yml # Resources/Prototypes/Loadouts/Jobs/Command/captain.yml # Resources/Prototypes/Loadouts/Jobs/Command/head_of_personnel.yml # Resources/Prototypes/Loadouts/Jobs/Engineering/atmospheric_technician.yml # Resources/Prototypes/Loadouts/Jobs/Engineering/chief_engineer.yml # Resources/Prototypes/Loadouts/Jobs/Engineering/station_engineer.yml # Resources/Prototypes/Loadouts/Jobs/Engineering/technical_assistant.yml # Resources/Prototypes/Loadouts/Jobs/Medical/chemist.yml # Resources/Prototypes/Loadouts/Jobs/Medical/chief_medical_officer.yml # Resources/Prototypes/Loadouts/Jobs/Medical/medical_doctor.yml # Resources/Prototypes/Loadouts/Jobs/Medical/medical_intern.yml # Resources/Prototypes/Loadouts/Jobs/Medical/paramedic.yml # Resources/Prototypes/Loadouts/Jobs/Science/research_director.yml # Resources/Prototypes/Loadouts/Jobs/Science/scientist.yml # Resources/Prototypes/Loadouts/Jobs/Security/detective.yml # Resources/Prototypes/Loadouts/Jobs/Security/head_of_security.yml # Resources/Prototypes/Loadouts/Jobs/Security/security_cadet.yml # Resources/Prototypes/Loadouts/Jobs/Security/security_officer.yml # Resources/Prototypes/Loadouts/Jobs/Security/warden.yml # Resources/Prototypes/Loadouts/Miscellaneous/trinkets.yml # Resources/Prototypes/Recipes/Lathes/medical.yml # Resources/Prototypes/Roles/Jobs/Cargo/quartermaster.yml # Resources/Prototypes/Roles/Jobs/Command/captain.yml # Resources/Prototypes/Roles/Jobs/Command/head_of_personnel.yml # Resources/Prototypes/Roles/Jobs/Engineering/chief_engineer.yml # Resources/Prototypes/Roles/Jobs/Medical/chief_medical_officer.yml # Resources/Prototypes/Roles/Jobs/Science/research_director.yml # Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml # Resources/Textures/Clothing/Mask/sadmime.rsi/meta.json # Resources/Textures/Clothing/Mask/scaredmime.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coat.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatatmos.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatcap.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatcargo.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatce.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatcentcom.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatchem.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatcmo.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatengi.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatgen.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coathop.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coathos.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coathydro.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatjani.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatmed.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatmime.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatminer.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatparamed.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatqm.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatrd.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatrobo.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatsci.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatsec.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatviro.rsi/meta.json # Resources/Textures/Clothing/OuterClothing/WinterCoats/coatwarden.rsi/meta.json # Resources/Textures/Structures/Power/apc.rsi/base.png # Resources/Textures/Structures/Power/apc.rsi/broken.png # Resources/Textures/Structures/Power/apc.rsi/display-charging.png # Resources/Textures/Structures/Power/apc.rsi/display-full.png # Resources/Textures/Structures/Power/apc.rsi/display-lack.png # Resources/Textures/Structures/Power/apc.rsi/display-remote.png # Resources/Textures/Structures/Power/apc.rsi/emag-unlit.png # Resources/Textures/Structures/Power/apc.rsi/frame.png # Resources/Textures/Structures/Power/apc.rsi/static.png
105 lines
3.9 KiB
C#
105 lines
3.9 KiB
C#
using Content.Server._Sunrise.Carrying;
|
|
using Content.Server.Carrying;
|
|
using Content.Server.Popups;
|
|
using Content.Shared.Storage.Components;
|
|
using Content.Shared.ActionBlocker;
|
|
using Content.Shared.DoAfter;
|
|
using Content.Shared.Hands.EntitySystems;
|
|
using Content.Shared.Interaction.Events;
|
|
using Content.Shared.Inventory;
|
|
using Content.Shared.Movement.Events;
|
|
using Content.Shared.Resist;
|
|
using Content.Shared.Storage;
|
|
using Robust.Shared.Containers;
|
|
|
|
namespace Content.Server.Resist;
|
|
|
|
public sealed class EscapeInventorySystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
|
|
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
|
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
|
|
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
|
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
|
[Dependency] private readonly CarryingSystem _carryingSystem = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<CanEscapeInventoryComponent, MoveInputEvent>(OnRelayMovement);
|
|
SubscribeLocalEvent<CanEscapeInventoryComponent, EscapeInventoryEvent>(OnEscape);
|
|
SubscribeLocalEvent<CanEscapeInventoryComponent, DroppedEvent>(OnDropped);
|
|
}
|
|
|
|
private void OnRelayMovement(EntityUid uid, CanEscapeInventoryComponent component, ref MoveInputEvent args)
|
|
{
|
|
if (!args.HasDirectionalMovement)
|
|
return;
|
|
|
|
if (!_containerSystem.TryGetContainingContainer((uid, null, null), out var container) || !_actionBlockerSystem.CanInteract(uid, container.Owner))
|
|
return;
|
|
|
|
// Make sure there's nothing stopped the removal (like being glued)
|
|
if (!_containerSystem.CanRemove(uid, container))
|
|
{
|
|
_popupSystem.PopupEntity(Loc.GetString("escape-inventory-component-failed-resisting"), uid, uid);
|
|
return;
|
|
}
|
|
|
|
// Contested
|
|
if (_handsSystem.IsHolding(container.Owner, uid, out _))
|
|
{
|
|
AttemptEscape(uid, container.Owner, component);
|
|
return;
|
|
}
|
|
|
|
// Uncontested
|
|
if (HasComp<StorageComponent>(container.Owner) || HasComp<InventoryComponent>(container.Owner) || HasComp<SecretStashComponent>(container.Owner))
|
|
AttemptEscape(uid, container.Owner, component);
|
|
}
|
|
|
|
public void AttemptEscape(EntityUid user, EntityUid container, CanEscapeInventoryComponent component, float multiplier = 1f)
|
|
{
|
|
if (component.IsEscaping)
|
|
return;
|
|
|
|
var doAfterEventArgs = new DoAfterArgs(EntityManager, user, component.BaseResistTime * multiplier, new EscapeInventoryEvent(), user, target: container)
|
|
{
|
|
BreakOnMove = true,
|
|
BreakOnDamage = true,
|
|
NeedHand = false
|
|
};
|
|
|
|
if (!_doAfterSystem.TryStartDoAfter(doAfterEventArgs, out component.DoAfter))
|
|
return;
|
|
|
|
_popupSystem.PopupEntity(Loc.GetString("escape-inventory-component-start-resisting"), user, user);
|
|
_popupSystem.PopupEntity(Loc.GetString("escape-inventory-component-start-resisting-target"), container, container);
|
|
}
|
|
|
|
private void OnEscape(EntityUid uid, CanEscapeInventoryComponent component, EscapeInventoryEvent args)
|
|
{
|
|
component.DoAfter = null;
|
|
|
|
if (args.Handled || args.Cancelled)
|
|
return;
|
|
|
|
// Sunrise-Start
|
|
if (TryComp<BeingCarriedComponent>(uid, out var carried))
|
|
{
|
|
_carryingSystem.DropCarried(carried.Carrier, uid);
|
|
return;
|
|
}
|
|
// Sunrise-End
|
|
|
|
_containerSystem.AttachParentToContainerOrGrid((uid, Transform(uid)));
|
|
args.Handled = true;
|
|
}
|
|
|
|
private void OnDropped(EntityUid uid, CanEscapeInventoryComponent component, DroppedEvent args)
|
|
{
|
|
if (component.DoAfter != null)
|
|
_doAfterSystem.Cancel(component.DoAfter);
|
|
}
|
|
}
|