Fix nullable errors with AfterInteract in UtensilComponent.
This commit is contained in:
@@ -112,9 +112,9 @@ namespace Content.Server.GameObjects.Components.Culinary
|
||||
TryUseUtensil(eventArgs.User, eventArgs.Target);
|
||||
}
|
||||
|
||||
private void TryUseUtensil(IEntity user, IEntity target)
|
||||
private void TryUseUtensil(IEntity user, IEntity? target)
|
||||
{
|
||||
if (!target.TryGetComponent(out FoodComponent? food))
|
||||
if (target == null || !target.TryGetComponent(out FoodComponent? food))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -411,7 +411,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
|
||||
}
|
||||
|
||||
var afterInteracts = weapon.GetAllComponents<IAfterInteract>().ToList();
|
||||
var afterInteractEventArgs = new AfterInteractEventArgs { User = user, ClickLocation = clickLocation, CanReach = canReach };
|
||||
var afterInteractEventArgs = new AfterInteractEventArgs(user, clickLocation, null, canReach);
|
||||
|
||||
foreach (var afterInteract in afterInteracts)
|
||||
{
|
||||
@@ -460,10 +460,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
|
||||
|
||||
// If we aren't directly attacking the nearby object, lets see if our item has an after attack we can do
|
||||
var afterAttacks = weapon.GetAllComponents<IAfterInteract>().ToList();
|
||||
var afterAttackEventArgs = new AfterInteractEventArgs
|
||||
{
|
||||
User = user, ClickLocation = clickLocation, Target = attacked, CanReach = true
|
||||
};
|
||||
var afterAttackEventArgs = new AfterInteractEventArgs(user, clickLocation, attacked, canReach: true);
|
||||
|
||||
foreach (var afterAttack in afterAttacks)
|
||||
{
|
||||
@@ -833,10 +830,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
|
||||
return;
|
||||
|
||||
var afterAttacks = weapon.GetAllComponents<IAfterInteract>().ToList();
|
||||
var afterAttackEventArgs = new AfterInteractEventArgs
|
||||
{
|
||||
User = user, ClickLocation = clickLocation, Target = attacked, CanReach = false
|
||||
};
|
||||
var afterAttackEventArgs = new AfterInteractEventArgs(user, clickLocation, attacked, canReach: false);
|
||||
|
||||
//See if we have a ranged attack interaction
|
||||
foreach (var afterAttack in afterAttacks)
|
||||
|
||||
@@ -6,7 +6,6 @@ using Content.Shared.Utility;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
@@ -161,7 +160,7 @@ namespace Content.Shared.GameObjects.EntitySystems
|
||||
public static bool InRangeUnOccluded(AfterInteractEventArgs args, float range, Ignored? predicate, bool ignoreInsideBlocker = true)
|
||||
{
|
||||
var originPos = args.User.Transform.MapPosition;
|
||||
var otherPos = args.Target.Transform.MapPosition;
|
||||
var otherPos = args.Target?.Transform.MapPosition ?? args.ClickLocation.ToMap(args.User.EntityManager);
|
||||
|
||||
return InRangeUnOccluded(originPos, otherPos, range, predicate, ignoreInsideBlocker);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Content.Shared.Interfaces.GameObjects.Components
|
||||
{
|
||||
/// <summary>
|
||||
@@ -22,10 +24,18 @@ namespace Content.Shared.Interfaces.GameObjects.Components
|
||||
|
||||
public class AfterInteractEventArgs : EventArgs
|
||||
{
|
||||
public IEntity User { get; set; }
|
||||
public EntityCoordinates ClickLocation { get; set; }
|
||||
public IEntity Target { get; set; }
|
||||
public bool CanReach { get; set; }
|
||||
public IEntity User { get; }
|
||||
public EntityCoordinates ClickLocation { get; }
|
||||
public IEntity? Target { get; }
|
||||
public bool CanReach { get; }
|
||||
|
||||
public AfterInteractEventArgs(IEntity user, EntityCoordinates clickLocation, IEntity? target, bool canReach)
|
||||
{
|
||||
User = user;
|
||||
ClickLocation = clickLocation;
|
||||
Target = target;
|
||||
CanReach = canReach;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -52,7 +62,7 @@ namespace Content.Shared.Interfaces.GameObjects.Components
|
||||
/// <summary>
|
||||
/// Entity that was attacked. This can be null if the attack did not click on an entity.
|
||||
/// </summary>
|
||||
public IEntity Attacked { get; }
|
||||
public IEntity? Attacked { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Location that the user clicked outside of their interaction range.
|
||||
@@ -65,7 +75,8 @@ namespace Content.Shared.Interfaces.GameObjects.Components
|
||||
/// </summary>
|
||||
public bool CanReach { get; }
|
||||
|
||||
public AfterInteractMessage(IEntity user, IEntity itemInHand, IEntity attacked, EntityCoordinates clickLocation, bool canReach)
|
||||
public AfterInteractMessage(IEntity user, IEntity itemInHand, IEntity? attacked,
|
||||
EntityCoordinates clickLocation, bool canReach)
|
||||
{
|
||||
User = user;
|
||||
Attacked = attacked;
|
||||
@@ -74,5 +85,4 @@ namespace Content.Shared.Interfaces.GameObjects.Components
|
||||
CanReach = canReach;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user