Re-do InteractionSystem IEntity -> EntityUid conversion (#5767)
This commit is contained in:
committed by
GitHub
parent
fe1836c99d
commit
e3478f894e
@@ -35,10 +35,10 @@ namespace Content.Server.Chemistry.EntitySystems
|
|||||||
|
|
||||||
public void OnClickAttack(EntityUid uid, HyposprayComponent comp, ClickAttackEvent args)
|
public void OnClickAttack(EntityUid uid, HyposprayComponent comp, ClickAttackEvent args)
|
||||||
{
|
{
|
||||||
var target = args.TargetEntity;
|
if (args.Target == null)
|
||||||
var user = args.User;
|
return;
|
||||||
|
|
||||||
comp.TryDoInject(target, user);
|
comp.TryDoInject(args.Target.Value, args.User);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using Content.Server.Items;
|
|||||||
using Content.Server.Pulling;
|
using Content.Server.Pulling;
|
||||||
using Content.Server.Storage.Components;
|
using Content.Server.Storage.Components;
|
||||||
using Content.Shared.ActionBlocker;
|
using Content.Shared.ActionBlocker;
|
||||||
|
using Content.Shared.Administration.Logs;
|
||||||
using Content.Shared.Database;
|
using Content.Shared.Database;
|
||||||
using Content.Shared.DragDrop;
|
using Content.Shared.DragDrop;
|
||||||
using Content.Shared.Input;
|
using Content.Shared.Input;
|
||||||
@@ -38,7 +39,6 @@ namespace Content.Server.Interaction
|
|||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public sealed class InteractionSystem : SharedInteractionSystem
|
public sealed class InteractionSystem : SharedInteractionSystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
|
||||||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||||
[Dependency] private readonly PullingSystem _pullSystem = default!;
|
[Dependency] private readonly PullingSystem _pullSystem = default!;
|
||||||
[Dependency] private readonly RotateToFaceSystem _rotateToFaceSystem = default!;
|
[Dependency] private readonly RotateToFaceSystem _rotateToFaceSystem = default!;
|
||||||
@@ -74,7 +74,7 @@ namespace Content.Server.Interaction
|
|||||||
{
|
{
|
||||||
userEntity = null;
|
userEntity = null;
|
||||||
|
|
||||||
if (!coords.IsValid(_entityManager))
|
if (!coords.IsValid(EntityManager))
|
||||||
{
|
{
|
||||||
Logger.InfoS("system.interaction", $"Invalid Coordinates: client={session}, coords={coords}");
|
Logger.InfoS("system.interaction", $"Invalid Coordinates: client={session}, coords={coords}");
|
||||||
return false;
|
return false;
|
||||||
@@ -89,7 +89,7 @@ namespace Content.Server.Interaction
|
|||||||
|
|
||||||
userEntity = ((IPlayerSession?) session)?.AttachedEntity;
|
userEntity = ((IPlayerSession?) session)?.AttachedEntity;
|
||||||
|
|
||||||
if (userEntity == null || !EntityManager.EntityExists(userEntity.Value))
|
if (userEntity == null || !userEntity.Value.IsValid())
|
||||||
{
|
{
|
||||||
Logger.WarningS("system.interaction",
|
Logger.WarningS("system.interaction",
|
||||||
$"Client sent interaction with no attached entity. Session={session}");
|
$"Client sent interaction with no attached entity. Session={session}");
|
||||||
@@ -101,19 +101,19 @@ namespace Content.Server.Interaction
|
|||||||
|
|
||||||
public override bool CanAccessViaStorage(EntityUid user, EntityUid target)
|
public override bool CanAccessViaStorage(EntityUid user, EntityUid target)
|
||||||
{
|
{
|
||||||
if (!EntityManager.EntityExists(target))
|
if (Deleted(target))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!target.TryGetContainer(out var container))
|
if (!target.TryGetContainer(out var container))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!EntityManager.TryGetComponent(container.Owner, out ServerStorageComponent storage))
|
if (!TryComp(container.Owner, out ServerStorageComponent? storage))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (storage.Storage?.ID != container.ID)
|
if (storage.Storage?.ID != container.ID)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!EntityManager.TryGetComponent(user, out ActorComponent actor))
|
if (!TryComp(user, out ActorComponent? actor))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// we don't check if the user can access the storage entity itself. This should be handed by the UI system.
|
// we don't check if the user can access the storage entity itself. This should be handed by the UI system.
|
||||||
@@ -127,15 +127,17 @@ namespace Content.Server.Interaction
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void HandleInteractInventorySlotEvent(InteractInventorySlotEvent msg, EntitySessionEventArgs args)
|
private void HandleInteractInventorySlotEvent(InteractInventorySlotEvent msg, EntitySessionEventArgs args)
|
||||||
{
|
{
|
||||||
if (!EntityManager.EntityExists(msg.ItemUid))
|
if (Deleted(msg.ItemUid))
|
||||||
{
|
{
|
||||||
Logger.WarningS("system.interaction",
|
Logger.WarningS("system.interaction",
|
||||||
$"Client sent inventory interaction with an invalid target item. Session={args.SenderSession}");
|
$"Client sent inventory interaction with an invalid target item. Session={args.SenderSession}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var itemCoords = Transform(msg.ItemUid).Coordinates;
|
||||||
|
|
||||||
// client sanitization
|
// client sanitization
|
||||||
if (!ValidateClientInput(args.SenderSession, EntityManager.GetComponent<TransformComponent>(msg.ItemUid).Coordinates, msg.ItemUid, out var userEntity))
|
if (!ValidateClientInput(args.SenderSession, itemCoords, msg.ItemUid, out var userEntity))
|
||||||
{
|
{
|
||||||
Logger.InfoS("system.interaction", $"Inventory interaction validation failed. Session={args.SenderSession}");
|
Logger.InfoS("system.interaction", $"Inventory interaction validation failed. Session={args.SenderSession}");
|
||||||
return;
|
return;
|
||||||
@@ -143,7 +145,7 @@ namespace Content.Server.Interaction
|
|||||||
|
|
||||||
if (msg.AltInteract)
|
if (msg.AltInteract)
|
||||||
// Use 'UserInteraction' function - behaves as if the user alt-clicked the item in the world.
|
// Use 'UserInteraction' function - behaves as if the user alt-clicked the item in the world.
|
||||||
UserInteraction(userEntity.Value, EntityManager.GetComponent<TransformComponent>(msg.ItemUid).Coordinates, msg.ItemUid, msg.AltInteract);
|
UserInteraction(userEntity.Value, itemCoords, msg.ItemUid, msg.AltInteract);
|
||||||
else
|
else
|
||||||
// User used 'E'. We want to activate it, not simulate clicking on the item
|
// User used 'E'. We want to activate it, not simulate clicking on the item
|
||||||
InteractionActivate(userEntity.Value, msg.ItemUid);
|
InteractionActivate(userEntity.Value, msg.ItemUid);
|
||||||
@@ -161,9 +163,7 @@ namespace Content.Server.Interaction
|
|||||||
if (!_actionBlockerSystem.CanInteract(userEntity.Value))
|
if (!_actionBlockerSystem.CanInteract(userEntity.Value))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!EntityManager.EntityExists(msg.Dropped))
|
if (Deleted(msg.Dropped) || Deleted(msg.Target))
|
||||||
return;
|
|
||||||
if (!EntityManager.EntityExists(msg.Target))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var interactionArgs = new DragDropEvent(userEntity.Value, msg.DropLocation, msg.Dropped, msg.Target);
|
var interactionArgs = new DragDropEvent(userEntity.Value, msg.DropLocation, msg.Dropped, msg.Target);
|
||||||
@@ -175,7 +175,7 @@ namespace Content.Server.Interaction
|
|||||||
|
|
||||||
// trigger dragdrops on the dropped entity
|
// trigger dragdrops on the dropped entity
|
||||||
RaiseLocalEvent(msg.Dropped, interactionArgs);
|
RaiseLocalEvent(msg.Dropped, interactionArgs);
|
||||||
foreach (var dragDrop in EntityManager.GetComponents<IDraggable>(msg.Dropped))
|
foreach (var dragDrop in AllComps<IDraggable>(msg.Dropped))
|
||||||
{
|
{
|
||||||
if (dragDrop.CanDrop(interactionArgs) &&
|
if (dragDrop.CanDrop(interactionArgs) &&
|
||||||
dragDrop.Drop(interactionArgs))
|
dragDrop.Drop(interactionArgs))
|
||||||
@@ -186,7 +186,7 @@ namespace Content.Server.Interaction
|
|||||||
|
|
||||||
// trigger dragdropons on the targeted entity
|
// trigger dragdropons on the targeted entity
|
||||||
RaiseLocalEvent(msg.Target, interactionArgs, false);
|
RaiseLocalEvent(msg.Target, interactionArgs, false);
|
||||||
foreach (var dragDropOn in EntityManager.GetComponents<IDragDropOn>(msg.Target))
|
foreach (var dragDropOn in AllComps<IDragDropOn>(msg.Target))
|
||||||
{
|
{
|
||||||
if (dragDropOn.CanDragDropOn(interactionArgs) &&
|
if (dragDropOn.CanDragDropOn(interactionArgs) &&
|
||||||
dragDropOn.DragDropOn(interactionArgs))
|
dragDropOn.DragDropOn(interactionArgs))
|
||||||
@@ -206,7 +206,7 @@ namespace Content.Server.Interaction
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EntityManager.EntityExists(uid))
|
if (Deleted(uid))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
InteractionActivate(user.Value, uid);
|
InteractionActivate(user.Value, uid);
|
||||||
@@ -223,7 +223,7 @@ namespace Content.Server.Interaction
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EntityManager.TryGetComponent(userEntity.Value, out CombatModeComponent? combatMode) && combatMode.IsInCombatMode)
|
if (TryComp(userEntity, out CombatModeComponent? combatMode) && combatMode.IsInCombatMode)
|
||||||
DoAttack(userEntity.Value, coords, true);
|
DoAttack(userEntity.Value, coords, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -238,7 +238,7 @@ namespace Content.Server.Interaction
|
|||||||
/// <param name="uid"></param>
|
/// <param name="uid"></param>
|
||||||
internal void AiUseInteraction(EntityUid entity, EntityCoordinates coords, EntityUid uid)
|
internal void AiUseInteraction(EntityUid entity, EntityCoordinates coords, EntityUid uid)
|
||||||
{
|
{
|
||||||
if (EntityManager.HasComponent<ActorComponent>(entity))
|
if (HasComp<ActorComponent>(entity))
|
||||||
throw new InvalidOperationException();
|
throw new InvalidOperationException();
|
||||||
|
|
||||||
UserInteraction(entity, coords, uid);
|
UserInteraction(entity, coords, uid);
|
||||||
@@ -253,7 +253,7 @@ namespace Content.Server.Interaction
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
UserInteraction(userEntity.Value, coords, uid);
|
UserInteraction(userEntity.Value, coords, !Deleted(uid) ? uid : null);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -267,7 +267,7 @@ namespace Content.Server.Interaction
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
UserInteraction(userEntity.Value, coords, uid, altInteract : true );
|
UserInteraction(userEntity.Value, coords, !Deleted(uid) ? uid : null, altInteract : true );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -280,16 +280,16 @@ namespace Content.Server.Interaction
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userEntity == uid)
|
if (userEntity.Value == uid)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!EntityManager.EntityExists(uid))
|
if (Deleted(uid))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!InRangeUnobstructed(userEntity.Value, uid, popup: true))
|
if (!InRangeUnobstructed(userEntity.Value, uid, popup: true))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!EntityManager.TryGetComponent(uid, out SharedPullableComponent? pull))
|
if (!TryComp(uid, out SharedPullableComponent? pull))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return _pullSystem.TogglePull(userEntity.Value, pull);
|
return _pullSystem.TogglePull(userEntity.Value, pull);
|
||||||
@@ -304,10 +304,10 @@ namespace Content.Server.Interaction
|
|||||||
/// <param name="altInteract">Whether to use default or alternative interactions (usually as a result of
|
/// <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
|
/// 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>
|
/// interaction. Having an item in the active hand also disables alternative interactions.</param>
|
||||||
public async void UserInteraction(EntityUid user, EntityCoordinates coordinates, EntityUid target, bool altInteract = false)
|
public async void UserInteraction(EntityUid user, EntityCoordinates coordinates, EntityUid? target, bool altInteract = false)
|
||||||
{
|
{
|
||||||
// TODO COMBAT Consider using alt-interact for advanced combat? maybe alt-interact disarms?
|
// TODO COMBAT Consider using alt-interact for advanced combat? maybe alt-interact disarms?
|
||||||
if (!altInteract && EntityManager.TryGetComponent(user, out CombatModeComponent? combatMode) && combatMode.IsInCombatMode)
|
if (!altInteract && TryComp(user, out CombatModeComponent? combatMode) && combatMode.IsInCombatMode)
|
||||||
{
|
{
|
||||||
DoAttack(user, coordinates, false, target);
|
DoAttack(user, coordinates, false, target);
|
||||||
return;
|
return;
|
||||||
@@ -321,22 +321,22 @@ namespace Content.Server.Interaction
|
|||||||
|
|
||||||
// Check if interacted entity is in the same container, the direct child, or direct parent of the user.
|
// Check if interacted entity is in the same container, the direct child, or direct parent of the user.
|
||||||
// This is bypassed IF the interaction happened through an item slot (e.g., backpack UI)
|
// This is bypassed IF the interaction happened through an item slot (e.g., backpack UI)
|
||||||
if (target != default && !user.IsInSameOrParentContainer(target) && !CanAccessViaStorage(user, target))
|
if (target != null && !Deleted(target.Value) && !user.IsInSameOrParentContainer(target.Value) && !CanAccessViaStorage(user, target.Value))
|
||||||
{
|
{
|
||||||
Logger.WarningS("system.interaction",
|
Logger.WarningS("system.interaction",
|
||||||
$"User entity named {EntityManager.GetComponent<MetaDataComponent>(user).EntityName} clicked on object {EntityManager.GetComponent<MetaDataComponent>(target).EntityName} that isn't the parent, child, or in the same container");
|
$"User entity {ToPrettyString(user):user} clicked on object {ToPrettyString(target.Value):target} that isn't the parent, child, or in the same container");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify user has a hand, and find what object they are currently holding in their active hand
|
// Verify user has a hand, and find what object they are currently holding in their active hand
|
||||||
if (!EntityManager.TryGetComponent<HandsComponent?>(user, out var hands))
|
if (!TryComp(user, out HandsComponent? hands))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var item = hands.GetActiveHand?.Owner;
|
var item = hands.GetActiveHand?.Owner;
|
||||||
|
|
||||||
// TODO: Replace with body interaction range when we get something like arm length or telekinesis or something.
|
// TODO: Replace with body interaction range when we get something like arm length or telekinesis or something.
|
||||||
var inRangeUnobstructed = user.InRangeUnobstructed(coordinates, ignoreInsideBlocker: true);
|
var inRangeUnobstructed = user.InRangeUnobstructed(coordinates, ignoreInsideBlocker: true);
|
||||||
if (target == default || !inRangeUnobstructed)
|
if (target == null || Deleted(target.Value) || !inRangeUnobstructed)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
return;
|
return;
|
||||||
@@ -350,29 +350,27 @@ namespace Content.Server.Interaction
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// We are close to the nearby object.
|
// We are close to the nearby object.
|
||||||
if (altInteract)
|
if (altInteract)
|
||||||
// Perform alternative interactions, using context menu verbs.
|
// Perform alternative interactions, using context menu verbs.
|
||||||
AltInteract(user, target);
|
AltInteract(user, target.Value);
|
||||||
else if (item != null && item != 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
|
// 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
|
// currently in our hand. We will use the item in our hand on the nearby object via InteractUsing
|
||||||
await InteractUsing(user, item.Value, target, coordinates);
|
await InteractUsing(user, item.Value, target.Value, coordinates);
|
||||||
else if (item == null)
|
else if (item == null)
|
||||||
// Since our hand is empty we will use InteractHand/Activate
|
// Since our hand is empty we will use InteractHand/Activate
|
||||||
InteractHand(user, target);
|
InteractHand(user, target.Value);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ValidateInteractAndFace(EntityUid user, EntityCoordinates coordinates)
|
private bool ValidateInteractAndFace(EntityUid user, EntityCoordinates coordinates)
|
||||||
{
|
{
|
||||||
// Verify user is on the same map as the entity they clicked on
|
// Verify user is on the same map as the entity they clicked on
|
||||||
if (coordinates.GetMapId(_entityManager) != EntityManager.GetComponent<TransformComponent>(user).MapID)
|
if (coordinates.GetMapId(EntityManager) != Transform(user).MapID)
|
||||||
{
|
{
|
||||||
Logger.WarningS("system.interaction",
|
Logger.WarningS("system.interaction",
|
||||||
$"User entity named {EntityManager.GetComponent<MetaDataComponent>(user).EntityName} clicked on a map they aren't located on");
|
$"User entity {ToPrettyString(user):user} clicked on a map they aren't located on");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,7 +398,7 @@ namespace Content.Server.Interaction
|
|||||||
|
|
||||||
var interactHandEventArgs = new InteractHandEventArgs(user, target);
|
var interactHandEventArgs = new InteractHandEventArgs(user, target);
|
||||||
|
|
||||||
var interactHandComps = EntityManager.GetComponents<IInteractHand>(target).ToList();
|
var interactHandComps = AllComps<IInteractHand>(target).ToList();
|
||||||
foreach (var interactHandComp in interactHandComps)
|
foreach (var interactHandComp in interactHandComps)
|
||||||
{
|
{
|
||||||
// If an InteractHand returns a status completion we finish our interaction
|
// If an InteractHand returns a status completion we finish our interaction
|
||||||
@@ -418,19 +416,19 @@ namespace Content.Server.Interaction
|
|||||||
/// Will have two behaviors, either "uses" the used entity at range on the target entity if it is capable of accepting that action
|
/// 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
|
/// Or it will use the used entity itself on the position clicked, regardless of what was there
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task<bool> InteractUsingRanged(EntityUid user, EntityUid used, EntityUid target, EntityCoordinates clickLocation, bool inRangeUnobstructed)
|
public async Task<bool> InteractUsingRanged(EntityUid user, EntityUid used, EntityUid? target, EntityCoordinates clickLocation, bool inRangeUnobstructed)
|
||||||
{
|
{
|
||||||
if (InteractDoBefore(user, used, inRangeUnobstructed ? target : null, clickLocation, false))
|
if (InteractDoBefore(user, used, inRangeUnobstructed ? target : null, clickLocation, false))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (target != default)
|
if (target != null)
|
||||||
{
|
{
|
||||||
var rangedMsg = new RangedInteractEvent(user, used, target, clickLocation);
|
var rangedMsg = new RangedInteractEvent(user, used, target.Value, clickLocation);
|
||||||
RaiseLocalEvent(target, rangedMsg);
|
RaiseLocalEvent(target.Value, rangedMsg);
|
||||||
if (rangedMsg.Handled)
|
if (rangedMsg.Handled)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
var rangedInteractions = EntityManager.GetComponents<IRangedInteract>(target).ToList();
|
var rangedInteractions = AllComps<IRangedInteract>(target.Value).ToList();
|
||||||
var rangedInteractionEventArgs = new RangedInteractEventArgs(user, used, clickLocation);
|
var rangedInteractionEventArgs = new RangedInteractEventArgs(user, used, clickLocation);
|
||||||
|
|
||||||
// See if we have a ranged interaction
|
// See if we have a ranged interaction
|
||||||
@@ -447,7 +445,7 @@ namespace Content.Server.Interaction
|
|||||||
return await InteractDoAfter(user, used, inRangeUnobstructed ? target : null, clickLocation, false);
|
return await InteractDoAfter(user, used, inRangeUnobstructed ? target : null, clickLocation, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DoAttack(EntityUid user, EntityCoordinates coordinates, bool wideAttack, EntityUid targetUid = default)
|
public void DoAttack(EntityUid user, EntityCoordinates coordinates, bool wideAttack, EntityUid? targetUid = null)
|
||||||
{
|
{
|
||||||
if (!ValidateInteractAndFace(user, coordinates))
|
if (!ValidateInteractAndFace(user, coordinates))
|
||||||
return;
|
return;
|
||||||
@@ -458,10 +456,10 @@ namespace Content.Server.Interaction
|
|||||||
if (!wideAttack)
|
if (!wideAttack)
|
||||||
{
|
{
|
||||||
// Check if interacted entity is in the same container, the direct child, or direct parent of the user.
|
// Check if interacted entity is in the same container, the direct child, or direct parent of the user.
|
||||||
if (targetUid != default && !user.IsInSameOrParentContainer(targetUid) && !CanAccessViaStorage(user, targetUid))
|
if (targetUid != null && !Deleted(targetUid.Value) && !user.IsInSameOrParentContainer(targetUid.Value) && !CanAccessViaStorage(user, targetUid.Value))
|
||||||
{
|
{
|
||||||
Logger.WarningS("system.interaction",
|
Logger.WarningS("system.interaction",
|
||||||
$"User entity named {EntityManager.GetComponent<MetaDataComponent>(user).EntityName} clicked on object {EntityManager.GetComponent<MetaDataComponent>(targetUid).EntityName} that isn't the parent, child, or in the same container");
|
$"User entity {ToPrettyString(user):user} clicked on object {ToPrettyString(targetUid.Value):target} that isn't the parent, child, or in the same container");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,47 +469,49 @@ namespace Content.Server.Interaction
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verify user has a hand, and find what object they are currently holding in their active hand
|
// Verify user has a hand, and find what object they are currently holding in their active hand
|
||||||
if (EntityManager.TryGetComponent<HandsComponent?>(user, out var hands))
|
if (TryComp(user, out HandsComponent? hands))
|
||||||
{
|
{
|
||||||
if (hands.GetActiveHand?.Owner is {Valid: true} item)
|
var item = hands.GetActiveHand?.Owner;
|
||||||
|
|
||||||
|
if (item != null && !Deleted(item.Value))
|
||||||
{
|
{
|
||||||
if (wideAttack)
|
if (wideAttack)
|
||||||
{
|
{
|
||||||
var ev = new WideAttackEvent(item, user, coordinates);
|
var ev = new WideAttackEvent(item.Value, user, coordinates);
|
||||||
RaiseLocalEvent(item, ev, false);
|
RaiseLocalEvent(item.Value, ev, false);
|
||||||
|
|
||||||
if (ev.Handled)
|
if (ev.Handled)
|
||||||
{
|
{
|
||||||
_adminLogSystem.Add(LogType.AttackArmedWide, LogImpact.Medium, $"{ToPrettyString(user):user} wide attacked with {ToPrettyString(item):used} at {coordinates}");
|
_adminLogSystem.Add(LogType.AttackArmedWide, LogImpact.Medium, $"{ToPrettyString(user):user} wide attacked with {ToPrettyString(item.Value):used} at {coordinates}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var ev = new ClickAttackEvent(item, user, coordinates, targetUid);
|
var ev = new ClickAttackEvent(item.Value, user, coordinates, targetUid);
|
||||||
RaiseLocalEvent(item, ev, false);
|
RaiseLocalEvent(item.Value, ev, false);
|
||||||
|
|
||||||
if (ev.Handled)
|
if (ev.Handled)
|
||||||
{
|
{
|
||||||
if (targetUid != default)
|
if (targetUid != null)
|
||||||
{
|
{
|
||||||
_adminLogSystem.Add(LogType.AttackArmedClick, LogImpact.Medium,
|
_adminLogSystem.Add(LogType.AttackArmedClick, LogImpact.Medium,
|
||||||
$"{ToPrettyString(user):user} attacked {ToPrettyString(targetUid):target} with {ToPrettyString(item):used} at {coordinates}");
|
$"{ToPrettyString(user):user} attacked {ToPrettyString(targetUid.Value):target} with {ToPrettyString(item.Value):used} at {coordinates}");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_adminLogSystem.Add(LogType.AttackArmedClick, LogImpact.Medium,
|
_adminLogSystem.Add(LogType.AttackArmedClick, LogImpact.Medium,
|
||||||
$"{ToPrettyString(user):user} attacked with {ToPrettyString(item):used} at {coordinates}");
|
$"{ToPrettyString(user):user} attacked with {ToPrettyString(item.Value):used} at {coordinates}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!wideAttack && targetUid != default && _entityManager.HasComponent<ItemComponent>(targetUid))
|
else if (!wideAttack && targetUid != null && HasComp<ItemComponent>(targetUid.Value))
|
||||||
{
|
{
|
||||||
// We pick up items if our hand is empty, even if we're in combat mode.
|
// We pick up items if our hand is empty, even if we're in combat mode.
|
||||||
InteractHand(user, targetUid);
|
InteractHand(user, targetUid.Value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -531,10 +531,10 @@ namespace Content.Server.Interaction
|
|||||||
RaiseLocalEvent(user, ev, false);
|
RaiseLocalEvent(user, ev, false);
|
||||||
if (ev.Handled)
|
if (ev.Handled)
|
||||||
{
|
{
|
||||||
if (targetUid != default)
|
if (targetUid != null)
|
||||||
{
|
{
|
||||||
_adminLogSystem.Add(LogType.AttackUnarmedClick, LogImpact.Medium,
|
_adminLogSystem.Add(LogType.AttackUnarmedClick, LogImpact.Medium,
|
||||||
$"{ToPrettyString(user):user} attacked {ToPrettyString(targetUid):target} at {coordinates}");
|
$"{ToPrettyString(user):user} attacked {ToPrettyString(targetUid.Value):target} at {coordinates}");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ namespace Content.Server.Weapon.Melee
|
|||||||
args.Handled = true;
|
args.Handled = true;
|
||||||
var curTime = _gameTiming.CurTime;
|
var curTime = _gameTiming.CurTime;
|
||||||
|
|
||||||
if (curTime < comp.CooldownEnd || !args.Target.IsValid())
|
if (curTime < comp.CooldownEnd || args.Target == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var location = EntityManager.GetComponent<TransformComponent>(args.User).Coordinates;
|
var location = EntityManager.GetComponent<TransformComponent>(args.User).Coordinates;
|
||||||
@@ -101,10 +101,10 @@ namespace Content.Server.Weapon.Melee
|
|||||||
{
|
{
|
||||||
if (args.Used == args.User)
|
if (args.Used == args.User)
|
||||||
_logSystem.Add(LogType.MeleeHit,
|
_logSystem.Add(LogType.MeleeHit,
|
||||||
$"{ToPrettyString(args.User):user} melee attacked {ToPrettyString(args.Target):target} using their hands and dealt {damageResult.Total:damage} damage");
|
$"{ToPrettyString(args.User):user} melee attacked {ToPrettyString(args.Target.Value):target} using their hands and dealt {damageResult.Total:damage} damage");
|
||||||
else
|
else
|
||||||
_logSystem.Add(LogType.MeleeHit,
|
_logSystem.Add(LogType.MeleeHit,
|
||||||
$"{ToPrettyString(args.User):user} melee attacked {ToPrettyString(args.Target):target} using {ToPrettyString(args.Used):used} and dealt {damageResult.Total:damage} damage");
|
$"{ToPrettyString(args.User):user} melee attacked {ToPrettyString(args.Target.Value):target} using {ToPrettyString(args.Used):used} and dealt {damageResult.Total:damage} damage");
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundSystem.Play(Filter.Pvs(owner), comp.HitSound.GetSound(), target);
|
SoundSystem.Play(Filter.Pvs(owner), comp.HitSound.GetSound(), target);
|
||||||
|
|||||||
@@ -892,6 +892,7 @@ namespace Content.Shared.Hands.Components
|
|||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public IContainer? Container { get; set; }
|
public IContainer? Container { get; set; }
|
||||||
|
|
||||||
|
// TODO: Make this a nullable EntityUid...
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public EntityUid HeldEntity => Container?.ContainedEntities.FirstOrDefault() ?? EntityUid.Invalid;
|
public EntityUid HeldEntity => Container?.ContainedEntities.FirstOrDefault() ?? EntityUid.Invalid;
|
||||||
|
|
||||||
|
|||||||
@@ -27,21 +27,14 @@ namespace Content.Shared.Weapons.Melee
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// UID of the entity that was attacked.
|
/// UID of the entity that was attacked.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityUid Target { get; }
|
public EntityUid? Target { get; }
|
||||||
|
|
||||||
/// <summary>
|
public ClickAttackEvent(EntityUid used, EntityUid user, EntityCoordinates clickLocation, EntityUid? target = null)
|
||||||
/// Entity that was attacked.
|
|
||||||
/// </summary>
|
|
||||||
public EntityUid? TargetEntity { get; }
|
|
||||||
|
|
||||||
public ClickAttackEvent(EntityUid used, EntityUid user, EntityCoordinates clickLocation, EntityUid target = default)
|
|
||||||
{
|
{
|
||||||
Used = used;
|
Used = used;
|
||||||
User = user;
|
User = user;
|
||||||
ClickLocation = clickLocation;
|
ClickLocation = clickLocation;
|
||||||
Target = target;
|
Target = target;
|
||||||
|
|
||||||
TargetEntity = IoCManager.Resolve<IEntityManager>().EntityExists(Target) ? Target : default(EntityUid?);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user