Refactor slip dropping to use throwing (#5476)

* Refactor slip dropping to use throwing

* Update Content.Server/Fluids/EntitySystems/SpillableSystem.cs

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* Uncringe

* Update Content.Server/Fluids/EntitySystems/SpillableSystem.cs

Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
This commit is contained in:
Clyybber
2021-11-24 00:38:39 +01:00
committed by GitHub
parent ee27c75224
commit 0e98c1c524
10 changed files with 113 additions and 121 deletions

View File

@@ -146,7 +146,7 @@ namespace Content.Shared.Hands.Components
private void RemoveHand(Hand hand)
{
DropHeldEntityToFloor(hand, intentionalDrop: false);
DropHeldEntityToFloor(hand);
hand.Container?.Shutdown();
Hands.Remove(hand);
@@ -306,34 +306,34 @@ namespace Content.Shared.Hands.Components
/// <summary>
/// Tries to drop the contents of the active hand to the target location.
/// </summary>
public bool TryDropActiveHand(EntityCoordinates targetDropLocation, bool doMobChecks = true, bool intentional = true)
public bool TryDropActiveHand(EntityCoordinates targetDropLocation, bool doMobChecks = true)
{
if (!TryGetActiveHand(out var hand))
return false;
return TryDropHeldEntity(hand, targetDropLocation, doMobChecks, intentional);
return TryDropHeldEntity(hand, targetDropLocation, doMobChecks);
}
/// <summary>
/// Tries to drop the contents of a hand to the target location.
/// </summary>
public bool TryDropHand(string handName, EntityCoordinates targetDropLocation, bool checkActionBlocker = true, bool intentional = true)
public bool TryDropHand(string handName, EntityCoordinates targetDropLocation, bool checkActionBlocker = true)
{
if (!TryGetHand(handName, out var hand))
return false;
return TryDropHeldEntity(hand, targetDropLocation, checkActionBlocker, intentional);
return TryDropHeldEntity(hand, targetDropLocation, checkActionBlocker);
}
/// <summary>
/// Tries to drop a held entity to the target location.
/// </summary>
public bool TryDropEntity(IEntity entity, EntityCoordinates coords, bool doMobChecks = true, bool intentional = true)
public bool TryDropEntity(IEntity entity, EntityCoordinates coords, bool doMobChecks = true)
{
if (!TryGetHandHoldingEntity(entity, out var hand))
return false;
return TryDropHeldEntity(hand, coords, doMobChecks, intentional);
return TryDropHeldEntity(hand, coords, doMobChecks);
}
/// <summary>
@@ -369,23 +369,23 @@ namespace Content.Shared.Hands.Components
/// <summary>
/// Tries to drop the contents of a hand directly under the player.
/// </summary>
public bool Drop(string handName, bool checkActionBlocker = true, bool intentionalDrop = true)
public bool Drop(string handName, bool checkActionBlocker = true)
{
if (!TryGetHand(handName, out var hand))
return false;
return TryDropHeldEntity(hand, Owner.Transform.Coordinates, checkActionBlocker, intentionalDrop);
return TryDropHeldEntity(hand, Owner.Transform.Coordinates, checkActionBlocker);
}
/// <summary>
/// Tries to drop a held entity directly under the player.
/// </summary>
public bool Drop(IEntity entity, bool checkActionBlocker = true, bool intentionalDrop = true)
public bool Drop(IEntity entity, bool checkActionBlocker = true)
{
if (!TryGetHandHoldingEntity(entity, out var hand))
return false;
return TryDropHeldEntity(hand, Owner.Transform.Coordinates, checkActionBlocker, intentionalDrop);
return TryDropHeldEntity(hand, Owner.Transform.Coordinates, checkActionBlocker);
}
/// <summary>
@@ -467,7 +467,7 @@ namespace Content.Shared.Hands.Components
/// <summary>
/// Drops a hands contents to the target location.
/// </summary>
public void DropHeldEntity(Hand hand, EntityCoordinates targetDropLocation, bool intentionalDrop = true)
public void DropHeldEntity(Hand hand, EntityCoordinates targetDropLocation)
{
var heldEntity = hand.HeldEntity;
@@ -476,7 +476,7 @@ namespace Content.Shared.Hands.Components
RemoveHeldEntityFromHand(hand);
EntitySystem.Get<SharedInteractionSystem>().DroppedInteraction(Owner, heldEntity, intentionalDrop);
EntitySystem.Get<SharedInteractionSystem>().DroppedInteraction(Owner, heldEntity);
heldEntity.Transform.WorldPosition = GetFinalDropCoordinates(targetDropLocation);
@@ -510,7 +510,7 @@ namespace Content.Shared.Hands.Components
/// <summary>
/// Tries to drop a hands contents to the target location.
/// </summary>
private bool TryDropHeldEntity(Hand hand, EntityCoordinates location, bool checkActionBlocker, bool intentionalDrop = true)
private bool TryDropHeldEntity(Hand hand, EntityCoordinates location, bool checkActionBlocker)
{
if (!CanRemoveHeldEntityFromHand(hand))
return false;
@@ -518,16 +518,16 @@ namespace Content.Shared.Hands.Components
if (checkActionBlocker && !PlayerCanDrop())
return false;
DropHeldEntity(hand, location, intentionalDrop);
DropHeldEntity(hand, location);
return true;
}
/// <summary>
/// Drops the contents of a hand directly under the player.
/// </summary>
private void DropHeldEntityToFloor(Hand hand, bool intentionalDrop = true)
private void DropHeldEntityToFloor(Hand hand)
{
DropHeldEntity(hand, Owner.Transform.Coordinates, intentionalDrop);
DropHeldEntity(hand, Owner.Transform.Coordinates);
}
private bool CanPutHeldEntityIntoContainer(Hand hand, IContainer targetContainer, bool checkActionBlocker)

View File

@@ -18,47 +18,6 @@ namespace Content.Shared.Hands
SubscribeAllEvent<RequestSetHandEvent>(HandleSetHand);
}
public void DropHandItems(IEntity entity, bool doMobChecks = true)
{
DropHandItems(entity.Uid, doMobChecks);
}
public void DropHandItems(EntityUid uid, bool doMobChecks = true, SharedHandsComponent? hands = null)
{
if (!Resolve(uid, ref hands))
return;
DropHandItems(hands, doMobChecks);
}
private void DropHandItems(SharedHandsComponent handsComponent, bool doMobChecks = true)
{
var msg = new DropHandItemsAttemptEvent();
var entity = handsComponent.Owner;
var uid = entity.Uid;
var eventBus = EntityManager.EventBus;
eventBus.RaiseLocalEvent(uid, msg);
if (msg.Cancelled)
return;
if (entity.TryGetContainerMan(out var containerManager))
{
var parentMsg = new ContainedEntityDropHandItemsAttemptEvent(uid);
eventBus.RaiseLocalEvent(containerManager.OwnerUid, parentMsg);
if (parentMsg.Cancelled)
return;
}
DropAllItemsInHands(entity, doMobChecks);
}
protected virtual void DropAllItemsInHands(IEntity entity, bool doMobChecks = true)
{
}
private static void HandleSetHand(RequestSetHandEvent msg, EntitySessionEventArgs eventArgs)
{
var entity = eventArgs.SenderSession.AttachedEntity;
@@ -78,18 +37,6 @@ namespace Content.Shared.Hands
}
}
public sealed class ContainedEntityDropHandItemsAttemptEvent : CancellableEntityEventArgs
{
public EntityUid EntityUid { get; }
public ContainedEntityDropHandItemsAttemptEvent(EntityUid uid)
{
EntityUid = uid;
}
}
public sealed class DropHandItemsAttemptEvent : CancellableEntityEventArgs {}
[Serializable, NetSerializable]
public class RequestSetHandEvent : EntityEventArgs
{

View File

@@ -17,15 +17,12 @@ namespace Content.Shared.Interaction
public class DroppedEventArgs : EventArgs
{
public DroppedEventArgs(IEntity user, bool intentional)
public DroppedEventArgs(IEntity user)
{
User = user;
Intentional = intentional;
}
public IEntity User { get; }
public bool Intentional { get; }
}
/// <summary>
@@ -44,16 +41,10 @@ namespace Content.Shared.Interaction
/// </summary>
public EntityUid DroppedUid { get; }
/// <summary>
/// If the item was dropped intentionally.
/// </summary>
public bool Intentional { get; }
public DroppedEvent(EntityUid user, EntityUid dropped, bool intentional)
public DroppedEvent(EntityUid user, EntityUid dropped)
{
UserUid = user;
DroppedUid = dropped;
Intentional = intentional;
}
}
}

