Throwing event improvements (#10055)
This commit is contained in:
@@ -190,7 +190,7 @@ namespace Content.Server.Hands.Systems
|
||||
player.IsInContainer() ||
|
||||
!TryComp(player, out SharedHandsComponent? hands) ||
|
||||
hands.ActiveHandEntity is not EntityUid throwEnt ||
|
||||
!_actionBlockerSystem.CanThrow(player))
|
||||
!_actionBlockerSystem.CanThrow(player, throwEnt))
|
||||
return false;
|
||||
|
||||
if (EntityManager.TryGetComponent(throwEnt, out StackComponent? stack) && stack.Count > 1 && stack.ThrowIndividually)
|
||||
@@ -202,8 +202,6 @@ namespace Content.Server.Hands.Systems
|
||||
|
||||
throwEnt = splitStack.Value;
|
||||
}
|
||||
else if (!TryDrop(player, throwEnt, handsComp: hands))
|
||||
return false;
|
||||
|
||||
var direction = coords.ToMapPos(EntityManager) - Transform(player).WorldPosition;
|
||||
if (direction == Vector2.Zero)
|
||||
@@ -212,11 +210,23 @@ namespace Content.Server.Hands.Systems
|
||||
direction = direction.Normalized * Math.Min(direction.Length, hands.ThrowRange);
|
||||
|
||||
var throwStrength = hands.ThrowForceMultiplier;
|
||||
_throwingSystem.TryThrow(throwEnt, direction, throwStrength, player);
|
||||
|
||||
// Let other systems change the thrown entity (useful for virtual items)
|
||||
// or the throw strength.
|
||||
var ev = new BeforeThrowEvent(throwEnt, direction, throwStrength, player);
|
||||
RaiseLocalEvent(player, ev, false);
|
||||
|
||||
if (ev.Handled)
|
||||
return true;
|
||||
|
||||
// This can grief the above event so we raise it afterwards
|
||||
if (!TryDrop(player, throwEnt, handsComp: hands))
|
||||
return false;
|
||||
|
||||
_throwingSystem.TryThrow(ev.ItemUid, ev.Direction, ev.ThrowStrength, ev.PlayerUid);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void HandleSmartEquipBackpack(ICommonSession? session)
|
||||
{
|
||||
HandleSmartEquip(session, "back");
|
||||
|
||||
@@ -97,9 +97,9 @@ namespace Content.Shared.ActionBlocker
|
||||
return !ev.Cancelled;
|
||||
}
|
||||
|
||||
public bool CanThrow(EntityUid user)
|
||||
public bool CanThrow(EntityUid user, EntityUid itemUid)
|
||||
{
|
||||
var ev = new ThrowAttemptEvent(user);
|
||||
var ev = new ThrowAttemptEvent(user, itemUid);
|
||||
RaiseLocalEvent(user, ev, true);
|
||||
|
||||
return !ev.Cancelled;
|
||||
|
||||
18
Content.Shared/Throwing/BeforeThrowEvent.cs
Normal file
18
Content.Shared/Throwing/BeforeThrowEvent.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace Content.Shared.Throwing
|
||||
{
|
||||
public sealed class BeforeThrowEvent : HandledEntityEventArgs
|
||||
{
|
||||
public BeforeThrowEvent(EntityUid itemUid, Vector2 direction, float throwStrength, EntityUid playerUid)
|
||||
{
|
||||
ItemUid = itemUid;
|
||||
Direction = direction;
|
||||
ThrowStrength = throwStrength;
|
||||
PlayerUid = playerUid;
|
||||
}
|
||||
|
||||
public EntityUid ItemUid { get; set; }
|
||||
public Vector2 Direction { get; }
|
||||
public float ThrowStrength { get; set;}
|
||||
public EntityUid PlayerUid { get; }
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,15 @@
|
||||
{
|
||||
public sealed class ThrowAttemptEvent : CancellableEntityEventArgs
|
||||
{
|
||||
public ThrowAttemptEvent(EntityUid uid)
|
||||
public ThrowAttemptEvent(EntityUid uid, EntityUid itemUid)
|
||||
{
|
||||
Uid = uid;
|
||||
ItemUid = itemUid;
|
||||
}
|
||||
|
||||
public EntityUid Uid { get; }
|
||||
|
||||
public EntityUid ItemUid { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user