ECS dragdrop (#12973)

* ECS dragdrop

No more excuses.

* AAAAAAAAAAAAAA

* kry

* events

* aaaaaaaaaa

* HUH

* Fix stripping

* aaaaaa

* spoike

* asease

* fix table vaulting

* ded

* rebiew

* aaaaaaaaaaaaa

* drag

* aeaeae

* weh
This commit is contained in:
metalgearsloth
2023-02-14 00:29:34 +11:00
committed by GitHub
parent 4183b5f449
commit c8f89eca60
53 changed files with 936 additions and 1079 deletions

View File

@@ -1,6 +1,7 @@
using Content.Shared.Body.Events;
using Content.Shared.DragDrop;
using Content.Shared.Emoting;
using Content.Shared.Hands;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Item;
@@ -115,7 +116,7 @@ namespace Content.Shared.ActionBlocker
public bool CanDrop(EntityUid uid)
{
var ev = new DropAttemptEvent(uid);
var ev = new DropAttemptEvent();
RaiseLocalEvent(uid, ev);
return !ev.Cancelled;

View File

@@ -1,7 +1,6 @@
using Content.Shared.Body.Part;
using Content.Shared.Body.Prototypes;
using Content.Shared.Body.Systems;
using Content.Shared.DragDrop;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
@@ -10,7 +9,7 @@ namespace Content.Shared.Body.Components;
[RegisterComponent, NetworkedComponent]
[Access(typeof(SharedBodySystem))]
public sealed class BodyComponent : Component, IDraggable
public sealed class BodyComponent : Component
{
[DataField("prototype", customTypeSerializer: typeof(PrototypeIdSerializer<BodyPrototype>))]
public readonly string? Prototype;
@@ -27,14 +26,4 @@ public sealed class BodyComponent : Component, IDraggable
/// </summary>
[DataField("requiredLegs")]
public int RequiredLegs;
bool IDraggable.CanStartDrag(StartDragDropEvent args)
{
return true;
}
bool IDraggable.CanDrop(CanDropEvent args)
{
return true;
}
}

View File

@@ -5,6 +5,7 @@ using Content.Shared.Body.Organ;
using Content.Shared.Body.Part;
using Content.Shared.Body.Prototypes;
using Content.Shared.Coordinates;
using Content.Shared.DragDrop;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
@@ -18,6 +19,12 @@ public partial class SharedBodySystem
SubscribeLocalEvent<BodyComponent, ComponentGetState>(OnBodyGetState);
SubscribeLocalEvent<BodyComponent, ComponentHandleState>(OnBodyHandleState);
SubscribeLocalEvent<BodyComponent, CanDragEvent>(OnBodyCanDrag);
}
private void OnBodyCanDrag(EntityUid uid, BodyComponent component, ref CanDragEvent args)
{
args.Handled = true;
}
private void OnBodyInit(EntityUid bodyId, BodyComponent body, ComponentInit args)

View File

@@ -13,7 +13,7 @@ public abstract partial class SharedBuckleSystem
{
SubscribeLocalEvent<StrapComponent, MoveEvent>(OnStrapRotate);
SubscribeLocalEvent<StrapComponent, ComponentHandleState>(OnStrapHandleState);
SubscribeLocalEvent<StrapComponent, CanDragDropOnEvent>(OnStrapCanDragDropOn);
SubscribeLocalEvent<StrapComponent, CanDropTargetEvent>(OnStrapCanDropOn);
}
private void OnStrapHandleState(EntityUid uid, StrapComponent component, ref ComponentHandleState args)
@@ -85,9 +85,9 @@ public abstract partial class SharedBuckleSystem
return _interactions.InRangeUnobstructed(target, buckleId, buckle.Range, predicate: Ignored);
}
private void OnStrapCanDragDropOn(EntityUid uid, StrapComponent strap, CanDragDropOnEvent args)
private void OnStrapCanDropOn(EntityUid uid, StrapComponent strap, ref CanDropTargetEvent args)
{
args.CanDrop = StrapCanDragDropOn(args.Target, args.User, args.Target, args.Dragged, strap);
args.CanDrop = StrapCanDragDropOn(uid, args.User, uid, args.Dragged, strap);
args.Handled = true;
}
}

View File

