Spill hand contents when dropping them in a fall (#3304)

* Spill hand contents when dropping them due to falling down

* Better approach

* cleanup

* grammar

* stupid
This commit is contained in:
Clyybber
2021-02-18 21:43:46 +01:00
committed by GitHub
parent 3766410178
commit c996021b5d
6 changed files with 50 additions and 33 deletions

View File

@@ -3,13 +3,14 @@ using Content.Shared.GameObjects.Components.Chemistry;
using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
using Content.Shared.GameObjects.Verbs;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
namespace Content.Server.GameObjects.Components.Fluids
{
[RegisterComponent]
public class SpillableComponent : Component
public class SpillableComponent : Component, IDropped
{
public override string Name => "Spillable";
@@ -51,10 +52,16 @@ namespace Content.Server.GameObjects.Components.Fluids
}
// Need this as when we split the component's owner may be deleted
var entityLocation = component.Owner.Transform.Coordinates;
var solution = solutionComponent.Drain(solutionComponent.DrainAvailable);
solution.SpillAt(entityLocation, "PuddleSmear");
}
solutionComponent.Drain(solutionComponent.DrainAvailable).SpillAt(component.Owner.Transform.Coordinates, "PuddleSmear");
}
}
}
void IDropped.Dropped(DroppedEventArgs eventArgs)
{
if (!eventArgs.Intentional && Owner.TryGetComponent(out ISolutionInteractionsComponent solutionComponent))
{
solutionComponent.Drain(solutionComponent.DrainAvailable).SpillAt(Owner.Transform.Coordinates, "PuddleSmear");
}
}
}

View File

