Adjust interaction ordering & interaction conditions (#6387)

This commit is contained in:
Leon Friedrich
2022-02-05 15:39:01 +13:00
committed by GitHub
parent 442d7dbf8e
commit dd61fb46ea
28 changed files with 88 additions and 167 deletions

View File

@@ -138,10 +138,7 @@ namespace Content.Server.Chemistry.Components
return true;
}
if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
return false;
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(eventArgs.User))
if (!eventArgs.CanReach)
return false;
var solutionsSys = EntitySystem.Get<SolutionContainerSystem>();

View File

@@ -115,7 +115,7 @@ namespace Content.Server.Chemistry.Components
{
var solutionsSys = EntitySystem.Get<SolutionContainerSystem>();
if (!eventArgs.InRangeUnobstructed() || eventArgs.Target == null)
if (!eventArgs.CanReach || eventArgs.Target == null)
return false;
if (!_entities.HasComponent<SolutionContainerManagerComponent>(Owner))

View File

@@ -33,7 +33,8 @@ namespace Content.Server.Construction
if (!EntityManager.TryGetComponent(args.Used, out ToolComponent? usedTool))
return;
args.Handled = await TryToggleAnchor(uid, args.User, args.Used, anchorable, usingTool:usedTool);
args.Handled = true;
await TryToggleAnchor(uid, args.User, args.Used, anchorable, usingTool:usedTool);
}
/// <summary>

View File