@@ -22,7 +22,7 @@ public sealed class BonkSystem : EntitySystem
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BonkableComponent, DragDropEvent>(OnDragDrop);
SubscribeLocalEvent<BonkableComponent, DragDropTargetEvent>(OnDragDrop);
}
public bool TryBonk(EntityUid user, EntityUid bonkableUid, BonkableComponent? bonkableComponent = null)
@@ -56,8 +56,8 @@ public sealed class BonkSystem : EntitySystem
return false;
}
private void OnDragDrop(EntityUid user, BonkableComponent bonkableComponent, DragDropEvent args)
private void OnDragDrop(EntityUid uid, BonkableComponent bonkableComponent, ref DragDropTargetEvent args)
{
TryBonk(args.Dragged, args.Target);
TryBonk(args.Dragged, uid);
}
}

View File

@@ -1,5 +1,4 @@
using Content.Shared.DragDrop;
using Content.Shared.Movement;
using Content.Shared.Movement.Events;
namespace Content.Shared.Climbing;
@@ -10,7 +9,6 @@ public abstract class SharedClimbSystem : EntitySystem
{
base.Initialize();
SubscribeLocalEvent<ClimbingComponent, UpdateCanMoveEvent>(HandleMoveAttempt);
SubscribeLocalEvent<ClimbableComponent, CanDragDropOnEvent>(OnCanDragDropOn);
}
private static void HandleMoveAttempt(EntityUid uid, ClimbingComponent component, UpdateCanMoveEvent args)
@@ -22,7 +20,7 @@ public abstract class SharedClimbSystem : EntitySystem
args.Cancel();
}
protected virtual void OnCanDragDropOn(EntityUid uid, ClimbableComponent component, CanDragDropOnEvent args)
protected virtual void OnCanDragDropOn(EntityUid uid, ClimbableComponent component, ref CanDropTargetEvent args)
{
args.CanDrop = HasComp<ClimbingComponent>(args.Dragged);
}

View File

@@ -2,6 +2,7 @@ using Content.Shared.ActionBlocker;
using Content.Shared.Alert;
using Content.Shared.Cuffs.Components;
using Content.Shared.DragDrop;
using Content.Shared.Hands;
using Content.Shared.Hands.Components;
using Content.Shared.Interaction.Events;
using Content.Shared.Inventory.Events;

View File

