2021-04-01 00:04:56 -07:00
|
|
|
using System;
|
2021-06-07 05:49:43 -07:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2018-02-05 13:57:26 -06:00
|
|
|
using System.Linq;
|
2020-08-18 14:39:08 +02:00
|
|
|
using System.Threading.Tasks;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Buckle.Components;
|
|
|
|
|
using Content.Server.CombatMode;
|
|
|
|
|
using Content.Server.Hands.Components;
|
|
|
|
|
using Content.Server.Items;
|
|
|
|
|
using Content.Server.Pulling;
|
2021-10-05 14:29:03 +11:00
|
|
|
using Content.Server.Verbs;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.ActionBlocker;
|
|
|
|
|
using Content.Shared.DragDrop;
|
2018-08-16 15:57:11 -07:00
|
|
|
using Content.Shared.Input;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Interaction;
|
|
|
|
|
using Content.Shared.Interaction.Helpers;
|
2021-09-26 15:18:45 +02:00
|
|
|
using Content.Shared.Popups;
|
2021-10-05 14:29:03 +11:00
|
|
|
using Content.Shared.Pulling.Components;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Rotatable;
|
2021-10-25 20:06:12 +13:00
|
|
|
using Content.Shared.Timing;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Weapons.Melee;
|
2019-05-16 15:51:26 +02:00
|
|
|
using JetBrains.Annotations;
|
2020-06-18 22:52:44 +10:00
|
|
|
using Robust.Server.GameObjects;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Server.Player;
|
2020-07-07 01:00:29 +02:00
|
|
|
using Robust.Shared.Containers;
|
2019-05-16 15:51:26 +02:00
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.Input;
|
2020-05-31 14:32:05 -07:00
|
|
|
using Robust.Shared.Input.Binding;
|
2019-04-20 16:20:18 -07:00
|
|
|
using Robust.Shared.IoC;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Robust.Shared.Localization;
|
2019-05-16 15:51:26 +02:00
|
|
|
using Robust.Shared.Log;
|
|
|
|
|
using Robust.Shared.Map;
|
2020-02-07 08:54:56 -08:00
|
|
|
using Robust.Shared.Maths;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Shared.Players;
|
2021-05-09 10:09:14 +02:00
|
|
|
using Robust.Shared.Random;
|
2018-02-05 13:57:26 -06:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Interaction
|
2018-02-05 13:57:26 -06:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Governs interactions during clicking on entities
|
|
|
|
|
/// </summary>
|
2019-05-16 15:51:26 +02:00
|
|
|
[UsedImplicitly]
|
2020-04-22 00:58:31 +10:00
|
|
|
public sealed class InteractionSystem : SharedInteractionSystem
|
2018-02-05 13:57:26 -06:00
|
|
|
{
|
2020-09-06 16:11:53 +02:00
|
|
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
2021-07-26 12:58:17 +02:00
|
|
|
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
2021-10-04 16:10:54 +01:00
|
|
|
[Dependency] private readonly PullingSystem _pullSystem = default!;
|
2021-11-02 18:38:47 +00:00
|
|
|
[Dependency] private readonly RotateToFaceSystem _rotateToFaceSystem = default!;
|
2019-04-20 16:20:18 -07:00
|
|
|
|
2018-08-16 15:57:11 -07:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
SubscribeNetworkEvent<DragDropRequestEvent>(HandleDragDropRequestEvent);
|
2021-08-22 03:20:18 +10:00
|
|
|
SubscribeNetworkEvent<InteractInventorySlotEvent>(HandleInteractInventorySlotEvent);
|
2020-07-06 14:27:03 -07:00
|
|
|
|
2020-05-31 14:32:05 -07:00
|
|
|
CommandBinds.Builder
|
|
|
|
|
.Bind(EngineKeyFunctions.Use,
|
2021-06-07 05:49:43 -07:00
|
|
|
new PointerInputCmdHandler(HandleUseInteraction))
|
2021-08-22 03:20:18 +10:00
|
|
|
.Bind(ContentKeyFunctions.AltActivateItemInWorld,
|
|
|
|
|
new PointerInputCmdHandler(HandleAltUseInteraction))
|
2020-05-31 14:32:05 -07:00
|
|
|
.Bind(ContentKeyFunctions.WideAttack,
|
|
|
|
|
new PointerInputCmdHandler(HandleWideAttack))
|
|
|
|
|
.Bind(ContentKeyFunctions.ActivateItemInWorld,
|
|
|
|
|
new PointerInputCmdHandler(HandleActivateItemInWorld))
|
2021-06-07 05:49:43 -07:00
|
|
|
.Bind(ContentKeyFunctions.TryPullObject,
|
|
|
|
|
new PointerInputCmdHandler(HandleTryPullObject))
|
2020-05-31 14:32:05 -07:00
|
|
|
.Register<InteractionSystem>();
|
2018-08-22 01:19:47 -07:00
|
|
|
}
|
|
|
|
|
|
2020-05-31 14:32:05 -07:00
|
|
|
public override void Shutdown()
|
|
|
|
|
{
|
|
|
|
|
CommandBinds.Unregister<InteractionSystem>();
|
|
|
|
|
base.Shutdown();
|
|
|
|
|
}
|
2020-02-28 17:52:18 +01:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
#region Client Input Validation
|
|
|
|
|
private bool ValidateClientInput(ICommonSession? session, EntityCoordinates coords, EntityUid uid, [NotNullWhen(true)] out IEntity? userEntity)
|
2020-07-06 14:27:03 -07:00
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
userEntity = null;
|
2021-03-16 15:50:20 +01:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
if (!coords.IsValid(_entityManager))
|
|
|
|
|
{
|
|
|
|
|
Logger.InfoS("system.interaction", $"Invalid Coordinates: client={session}, coords={coords}");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (uid.IsClientSide())
|
|
|
|
|
{
|
|
|
|
|
Logger.WarningS("system.interaction",
|
|
|
|
|
$"Client sent interaction with client-side entity. Session={session}, Uid={uid}");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userEntity = ((IPlayerSession?) session)?.AttachedEntity;
|
|
|
|
|
|
|
|
|
|
if (userEntity == null || !userEntity.IsValid())
|
|
|
|
|
{
|
|
|
|
|
Logger.WarningS("system.interaction",
|
|
|
|
|
$"Client sent interaction with no attached entity. Session={session}");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
2021-08-22 03:20:18 +10:00
|
|
|
/// <summary>
|
|
|
|
|
/// Handles the event were a client uses an item in their inventory or in their hands, either by
|
|
|
|
|
/// alt-clicking it or pressing 'E' while hovering over it.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void HandleInteractInventorySlotEvent(InteractInventorySlotEvent msg, EntitySessionEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (!EntityManager.TryGetEntity(msg.ItemUid, out var item))
|
|
|
|
|
{
|
|
|
|
|
Logger.WarningS("system.interaction",
|
|
|
|
|
$"Client sent inventory interaction with an invalid target item. Session={args.SenderSession}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// client sanitization
|
|
|
|
|
if (!ValidateClientInput(args.SenderSession, item.Transform.Coordinates, msg.ItemUid, out var userEntity))
|
|
|
|
|
{
|
|
|
|
|
Logger.InfoS("system.interaction", $"Inventory interaction validation failed. Session={args.SenderSession}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (msg.AltInteract)
|
|
|
|
|
// Use 'UserInteraction' function - behaves as if the user alt-clicked the item in the world.
|
|
|
|
|
UserInteraction(userEntity, item.Transform.Coordinates, msg.ItemUid, msg.AltInteract);
|
|
|
|
|
else
|
|
|
|
|
// User used 'E'. We want to activate it, not simulate clicking on the item
|
|
|
|
|
InteractionActivate(userEntity, item);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
#region Drag drop
|
|
|
|
|
private void HandleDragDropRequestEvent(DragDropRequestEvent msg, EntitySessionEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (!ValidateClientInput(args.SenderSession, msg.DropLocation, msg.Target, out var userEntity))
|
|
|
|
|
{
|
|
|
|
|
Logger.InfoS("system.interaction", $"DragDropRequestEvent input validation failed");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!EntityManager.TryGetEntity(msg.Dropped, out var dropped))
|
|
|
|
|
return;
|
|
|
|
|
if (!EntityManager.TryGetEntity(msg.Target, out var target))
|
|
|
|
|
return;
|
2020-07-06 14:27:03 -07:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
var interactionArgs = new DragDropEvent(userEntity, msg.DropLocation, dropped, target);
|
2020-07-06 14:27:03 -07:00
|
|
|
|
|
|
|
|
// must be in range of both the target and the object they are drag / dropping
|
2021-01-11 22:14:01 +11:00
|
|
|
// Client also does this check but ya know we gotta validate it.
|
2021-06-07 05:49:43 -07:00
|
|
|
if (!interactionArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
|
|
|
|
|
return;
|
2020-07-06 14:27:03 -07:00
|
|
|
|
|
|
|
|
// trigger dragdrops on the dropped entity
|
2021-03-09 11:22:48 -08:00
|
|
|
RaiseLocalEvent(dropped.Uid, interactionArgs);
|
2020-10-14 15:24:07 +02:00
|
|
|
foreach (var dragDrop in dropped.GetAllComponents<IDraggable>())
|
2020-07-06 14:27:03 -07:00
|
|
|
{
|
2020-10-14 15:24:07 +02:00
|
|
|
if (dragDrop.CanDrop(interactionArgs) &&
|
|
|
|
|
dragDrop.Drop(interactionArgs))
|
Add the trash man (#1367)
* Add disposal.rsi
* Rename disposal resource to disposal.rsi and create basic components
* Add disposal nets
* Add pushing entities along the disposal network
* Add disposal unit
* Unregister disposable component
* Add flush and selfinsert verbs to disposal unit
* Add gradual disposals movement
* Fix being able to walk through space for a while after exiting disposals
* Multiply disposals speed by 10
And fix early returns when moving an entity
* Rename Disposable component to InDisposals
* Remove DisposalNet and add on anchor events
* Remove anchored events, moved to interfaces
* Code cleanup
* Fix adjacent tubes' connections when a tube connects
* Fix jittery movement in disposals
* Remove Logger.Debug call
* Move disposals updates to InDisposalsComponent
* Fix adjacent connection valid directions check
* Disposal tubes now throw you out where they are facing
* Add disposal unit exit cooldown
* Set different disposal pipe sprite state depending on anchored value
* Add recycler
* Add recycler animation
* Add bloody texture to the recycler when grinding a living being
* Add PowerDevice component to the disposal unit
* Made the Recycler center on the grid
* Add disposal junction
* Add picking a random direction if junction is entered from the output side
* Add disposal flush and clang sounds
Taken from VGStation
* Move disposal flush and clang sound file names to exposedata
* Add disposalsmap.yml to test with
* Add summaries to DisposalUnit fields
* Add sideDegrees yaml property to disposal junctions
* Fix outdated usings
* Add conveyor resources
* Update RobustToolbox
* More merge fixes
Add conveyor collision masks
* Add ConveyorComponent
* Fix crash when reentering a body
* Merge branch 'master' into disposals-1147
* Reduce recycler bounds, set hard to false, add summary and expose "safe" to yaml
* Move IAnchored and IUnAnchored to AnchorableComponent
* Update power components and remove old disposals map
* Remove redundant sprite layers
* Add tile pry command
* Fix tilepry command
* Fix DisposalJunctionComponent missing a component reference
* Add anchor by radius command
* Add Y-Junctions
* Add disposal bend
* Add unanchor command
* Change DisposalJunction prototypes to specify their angles
* Fix disposal units being hidden below the floor
* Removed IAnhored and IUnAnchored interfaces
* Replace CanBeNull annotation with nullable reference types
* Update showwires command
* Add recycler recycling items
* Added angle and speed properties to ConveyorComponent
* Fix conveyort textures
* Add animation to the disposal unit
* Fix anchor and unanchor commands sometimes not finding any entities
* Fix not reading flush_time from disposal unit prototype
* Fix merge conflict wrong using
* Fix disposal, recycling and conveyor texture paths
Delete diverters
* Update visualizer names
* Add DisposableComponent, change drag and drop to work with multiple components
Ignoreinsideblocker client side for drag and drops, like on the server
Add more comments
* Add conveyor belts properly moving entities on top
* Anchorr wires
* Change conveyor bounds to 0.49
* Anchor catwalks, airlocks, gravity generators, low walls, wires and windows
* Add starting/stopping conveyors
* Add reversed conveyors
* Add conveyor switches
* Move InDisposalsComponent code to DisposableComponent
* Add ExitVector method to tubes
* Fix not updating tube references when disconnecting one
* Replace IoCManager call with dependency
* Add tubes disconnecting if they move too far apart from one another
* Move disposals action blocking to shared
* Add rotating and flipping pipes
* Make conveyor intersection calculations approximate
* Fix 1% chance of the server crashing when initializing the map
Happens when emergency lockers remove themselves
* Add disposal unit interface
* Make disposal units refuse items if not powered
* Make disposal tubes hide only when anchored
* Make disposal junction arrows visible to mere mortals
* Add disposal tubes breaking
* Add tubeconnections command
* Add missing verb attribute
* Add flipped disposal junction
* Add ids and linking to conveyors and switches
* Add conveyor switch prying and placing
* Add anchoring conveyor switches and refactor placing them
* Add missing serializable attributes from DisposableComponentState
* Make conveyor speed VV ReadWrite
* Change drawdepth of conveyors to FloorObjects
* Make conveyor anchored check consistent
* Remove anchoring interaction from switches
* Add conveyor switch id syncing and move switches slightly when pried
* Make entities in containers not able to be moved by conveyors
* Add conveyor and switches loose textures
* Merge conflict fixes
* Add disposal unit test
* Add flushing test to disposal unit test
* Add disposal unit flush fail test
* Add disposals to the saltern map
* Fix saltern disposal junctions
* Add power checks to the recycler
* Fix disposal unit placement in maintenance closet
* Remove disposal junctions from saltern
* Readd junctions to saltern
* Add the chemmaster to saltern at the request of Ike
* Move the chemistry disposal unit
* Fix casing of disposal flush sound
* More merge conflict fixes
* Fix a compiler warning.
* Remove popup invocation from buckle
* Remove showPopup parameter from InteractionChecks
* Remove unnecessary physics components
Fixes the physics system dying
* Replace PhysicsComponent usages with CollidableComponent
* Update existing code for the new controller system
* Change conveyors to use a VirtualController instead of teleporting the entity
* Remove visualizer 2d suffix and update physics code
* Transition code to new controller system
* Fix shuttles not moving
* Fix throwing
* Fix guns
* Change hands to use physics.Stop() and remove item fumble method
* Add syncing conveyor switches states
* Fix the recycler wanting to be a conveyor too hard
* Fix showwires > showsubfloor rename in mapping command
* Fix wifi air conveyors
* Fix test error
* Add showsubfloorforever command
Changes drawdepth of the relevant entities
* Disable opening the disposal unit interface while inside
* Add closing the disposal unit interface when getting inside
* Add closing the interface when the disposal unit component is removed
* Add removing entities on disposal unit component removal
* Delay disposal unit flush and fix serialization
* Implement pressure in disposal units
* Fix chain engaging a disposal unit
* Implement states to the disposal unit
* Fix missing imports from merge conflict
* Update Content.Server/GameObjects/Components/Conveyor/ConveyorComponent.cs
Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
* Address some reviews
* Fix za buildo
* Use container helper to detach disposables
* Make conveyors use the construction system
* Make conveyor groups and syncing sane
* Make flip flip
brave
* Add activate interface to conveyor switches
* Fix not removing the switch from its group when it's deleted
* Fix not registering conveyors and switches on initialize
* Stop using 0 as null
* Disconnect conveyors and switches when disposing of a group
* Make disposal units not able to be exited when flushing
* Make disposal units flush after a configurable 30 seconds
* Add handle and light layers to the disposal unit
* Merge engaging and flushing
* Update saltern.yml
* I love using 0 as null
* Make disposal unit visual layers make sense
* Remove duplicate remove method in disposal units and update light
* Replace DisposableComponent with disposal holders
* Fix disposal holders deleting their contents on deletion
* Account for disposal unit pressure in tests and make a failed flush autoengage
* Rename disposable to holder
* Fix junction connections
* Disable self insert and flush verbs when inside a disposal unit
* Fix spamming the engage button making the animation reset
* Make the recycler take materials into account properly
Fix cablestack1 not existing
* Merge conflict fixes
* Fix pipes not being saved anchored
* Change conveyors and groups to not use an id
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
2020-07-30 23:45:28 +02:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-07-06 14:27:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// trigger dragdropons on the targeted entity
|
2021-03-09 11:22:48 -08:00
|
|
|
RaiseLocalEvent(target.Uid, interactionArgs, false);
|
2020-07-06 14:27:03 -07:00
|
|
|
foreach (var dragDropOn in target.GetAllComponents<IDragDropOn>())
|
|
|
|
|
{
|
Add the trash man (#1367)
* Add disposal.rsi
* Rename disposal resource to disposal.rsi and create basic components
* Add disposal nets
* Add pushing entities along the disposal network
* Add disposal unit
* Unregister disposable component
* Add flush and selfinsert verbs to disposal unit
* Add gradual disposals movement
* Fix being able to walk through space for a while after exiting disposals
* Multiply disposals speed by 10
And fix early returns when moving an entity
* Rename Disposable component to InDisposals
* Remove DisposalNet and add on anchor events
* Remove anchored events, moved to interfaces
* Code cleanup
* Fix adjacent tubes' connections when a tube connects
* Fix jittery movement in disposals
* Remove Logger.Debug call
* Move disposals updates to InDisposalsComponent
* Fix adjacent connection valid directions check
* Disposal tubes now throw you out where they are facing
* Add disposal unit exit cooldown
* Set different disposal pipe sprite state depending on anchored value
* Add recycler
* Add recycler animation
* Add bloody texture to the recycler when grinding a living being
* Add PowerDevice component to the disposal unit
* Made the Recycler center on the grid
* Add disposal junction
* Add picking a random direction if junction is entered from the output side
* Add disposal flush and clang sounds
Taken from VGStation
* Move disposal flush and clang sound file names to exposedata
* Add disposalsmap.yml to test with
* Add summaries to DisposalUnit fields
* Add sideDegrees yaml property to disposal junctions
* Fix outdated usings
* Add conveyor resources
* Update RobustToolbox
* More merge fixes
Add conveyor collision masks
* Add ConveyorComponent
* Fix crash when reentering a body
* Merge branch 'master' into disposals-1147
* Reduce recycler bounds, set hard to false, add summary and expose "safe" to yaml
* Move IAnchored and IUnAnchored to AnchorableComponent
* Update power components and remove old disposals map
* Remove redundant sprite layers
* Add tile pry command
* Fix tilepry command
* Fix DisposalJunctionComponent missing a component reference
* Add anchor by radius command
* Add Y-Junctions
* Add disposal bend
* Add unanchor command
* Change DisposalJunction prototypes to specify their angles
* Fix disposal units being hidden below the floor
* Removed IAnhored and IUnAnchored interfaces
* Replace CanBeNull annotation with nullable reference types
* Update showwires command
* Add recycler recycling items
* Added angle and speed properties to ConveyorComponent
* Fix conveyort textures
* Add animation to the disposal unit
* Fix anchor and unanchor commands sometimes not finding any entities
* Fix not reading flush_time from disposal unit prototype
* Fix merge conflict wrong using
* Fix disposal, recycling and conveyor texture paths
Delete diverters
* Update visualizer names
* Add DisposableComponent, change drag and drop to work with multiple components
Ignoreinsideblocker client side for drag and drops, like on the server
Add more comments
* Add conveyor belts properly moving entities on top
* Anchorr wires
* Change conveyor bounds to 0.49
* Anchor catwalks, airlocks, gravity generators, low walls, wires and windows
* Add starting/stopping conveyors
* Add reversed conveyors
* Add conveyor switches
* Move InDisposalsComponent code to DisposableComponent
* Add ExitVector method to tubes
* Fix not updating tube references when disconnecting one
* Replace IoCManager call with dependency
* Add tubes disconnecting if they move too far apart from one another
* Move disposals action blocking to shared
* Add rotating and flipping pipes
* Make conveyor intersection calculations approximate
* Fix 1% chance of the server crashing when initializing the map
Happens when emergency lockers remove themselves
* Add disposal unit interface
* Make disposal units refuse items if not powered
* Make disposal tubes hide only when anchored
* Make disposal junction arrows visible to mere mortals
* Add disposal tubes breaking
* Add tubeconnections command
* Add missing verb attribute
* Add flipped disposal junction
* Add ids and linking to conveyors and switches
* Add conveyor switch prying and placing
* Add anchoring conveyor switches and refactor placing them
* Add missing serializable attributes from DisposableComponentState
* Make conveyor speed VV ReadWrite
* Change drawdepth of conveyors to FloorObjects
* Make conveyor anchored check consistent
* Remove anchoring interaction from switches
* Add conveyor switch id syncing and move switches slightly when pried
* Make entities in containers not able to be moved by conveyors
* Add conveyor and switches loose textures
* Merge conflict fixes
* Add disposal unit test
* Add flushing test to disposal unit test
* Add disposal unit flush fail test
* Add disposals to the saltern map
* Fix saltern disposal junctions
* Add power checks to the recycler
* Fix disposal unit placement in maintenance closet
* Remove disposal junctions from saltern
* Readd junctions to saltern
* Add the chemmaster to saltern at the request of Ike
* Move the chemistry disposal unit
* Fix casing of disposal flush sound
* More merge conflict fixes
* Fix a compiler warning.
* Remove popup invocation from buckle
* Remove showPopup parameter from InteractionChecks
* Remove unnecessary physics components
Fixes the physics system dying
* Replace PhysicsComponent usages with CollidableComponent
* Update existing code for the new controller system
* Change conveyors to use a VirtualController instead of teleporting the entity
* Remove visualizer 2d suffix and update physics code
* Transition code to new controller system
* Fix shuttles not moving
* Fix throwing
* Fix guns
* Change hands to use physics.Stop() and remove item fumble method
* Add syncing conveyor switches states
* Fix the recycler wanting to be a conveyor too hard
* Fix showwires > showsubfloor rename in mapping command
* Fix wifi air conveyors
* Fix test error
* Add showsubfloorforever command
Changes drawdepth of the relevant entities
* Disable opening the disposal unit interface while inside
* Add closing the disposal unit interface when getting inside
* Add closing the interface when the disposal unit component is removed
* Add removing entities on disposal unit component removal
* Delay disposal unit flush and fix serialization
* Implement pressure in disposal units
* Fix chain engaging a disposal unit
* Implement states to the disposal unit
* Fix missing imports from merge conflict
* Update Content.Server/GameObjects/Components/Conveyor/ConveyorComponent.cs
Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
* Address some reviews
* Fix za buildo
* Use container helper to detach disposables
* Make conveyors use the construction system
* Make conveyor groups and syncing sane
* Make flip flip
brave
* Add activate interface to conveyor switches
* Fix not removing the switch from its group when it's deleted
* Fix not registering conveyors and switches on initialize
* Stop using 0 as null
* Disconnect conveyors and switches when disposing of a group
* Make disposal units not able to be exited when flushing
* Make disposal units flush after a configurable 30 seconds
* Add handle and light layers to the disposal unit
* Merge engaging and flushing
* Update saltern.yml
* I love using 0 as null
* Make disposal unit visual layers make sense
* Remove duplicate remove method in disposal units and update light
* Replace DisposableComponent with disposal holders
* Fix disposal holders deleting their contents on deletion
* Account for disposal unit pressure in tests and make a failed flush autoengage
* Rename disposable to holder
* Fix junction connections
* Disable self insert and flush verbs when inside a disposal unit
* Fix spamming the engage button making the animation reset
* Make the recycler take materials into account properly
Fix cablestack1 not existing
* Merge conflict fixes
* Fix pipes not being saved anchored
* Change conveyors and groups to not use an id
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
2020-07-30 23:45:28 +02:00
|
|
|
if (dragDropOn.CanDragDropOn(interactionArgs) &&
|
|
|
|
|
dragDropOn.DragDropOn(interactionArgs))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-07-06 14:27:03 -07:00
|
|
|
}
|
|
|
|
|
}
|
2021-06-07 05:49:43 -07:00
|
|
|
#endregion
|
2020-07-06 14:27:03 -07:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
#region ActivateItemInWorld
|
2021-03-16 15:50:20 +01:00
|
|
|
private bool HandleActivateItemInWorld(ICommonSession? session, EntityCoordinates coords, EntityUid uid)
|
2018-08-22 01:19:47 -07:00
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
if (!ValidateClientInput(session, coords, uid, out var user))
|
2019-05-16 15:51:26 +02:00
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
Logger.InfoS("system.interaction", $"ActivateItemInWorld input validation failed");
|
2019-09-17 16:08:45 -07:00
|
|
|
return false;
|
2019-05-16 15:51:26 +02:00
|
|
|
}
|
2018-08-22 01:19:47 -07:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
if (!EntityManager.TryGetEntity(uid, out var used))
|
2019-09-17 16:08:45 -07:00
|
|
|
return false;
|
2019-05-16 15:51:26 +02:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
InteractionActivate(user, used);
|
2019-09-17 16:08:45 -07:00
|
|
|
return true;
|
2019-05-16 15:51:26 +02:00
|
|
|
}
|
2021-06-07 05:49:43 -07:00
|
|
|
#endregion
|
2018-08-16 15:57:11 -07:00
|
|
|
|
2021-03-16 15:50:20 +01:00
|
|
|
private bool HandleWideAttack(ICommonSession? session, EntityCoordinates coords, EntityUid uid)
|
2018-08-16 15:57:11 -07:00
|
|
|
{
|
2018-10-25 17:29:33 -07:00
|
|
|
// client sanitization
|
2021-06-07 05:49:43 -07:00
|
|
|
if (!ValidateClientInput(session, coords, uid, out var userEntity))
|
2019-09-06 10:13:48 -07:00
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
Logger.InfoS("system.interaction", $"WideAttack input validation failed");
|
2019-09-17 16:08:45 -07:00
|
|
|
return true;
|
2019-09-06 10:13:48 -07:00
|
|
|
}
|
|
|
|
|
|
2021-03-16 15:50:20 +01:00
|
|
|
if (userEntity.TryGetComponent(out CombatModeComponent? combatMode) && combatMode.IsInCombatMode)
|
2020-08-31 18:55:42 +02:00
|
|
|
DoAttack(userEntity, coords, true);
|
2020-01-26 03:38:51 +01:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-18 22:52:44 +10:00
|
|
|
/// <summary>
|
|
|
|
|
/// Entity will try and use their active hand at the target location.
|
|
|
|
|
/// Don't use for players
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="entity"></param>
|
|
|
|
|
/// <param name="coords"></param>
|
|
|
|
|
/// <param name="uid"></param>
|
2021-06-07 05:49:43 -07:00
|
|
|
internal void AiUseInteraction(IEntity entity, EntityCoordinates coords, EntityUid uid)
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
2021-05-12 13:42:18 +02:00
|
|
|
if (entity.HasComponent<ActorComponent>())
|
2020-06-18 22:52:44 +10:00
|
|
|
throw new InvalidOperationException();
|
|
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
UserInteraction(entity, coords, uid);
|
2020-06-18 22:52:44 +10:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
public bool HandleUseInteraction(ICommonSession? session, EntityCoordinates coords, EntityUid uid)
|
2020-01-26 03:38:51 +01:00
|
|
|
{
|
|
|
|
|
// client sanitization
|
2021-06-07 05:49:43 -07:00
|
|
|
if (!ValidateClientInput(session, coords, uid, out var userEntity))
|
2020-01-26 03:38:51 +01:00
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
Logger.InfoS("system.interaction", $"Use input validation failed");
|
2020-01-26 03:38:51 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
UserInteraction(userEntity, coords, uid);
|
2020-01-26 03:38:51 +01:00
|
|
|
|
2019-09-17 16:08:45 -07:00
|
|
|
return true;
|
2018-08-16 15:57:11 -07:00
|
|
|
}
|
|
|
|
|
|
2021-08-22 03:20:18 +10:00
|
|
|
public bool HandleAltUseInteraction(ICommonSession? session, EntityCoordinates coords, EntityUid uid)
|
|
|
|
|
{
|
|
|
|
|
// client sanitization
|
|
|
|
|
if (!ValidateClientInput(session, coords, uid, out var userEntity))
|
|
|
|
|
{
|
|
|
|
|
Logger.InfoS("system.interaction", $"Alt-use input validation failed");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UserInteraction(userEntity, coords, uid, altInteract : true );
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-16 15:50:20 +01:00
|
|
|
private bool HandleTryPullObject(ICommonSession? session, EntityCoordinates coords, EntityUid uid)
|
2020-07-27 00:54:32 +02:00
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
if (!ValidateClientInput(session, coords, uid, out var userEntity))
|
2020-07-27 00:54:32 +02:00
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
Logger.InfoS("system.interaction", $"TryPullObject input validation failed");
|
|
|
|
|
return true;
|
2020-07-27 00:54:32 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
if (userEntity.Uid == uid)
|
2020-07-27 00:54:32 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!EntityManager.TryGetEntity(uid, out var pulledObject))
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
if (!InRangeUnobstructed(userEntity, pulledObject, popup: true))
|
2020-07-27 00:54:32 +02:00
|
|
|
return false;
|
|
|
|
|
|
2021-10-05 14:29:03 +11:00
|
|
|
if (!pulledObject.TryGetComponent(out SharedPullableComponent? pull))
|
2020-07-27 00:54:32 +02:00
|
|
|
return false;
|
|
|
|
|
|
2021-10-04 16:10:54 +01:00
|
|
|
return _pullSystem.TogglePull(userEntity, pull);
|
2020-07-27 00:54:32 +02:00
|
|
|
}
|
|
|
|
|
|
2021-08-22 03:20:18 +10:00
|
|
|
/// <summary>
|
|
|
|
|
/// Resolves user interactions with objects.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
2021-09-26 15:18:45 +02:00
|
|
|
/// Checks Whether combat mode is enabled and whether the user can actually interact with the given entity.
|
2021-08-22 03:20:18 +10:00
|
|
|
/// </remarks>
|
|
|
|
|
/// <param name="altInteract">Whether to use default or alternative interactions (usually as a result of
|
|
|
|
|
/// alt+clicking). If combat mode is enabled, the alternative action is to perform the default non-combat
|
|
|
|
|
/// interaction. Having an item in the active hand also disables alternative interactions.</param>
|
|
|
|
|
public async void UserInteraction(IEntity user, EntityCoordinates coordinates, EntityUid clickedUid, bool altInteract = false )
|
2018-02-05 13:57:26 -06:00
|
|
|
{
|
2021-08-22 03:20:18 +10:00
|
|
|
// TODO COMBAT Consider using alt-interact for advanced combat? maybe alt-interact disarms?
|
|
|
|
|
if (!altInteract && user.TryGetComponent(out CombatModeComponent? combatMode) && combatMode.IsInCombatMode)
|
2019-05-16 15:51:26 +02:00
|
|
|
{
|
2021-09-26 15:18:45 +02:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
DoAttack(user, coordinates, false, clickedUid);
|
|
|
|
|
return;
|
2021-08-22 03:20:18 +10:00
|
|
|
|
2019-05-16 15:51:26 +02:00
|
|
|
}
|
2018-05-10 19:21:15 +02:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
if (!ValidateInteractAndFace(user, coordinates))
|
|
|
|
|
return;
|
|
|
|
|
|
2021-07-26 12:58:17 +02:00
|
|
|
if (!_actionBlockerSystem.CanInteract(user))
|
2018-03-09 10:59:03 -06:00
|
|
|
return;
|
2019-05-16 15:51:26 +02:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
// Get entity clicked upon from UID if valid UID, if not assume no entity clicked upon and null
|
|
|
|
|
EntityManager.TryGetEntity(clickedUid, out var target);
|
|
|
|
|
|
|
|
|
|
// Check if interacted entity is in the same container, the direct child, or direct parent of the user.
|
|
|
|
|
if (target != null && !user.IsInSameOrParentContainer(target))
|
2018-02-05 13:57:26 -06:00
|
|
|
{
|
2019-05-16 15:51:26 +02:00
|
|
|
Logger.WarningS("system.interaction",
|
2021-06-07 05:49:43 -07:00
|
|
|
$"User entity named {user.Name} clicked on object {target.Name} that isn't the parent, child, or in the same container");
|
2018-02-05 13:57:26 -06:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-13 11:58:44 +02:00
|
|
|
// Verify user has a hand, and find what object they are currently holding in their active hand
|
2021-06-07 05:49:43 -07:00
|
|
|
if (!user.TryGetComponent<IHandsComponent>(out var hands))
|
2018-02-05 13:57:26 -06:00
|
|
|
return;
|
2018-03-09 10:59:03 -06:00
|
|
|
|
2018-11-11 11:32:05 -08:00
|
|
|
var item = hands.GetActiveHand?.Owner;
|
2018-03-09 10:59:03 -06:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
// TODO: Replace with body interaction range when we get something like arm length or telekinesis or something.
|
|
|
|
|
var inRangeUnobstructed = user.InRangeUnobstructed(coordinates, ignoreInsideBlocker: true);
|
|
|
|
|
if (target == null || !inRangeUnobstructed)
|
2020-07-07 01:40:08 +02:00
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
if (item == null)
|
2020-07-08 15:37:18 +02:00
|
|
|
return;
|
2019-05-16 15:51:26 +02:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
if (!await InteractUsingRanged(user, item, target, coordinates, inRangeUnobstructed) &&
|
|
|
|
|
!inRangeUnobstructed)
|
2019-05-16 15:51:26 +02:00
|
|
|
{
|
2021-07-10 10:14:06 +02:00
|
|
|
var message = Loc.GetString("interaction-system-user-interaction-cannot-reach");
|
2021-06-07 05:49:43 -07:00
|
|
|
user.PopupMessage(message);
|
2019-05-16 15:51:26 +02:00
|
|
|
}
|
|
|
|
|
|
2018-04-22 06:11:38 -05:00
|
|
|
return;
|
|
|
|
|
}
|
2021-06-07 05:49:43 -07:00
|
|
|
else
|
2018-02-05 13:57:26 -06:00
|
|
|
{
|
2021-08-22 03:20:18 +10:00
|
|
|
// We are close to the nearby object.
|
|
|
|
|
if (altInteract)
|
2021-10-05 14:29:03 +11:00
|
|
|
// Perform alternative interactions, using context menu verbs.
|
2021-08-22 03:20:18 +10:00
|
|
|
AltInteract(user, target);
|
|
|
|
|
else if (item != null && item != target)
|
|
|
|
|
// We are performing a standard interaction with an item, and the target isn't the same as the item
|
|
|
|
|
// currently in our hand. We will use the item in our hand on the nearby object via InteractUsing
|
2021-06-07 05:49:43 -07:00
|
|
|
await InteractUsing(user, item, target, coordinates);
|
2021-08-22 03:20:18 +10:00
|
|
|
else if (item == null)
|
|
|
|
|
// Since our hand is empty we will use InteractHand/Activate
|
2021-06-07 05:49:43 -07:00
|
|
|
InteractHand(user, target);
|
2018-02-05 13:57:26 -06:00
|
|
|
}
|
2021-06-07 05:49:43 -07:00
|
|
|
}
|
2018-05-10 19:21:15 +02:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
private bool ValidateInteractAndFace(IEntity user, EntityCoordinates coordinates)
|
|
|
|
|
{
|
2021-09-13 11:58:44 +02:00
|
|
|
// Verify user is on the same map as the entity they clicked on
|
2021-06-07 05:49:43 -07:00
|
|
|
if (coordinates.GetMapId(_entityManager) != user.Transform.MapID)
|
2018-02-05 13:57:26 -06:00
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
Logger.WarningS("system.interaction",
|
2021-09-13 11:58:44 +02:00
|
|
|
$"User entity named {user.Name} clicked on a map they aren't located on");
|
2021-06-07 05:49:43 -07:00
|
|
|
return false;
|
2018-03-09 10:59:03 -06:00
|
|
|
}
|
2021-06-07 05:49:43 -07:00
|
|
|
|
2021-11-02 18:38:47 +00:00
|
|
|
_rotateToFaceSystem.TryFaceCoordinates(user, coordinates.ToMapPos(EntityManager));
|
2021-06-07 05:49:43 -07:00
|
|
|
|
|
|
|
|
return true;
|
2018-03-09 10:59:03 -06:00
|
|
|
}
|
|
|
|
|
|
2018-02-05 13:57:26 -06:00
|
|
|
/// <summary>
|
|
|
|
|
/// Uses an empty hand on an entity
|
2020-05-23 17:23:25 +02:00
|
|
|
/// Finds components with the InteractHand interface and calls their function
|
2021-06-07 05:49:43 -07:00
|
|
|
/// NOTE: Does not have an InRangeUnobstructed check
|
2018-02-05 13:57:26 -06:00
|
|
|
/// </summary>
|
2021-06-07 05:49:43 -07:00
|
|
|
public void InteractHand(IEntity user, IEntity target)
|
2018-02-05 13:57:26 -06:00
|
|
|
{
|
2021-07-26 12:58:17 +02:00
|
|
|
if (!_actionBlockerSystem.CanInteract(user))
|
2021-06-07 05:49:43 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// all interactions should only happen when in range / unobstructed, so no range check is needed
|
|
|
|
|
var message = new InteractHandEvent(user, target);
|
|
|
|
|
RaiseLocalEvent(target.Uid, message);
|
2019-05-16 15:51:26 +02:00
|
|
|
if (message.Handled)
|
2019-04-20 16:18:16 -07:00
|
|
|
return;
|
|
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
var interactHandEventArgs = new InteractHandEventArgs(user, target);
|
2018-02-05 13:57:26 -06:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
var interactHandComps = target.GetAllComponents<IInteractHand>().ToList();
|
|
|
|
|
foreach (var interactHandComp in interactHandComps)
|
2018-02-05 13:57:26 -06:00
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
// If an InteractHand returns a status completion we finish our interaction
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning disable 618
|
2021-06-07 05:49:43 -07:00
|
|
|
if (interactHandComp.InteractHand(interactHandEventArgs))
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning restore 618
|
2021-06-07 05:49:43 -07:00
|
|
|
return;
|
2018-02-05 13:57:26 -06:00
|
|
|
}
|
|
|
|
|
|
2019-05-16 15:51:26 +02:00
|
|
|
// Else we run Activate.
|
2021-06-07 05:49:43 -07:00
|
|
|
InteractionActivate(user, target);
|
2018-02-05 13:57:26 -06:00
|
|
|
}
|
|
|
|
|
|
2018-03-09 10:59:03 -06:00
|
|
|
/// <summary>
|
2021-06-07 05:49:43 -07:00
|
|
|
/// Will have two behaviors, either "uses" the used entity at range on the target entity if it is capable of accepting that action
|
|
|
|
|
/// Or it will use the used entity itself on the position clicked, regardless of what was there
|
2018-03-09 10:59:03 -06:00
|
|
|
/// </summary>
|
2021-06-07 05:49:43 -07:00
|
|
|
public async Task<bool> InteractUsingRanged(IEntity user, IEntity used, IEntity? target, EntityCoordinates clickLocation, bool inRangeUnobstructed)
|
2018-03-09 10:59:03 -06:00
|
|
|
{
|
2021-10-28 13:19:38 +02:00
|
|
|
if (InteractDoBefore(user, used, inRangeUnobstructed ? target : null, clickLocation, false))
|
2021-07-31 03:14:00 +02:00
|
|
|
return true;
|
|
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
if (target != null)
|
|
|
|
|
{
|
|
|
|
|
var rangedMsg = new RangedInteractEvent(user, used, target, clickLocation);
|
|
|
|
|
RaiseLocalEvent(target.Uid, rangedMsg);
|
|
|
|
|
if (rangedMsg.Handled)
|
|
|
|
|
return true;
|
2019-04-20 16:18:16 -07:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
var rangedInteractions = target.GetAllComponents<IRangedInteract>().ToList();
|
|
|
|
|
var rangedInteractionEventArgs = new RangedInteractEventArgs(user, used, clickLocation);
|
2018-03-09 10:59:03 -06:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
// See if we have a ranged interaction
|
|
|
|
|
foreach (var t in rangedInteractions)
|
2018-03-09 10:59:03 -06:00
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
// If an InteractUsingRanged returns a status completion we finish our interaction
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning disable 618
|
2021-06-07 05:49:43 -07:00
|
|
|
if (t.RangedInteract(rangedInteractionEventArgs))
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning restore 618
|
2021-06-07 05:49:43 -07:00
|
|
|
return true;
|
2018-03-09 10:59:03 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-31 03:14:00 +02:00
|
|
|
return await InteractDoAfter(user, used, inRangeUnobstructed ? target : null, clickLocation, false);
|
2021-02-03 14:05:31 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
public void DoAttack(IEntity user, EntityCoordinates coordinates, bool wideAttack, EntityUid targetUid = default)
|
2021-02-03 14:05:31 +01:00
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
if (!ValidateInteractAndFace(user, coordinates))
|
|
|
|
|
return;
|
2019-06-30 00:01:41 +02:00
|
|
|
|
2021-07-26 12:58:17 +02:00
|
|
|
if (!_actionBlockerSystem.CanAttack(user))
|
2019-06-30 00:01:41 +02:00
|
|
|
return;
|
|
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
IEntity? targetEnt = null;
|
2021-01-23 17:50:48 +01:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
if (!wideAttack)
|
2019-06-30 00:01:41 +02:00
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
// Get entity clicked upon from UID if valid UID, if not assume no entity clicked upon and null
|
|
|
|
|
EntityManager.TryGetEntity(targetUid, out targetEnt);
|
2019-06-30 00:01:41 +02:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
// Check if interacted entity is in the same container, the direct child, or direct parent of the user.
|
|
|
|
|
if (targetEnt != null && !user.IsInSameOrParentContainer(targetEnt))
|
2021-05-17 02:31:10 -07:00
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
Logger.WarningS("system.interaction",
|
|
|
|
|
$"User entity named {user.Name} clicked on object {targetEnt.Name} that isn't the parent, child, or in the same container");
|
2021-05-17 02:31:10 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2021-06-07 05:49:43 -07:00
|
|
|
|
|
|
|
|
// TODO: Replace with body attack range when we get something like arm length or telekinesis or something.
|
|
|
|
|
if (!user.InRangeUnobstructed(coordinates, ignoreInsideBlocker: true))
|
|
|
|
|
return;
|
2021-05-17 02:31:10 -07:00
|
|
|
}
|
|
|
|
|
|
2021-09-13 11:58:44 +02:00
|
|
|
// Verify user has a hand, and find what object they are currently holding in their active hand
|
2021-06-07 05:49:43 -07:00
|
|
|
if (user.TryGetComponent<IHandsComponent>(out var hands))
|
2019-06-30 00:01:41 +02:00
|
|
|
{
|
2020-06-21 18:31:56 -07:00
|
|
|
var item = hands.GetActiveHand?.Owner;
|
|
|
|
|
|
|
|
|
|
if (item != null)
|
|
|
|
|
{
|
2021-06-05 18:05:57 +02:00
|
|
|
if (wideAttack)
|
|
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
var ev = new WideAttackEvent(item, user, coordinates);
|
2021-06-05 18:05:57 +02:00
|
|
|
RaiseLocalEvent(item.Uid, ev, false);
|
|
|
|
|
|
2021-06-21 02:21:20 -07:00
|
|
|
if (ev.Handled)
|
2021-06-05 18:05:57 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2021-06-05 00:20:52 -07:00
|
|
|
else
|
2021-06-05 18:05:57 +02:00
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
var ev = new ClickAttackEvent(item, user, coordinates, targetUid);
|
2021-06-05 18:05:57 +02:00
|
|
|
RaiseLocalEvent(item.Uid, ev, false);
|
|
|
|
|
|
2021-06-21 02:21:20 -07:00
|
|
|
if (ev.Handled)
|
2021-06-05 18:05:57 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2020-06-21 18:31:56 -07:00
|
|
|
}
|
2021-06-07 05:49:43 -07:00
|
|
|
else if (!wideAttack &&
|
|
|
|
|
(targetEnt != null || EntityManager.TryGetEntity(targetUid, out targetEnt)) &&
|
|
|
|
|
targetEnt.HasComponent<ItemComponent>())
|
2020-10-12 13:37:41 +02:00
|
|
|
{
|
|
|
|
|
// We pick up items if our hand is empty, even if we're in combat mode.
|
2021-06-07 05:49:43 -07:00
|
|
|
InteractHand(user, targetEnt);
|
|
|
|
|
return;
|
2020-10-12 13:37:41 +02:00
|
|
|
}
|
2019-06-30 00:01:41 +02:00
|
|
|
}
|
2021-06-05 18:05:57 +02:00
|
|
|
|
|
|
|
|
// TODO: Make this saner?
|
|
|
|
|
// Attempt to do unarmed combat. We don't check for handled just because at this point it doesn't matter.
|
2021-06-21 02:21:20 -07:00
|
|
|
if (wideAttack)
|
2021-06-07 05:49:43 -07:00
|
|
|
RaiseLocalEvent(user.Uid, new WideAttackEvent(user, user, coordinates), false);
|
2021-06-05 18:05:57 +02:00
|
|
|
else
|
2021-06-07 05:49:43 -07:00
|
|
|
RaiseLocalEvent(user.Uid, new ClickAttackEvent(user, user, coordinates, targetUid), false);
|
2019-06-30 00:01:41 +02:00
|
|
|
}
|
2018-02-05 13:57:26 -06:00
|
|
|
}
|
|
|
|
|
}
|