@@ -108,7 +108,7 @@ namespace Content.Server.Crayon
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
{
if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: false, popup: true,
if (!eventArgs.User.InRangeUnobstructed(eventArgs.ClickLocation, ignoreInsideBlocker: false, popup: true,
collisionMask: Shared.Physics.CollisionGroup.MobImpassable))
{
return true;

View File

@@ -179,7 +179,7 @@ namespace Content.Server.Cuffs.Components
return true;
}
if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true))
if (!eventArgs.CanReach)
{
eventArgs.User.PopupMessage(Loc.GetString("handcuff-component-too-far-away-error"));
return true;

View File

@@ -63,8 +63,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
// Interactions
SubscribeLocalEvent<DisposalUnitComponent, ActivateInWorldEvent>(HandleActivate);
SubscribeLocalEvent<DisposalUnitComponent, InteractHandEvent>(HandleInteractHand);
SubscribeLocalEvent<DisposalUnitComponent, InteractUsingEvent>(HandleInteractUsing);
SubscribeLocalEvent<DisposalUnitComponent, AfterInteractUsingEvent>(HandleAfterInteractUsing);
SubscribeLocalEvent<DisposalUnitComponent, DragDropEvent>(HandleDragDropOn);
SubscribeLocalEvent<DisposalUnitComponent, DestructionEventArgs>(HandleDestruction);
@@ -223,19 +222,11 @@ namespace Content.Server.Disposal.Unit.EntitySystems
}
}
private void HandleInteractHand(EntityUid uid, DisposalUnitComponent component, InteractHandEvent args)
private void HandleAfterInteractUsing(EntityUid uid, DisposalUnitComponent component, AfterInteractUsingEvent args)
{
if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor)) return;
if (args.Handled || !args.CanReach)
return;
// Duplicated code here, not sure how else to get actor inside to make UserInterface happy.
if (!IsValidInteraction(args)) return;
component.Owner.GetUIOrNull(SharedDisposalUnitComponent.DisposalUnitUiKey.Key)?.Open(actor.PlayerSession);
args.Handled = true;
}
private void HandleInteractUsing(EntityUid uid, DisposalUnitComponent component, InteractUsingEvent args)
{
if (!EntityManager.TryGetComponent(args.User, out HandsComponent? hands))
{
return;

View File

@@ -103,14 +103,13 @@ namespace Content.Server.Fluids.Components
var solutionSystem = EntitySystem.Get<SolutionContainerSystem>();
var spillableSystem = EntitySystem.Get<SpillableSystem>();
if (!solutionSystem.TryGetSolution(Owner, SolutionName, out var contents ) ||
Mopping ||
!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
if (!eventArgs.CanReach ||
!solutionSystem.TryGetSolution(Owner, SolutionName, out var contents ) ||
Mopping)
{
return false;
}
if (eventArgs.Target is not {Valid: true} target)
{
// Drop the liquid on the mop on to the ground

View File

@@ -118,7 +118,7 @@ namespace Content.Server.Guardian
private void OnCreatorInteract(EntityUid uid, GuardianCreatorComponent component, AfterInteractEvent args)
{
if (args.Handled || args.Target == null) return;
if (args.Handled || args.Target == null || !args.CanReach) return;
args.Handled = true;
UseCreator(args.User, args.Target.Value, component);
}

View File

@@ -234,10 +234,10 @@ namespace Content.Server.Interaction
/// Finds components with the InteractHand interface and calls their function
/// NOTE: Does not have an InRangeUnobstructed check
/// </summary>
public override void InteractHand(EntityUid user, EntityUid target)
public override void InteractHand(EntityUid user, EntityUid target, bool checkActionBlocker = true)
{
// TODO PREDICTION move server-side interaction logic into the shared system for interaction prediction.
if (!_actionBlockerSystem.CanInteract(user))
if (checkActionBlocker && !_actionBlockerSystem.CanInteract(user))
return;
// all interactions should only happen when in range / unobstructed, so no range check is needed
@@ -270,7 +270,7 @@ namespace Content.Server.Interaction
public override async Task<bool> InteractUsingRanged(EntityUid user, EntityUid used, EntityUid? target, EntityCoordinates clickLocation, bool inRangeUnobstructed)
{
// TODO PREDICTION move server-side interaction logic into the shared system for interaction prediction.
if (InteractDoBefore(user, used, inRangeUnobstructed ? target : null, clickLocation, false))
if (InteractDoBefore(user, used, target, clickLocation, inRangeUnobstructed))
return true;
if (target != null)
@@ -282,7 +282,7 @@ namespace Content.Server.Interaction
return true;
}
return await InteractDoAfter(user, used, inRangeUnobstructed ? target : null, clickLocation, false);
return await InteractDoAfter(user, used, target, clickLocation, inRangeUnobstructed);
}
public override void DoAttack(EntityUid user, EntityCoordinates coordinates, bool wideAttack, EntityUid? target = null)

View File

@@ -34,7 +34,7 @@ namespace Content.Server.Labels
private void AfterInteractOn(EntityUid uid, HandLabelerComponent handLabeler, AfterInteractEvent args)
{
if (args.Target is not {Valid: true} target || !handLabeler.Whitelist.IsValid(target))
if (args.Target is not {Valid: true} target || !handLabeler.Whitelist.IsValid(target) || !args.CanReach)
return;
AddLabelTo(uid, handLabeler, target, out string? result);

View File

@@ -35,7 +35,7 @@ namespace Content.Server.Medical.Components
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
{
if (eventArgs.Target == null)
if (eventArgs.Target == null || !eventArgs.CanReach)
{
return false;
}
@@ -54,12 +54,6 @@ namespace Content.Server.Medical.Components
return true;
}
if (eventArgs.User != eventArgs.Target &&
!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
{
return true;
}
if (_entMan.TryGetComponent<SharedStackComponent?>(Owner, out var stack) && !EntitySystem.Get<StackSystem>().Use(Owner, 1, stack))
{
return true;

View File

@@ -130,30 +130,15 @@ namespace Content.Server.Nutrition.EntitySystems
private void AfterInteract(EntityUid uid, DrinkComponent component, AfterInteractEvent args)
{
if (args.Handled || args.Target == null)
if (args.Handled || args.Target == null || !args.CanReach)
return;
if (!_actionBlockerSystem.CanInteract(args.User) || !_actionBlockerSystem.CanUse(args.User))
return;
if (!args.User.InRangeUnobstructed(uid, popup: true))
{
args.Handled = true;
return;
}
if (args.User == args.Target)
{
args.Handled = TryUseDrink(uid, args.User);
return;
}
if (!args.User.InRangeUnobstructed(args.Target.Value, popup: true))
{
args.Handled = true;
return;
}
if (args.User == args.Target)
args.Handled = TryUseDrink(uid, args.User, component);
else
@@ -164,15 +149,6 @@ namespace Content.Server.Nutrition.EntitySystems
{
if (args.Handled) return;
if (!_actionBlockerSystem.CanInteract(args.User) || !_actionBlockerSystem.CanUse(args.User))
return;
if (!args.User.InRangeUnobstructed(uid, popup: true))
{
args.Handled = true;
return;
}
if (!component.Opened)
{
//Do the opening stuff like playing the sounds.

View File

@@ -77,15 +77,6 @@ namespace Content.Server.Nutrition.EntitySystems
if (ev.Handled)
return;
if (!_actionBlockerSystem.CanInteract(ev.User) || !_actionBlockerSystem.CanUse(ev.User))
return;
if (!ev.User.InRangeUnobstructed(uid, popup: true))
{
ev.Handled = true;
return;
}
ev.Handled = TryUseFood(uid, ev.User);
}
@@ -94,30 +85,15 @@ namespace Content.Server.Nutrition.EntitySystems
/// </summary>
private void OnFeedFood(EntityUid uid, FoodComponent foodComponent, AfterInteractEvent args)
{
if (args.Handled || args.Target == null)
if (args.Handled || args.Target == null || !args.CanReach)
return;
if (!_actionBlockerSystem.CanInteract(args.User) || !_actionBlockerSystem.CanUse(args.User))
return;
if (!args.User.InRangeUnobstructed(uid, popup: true))
{
args.Handled = true;
return;
}
if (args.User == args.Target)
{
args.Handled = TryUseFood(uid, args.User);
return;
}
if (!args.User.InRangeUnobstructed(args.Target.Value, popup: true))
{
args.Handled = true;
return;
}
args.Handled = TryForceFeed(uid, args.User, args.Target.Value);
}

View File

@@ -56,6 +56,7 @@ namespace Content.Server.Nutrition.EntitySystems
{
var targetEntity = args.Target;
if (targetEntity == null ||
!args.CanReach ||
!EntityManager.TryGetComponent(uid, out SmokableComponent? smokable) ||
smokable.State == SmokableState.Lit)
return;

View File

@@ -32,7 +32,7 @@ namespace Content.Server.Nutrition.EntitySystems
/// </summary>
private void OnAfterInteract(EntityUid uid, UtensilComponent component, AfterInteractEvent ev)
{
if (ev.Target == null)
if (ev.Target == null || !ev.CanReach)
return;
if (TryUseUtensil(ev.User, ev.Target.Value, component))

View File

@@ -16,13 +16,10 @@ public sealed partial class CableSystem
private void OnCablePlacerAfterInteract(EntityUid uid, CablePlacerComponent component, AfterInteractEvent args)
{
if (args.Handled) return;
if (args.Handled || !args.CanReach) return;
if (component.CablePrototypeId == null) return;
if (!args.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
return;
if(!_mapManager.TryGetGrid(args.ClickLocation.GetGridId(EntityManager), out var grid))
return;

View File

@@ -25,6 +25,7 @@ namespace Content.Server.RCD.Systems
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
private readonly RcdMode[] _modes = (RcdMode[]) Enum.GetValues(typeof(RcdMode));
@@ -60,7 +61,7 @@ namespace Content.Server.RCD.Systems
private async void OnAfterInteract(EntityUid uid, RCDComponent rcd, AfterInteractEvent args)
{
if (args.Handled)
if (args.Handled || !args.CanReach)
return;
// FIXME: Make this work properly. Right now it relies on the click location being on a grid, which is bad.
@@ -159,7 +160,8 @@ namespace Content.Server.RCD.Systems
}
var coordinates = mapGrid.ToCoordinates(tile.GridIndices);
if (coordinates == EntityCoordinates.Invalid || !eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
if (coordinates == EntityCoordinates.Invalid ||
!_interactionSystem.InRangeUnobstructed(eventArgs.User, coordinates, ignoreInsideBlocker: true, popup: true))
{
return false;
}

View File

@@ -558,7 +558,7 @@ namespace Content.Server.Storage.Components
/// <returns></returns>
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
{
if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true)) return false;
if (!eventArgs.CanReach) return false;
// Pick up all entities in a radius around the clicked location.
// The last half of the if is because carpets exist and this is terrible

View File

@@ -56,7 +56,7 @@ namespace Content.Server.Tiles
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
{
if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
if (!eventArgs.CanReach)
return true;
if (!_entMan.TryGetComponent(Owner, out StackComponent? stack))

View File

@@ -25,7 +25,7 @@ public sealed partial class ToolSystem
private void OnTilePryingAfterInteract(EntityUid uid, TilePryingComponent component, AfterInteractEvent args)
{
if (args.Handled) return;
if (args.Handled || !args.CanReach) return;
if (TryPryTile(args.User, component, args.ClickLocation))
args.Handled = true;

View File

@@ -23,7 +23,7 @@ namespace Content.Server.Traitor.Uplink.Telecrystal
private void OnAfterInteract(EntityUid uid, TelecrystalComponent component, AfterInteractEvent args)
{
if (args.Handled)
if (args.Handled || !args.CanReach)
return;
if (args.Target == null || !EntityManager.TryGetComponent(args.Target.Value, out UplinkComponent? uplink))

View File

@@ -215,7 +215,7 @@ namespace Content.Server.Weapon.Melee
/// </summary>
private void OnAfterInteract(EntityUid owner, MeleeWeaponComponent comp, AfterInteractEvent args)
{
if (!args.CanReach)
if (args.Handled || !args.CanReach)
return;
var curTime = _gameTiming.CurTime;

View File

@@ -90,7 +90,7 @@ public sealed partial class GunSystem
private void OnSpeedLoaderAfterInteract(EntityUid uid, SpeedLoaderComponent component, AfterInteractEvent args)
{
if (args.Handled) return;
if (args.Handled || !args.CanReach) return;
if (args.Target == null)
{