@@ -27,7 +27,7 @@ namespace Content.Shared.Disposal
{
base.Initialize();
SubscribeLocalEvent<SharedDisposalUnitComponent, PreventCollideEvent>(OnPreventCollide);
SubscribeLocalEvent<SharedDisposalUnitComponent, CanDragDropOnEvent>(OnCanDragDropOn);
SubscribeLocalEvent<SharedDisposalUnitComponent, CanDropTargetEvent>(OnCanDragDropOn);
}
private void OnPreventCollide(EntityUid uid, SharedDisposalUnitComponent component, ref PreventCollideEvent args)
@@ -48,9 +48,10 @@ namespace Content.Shared.Disposal
}
}
private void OnCanDragDropOn(EntityUid uid, SharedDisposalUnitComponent component, CanDragDropOnEvent args)
private void OnCanDragDropOn(EntityUid uid, SharedDisposalUnitComponent component, ref CanDropTargetEvent args)
{
if (args.Handled) return;
if (args.Handled)
return;
args.CanDrop = CanInsert(component, args.Dragged);
args.Handled = true;

View File

@@ -1,36 +0,0 @@
namespace Content.Shared.DragDrop;
/// <summary>
/// Event that gets send to the target of a drag drop action
/// Mark this event as handled to specify that the entity can be dropped on
/// and set CanDrop to true or false, depending on whether dropping the entity onto the target is actually possible.
/// </summary>
public sealed class CanDragDropOnEvent : HandledEntityEventArgs
{
/// <summary>
/// Entity doing the drag and drop.
/// </summary>
public EntityUid User { get; }
/// <summary>
/// Entity that is being dragged.
/// </summary>
public EntityUid Dragged { get; }
/// <summary>
/// Entity that is being dropped on.
/// </summary>
public EntityUid Target { get; }
/// <summary>
/// If the dragged entity can be dropped on the target.
/// </summary>
public bool CanDrop { get; set; } = false;
public CanDragDropOnEvent(EntityUid user, EntityUid dragged, EntityUid target)
{
User = user;
Dragged = dragged;
Target = target;
}
}

View File

@@ -1,33 +1,26 @@
using Robust.Shared.Map;
using Robust.Shared.Serialization;
namespace Content.Shared.DragDrop
{
/// <summary>
/// Requests a drag / drop interaction to be performed
/// Raised on the client to the server requesting a drag-drop.
/// </summary>
[Serializable, NetSerializable]
public sealed class DragDropRequestEvent : EntityEventArgs
{
/// <summary>
/// Location that the entity was dropped.
/// </summary>
public EntityCoordinates DropLocation { get; }
/// <summary>
/// Entity that was dragged and dropped.
/// </summary>
public EntityUid Dropped { get; }
public EntityUid Dragged { get; }
/// <summary>
/// Entity that was drag dropped on.
/// </summary>
public EntityUid Target { get; }
public DragDropRequestEvent(EntityCoordinates dropLocation, EntityUid dropped, EntityUid target)
public DragDropRequestEvent(EntityUid dragged, EntityUid target)
{
DropLocation = dropLocation;
Dropped = dropped;
Dragged = dragged;
Target = target;
}
}

View File

@@ -0,0 +1,67 @@
namespace Content.Shared.DragDrop;
/// <summary>
/// Raised directed on an entity when attempting to start a drag.
/// </summary>
[ByRefEvent]
public record struct CanDragEvent
{
/// <summary>
/// False if we are unable to drag this entity.
/// </summary>
public bool Handled;
}
/// <summary>
/// Raised directed on a dragged entity to indicate whether it has interactions with the target entity.
/// </summary>
[ByRefEvent]
public record struct CanDropDraggedEvent(EntityUid User, EntityUid Target)
{
public readonly EntityUid User = User;
public readonly EntityUid Target = Target;
public bool Handled = false;
/// <summary>
/// Can we drop the entity onto the target? If the event is not handled then there is no supported interactions.
/// </summary>
public bool CanDrop = false;
}
/// <summary>
/// Raised directed on the target entity to indicate whether it has interactions with the dragged entity.
/// </summary>
[ByRefEvent]
public record struct CanDropTargetEvent(EntityUid User, EntityUid Dragged)
{
public readonly EntityUid User = User;
public readonly EntityUid Dragged = Dragged;
public bool Handled = false;
/// <summary>
/// <see cref="CanDropDraggedEvent"/>
/// </summary>
public bool CanDrop = false;
}
/// <summary>
/// Raised directed on a dragged entity when it is dropped on a target entity.
/// </summary>
[ByRefEvent]
public record struct DragDropDraggedEvent(EntityUid User, EntityUid Target)
{
public readonly EntityUid User = User;
public readonly EntityUid Target = Target;
public bool Handled = false;
}
/// <summary>
/// Raised directed on the target entity when a dragged entity is dragged onto it.
/// </summary>
[ByRefEvent]
public record struct DragDropTargetEvent(EntityUid User, EntityUid Dragged)
{
public readonly EntityUid User = User;
public readonly EntityUid Dragged = Dragged;
public bool Handled = false;
}

View File

@@ -1,12 +0,0 @@
namespace Content.Shared.DragDrop
{
public sealed class DropAttemptEvent : CancellableEntityEventArgs
{
public DropAttemptEvent(EntityUid uid)
{
Uid = uid;
}
public EntityUid Uid { get; }
}
}

View File

@@ -1,32 +0,0 @@
namespace Content.Shared.DragDrop
{
/// <summary>
/// This interface allows the component's entity to be dragged and dropped
/// onto by another entity and gives it behavior when that occurs.
/// </summary>
[RequiresExplicitImplementation]
public interface IDragDropOn
{
/// <summary>
/// Invoked when another entity is being dragged and dropped
/// onto this one before invoking <see cref="DragDropOn"/>.
/// Note that other drag and drop interactions may be attempted if
/// this one fails.
/// </summary>
/// <param name="eventArgs"></param>
/// <returns>true if <see cref="eventArgs"/> is valid, false otherwise.</returns>
bool CanDragDropOn(DragDropEvent eventArgs);
/// <summary>
/// Invoked server-side when another entity is being dragged and dropped
/// onto this one before invoking <see cref="DragDropOn"/>
/// Note that other drag and drop interactions may be attempted if
/// this one fails.
/// </summary>
/// <returns>
/// true if an interaction occurred and no further interaction should
/// be processed for this drop.
/// </returns>
bool DragDropOn(DragDropEvent eventArgs);
}
}

View File

@@ -1,124 +0,0 @@
using Robust.Shared.Map;
namespace Content.Shared.DragDrop
{
/// <summary>
/// This interface allows a local client to initiate dragging of the component's
/// entity by mouse, for drag and drop interactions.
/// </summary>
[RequiresExplicitImplementation]
public interface IDraggable
{
/// <summary>
/// Invoked when an user is attempting to initiate a drag with
/// this component's entity in range. It's fine to return true even if there
/// wouldn't be any valid targets - just return true if this entity is in a
/// "draggable" state.
/// </summary>
/// <param name="args">
/// The information about the drag, such as who is doing it.
/// </param>
/// <returns>True if the drag should be initiated, false otherwise.</returns>
bool CanStartDrag(StartDragDropEvent args)
{
return true;
}
/// <summary>
/// Invoked on entities visible to the user to check if this component's
/// entity can be dropped on the indicated target entity.
/// No need to check range / reachability in here.
/// Returning true will cause the target entity to be highlighted as
/// a potential target and allow dropping when in range.
/// </summary>
/// <returns>
/// True if target is a valid target to be dropped on by this component's
/// entity, false otherwise.
/// </returns>
bool CanDrop(CanDropEvent args);
/// <summary>
/// Invoked when this component's entity is being dropped on another.
/// Other drag and drop interactions may be attempted if this one fails.
/// </summary>
/// <param name="args">
/// The information about the drag, such as who is doing it.
/// </param>
/// <returns>
/// True if an interaction occurred and no further interaction should
/// be processed for this drop, false otherwise.
/// </returns>
bool Drop(DragDropEvent args)
{
return false;
}
}
[Virtual]
public class StartDragDropEvent : HandledEntityEventArgs
{
/// <summary>
/// Entity doing the drag and drop.
/// </summary>
public EntityUid User { get; }
/// <summary>
/// Entity that is being dragged.
/// </summary>
public EntityUid Dragged { get; }
/// <summary>
/// Creates a new instance of <see cref="StartDragDropEvent"/>.
/// </summary>
/// <param name="user">The entity doing the drag and drop.</param>
/// <param name="dragged">The entity that is being dragged and dropped.</param>
public StartDragDropEvent(EntityUid user, EntityUid dragged)
{
User = user;
Dragged = dragged;
}
}
[Virtual]
public class CanDropEvent : StartDragDropEvent
{
/// <summary>
/// The entity uid that <see cref="StartDragDropEvent.Dragged"/>
/// is being dropped onto.
/// </summary>
public EntityUid Target { get; }
/// <summary>
/// Creates a new instance of <see cref="CanDropEvent"/>.
/// </summary>
/// <param name="user">The entity doing the drag and drop.</param>
/// <param name="dragged">The entity that is being dragged and dropped.</param>
/// <param name="target">The entity that <see cref="dragged"/> is being dropped onto.</param>
public CanDropEvent(EntityUid user, EntityUid dragged, EntityUid target) : base(user, dragged)
{
Target = target;
}
}
[Virtual]
public class DragDropEvent : CanDropEvent
{
/// <summary>
/// The location where <see cref="StartDragDropEvent.Dragged"/>
/// is being dropped.
/// </summary>
public EntityCoordinates DropLocation { get; }
/// <summary>
/// Creates a new instance of <see cref="DragDropEvent"/>.
/// </summary>
/// <param name="user">The entity doing the drag and drop.</param>
/// <param name="dropLocation">The location where <see cref="dropped"/> is being dropped.</param>
/// <param name="dragged">The entity that is being dragged and dropped.</param>
/// <param name="target">The entity that <see cref="dropped"/> is being dropped onto.</param>
public DragDropEvent(EntityUid user, EntityCoordinates dropLocation, EntityUid dragged, EntityUid target) : base(user, dragged, target)
{
DropLocation = dropLocation;
}
}
}

View File

@@ -2,12 +2,5 @@
public abstract class SharedDragDropSystem : EntitySystem
{
protected bool? CheckDragDropOn(DragDropEvent eventArgs)
{
var canDragDropOnEvent = new CanDragDropOnEvent(eventArgs.User, eventArgs.Dragged, eventArgs.Target);
RaiseLocalEvent(eventArgs.Target, canDragDropOnEvent, false);
return canDragDropOnEvent.Handled ? canDragDropOnEvent.CanDrop : null;
}
}

View File

@@ -1,5 +1,6 @@
using Content.Shared.DragDrop;
using Content.Shared.Emoting;
using Content.Shared.Hands;
using Content.Shared.Interaction.Events;
using Content.Shared.Item;
using Robust.Shared.Serialization;
@@ -56,7 +57,7 @@ namespace Content.Shared.Ghost
DisplayName = displayName;
IsWarpPoint = isWarpPoint;
}
/// <summary>
/// The entity representing the warp point.
/// This is passed back to the server in <see cref="GhostWarpToTargetRequestEvent"/>

View File

@@ -7,6 +7,14 @@ using static Robust.Shared.GameObjects.SharedSpriteComponent;
namespace Content.Shared.Hands
{
/// <summary>
/// Raised directed on an entity when attempting to drop its hand items.
/// </summary>
public sealed class DropAttemptEvent : CancellableEntityEventArgs
{
public readonly EntityUid Uid;
}
/// <summary>
/// Raised directed at an item that needs to update its in-hand sprites/layers.
/// </summary>

View File

@@ -243,8 +243,8 @@ public abstract partial class InventorySystem
// that requires server/client specific code.
// Uhhh TODO, fix this. This doesn't even fucking check if the target item is IN the targets inventory.
return actor != target &&
HasComp<SharedStrippableComponent>(target) &&
HasComp<SharedStrippingComponent>(actor) &&
HasComp<StrippableComponent>(target) &&
HasComp<StrippingComponent>(actor) &&
HasComp<SharedHandsComponent>(actor);
}

View File

@@ -1,11 +1,11 @@
using Content.Shared.DragDrop;
using Content.Shared.Nutrition.Components;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Kitchen.Components
{
public abstract class SharedKitchenSpikeComponent : Component, IDragDropOn
[NetworkedComponent]
public abstract class SharedKitchenSpikeComponent : Component
{
[DataField("delay")]
public float SpikeDelay = 7.0f;
@@ -14,19 +14,6 @@ namespace Content.Shared.Kitchen.Components
[DataField("sound")]
public SoundSpecifier SpikeSound = new SoundPathSpecifier("/Audio/Effects/Fluids/splat.ogg");
bool IDragDropOn.CanDragDropOn(DragDropEvent eventArgs)
{
if (!IoCManager.Resolve<IEntityManager>().HasComponent<SharedButcherableComponent>(eventArgs.Dragged))
{
return false;
}
// TODO: Once we get silicons need to check organic
return true;
}
public abstract bool DragDropOn(DragDropEvent eventArgs);
[Serializable, NetSerializable]
public enum KitchenSpikeVisuals : byte
{

View File

@@ -0,0 +1,31 @@
using Content.Shared.DragDrop;
using Content.Shared.Kitchen.Components;
using Content.Shared.Nutrition.Components;
namespace Content.Shared.Kitchen;
public abstract class SharedKitchenSpikeSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SharedKitchenSpikeComponent, CanDropTargetEvent>(OnCanDrop);
}
private void OnCanDrop(EntityUid uid, SharedKitchenSpikeComponent component, ref CanDropTargetEvent args)
{
if (args.Handled)
return;
args.Handled = true;
if (!HasComp<ButcherableComponent>(args.Dragged))
{
args.CanDrop = false;
return;
}
// TODO: Once we get silicons need to check organic
args.CanDrop = true;
}
}

View File

@@ -9,7 +9,7 @@ using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Shared.Medical.Cryogenics;
[NetworkedComponent]
public abstract class SharedCryoPodComponent: Component, IDragDropOn
public abstract class SharedCryoPodComponent: Component
{
/// <summary>
/// Specifies the name of the atmospherics port to draw gas from.
@@ -87,19 +87,4 @@ public abstract class SharedCryoPodComponent: Component, IDragDropOn
ContainsEntity,
IsOn
}
public bool CanInsert(EntityUid entity)
{
return IoCManager.Resolve<IEntityManager>().HasComponent<BodyComponent>(entity);
}
bool IDragDropOn.CanDragDropOn(DragDropEvent eventArgs)
{
return CanInsert(eventArgs.Dragged);
}
bool IDragDropOn.DragDropOn(DragDropEvent eventArgs)
{
return false;
}
}

View File

@@ -1,4 +1,6 @@
using Content.Server.Medical.Components;
using Content.Shared.Body.Components;
using Content.Shared.DragDrop;
using Content.Shared.Emag.Systems;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
@@ -26,6 +28,12 @@ public abstract partial class SharedCryoPodSystem: EntitySystem
InitializeInsideCryoPod();
}
protected void OnCryoPodCanDropOn(EntityUid uid, SharedCryoPodComponent component, ref CanDropTargetEvent args)
{
args.CanDrop = args.CanDrop && HasComp<BodyComponent>(args.Dragged);
args.Handled = true;
}
protected void OnComponentInit(EntityUid uid, SharedCryoPodComponent cryoPodComponent, ComponentInit args)
{
cryoPodComponent.BodyContainer = _containerSystem.EnsureContainer<ContainerSlot>(uid, "scanner-body");

View File

@@ -1,19 +1,18 @@
using Content.Shared.Body.Components;
using Content.Shared.DragDrop;
using Robust.Shared.Serialization;
namespace Content.Shared.MedicalScanner
{
public abstract class SharedMedicalScannerComponent : Component, IDragDropOn
public abstract class SharedMedicalScannerComponent : Component
{
[Serializable, NetSerializable]
public enum MedicalScannerVisuals
public enum MedicalScannerVisuals : byte
{
Status
}
[Serializable, NetSerializable]
public enum MedicalScannerStatus
public enum MedicalScannerStatus : byte
{
Off,
Open,
@@ -22,17 +21,5 @@ namespace Content.Shared.MedicalScanner
Green,
Yellow,
}
public bool CanInsert(EntityUid entity)
{
return IoCManager.Resolve<IEntityManager>().HasComponent<BodyComponent>(entity);
}
bool IDragDropOn.CanDragDropOn(DragDropEvent eventArgs)
{
return CanInsert(eventArgs.Dragged);
}
public abstract bool DragDropOn(DragDropEvent eventArgs);
}
}

View File

@@ -2,6 +2,7 @@
using Content.Shared.Disease.Events;
using Content.Shared.DragDrop;
using Content.Shared.Emoting;
using Content.Shared.Hands;
using Content.Shared.Interaction.Events;
using Content.Shared.Inventory.Events;
using Content.Shared.Item;

View File

@@ -1,38 +1,31 @@
using Content.Shared.DragDrop;
using Content.Shared.Storage;
using Robust.Shared.GameStates;
namespace Content.Shared.Nutrition.Components
{
/// <summary>
/// Indicates that the entity can be thrown on a kitchen spike for butchering.
/// </summary>
[RegisterComponent]
public sealed class SharedButcherableComponent : Component, IDraggable
[RegisterComponent, NetworkedComponent]
public sealed class ButcherableComponent : Component
{
[DataField("spawned", required: true)]
public List<EntitySpawnEntry> SpawnedEntities = new();
[DataField("butcherDelay")]
[ViewVariables(VVAccess.ReadWrite), DataField("butcherDelay")]
public float ButcherDelay = 8.0f;
[DataField("butcheringType")]
[ViewVariables(VVAccess.ReadWrite), DataField("butcheringType")]
public ButcheringType Type = ButcheringType.Knife;
/// <summary>
/// Prevents butchering same entity on two and more spikes simultaneously and multiple doAfters on the same Spike
/// </summary>
[ViewVariables]
public bool BeingButchered;
// TODO: ECS this out!, my guess CanDropEvent should be client side only and then "ValidDragDrop" in the DragDropSystem needs a little touch
// But this may lead to creating client-side systems for every Draggable component subbed to CanDrop. Actually those systems could control
// CanDropOn behaviors as well (IDragDropOn)
bool IDraggable.CanDrop(CanDropEvent args)
{
return Type != ButcheringType.Knife;
}
}
public enum ButcheringType
public enum ButcheringType : byte
{
Knife, // e.g. goliaths
Spike, // e.g. monkeys

View File

@@ -1,6 +1,7 @@
using Content.Shared.ActionBlocker;
using Content.Shared.Actions;
using Content.Shared.DragDrop;
using Content.Shared.Hands;
using Content.Shared.Interaction.Events;
using Content.Shared.Item;
using Content.Shared.Movement;

View File

@@ -1,29 +0,0 @@
using Content.Shared.ActionBlocker;
using Content.Shared.DragDrop;
using Content.Shared.Hands.Components;
namespace Content.Shared.Strip.Components
{
/// <summary>
/// Give to an entity to say they can strip another entity.
/// </summary>
[RegisterComponent]
public sealed class SharedStrippingComponent : Component, IDragDropOn
{
bool IDragDropOn.CanDragDropOn(DragDropEvent eventArgs)
{
var ent = IoCManager.Resolve<IEntityManager>();
return eventArgs.Target != eventArgs.Dragged &&
eventArgs.Target == eventArgs.User &&
ent.HasComponent<SharedStrippableComponent>(eventArgs.Dragged) &&
ent.HasComponent<SharedHandsComponent>(eventArgs.User) &&
ent.EntitySysManager.GetEntitySystem<ActionBlockerSystem>().CanInteract(eventArgs.User, eventArgs.Dragged);
}
bool IDragDropOn.DragDropOn(DragDropEvent eventArgs)
{
// Handled by StrippableComponent
return true;
}
}
}

View File

@@ -1,24 +1,17 @@
using Content.Shared.ActionBlocker;
using Content.Shared.DragDrop;
using Content.Shared.Hands.Components;
using Content.Shared.Inventory;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Strip.Components
{
public abstract class SharedStrippableComponent : Component, IDraggable
[RegisterComponent, NetworkedComponent]
public sealed class StrippableComponent : Component
{
bool IDraggable.CanDrop(CanDropEvent args)
{
var ent = IoCManager.Resolve<IEntityManager>();
return args.Target != args.Dragged &&
args.Target == args.User &&
ent.HasComponent<SharedStrippingComponent>(args.User) &&
ent.HasComponent<SharedHandsComponent>(args.User) &&
ent.EntitySysManager.GetEntitySystem<ActionBlockerSystem>().CanInteract(args.User, args.Dragged);
}
public abstract bool Drop(DragDropEvent args);
/// <summary>
/// The strip delay for hands.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("handDelay")]
public float HandStripDelay = 4f;
}
[NetSerializable, Serializable]

View File

@@ -0,0 +1,10 @@
using Robust.Shared.GameStates;
namespace Content.Shared.Strip.Components
{
/// <summary>
/// Give to an entity to say they can strip another entity.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed class StrippingComponent : Component {}
}

View File

@@ -0,0 +1,49 @@
using Content.Shared.DragDrop;
using Content.Shared.Hands.Components;
using Content.Shared.Strip.Components;
namespace Content.Shared.Strip;
public abstract class SharedStrippableSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<StrippingComponent, CanDropTargetEvent>(OnCanDropOn);
SubscribeLocalEvent<StrippableComponent, CanDropDraggedEvent>(OnCanDrop);
SubscribeLocalEvent<StrippableComponent, DragDropDraggedEvent>(OnDragDrop);
}
private void OnDragDrop(EntityUid uid, StrippableComponent component, ref DragDropDraggedEvent args)
{
// If the user drags a strippable thing onto themselves.
if (args.Handled || args.Target != args.User)
return;
StartOpeningStripper(args.User, component);
args.Handled = true;
}
public virtual void StartOpeningStripper(EntityUid user, StrippableComponent component, bool openInCombat = false)
{
}
private void OnCanDropOn(EntityUid uid, StrippingComponent component, ref CanDropTargetEvent args)
{
args.Handled = true;
args.CanDrop |= uid == args.User &&
HasComp<StrippableComponent>(args.Dragged) &&
HasComp<SharedHandsComponent>(args.User);
}
private void OnCanDrop(EntityUid uid, StrippableComponent component, ref CanDropDraggedEvent args)
{
args.CanDrop |= args.Target == args.User &&
HasComp<StrippingComponent>(args.User) &&
HasComp<SharedHandsComponent>(args.User);
if (args.CanDrop)
args.Handled = true;
}
}

View File

@@ -8,6 +8,7 @@ using Content.Shared.Inventory.Events;
using Content.Shared.Item;
using Content.Shared.Bed.Sleep;
using Content.Shared.Database;
using Content.Shared.Hands;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;