diff --git a/Content.Server/GameObjects/Components/Culinary/UtensilComponent.cs b/Content.Server/GameObjects/Components/Culinary/UtensilComponent.cs index e86a311463..d6c8629c6b 100644 --- a/Content.Server/GameObjects/Components/Culinary/UtensilComponent.cs +++ b/Content.Server/GameObjects/Components/Culinary/UtensilComponent.cs @@ -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; } diff --git a/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs b/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs index 245d2eb308..5b774388e7 100644 --- a/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs @@ -411,7 +411,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click } var afterInteracts = weapon.GetAllComponents().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().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().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) diff --git a/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs b/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs index b052dc4ea9..0a20721eac 100644 --- a/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs +++ b/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs @@ -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); } diff --git a/Content.Shared/Interfaces/GameObjects/Components/Interaction/IAfterInteract.cs b/Content.Shared/Interfaces/GameObjects/Components/Interaction/IAfterInteract.cs index 8225b0d4e9..16299a23c9 100644 --- a/Content.Shared/Interfaces/GameObjects/Components/Interaction/IAfterInteract.cs +++ b/Content.Shared/Interfaces/GameObjects/Components/Interaction/IAfterInteract.cs @@ -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 { /// @@ -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; + } } /// @@ -52,7 +62,7 @@ namespace Content.Shared.Interfaces.GameObjects.Components /// /// Entity that was attacked. This can be null if the attack did not click on an entity. /// - public IEntity Attacked { get; } + public IEntity? Attacked { get; } /// /// Location that the user clicked outside of their interaction range. @@ -65,7 +75,8 @@ namespace Content.Shared.Interfaces.GameObjects.Components /// 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; } } - }