Fix drop/equip code (#8336)

This commit is contained in:
Leon Friedrich
2022-05-22 08:58:57 +12:00
committed by GitHub
parent 8b7b458167
commit 959c9a9615
2 changed files with 22 additions and 6 deletions

View File

@@ -66,17 +66,24 @@ public abstract partial class SharedHandsSystem : EntitySystem
var entity = hand.HeldEntity!.Value; var entity = hand.HeldEntity!.Value;
DoDrop(uid, hand, doDropInteraction: doDropInteraction, handsComp); DoDrop(uid, hand, doDropInteraction: doDropInteraction, handsComp);
var xform = Transform(uid); var userXform = Transform(uid);
var itemXform = Transform(entity);
var isInContainer = _containerSystem.IsEntityInContainer(uid);
if (targetDropLocation == null) if (targetDropLocation == null || isInContainer)
{ {
// If user is in a container, drop item into that container. Otherwise, attach to grid or map.\
// TODO recursively check upwards for containers // TODO recursively check upwards for containers
Transform(entity).AttachParentToContainerOrGrid(EntityManager);
if (!isInContainer
|| !_containerSystem.TryGetContainingContainer(userXform.ParentUid, uid, out var container, skipExistCheck: true)
|| !container.Insert(entity, EntityManager, itemXform))
itemXform.AttachToGridOrMap();
return true; return true;
} }
var target = targetDropLocation.Value.ToMap(EntityManager); var target = targetDropLocation.Value.ToMap(EntityManager);
Transform(entity).WorldPosition = GetFinalDropCoordinates(uid, xform.MapPosition, target); itemXform.WorldPosition = GetFinalDropCoordinates(uid, userXform.MapPosition, target);
return true; return true;
} }

View File

@@ -1,6 +1,7 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Content.Shared.ActionBlocker; using Content.Shared.ActionBlocker;
using Content.Shared.Clothing.Components; using Content.Shared.Clothing.Components;
using Content.Shared.Hands;
using Content.Shared.Hands.Components; using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems; using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction; using Content.Shared.Interaction;
@@ -144,8 +145,16 @@ public abstract partial class InventorySystem
return; return;
} }
if (_handsSystem.CanDropHeld(actor, hands.ActiveHand!, checkActionBlocker: false)) if (!_handsSystem.CanDropHeld(actor, hands.ActiveHand!, checkActionBlocker: false))
TryEquip(actor, actor, held.Value, ev.Slot, predicted: true, inventory: inventory); return;
var gotUnequipped = new GotUnequippedHandEvent(actor, held.Value, hands.ActiveHand!);
var didUnequip = new DidUnequipHandEvent(actor, held.Value, hands.ActiveHand!);
RaiseLocalEvent(held.Value, gotUnequipped, false);
RaiseLocalEvent(actor, didUnequip);
RaiseLocalEvent(held.Value, new HandDeselectedEvent(actor), false);
TryEquip(actor, actor, held.Value, ev.Slot, predicted: true, inventory: inventory, force: true);
} }
public bool TryEquip(EntityUid uid, EntityUid itemUid, string slot, bool silent = false, bool force = false, bool predicted = false, public bool TryEquip(EntityUid uid, EntityUid itemUid, string slot, bool silent = false, bool force = false, bool predicted = false,