Melee refactor (#10897)
Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
This commit is contained in:
@@ -1,18 +1,14 @@
|
||||
|
||||
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Pulling;
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Server.Weapon.Melee.Components;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.DragDrop;
|
||||
using Content.Shared.Input;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Pulling.Components;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
using Content.Shared.Storage;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Containers;
|
||||
@@ -20,7 +16,6 @@ using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Random;
|
||||
using static Content.Shared.Storage.SharedStorageComponent;
|
||||
|
||||
namespace Content.Server.Interaction
|
||||
{
|
||||
@@ -34,9 +29,8 @@ namespace Content.Server.Interaction
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||
[Dependency] private readonly PullingSystem _pullSystem = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
|
||||
[Dependency] private readonly InventorySystem _inventory = default!;
|
||||
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -61,7 +55,7 @@ namespace Content.Server.Interaction
|
||||
if (Deleted(target))
|
||||
return false;
|
||||
|
||||
if (!target.TryGetContainer(out var container))
|
||||
if (!_container.TryGetContainingContainer(target, out var container))
|
||||
return false;
|
||||
|
||||
if (!TryComp(container.Owner, out ServerStorageComponent? storage))
|
||||
@@ -74,7 +68,7 @@ namespace Content.Server.Interaction
|
||||
return false;
|
||||
|
||||
// we don't check if the user can access the storage entity itself. This should be handed by the UI system.
|
||||
return _uiSystem.SessionHasOpenUi(container.Owner, StorageUiKey.Key, actor.PlayerSession);
|
||||
return _uiSystem.SessionHasOpenUi(container.Owner, SharedStorageComponent.StorageUiKey.Key, actor.PlayerSession);
|
||||
}
|
||||
|
||||
#region Drag drop
|
||||
@@ -132,21 +126,6 @@ namespace Content.Server.Interaction
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <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>
|
||||
internal void AiUseInteraction(EntityUid entity, EntityCoordinates coords, EntityUid uid)
|
||||
{
|
||||
if (HasComp<ActorComponent>(entity))
|
||||
throw new InvalidOperationException();
|
||||
|
||||
UserInteraction(entity, coords, uid);
|
||||
}
|
||||
|
||||
private bool HandleTryPullObject(ICommonSession? session, EntityCoordinates coords, EntityUid uid)
|
||||
{
|
||||
if (!ValidateClientInput(session, coords, uid, out var userEntity))
|
||||
@@ -169,103 +148,5 @@ namespace Content.Server.Interaction
|
||||
|
||||
return _pullSystem.TogglePull(userEntity.Value, pull);
|
||||
}
|
||||
|
||||
public override void DoAttack(EntityUid user, EntityCoordinates coordinates, bool wideAttack, EntityUid? target = null)
|
||||
{
|
||||
// TODO PREDICTION move server-side interaction logic into the shared system for interaction prediction.
|
||||
if (!ValidateInteractAndFace(user, coordinates))
|
||||
return;
|
||||
|
||||
// Check general interaction blocking.
|
||||
if (!_actionBlockerSystem.CanInteract(user, target))
|
||||
return;
|
||||
|
||||
// Check combat-specific action blocking.
|
||||
if (!_actionBlockerSystem.CanAttack(user, target))
|
||||
return;
|
||||
|
||||
if (!wideAttack)
|
||||
{
|
||||
// Check if interacted entity is in the same container, the direct child, or direct parent of the user.
|
||||
if (target != null && !Deleted(target.Value) && !ContainerSystem.IsInSameOrParentContainer(user, target.Value) && !CanAccessViaStorage(user, target.Value))
|
||||
{
|
||||
Logger.WarningS("system.interaction",
|
||||
$"User entity {ToPrettyString(user):user} clicked on object {ToPrettyString(target.Value):target} that isn't the parent, child, or in the same container");
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Replace with body attack range when we get something like arm length or telekinesis or something.
|
||||
var unobstructed = (target == null)
|
||||
? InRangeUnobstructed(user, coordinates)
|
||||
: InRangeUnobstructed(user, target.Value);
|
||||
|
||||
if (!unobstructed)
|
||||
return;
|
||||
}
|
||||
else if (ContainerSystem.IsEntityInContainer(user))
|
||||
{
|
||||
// No wide attacking while in containers (holos, lockers, etc).
|
||||
// Can't think of a valid case where you would want this.
|
||||
return;
|
||||
}
|
||||
|
||||
// Verify user has a hand, and find what object they are currently holding in their active hand
|
||||
if (TryComp(user, out HandsComponent? hands))
|
||||
{
|
||||
var item = hands.ActiveHandEntity;
|
||||
|
||||
if (!Deleted(item))
|
||||
{
|
||||
var meleeVee = new MeleeAttackAttemptEvent();
|
||||
RaiseLocalEvent(item.Value, ref meleeVee, true);
|
||||
|
||||
if (meleeVee.Cancelled) return;
|
||||
|
||||
if (wideAttack)
|
||||
{
|
||||
var ev = new WideAttackEvent(item.Value, user, coordinates);
|
||||
RaiseLocalEvent(item.Value, ev, false);
|
||||
|
||||
if (ev.Handled)
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
var ev = new ClickAttackEvent(item.Value, user, coordinates, target);
|
||||
RaiseLocalEvent(item.Value, ev, false);
|
||||
|
||||
if (ev.Handled)
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!wideAttack && target != null && HasComp<ItemComponent>(target.Value))
|
||||
{
|
||||
// We pick up items if our hand is empty, even if we're in combat mode.
|
||||
InteractHand(user, target.Value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Make this saner?
|
||||
// Attempt to do unarmed combat. We don't check for handled just because at this point it doesn't matter.
|
||||
|
||||
var used = user;
|
||||
|
||||
if (_inventory.TryGetSlotEntity(user, "gloves", out var gloves) && HasComp<MeleeWeaponComponent>(gloves))
|
||||
used = (EntityUid) gloves;
|
||||
|
||||
if (wideAttack)
|
||||
{
|
||||
var ev = new WideAttackEvent(used, user, coordinates);
|
||||
RaiseLocalEvent(used, ev, false);
|
||||
if (ev.Handled)
|
||||
_adminLogger.Add(LogType.AttackUnarmedWide, LogImpact.Low, $"{ToPrettyString(user):user} wide attacked at {coordinates}");
|
||||
}
|
||||
else
|
||||
{
|
||||
var ev = new ClickAttackEvent(used, user, coordinates, target);
|
||||
RaiseLocalEvent(used, ev, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user