Moved dropping items over PlaceableSurfaces from AfterAttack to AttackBy (#209)
Added ClickLocation variable to AttackByEventArgs
This commit is contained in:
committed by
Pieter-Jan Briers
parent
8655dcaaf6
commit
b16768fd0b
@@ -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<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))
|
||||
|
||||
@@ -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<HandsComponent>(out var handComponent))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
handComponent.Drop(eventArgs.AttackWith);
|
||||
eventArgs.AttackWith.Transform.WorldPosition = eventArgs.ClickLocation.Position;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user