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;
|
|
|
|
|
using Content.Server.Timing;
|
|
|
|
|
using Content.Shared.ActionBlocker;
|
|
|
|
|
using Content.Shared.DragDrop;
|
|
|
|
|
using Content.Shared.Hands;
|
|
|
|
|
using Content.Shared.Hands.Components;
|
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;
|
|
|
|
|
using Content.Shared.Inventory;
|
2021-09-26 15:18:45 +02:00
|
|
|
using Content.Shared.Popups;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Rotatable;
|
|
|
|
|
using Content.Shared.Throwing;
|
2021-08-22 03:20:18 +10:00
|
|
|
using Content.Shared.Verbs;
|
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-05-09 10:09:14 +02:00
|
|
|
[Dependency] private readonly IRobustRandom _random = 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!;
|
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
|
|
|
}
|
2018-08-22 01:19:47 -07:00
|
|
|
|
2020-01-17 18:41:47 -08:00
|
|
|
/// <summary>
|
2020-12-13 14:28:20 -08:00
|
|
|
/// Activates the IActivate behavior of an object
|
2020-01-17 18:41:47 -08:00
|
|
|
/// Verifies that the user is capable of doing the use interaction first
|
|
|
|
|
/// </summary>
|
2021-03-16 15:50:20 +01:00
|
|
|
public void TryInteractionActivate(IEntity? user, IEntity? used)
|
2020-01-17 18:41:47 -08:00
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
if (user == null || used == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
InteractionActivate(user, used);
|
2020-01-17 18:41:47 -08:00
|
|
|
}
|
|
|
|
|
|
2019-05-16 15:51:26 +02:00
|
|
|
private void InteractionActivate(IEntity user, IEntity used)
|
|
|
|
|
{
|
2021-10-02 11:02:02 +02:00
|
|
|
if (used.TryGetComponent<UseDelayComponent>(out var delayComponent))
|
|
|
|
|
{
|
|
|
|
|
if (delayComponent.ActiveDelay)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
delayComponent.BeginDelay();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-26 12:58:17 +02:00
|
|
|
if (!_actionBlockerSystem.CanInteract(user) || ! _actionBlockerSystem.CanUse(user))
|
2021-06-07 05:49:43 -07:00
|
|
|
return;
|
|
|
|
|
|
2021-06-19 10:03:24 +02:00
|
|
|
// all activates should only fire when in range / unobstructed
|
2021-06-07 05:49:43 -07:00
|
|
|
if (!InRangeUnobstructed(user, used, ignoreInsideBlocker: true, popup: true))
|
|
|
|
|
return;
|
|
|
|
|
|
2021-05-22 21:06:40 -07:00
|
|
|
var activateMsg = new ActivateInWorldEvent(user, used);
|
2021-04-01 00:04:56 -07:00
|
|
|
RaiseLocalEvent(used.Uid, activateMsg);
|
2019-05-16 15:51:26 +02:00
|
|
|
if (activateMsg.Handled)
|
2019-04-20 16:18:16 -07:00
|
|
|
return;
|
|
|
|
|
|
2021-03-16 15:50:20 +01:00
|
|
|
if (!used.TryGetComponent(out IActivate? activateComp))
|
2019-04-20 16:18:16 -07:00
|
|
|
return;
|
|
|
|
|
|
2021-03-15 21:55:49 +01:00
|
|
|
var activateEventArgs = new ActivateEventArgs(user, used);
|
2021-06-07 05:49:43 -07:00
|
|
|
activateComp.Activate(activateEventArgs);
|
2018-08-16 15:57:11 -07: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-03-16 15:50:20 +01:00
|
|
|
if (!pulledObject.TryGetComponent(out PullableComponent? 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)
|
|
|
|
|
// We are trying to use alternative interactions. Perform alternative interactions, using context
|
|
|
|
|
// menu verbs.
|
|
|
|
|
|
|
|
|
|
// Verbs can be triggered with an item in the hand, but currently there are no verbs that depend on
|
|
|
|
|
// the currently held item. Maybe this if statement should be changed to
|
|
|
|
|
// (altInteract && (item == null || item == target)).
|
|
|
|
|
// Note that item == target will happen when alt-clicking the item currently in your hands.
|
|
|
|
|
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
|
|
|
|
|
|
|
|
FaceClickCoordinates(user, coordinates);
|
|
|
|
|
|
|
|
|
|
return true;
|
2018-03-09 10:59:03 -06:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
private void FaceClickCoordinates(IEntity user, EntityCoordinates coordinates)
|
2021-01-23 17:50:48 +01:00
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
var diff = coordinates.ToMapPos(EntityManager) - user.Transform.MapPosition.Position;
|
2021-05-27 11:51:14 +01:00
|
|
|
if (diff.LengthSquared <= 0.01f)
|
|
|
|
|
return;
|
|
|
|
|
var diffAngle = Angle.FromWorldVec(diff);
|
2021-07-26 12:58:17 +02:00
|
|
|
if (_actionBlockerSystem.CanChangeDirection(user))
|
2021-01-23 17:50:48 +01:00
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
user.Transform.WorldRotation = diffAngle;
|
2021-05-27 11:51:14 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
if (user.TryGetComponent(out BuckleComponent? buckle) && (buckle.BuckledTo != null))
|
2021-01-23 17:50:48 +01:00
|
|
|
{
|
2021-05-27 11:51:14 +01:00
|
|
|
// We're buckled to another object. Is that object rotatable?
|
|
|
|
|
if (buckle.BuckledTo!.Owner.TryGetComponent(out SharedRotatableComponent? rotatable) && rotatable.RotateWhileAnchored)
|
|
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
// Note the assumption that even if unanchored, user can only do spinnychair with an "independent wheel".
|
|
|
|
|
// (Since the user being buckled to it holds it down with their weight.)
|
2021-05-27 11:51:14 +01:00
|
|
|
// This is logically equivalent to RotateWhileAnchored.
|
|
|
|
|
// Barstools and office chairs have independent wheels, while regular chairs don't.
|
|
|
|
|
rotatable.Owner.Transform.LocalRotation = diffAngle;
|
|
|
|
|
}
|
2021-01-23 17:50:48 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-09 10:59:03 -06:00
|
|
|
/// <summary>
|
2020-05-23 17:23:25 +02:00
|
|
|
/// We didn't click on any entity, try doing an AfterInteract on the click location
|
2018-03-09 10:59:03 -06:00
|
|
|
/// </summary>
|
2021-06-07 05:49:43 -07:00
|
|
|
private async Task<bool> InteractDoAfter(IEntity user, IEntity used, IEntity? target, EntityCoordinates clickLocation, bool canReach)
|
2018-03-09 10:59:03 -06:00
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
var afterInteractEvent = new AfterInteractEvent(user, used, target, clickLocation, canReach);
|
|
|
|
|
RaiseLocalEvent(used.Uid, afterInteractEvent, false);
|
|
|
|
|
if (afterInteractEvent.Handled)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
var afterInteractEventArgs = new AfterInteractEventArgs(user, clickLocation, target, canReach);
|
|
|
|
|
var afterInteracts = used.GetAllComponents<IAfterInteract>().OrderByDescending(x => x.Priority).ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var afterInteract in afterInteracts)
|
2019-05-16 15:51:26 +02:00
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
if (await afterInteract.AfterInteract(afterInteractEventArgs))
|
|
|
|
|
return true;
|
2019-05-16 15:51:26 +02:00
|
|
|
}
|
2019-04-20 16:18:16 -07:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
return false;
|
2018-02-05 13:57:26 -06:00
|
|
|
}
|
|
|
|
|
|
2021-07-31 03:14:00 +02:00
|
|
|
private async Task<bool> InteractDoBefore(
|
|
|
|
|
IEntity user,
|
|
|
|
|
IEntity used,
|
|
|
|
|
IEntity? target,
|
|
|
|
|
EntityCoordinates clickLocation,
|
|
|
|
|
bool canReach)
|
|
|
|
|
{
|
|
|
|
|
var ev = new BeforeInteractEvent(user, used, target, clickLocation, canReach);
|
|
|
|
|
RaiseLocalEvent(used.Uid, ev, false);
|
|
|
|
|
return ev.Handled;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-05 13:57:26 -06:00
|
|
|
/// <summary>
|
2021-06-07 05:49:43 -07:00
|
|
|
/// Uses a item/object on an entity
|
2020-05-23 17:23:25 +02:00
|
|
|
/// Finds components with the InteractUsing 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 async Task InteractUsing(IEntity user, IEntity used, IEntity target, EntityCoordinates clickLocation)
|
2018-02-05 13:57:26 -06:00
|
|
|
{
|
2021-07-26 12:58:17 +02:00
|
|
|
if (!_actionBlockerSystem.CanInteract(user))
|
2019-04-20 16:18:16 -07:00
|
|
|
return;
|
|
|
|
|
|
2021-07-31 03:14:00 +02:00
|
|
|
if (await InteractDoBefore(user, used, target, clickLocation, true))
|
|
|
|
|
return;
|
|
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
// all interactions should only happen when in range / unobstructed, so no range check is needed
|
|
|
|
|
var interactUsingEvent = new InteractUsingEvent(user, used, target, clickLocation);
|
|
|
|
|
RaiseLocalEvent(target.Uid, interactUsingEvent);
|
|
|
|
|
if (interactUsingEvent.Handled)
|
|
|
|
|
return;
|
2018-02-05 13:57:26 -06:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
var interactUsingEventArgs = new InteractUsingEventArgs(user, clickLocation, used, target);
|
2020-04-29 13:43:07 +02:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
var interactUsings = target.GetAllComponents<IInteractUsing>().OrderByDescending(x => x.Priority);
|
|
|
|
|
foreach (var interactUsing in interactUsings)
|
2019-05-16 15:51:26 +02:00
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
// If an InteractUsing returns a status completion we finish our interaction
|
|
|
|
|
if (await interactUsing.InteractUsing(interactUsingEventArgs))
|
|
|
|
|
return;
|
2019-05-16 15:51:26 +02:00
|
|
|
}
|
2018-04-05 17:32:51 -05:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
// If we aren't directly interacting with the nearby object, lets see if our item has an after interact we can do
|
|
|
|
|
await InteractDoAfter(user, used, target, clickLocation, true);
|
2018-02-05 13:57:26 -06:00
|
|
|
}
|
|
|
|
|
|
2021-08-22 03:20:18 +10:00
|
|
|
/// <summary>
|
2021-09-26 15:18:45 +02:00
|
|
|
/// Alternative interactions on an entity.
|
2021-08-22 03:20:18 +10:00
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Uses the context menu verb list, and acts out the first verb marked as an alternative interaction. Note
|
|
|
|
|
/// that this does not have any checks to see whether this interaction is valid, as these are all done in <see
|
|
|
|
|
/// cref="UserInteraction(IEntity, EntityCoordinates, EntityUid, bool)"/>
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public void AltInteract(IEntity user, IEntity target)
|
|
|
|
|
{
|
|
|
|
|
// TODO VERB SYSTEM when ECS-ing verbs and re-writing VerbUtility.GetVerbs, maybe sort verbs by some
|
|
|
|
|
// priority property, such that which verbs appear first is more predictable?.
|
|
|
|
|
|
|
|
|
|
// Iterate through list of verbs that apply to target. We do not include global verbs here. If in the future
|
|
|
|
|
// alt click should also support global verbs, this needs to be changed.
|
|
|
|
|
foreach (var (component, verb) in VerbUtility.GetVerbs(target))
|
|
|
|
|
{
|
|
|
|
|
// Check that the verb marked as an alternative interaction?
|
|
|
|
|
if (!verb.AlternativeInteraction)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Can the verb be acted out?
|
|
|
|
|
if (!VerbUtility.VerbAccessChecks(user, target, verb))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Is the verb currently enabled?
|
|
|
|
|
var verbData = verb.GetData(user, component);
|
|
|
|
|
if (verbData.IsInvisible || verbData.IsDisabled)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Act out the verb. Note that, if there is more than one AlternativeInteraction verb, only the first
|
|
|
|
|
// one is activated. The priority is effectively determined by the order in which VerbUtility.GetVerbs()
|
|
|
|
|
// returns the verbs.
|
|
|
|
|
verb.Activate(user, component);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
if (interactHandComp.InteractHand(interactHandEventArgs))
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
#region Hands
|
|
|
|
|
#region Use
|
2018-04-22 06:11:38 -05:00
|
|
|
/// <summary>
|
2020-12-13 14:28:20 -08:00
|
|
|
/// Activates the IUse behaviors of an entity
|
2018-04-22 06:11:38 -05:00
|
|
|
/// Verifies that the user is capable of doing the use interaction first
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="user"></param>
|
|
|
|
|
/// <param name="used"></param>
|
2021-08-22 03:20:18 +10:00
|
|
|
public void TryUseInteraction(IEntity user, IEntity used, bool altInteract = false)
|
2018-04-22 06:11:38 -05:00
|
|
|
{
|
2021-07-26 12:58:17 +02:00
|
|
|
if (user != null && used != null && _actionBlockerSystem.CanUse(user))
|
2018-04-22 06:11:38 -05:00
|
|
|
{
|
2021-08-22 03:20:18 +10:00
|
|
|
if (altInteract)
|
|
|
|
|
AltInteract(user, used);
|
|
|
|
|
else
|
|
|
|
|
UseInteraction(user, used);
|
2018-04-22 06:11:38 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-05 13:57:26 -06:00
|
|
|
/// <summary>
|
2020-12-13 14:28:20 -08:00
|
|
|
/// Activates the IUse behaviors of an entity without first checking
|
|
|
|
|
/// if the user is capable of doing the use interaction.
|
2018-02-05 13:57:26 -06:00
|
|
|
/// </summary>
|
2019-04-20 16:18:16 -07:00
|
|
|
public void UseInteraction(IEntity user, IEntity used)
|
2018-02-05 13:57:26 -06:00
|
|
|
{
|
2020-01-22 17:08:14 -05:00
|
|
|
if (used.TryGetComponent<UseDelayComponent>(out var delayComponent))
|
|
|
|
|
{
|
2020-01-26 03:38:51 +01:00
|
|
|
if (delayComponent.ActiveDelay)
|
2020-01-22 19:37:07 -05:00
|
|
|
return;
|
2021-10-02 11:02:02 +02:00
|
|
|
|
|
|
|
|
delayComponent.BeginDelay();
|
2020-01-22 17:08:14 -05:00
|
|
|
}
|
|
|
|
|
|
2021-05-22 21:06:40 -07:00
|
|
|
var useMsg = new UseInHandEvent(user, used);
|
2021-03-09 11:22:48 -08:00
|
|
|
RaiseLocalEvent(used.Uid, useMsg);
|
2019-05-16 15:51:26 +02:00
|
|
|
if (useMsg.Handled)
|
2019-04-20 16:18:16 -07:00
|
|
|
return;
|
|
|
|
|
|
2019-05-16 15:51:26 +02:00
|
|
|
var uses = used.GetAllComponents<IUse>().ToList();
|
2018-02-05 13:57:26 -06:00
|
|
|
|
2019-05-16 15:51:26 +02:00
|
|
|
// Try to use item on any components which have the interface
|
|
|
|
|
foreach (var use in uses)
|
2018-02-05 13:57:26 -06:00
|
|
|
{
|
2021-06-07 05:49:43 -07:00
|
|
|
// If a Use returns a status completion we finish our interaction
|
2021-03-15 21:55:49 +01:00
|
|
|
if (use.UseEntity(new UseEntityEventArgs(user)))
|
2018-02-05 13:57:26 -06:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-07 05:49:43 -07:00
|
|
|
#endregion
|
2018-03-09 10:59:03 -06:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
#region Throw
|
2019-07-18 23:33:02 +02:00
|
|
|
/// <summary>
|
2019-11-25 00:11:47 +01:00
|
|
|
/// Activates the Throw behavior of an object
|
|
|
|
|
/// Verifies that the user is capable of doing the throw interaction first
|
2019-07-18 23:33:02 +02:00
|
|
|
/// </summary>
|
|
|
|
|
public bool TryThrowInteraction(IEntity user, IEntity item)
|
|
|
|
|
{
|
2021-07-26 12:58:17 +02:00
|
|
|
if (user == null || item == null || !_actionBlockerSystem.CanThrow(user)) return false;
|
2019-07-18 23:33:02 +02:00
|
|
|
|
|
|
|
|
ThrownInteraction(user, item);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Calls Thrown on all components that implement the IThrown interface
|
|
|
|
|
/// on an entity that has been thrown.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void ThrownInteraction(IEntity user, IEntity thrown)
|
|
|
|
|
{
|
2021-05-22 21:06:40 -07:00
|
|
|
var throwMsg = new ThrownEvent(user, thrown);
|
2021-03-09 11:22:48 -08:00
|
|
|
RaiseLocalEvent(thrown.Uid, throwMsg);
|
2019-07-18 23:33:02 +02:00
|
|
|
if (throwMsg.Handled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var comps = thrown.GetAllComponents<IThrown>().ToList();
|
2021-03-08 04:09:59 +11:00
|
|
|
var args = new ThrownEventArgs(user);
|
2019-07-18 23:33:02 +02:00
|
|
|
|
|
|
|
|
// Call Thrown on all components that implement the interface
|
|
|
|
|
foreach (var comp in comps)
|
|
|
|
|
{
|
2021-03-08 04:09:59 +11:00
|
|
|
comp.Thrown(args);
|
2020-09-22 15:34:30 +02:00
|
|
|
}
|
|
|
|
|
}
|
2021-06-07 05:49:43 -07:00
|
|
|
#endregion
|
2020-09-22 15:34:30 +02:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
#region Equip
|
2020-04-21 14:38:35 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Calls Equipped on all components that implement the IEquipped interface
|
|
|
|
|
/// on an entity that has been equipped.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void EquippedInteraction(IEntity user, IEntity equipped, EquipmentSlotDefines.Slots slot)
|
|
|
|
|
{
|
2021-05-22 21:06:40 -07:00
|
|
|
var equipMsg = new EquippedEvent(user, equipped, slot);
|
2021-03-09 11:22:48 -08:00
|
|
|
RaiseLocalEvent(equipped.Uid, equipMsg);
|
2020-04-21 14:38:35 +02:00
|
|
|
if (equipMsg.Handled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var comps = equipped.GetAllComponents<IEquipped>().ToList();
|
|
|
|
|
|
|
|
|
|
// Call Thrown on all components that implement the interface
|
|
|
|
|
foreach (var comp in comps)
|
|
|
|
|
{
|
|
|
|
|
comp.Equipped(new EquippedEventArgs(user, slot));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Calls Unequipped on all components that implement the IUnequipped interface
|
|
|
|
|
/// on an entity that has been equipped.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void UnequippedInteraction(IEntity user, IEntity equipped, EquipmentSlotDefines.Slots slot)
|
|
|
|
|
{
|
2021-05-22 21:06:40 -07:00
|
|
|
var unequipMsg = new UnequippedEvent(user, equipped, slot);
|
2021-03-09 11:22:48 -08:00
|
|
|
RaiseLocalEvent(equipped.Uid, unequipMsg);
|
2020-04-21 14:38:35 +02:00
|
|
|
if (unequipMsg.Handled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var comps = equipped.GetAllComponents<IUnequipped>().ToList();
|
|
|
|
|
|
|
|
|
|
// Call Thrown on all components that implement the interface
|
|
|
|
|
foreach (var comp in comps)
|
|
|
|
|
{
|
|
|
|
|
comp.Unequipped(new UnequippedEventArgs(user, slot));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
#region Equip Hand
|
2020-12-13 14:28:20 -08:00
|
|
|
/// <summary>
|
|
|
|
|
/// Calls EquippedHand on all components that implement the IEquippedHand interface
|
|
|
|
|
/// on an item.
|
|
|
|
|
/// </summary>
|
2021-06-21 02:21:20 -07:00
|
|
|
public void EquippedHandInteraction(IEntity user, IEntity item, HandState hand)
|
2020-12-13 14:28:20 -08:00
|
|
|
{
|
2021-05-22 21:06:40 -07:00
|
|
|
var equippedHandMessage = new EquippedHandEvent(user, item, hand);
|
2021-03-09 11:22:48 -08:00
|
|
|
RaiseLocalEvent(item.Uid, equippedHandMessage);
|
2020-12-13 14:28:20 -08:00
|
|
|
if (equippedHandMessage.Handled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var comps = item.GetAllComponents<IEquippedHand>().ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var comp in comps)
|
|
|
|
|
{
|
|
|
|
|
comp.EquippedHand(new EquippedHandEventArgs(user, hand));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Calls UnequippedHand on all components that implement the IUnequippedHand interface
|
|
|
|
|
/// on an item.
|
|
|
|
|
/// </summary>
|
2021-06-21 02:21:20 -07:00
|
|
|
public void UnequippedHandInteraction(IEntity user, IEntity item, HandState hand)
|
2020-12-13 14:28:20 -08:00
|
|
|
{
|
2021-05-22 21:06:40 -07:00
|
|
|
var unequippedHandMessage = new UnequippedHandEvent(user, item, hand);
|
2021-03-09 11:22:48 -08:00
|
|
|
RaiseLocalEvent(item.Uid, unequippedHandMessage);
|
2020-12-13 14:28:20 -08:00
|
|
|
if (unequippedHandMessage.Handled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var comps = item.GetAllComponents<IUnequippedHand>().ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var comp in comps)
|
|
|
|
|
{
|
|
|
|
|
comp.UnequippedHand(new UnequippedHandEventArgs(user, hand));
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-07 05:49:43 -07:00
|
|
|
#endregion
|
|
|
|
|
#endregion
|
2020-12-13 14:28:20 -08:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
#region Drop
|
2019-11-25 00:11:47 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Activates the Dropped behavior of an object
|
|
|
|
|
/// Verifies that the user is capable of doing the drop interaction first
|
|
|
|
|
/// </summary>
|
2021-02-18 21:43:46 +01:00
|
|
|
public bool TryDroppedInteraction(IEntity user, IEntity item, bool intentional)
|
2019-11-25 00:11:47 +01:00
|
|
|
{
|
2021-07-26 12:58:17 +02:00
|
|
|
if (user == null || item == null || !_actionBlockerSystem.CanDrop(user)) return false;
|
2019-11-25 00:11:47 +01:00
|
|
|
|
2021-02-18 21:43:46 +01:00
|
|
|
DroppedInteraction(user, item, intentional);
|
2019-11-25 00:11:47 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Calls Dropped on all components that implement the IDropped interface
|
|
|
|
|
/// on an entity that has been dropped.
|
|
|
|
|
/// </summary>
|
2021-02-18 21:43:46 +01:00
|
|
|
public void DroppedInteraction(IEntity user, IEntity item, bool intentional)
|
2019-11-25 00:11:47 +01:00
|
|
|
{
|
2021-05-22 21:06:40 -07:00
|
|
|
var dropMsg = new DroppedEvent(user, item, intentional);
|
2021-03-09 11:22:48 -08:00
|
|
|
RaiseLocalEvent(item.Uid, dropMsg);
|
2019-11-25 00:11:47 +01:00
|
|
|
if (dropMsg.Handled)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-05-09 22:36:19 +02:00
|
|
|
item.Transform.LocalRotation = intentional ? Angle.Zero : (_random.Next(0, 100) / 100f) * MathHelper.TwoPi;
|
2021-05-09 10:09:14 +02:00
|
|
|
|
2019-11-25 00:11:47 +01:00
|
|
|
var comps = item.GetAllComponents<IDropped>().ToList();
|
|
|
|
|
|
|
|
|
|
// Call Land on all components that implement the interface
|
|
|
|
|
foreach (var comp in comps)
|
|
|
|
|
{
|
2021-02-18 21:43:46 +01:00
|
|
|
comp.Dropped(new DroppedEventArgs(user, intentional));
|
2019-11-25 00:11:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-06-07 05:49:43 -07:00
|
|
|
#endregion
|
2019-11-25 00:11:47 +01:00
|
|
|
|
2021-06-07 05:49:43 -07:00
|
|
|
#region Hand Selected
|
2019-11-25 00:11:47 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Calls HandSelected on all components that implement the IHandSelected interface
|
|
|
|
|
/// on an item entity on a hand that has just been selected.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void HandSelectedInteraction(IEntity user, IEntity item)
|
|
|
|
|
{
|
2021-05-22 21:06:40 -07:00
|
|
|
var handSelectedMsg = new HandSelectedEvent(user, item);
|
2021-03-09 11:22:48 -08:00
|
|
|
RaiseLocalEvent(item.Uid, handSelectedMsg);
|
2020-01-22 23:09:36 +01:00
|
|
|
if (handSelectedMsg.Handled)
|
2019-11-25 00:11:47 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var comps = item.GetAllComponents<IHandSelected>().ToList();
|
|
|
|
|
|
|
|
|
|
// Call Land on all components that implement the interface
|
|
|
|
|
foreach (var comp in comps)
|
|
|
|
|
{
|
|
|
|
|
comp.HandSelected(new HandSelectedEventArgs(user));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Calls HandDeselected on all components that implement the IHandDeselected interface
|
|
|
|
|
/// on an item entity on a hand that has just been deselected.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void HandDeselectedInteraction(IEntity user, IEntity item)
|
|
|
|
|
{
|
2021-05-22 21:06:40 -07:00
|
|
|
var handDeselectedMsg = new HandDeselectedEvent(user, item);
|
2021-03-09 11:22:48 -08:00
|
|
|
RaiseLocalEvent(item.Uid, handDeselectedMsg);
|
2020-01-22 23:09:36 +01:00
|
|
|
if (handDeselectedMsg.Handled)
|
2019-11-25 00:11:47 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var comps = item.GetAllComponents<IHandDeselected>().ToList();
|
|
|
|
|
|
|
|
|
|
// Call Land on all components that implement the interface
|
|
|
|
|
foreach (var comp in comps)
|
|
|
|
|
{
|
|
|
|
|
comp.HandDeselected(new HandDeselectedEventArgs(user));
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-07 05:49:43 -07:00
|
|
|
#endregion
|
|
|
|
|
#endregion
|
2019-11-25 00:11:47 +01: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-07-31 03:14:00 +02:00
|
|
|
if (await InteractDoBefore(user, used, inRangeUnobstructed ? target : null, clickLocation, false))
|
|
|
|
|
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
|
|
|
|
|
if (t.RangedInteract(rangedInteractionEventArgs))
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|