Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Carrying/escape-inventory tweaks #834

Merged
36 changes: 35 additions & 1 deletion Content.Server/Nyanotrasen/Carrying/CarryingSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Numerics;
using System.Threading;
using Content.Server.DoAfter;
using Content.Server.Body.Systems;
Expand All @@ -22,9 +23,11 @@
using Content.Shared.Pulling.Components;
using Content.Shared.Standing;
using Content.Shared.ActionBlocker;
using Content.Shared.Mind.Components;
using Content.Shared.Throwing;
using Content.Shared.Physics.Pull;
using Content.Shared.Mobs.Systems;
using Content.Shared.Popups;
using Robust.Shared.Map.Components;

namespace Content.Server.Carrying
Expand Down Expand Up @@ -124,7 +127,12 @@ private void OnThrow(EntityUid uid, CarryingComponent component, BeforeThrowEven

private void OnParentChanged(EntityUid uid, CarryingComponent component, ref EntParentChangedMessage args)
{
if (Transform(uid).MapID != args.OldMapId)
var xform = Transform(uid);
if (xform.MapID != args.OldMapId)
return;

// Do not drop the carried entity if the new parent is a grid
if (xform.ParentUid == xform.GridUid)
return;

DropCarried(uid, component.Carried);
Expand Down Expand Up @@ -206,6 +214,7 @@ private void OnDoAfter(EntityUid uid, CarriableComponent component, CarryDoAfter
Carry(args.Args.User, uid);
args.Handled = true;
}

private void StartCarryDoAfter(EntityUid carrier, EntityUid carried, CarriableComponent component)
{
TimeSpan length = TimeSpan.FromSeconds(3);
Expand Down Expand Up @@ -234,13 +243,19 @@ private void StartCarryDoAfter(EntityUid carrier, EntityUid carried, CarriableCo
NeedHand = true
};
_doAfterSystem.TryStartDoAfter(args);

_popupSystem.PopupEntity(Loc.GetString("carry-started", ("carrier", carrier)), carried, carried);
}

private void Carry(EntityUid carrier, EntityUid carried)
{
if (TryComp<SharedPullableComponent>(carried, out var pullable))
_pullingSystem.TryStopPull(pullable);

// Don't allow people to stack upon each other. They're too weak for that!
if (TryComp<CarryingComponent>(carried, out var carryComp))
DropCarried(carried, carryComp.Carried);

Transform(carrier).AttachToGridOrMap();
Transform(carried).AttachToGridOrMap();
Transform(carried).Coordinates = Transform(carrier).Coordinates;
Expand Down Expand Up @@ -310,5 +325,24 @@ public bool CanCarry(EntityUid carrier, EntityUid carried, CarriableComponent? c

return true;
}

public override void Update(float frameTime)
{
var query = EntityQueryEnumerator<BeingCarriedComponent>();
while (query.MoveNext(out var carried, out var comp))
{
var carrier = comp.Carrier;
if (carrier is not { Valid: true } || carried is not { Valid: true })
continue;

// Make sure the carried entity is always centered relative to the carrier, as gravity pulls can offset it otherwise
var xform = Transform(carried);
if (!xform.LocalPosition.EqualsApprox(Vector2.Zero))
{
xform.LocalPosition = Vector2.Zero;
}
}
query.Dispose();
}
}
}
4 changes: 4 additions & 0 deletions Content.Server/Resist/CanEscapeInventoryComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ public sealed partial class CanEscapeInventoryComponent : Component

[DataField("doAfter")]
public DoAfterId? DoAfter;

// Frontier
[DataField]
public EntityUid? EscapeCancelAction;
}
36 changes: 36 additions & 0 deletions Content.Server/Resist/EscapeInventorySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
using Robust.Shared.Containers;
using Content.Server.Storage.Components;
using Content.Server.Carrying;
using Content.Shared.Actions;
using Robust.Shared.Prototypes;

namespace Content.Server.Resist;

Expand All @@ -28,6 +30,12 @@ public sealed class EscapeInventorySystem : EntitySystem
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] private readonly ContestsSystem _contests = default!;
[Dependency] private readonly CarryingSystem _carryingSystem = default!; // Carrying system from Nyanotrasen.
[Dependency] private readonly SharedActionsSystem _actions = default!;
[Dependency] private readonly EntityManager _entityManager = default!;