@@ -252,18 +252,19 @@ namespace Content.Server.GameObjects.Components.GUI
/// </summary>
/// <param name="item">The itemcomponent of the item to be dropped</param>
/// <param name="doMobChecks">Check if the item can be dropped</param>
/// <param name="intentional">If the item was dropped intentionally</param>
/// <returns>True if IDropped.Dropped was called, otherwise false</returns>
private bool DroppedInteraction(ItemComponent item, bool doMobChecks)
private bool DroppedInteraction(ItemComponent item, bool doMobChecks, bool intentional)
{
var interactionSystem = _entitySystemManager.GetEntitySystem<InteractionSystem>();
if (doMobChecks)
{
if (!interactionSystem.TryDroppedInteraction(Owner, item.Owner))
if (!interactionSystem.TryDroppedInteraction(Owner, item.Owner, intentional))
return false;
}
else
{
interactionSystem.DroppedInteraction(Owner, item.Owner);
interactionSystem.DroppedInteraction(Owner, item.Owner, intentional);
}
return true;
}
@@ -284,7 +285,7 @@ namespace Content.Server.GameObjects.Components.GUI
return false;
}
public bool Drop(string slot, EntityCoordinates coords, bool doMobChecks = true, bool doDropInteraction = true)
public bool Drop(string slot, EntityCoordinates coords, bool doMobChecks = true, bool doDropInteraction = true, bool intentional = true)
{
var hand = GetHand(slot);
if (!CanDrop(slot, doMobChecks) || hand?.Entity == null)
@@ -302,7 +303,7 @@ namespace Content.Server.GameObjects.Components.GUI
_entitySystemManager.GetEntitySystem<InteractionSystem>().UnequippedHandInteraction(Owner, item.Owner,
ToSharedHand(hand));
if (doDropInteraction && !DroppedInteraction(item, false))
if (doDropInteraction && !DroppedInteraction(item, false, intentional))
return false;
item.RemovedFromSlot();
@@ -325,7 +326,7 @@ namespace Content.Server.GameObjects.Components.GUI
}
public bool Drop(string slot, BaseContainer targetContainer, bool doMobChecks = true, bool doDropInteraction = true)
public bool Drop(string slot, BaseContainer targetContainer, bool doMobChecks = true, bool doDropInteraction = true, bool intentional = true)
{
if (slot == null)
{
@@ -363,7 +364,7 @@ namespace Content.Server.GameObjects.Components.GUI
_entitySystemManager.GetEntitySystem<InteractionSystem>().UnequippedHandInteraction(Owner, item.Owner,
ToSharedHand(hand));
if (doDropInteraction && !DroppedInteraction(item, doMobChecks))
if (doDropInteraction && !DroppedInteraction(item, doMobChecks, intentional))
return false;
item.RemovedFromSlot();
@@ -379,7 +380,7 @@ namespace Content.Server.GameObjects.Components.GUI
return true;
}
public bool Drop(IEntity entity, EntityCoordinates coords, bool doMobChecks = true, bool doDropInteraction = true)
public bool Drop(IEntity entity, EntityCoordinates coords, bool doMobChecks = true, bool doDropInteraction = true, bool intentional = true)
{
if (entity == null)
{
@@ -391,15 +392,15 @@ namespace Content.Server.GameObjects.Components.GUI
throw new ArgumentException("Entity must be held in one of our hands.", nameof(entity));
}
return Drop(slot, coords, doMobChecks, doDropInteraction);
return Drop(slot, coords, doMobChecks, doDropInteraction, intentional);
}
public bool Drop(string slot, bool mobChecks = true, bool doDropInteraction = true)
public bool Drop(string slot, bool mobChecks = true, bool doDropInteraction = true, bool intentional = true)
{
return Drop(slot, Owner.Transform.Coordinates, mobChecks, doDropInteraction);
return Drop(slot, Owner.Transform.Coordinates, mobChecks, doDropInteraction, intentional);
}
public bool Drop(IEntity entity, bool mobChecks = true, bool doDropInteraction = true)
public bool Drop(IEntity entity, bool mobChecks = true, bool doDropInteraction = true, bool intentional = true)
{
if (entity == null)
{
@@ -411,10 +412,10 @@ namespace Content.Server.GameObjects.Components.GUI
throw new ArgumentException("Entity must be held in one of our hands.", nameof(entity));
}
return Drop(slot, Owner.Transform.Coordinates, mobChecks, doDropInteraction);
return Drop(slot, Owner.Transform.Coordinates, mobChecks, doDropInteraction, intentional);
}
public bool Drop(IEntity entity, BaseContainer targetContainer, bool doMobChecks = true, bool doDropInteraction = true)
public bool Drop(IEntity entity, BaseContainer targetContainer, bool doMobChecks = true, bool doDropInteraction = true, bool intentional = true)
{
if (entity == null)
{
@@ -426,7 +427,7 @@ namespace Content.Server.GameObjects.Components.GUI
throw new ArgumentException("Entity must be held in one of our hands.", nameof(entity));
}
return Drop(slot, targetContainer, doMobChecks, doDropInteraction);
return Drop(slot, targetContainer, doMobChecks, doDropInteraction, intentional);
}
/// <summary>

View File

@@ -716,11 +716,11 @@ namespace Content.Server.GameObjects.EntitySystems.Click
/// 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)
public bool TryDroppedInteraction(IEntity user, IEntity item, bool intentional)
{
if (user == null || item == null || !ActionBlockerSystem.CanDrop(user)) return false;
DroppedInteraction(user, item);
DroppedInteraction(user, item, intentional);
return true;
}
@@ -728,9 +728,9 @@ namespace Content.Server.GameObjects.EntitySystems.Click
/// 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)
public void DroppedInteraction(IEntity user, IEntity item, bool intentional)
{
var dropMsg = new DroppedMessage(user, item);
var dropMsg = new DroppedMessage(user, item, intentional);
RaiseLocalEvent(dropMsg);
if (dropMsg.Handled)
{
@@ -742,7 +742,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
// Call Land on all components that implement the interface
foreach (var comp in comps)
{
comp.Dropped(new DroppedEventArgs(user));
comp.Dropped(new DroppedEventArgs(user, intentional));
}
}

View File

@@ -57,7 +57,7 @@ namespace Content.Server.GameObjects.EntitySystems
foreach (var heldItem in hands.GetAllHeldItems())
{
hands.Drop(heldItem.Owner, doMobChecks);
hands.Drop(heldItem.Owner, doMobChecks, intentional:false);
}
}

View File

@@ -110,7 +110,7 @@ namespace Content.Server.Interfaces.GameObjects.Components.Items
/// <param name="mobChecks">Whether to check the <see cref="ActionBlockerSystem.CanDrop()"/> for the mob or not.</param>
/// <param name="doDropInteraction">Whether to perform Dropped interactions.</param>
/// <returns>True on success, false if something blocked the drop.</returns>
bool Drop(string slot, bool mobChecks = true, bool doDropInteraction = true);
bool Drop(string slot, bool mobChecks = true, bool doDropInteraction = true, bool intentional = true);
/// <summary>
/// Drops an item held by one of our hand slots to the same position as our owning entity.
@@ -125,7 +125,7 @@ namespace Content.Server.Interfaces.GameObjects.Components.Items
/// <exception cref="ArgumentException">
/// Thrown if <see cref="entity"/> is not actually held in any hand.
/// </exception>
bool Drop(IEntity entity, bool mobChecks = true, bool doDropInteraction = true);
bool Drop(IEntity entity, bool mobChecks = true, bool doDropInteraction = true, bool intentional = true);
/// <summary>
/// Drops the item in a slot.
@@ -135,7 +135,7 @@ namespace Content.Server.Interfaces.GameObjects.Components.Items
/// <param name="doMobChecks">Whether to check the <see cref="ActionBlockerSystem.CanDrop()"/> for the mob or not.</param>
/// <param name="doDropInteraction">Whether to perform Dropped interactions.</param>
/// <returns>True if an item was dropped, false otherwise.</returns>
bool Drop(string slot, EntityCoordinates coords, bool doMobChecks = true, bool doDropInteraction = true);
bool Drop(string slot, EntityCoordinates coords, bool doMobChecks = true, bool doDropInteraction = true, bool intentional = true);
/// <summary>
/// Drop the specified entity in our hands to a certain position.
@@ -158,7 +158,7 @@ namespace Content.Server.Interfaces.GameObjects.Components.Items
/// <exception cref="ArgumentException">
/// Thrown if <see cref="entity"/> is not actually held in any hand.
/// </exception>
bool Drop(IEntity entity, EntityCoordinates coords, bool doMobChecks = true, bool doDropInteraction = true);
bool Drop(IEntity entity, EntityCoordinates coords, bool doMobChecks = true, bool doDropInteraction = true, bool intentional = true);
/// <summary>
/// Drop the item contained in a slot into another container.
@@ -173,7 +173,7 @@ namespace Content.Server.Interfaces.GameObjects.Components.Items
/// but practical remove or insert returned false anyways.
/// This is an edge-case that is currently unhandled.
/// </exception>
bool Drop(string slot, BaseContainer targetContainer, bool doMobChecks = true, bool doDropInteraction = true);
bool Drop(string slot, BaseContainer targetContainer, bool doMobChecks = true, bool doDropInteraction = true, bool intentional = true);
/// <summary>
/// Drops an item in one of the hands into a container.
@@ -194,7 +194,7 @@ namespace Content.Server.Interfaces.GameObjects.Components.Items
/// <exception cref="ArgumentException">
/// Thrown if <see cref="entity"/> is not actually held in any hand.
/// </exception>
bool Drop(IEntity entity, BaseContainer targetContainer, bool doMobChecks = true, bool doDropInteraction = true);
bool Drop(IEntity entity, BaseContainer targetContainer, bool doMobChecks = true, bool doDropInteraction = true, bool intentional = true);
/// <summary>
/// Checks whether the item in the specified hand can be dropped.

View File

@@ -16,12 +16,15 @@ namespace Content.Shared.Interfaces.GameObjects.Components
public class DroppedEventArgs : EventArgs
{
public DroppedEventArgs(IEntity user)
public DroppedEventArgs(IEntity user, bool intentional)
{
User = user;
Intentional = intentional;
}
public IEntity User { get; }
public bool Intentional { get; }
}
/// <summary>
@@ -45,10 +48,16 @@ namespace Content.Shared.Interfaces.GameObjects.Components
/// </summary>
public IEntity Dropped { get; }
public DroppedMessage(IEntity user, IEntity dropped)
/// <summary>
/// If the item was dropped intentionally.
/// </summary>
public bool Intentional { get; }
public DroppedMessage(IEntity user, IEntity dropped, bool intentional)
{
User = user;
Dropped = dropped;
Intentional = intentional;
}
}
}