Skip to content

Commit

Permalink
Moved dropping items over PlaceableSurfaces from AfterAttack to Attac…
Browse files Browse the repository at this point in the history
…kBy (#209)

Added ClickLocation variable to AttackByEventArgs
  • Loading branch information
DamianX authored and PJB3005 committed Apr 25, 2019
1 parent 8655dca commit b16768f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

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;
Expand Down Expand Up @@ -91,21 +91,6 @@ public override ComponentState GetComponentState()
return new ItemComponentState(EquippedPrefix);
}

public void AfterAttack(AfterAttackEventArgs eventArgs)
{
if (!eventArgs.User.TryGetComponent<HandsComponent>(out var handComponent))
{
return;
}
if (eventArgs.Attacked == null || !eventArgs.Attacked.TryGetComponent<PlaceableSurfaceComponent>(out var placeableSurfaceComponent))
{
return;
}
handComponent.Drop(handComponent.ActiveIndex);
Owner.Transform.WorldPosition = eventArgs.ClickLocation.Position;
return;
}

public void Fumble()
{
if (Owner.TryGetComponent<PhysicsComponent>(out var physicsComponent))
Expand Down
15 changes: 13 additions & 2 deletions Content.Server/GameObjects/Components/PlaceableSurfaceComponent.cs
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -16,5 +17,15 @@ public override void ExposeData(ObjectSerializer serializer)

serializer.DataField(ref _isPlaceable, "IsPlaceable", true);
}
public bool AttackBy(AttackByEventArgs eventArgs)
{
if(!eventArgs.User.TryGetComponent<HandsComponent>(out var handComponent))
{
return true;
}
handComponent.Drop(eventArgs.AttackWith);
eventArgs.AttackWith.Transform.WorldPosition = eventArgs.ClickLocation.Position;
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public interface IAttackBy
public class AttackByEventArgs : EventArgs
{
public IEntity User { get; set; }
public GridCoordinates ClickLocation { get; set; }
public IEntity AttackWith { get; set; }
}

Expand Down Expand Up @@ -321,7 +322,7 @@ public void Interaction(IEntity user, IEntity weapon, IEntity attacked, GridCoor

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;
}
Expand Down

0 comments on commit b16768f

Please sign in to comment.