// Frontier - cancel inventory escape
[ValidatePrototypeId<EntityPrototype>]
private readonly string _escapeCancelAction = "ActionCancelEscape";

/// <summary>
/// You can't escape the hands of an entity this many times more massive than you.
Expand All @@ -41,6 +49,7 @@ public override void Initialize()
SubscribeLocalEvent<CanEscapeInventoryComponent, MoveInputEvent>(OnRelayMovement);
SubscribeLocalEvent<CanEscapeInventoryComponent, EscapeInventoryEvent>(OnEscape);
SubscribeLocalEvent<CanEscapeInventoryComponent, DroppedEvent>(OnDropped);
SubscribeLocalEvent<CanEscapeInventoryComponent, EscapeInventoryCancelActionEvent>(OnCancelEscape); // Frontier
}

private void OnRelayMovement(EntityUid uid, CanEscapeInventoryComponent component, ref MoveInputEvent args)
Expand Down Expand Up @@ -90,6 +99,10 @@ private void OnRelayMovement(EntityUid uid, CanEscapeInventoryComponent componen
Dirty(user, component);
_popupSystem.PopupEntity(Loc.GetString("escape-inventory-component-start-resisting"), user, user);
_popupSystem.PopupEntity(Loc.GetString("escape-inventory-component-start-resisting-target"), container, container);

// Frontier - escape cancel action
if (component.EscapeCancelAction is not { Valid: true })
_actions.AddAction(user, ref component.EscapeCancelAction, _escapeCancelAction);
}

private void OnEscape(EntityUid uid, CanEscapeInventoryComponent component, EscapeInventoryEvent args)
Expand All @@ -100,6 +113,8 @@ private void OnEscape(EntityUid uid, CanEscapeInventoryComponent component, Esca
if (args.Handled || args.Cancelled)
return;

RemoveCancelAction(uid, component); // Frontier

if (TryComp<BeingCarriedComponent>(uid, out var carried)) // Start of carrying system of nyanotrasen.
{
_carryingSystem.DropCarried(carried.Carrier, uid);
Expand All @@ -114,5 +129,26 @@ private void OnDropped(EntityUid uid, CanEscapeInventoryComponent component, Dro
{
if (component.DoAfter != null)
_doAfterSystem.Cancel(component.DoAfter);

RemoveCancelAction(uid, component); // Frontier
}

// Frontier
private void RemoveCancelAction(EntityUid uid, CanEscapeInventoryComponent component)
{
if (component.EscapeCancelAction is not { Valid: true })
return;

_actions.RemoveAction(uid, component.EscapeCancelAction);
component.EscapeCancelAction = null;
}

// Frontier
private void OnCancelEscape(EntityUid uid, CanEscapeInventoryComponent component, EscapeInventoryCancelActionEvent args)
{
if (component.DoAfter != null)
_doAfterSystem.Cancel(component.DoAfter);

RemoveCancelAction(uid, component);
}
}
5 changes: 5 additions & 0 deletions Content.Shared/Resist/EscapeInventoryCancelEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using Content.Shared.Actions;

public sealed partial class EscapeInventoryCancelActionEvent : InstantActionEvent
{
}
1 change: 1 addition & 0 deletions Resources/Locale/en-US/nyanotrasen/carrying/carry.ftl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
carry-verb = Carry

carry-too-heavy = You're not strong enough.
carry-started = {THE($carrier)} is trying to pick you up!
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- type: entity
id: ActionCancelEscape
name: Stop escaping
description: Calm down and sit peacefuly in your carrier's inventory
noSpawn: true
components:
- type: InstantAction
icon: _NF/Actions/escapeinventory.rsi/cancel-escape.png
event: !type:EscapeInventoryCancelActionEvent
useDelay: 2
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions Resources/Textures/_NF/Actions/escapeinventory.rsi/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Duffelbag icon taken from tgstation at commit https://github.com/tgstation/tgstation/commit/547852588166c8e091b441e4e67169e156bb09c1 | Modified by Mnemotechnician (github)",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "cancel-escape"
}
]
}
Loading