From b16768fd0b4a6cc8ffb5e144de55baba437e33c8 Mon Sep 17 00:00:00 2001 From: DamianX Date: Thu, 25 Apr 2019 22:22:51 +0100 Subject: [PATCH] Moved dropping items over PlaceableSurfaces from AfterAttack to AttackBy (#209) Added ClickLocation variable to AttackByEventArgs --- .../Components/Items/Storage/ItemComponent.cs | 17 +---------------- .../Components/PlaceableSurfaceComponent.cs | 15 +++++++++++++-- .../EntitySystems/Click/InteractionSystem.cs | 3 ++- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/Content.Server/GameObjects/Components/Items/Storage/ItemComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/ItemComponent.cs index d750053df0..5242e930d8 100644 --- a/Content.Server/GameObjects/Components/Items/Storage/ItemComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Storage/ItemComponent.cs @@ -12,7 +12,7 @@ using Robust.Shared.Maths; namespace Content.Server.GameObjects { - public class ItemComponent : StoreableComponent, IAttackHand, IAfterAttack + public class ItemComponent : StoreableComponent, IAttackHand { public override string Name => "Item"; public override uint? NetID => ContentNetIDs.ITEM; @@ -91,21 +91,6 @@ namespace Content.Server.GameObjects return new ItemComponentState(EquippedPrefix); } - public void AfterAttack(AfterAttackEventArgs eventArgs) - { - if (!eventArgs.User.TryGetComponent(out var handComponent)) - { - return; - } - if (eventArgs.Attacked == null || !eventArgs.Attacked.TryGetComponent(out var placeableSurfaceComponent)) - { - return; - } - handComponent.Drop(handComponent.ActiveIndex); - Owner.Transform.WorldPosition = eventArgs.ClickLocation.Position; - return; - } - public void Fumble() { if (Owner.TryGetComponent(out var physicsComponent)) diff --git a/Content.Server/GameObjects/Components/PlaceableSurfaceComponent.cs b/Content.Server/GameObjects/Components/PlaceableSurfaceComponent.cs index 645e6e5282..7d8a624f1a 100644 --- a/Content.Server/GameObjects/Components/PlaceableSurfaceComponent.cs +++ b/Content.Server/GameObjects/Components/PlaceableSurfaceComponent.cs @@ -1,9 +1,10 @@ -using Robust.Shared.GameObjects; +using Content.Server.GameObjects.EntitySystems; +using Robust.Shared.GameObjects; using Robust.Shared.Serialization; namespace Content.Server.GameObjects.Components { - public class PlaceableSurfaceComponent : Component + public class PlaceableSurfaceComponent : Component, IAttackBy { public override string Name => "PlaceableSurface"; @@ -16,5 +17,15 @@ namespace Content.Server.GameObjects.Components serializer.DataField(ref _isPlaceable, "IsPlaceable", true); } + public bool AttackBy(AttackByEventArgs eventArgs) + { + if(!eventArgs.User.TryGetComponent(out var handComponent)) + { + return true; + } + handComponent.Drop(eventArgs.AttackWith); + eventArgs.AttackWith.Transform.WorldPosition = eventArgs.ClickLocation.Position; + return true; + } } } diff --git a/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs b/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs index 45436dd0e1..9368ee223d 100644 --- a/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs @@ -35,6 +35,7 @@ namespace Content.Server.GameObjects.EntitySystems public class AttackByEventArgs : EventArgs { public IEntity User { get; set; } + public GridCoordinates ClickLocation { get; set; } public IEntity AttackWith { get; set; } } @@ -321,7 +322,7 @@ namespace Content.Server.GameObjects.EntitySystems for (var i = 0; i < interactables.Count; i++) { - if (interactables[i].AttackBy(new AttackByEventArgs { User = user, AttackWith = weapon })) //If an attackby returns a status completion we finish our attack + if (interactables[i].AttackBy(new AttackByEventArgs { User = user, ClickLocation = clicklocation, AttackWith = weapon })) //If an attackby returns a status completion we finish our attack { return; }