View File

@@ -658,11 +658,11 @@ namespace Content.Shared.Interaction
/// Activates the Dropped behavior of an object
/// Verifies that the user is capable of doing the drop interaction first
/// </summary>
public bool TryDroppedInteraction(IEntity user, IEntity item, bool intentional)
public bool TryDroppedInteraction(IEntity user, IEntity item)
{
if (user == null || item == null || !_actionBlockerSystem.CanDrop(user.Uid)) return false;
DroppedInteraction(user, item, intentional);
DroppedInteraction(user, item);
return true;
}
@@ -670,21 +670,21 @@ namespace Content.Shared.Interaction
/// Calls Dropped on all components that implement the IDropped interface
/// on an entity that has been dropped.
/// </summary>
public void DroppedInteraction(IEntity user, IEntity item, bool intentional)
public void DroppedInteraction(IEntity user, IEntity item)
{
var dropMsg = new DroppedEvent(user.Uid, item.Uid, intentional);
var dropMsg = new DroppedEvent(user.Uid, item.Uid);
RaiseLocalEvent(item.Uid, dropMsg);
if (dropMsg.Handled)
return;
item.Transform.LocalRotation = intentional ? Angle.Zero : (_random.Next(0, 100) / 100f) * MathHelper.TwoPi;
item.Transform.LocalRotation = Angle.Zero;
var comps = item.GetAllComponents<IDropped>().ToList();
// Call Land on all components that implement the interface
foreach (var comp in comps)
{
comp.Dropped(new DroppedEventArgs(user, intentional));
comp.Dropped(new DroppedEventArgs(user));
}
}
#endregion

View File

@@ -43,7 +43,7 @@ namespace Content.Shared.Standing
// and ultimately this is just to avoid boilerplate in Down callers + keep their behavior consistent.
if (dropHeldItems && hands != null)
{
_sharedHandsSystem.DropHandItems(uid, false, hands);
RaiseLocalEvent(uid, new DropHandItemsEvent(), false);
}
var msg = new DownAttemptEvent();
@@ -97,6 +97,10 @@ namespace Content.Shared.Standing
}
}
public sealed class DropHandItemsEvent : EventArgs
{
}
/// <summary>
/// Subscribe if you can potentially block a down attempt.
/// </summary>