Fix tabletop error (#7830)
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
using Content.Shared.Tabletop.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Client.Tabletop.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedTabletopDraggableComponent))]
|
||||
public sealed class TabletopDraggableComponent : SharedTabletopDraggableComponent
|
||||
{
|
||||
// The player dragging the piece
|
||||
[ViewVariables]
|
||||
public NetUserId? DraggingPlayer;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using Content.Client.Tabletop.Components;
|
||||
using Content.Client.Tabletop.UI;
|
||||
using Content.Client.Viewport;
|
||||
using Content.Shared.Tabletop;
|
||||
using Content.Shared.Tabletop.Components;
|
||||
using Content.Shared.Tabletop.Events;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
@@ -10,14 +10,10 @@ using Robust.Client.Input;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
using static Robust.Shared.Input.Binding.PointerInputCmdHandler;
|
||||
using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
|
||||
@@ -51,6 +47,13 @@ namespace Content.Client.Tabletop
|
||||
|
||||
SubscribeNetworkEvent<TabletopPlayEvent>(OnTabletopPlay);
|
||||
SubscribeLocalEvent<TabletopDraggableComponent, ComponentHandleState>(HandleComponentState);
|
||||
SubscribeLocalEvent<TabletopDraggableComponent, ComponentRemove>(HandleDraggableRemoved);
|
||||
}
|
||||
|
||||
private void HandleDraggableRemoved(EntityUid uid, TabletopDraggableComponent component, ComponentRemove args)
|
||||
{
|
||||
if (_draggedEntity == uid)
|
||||
StopDragging(false);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
@@ -59,14 +62,12 @@ namespace Content.Client.Tabletop
|
||||
if (!_gameTiming.IsFirstTimePredicted)
|
||||
return;
|
||||
|
||||
if (_window == null)
|
||||
return;
|
||||
|
||||
// If there is no player entity, return
|
||||
if (_playerManager.LocalPlayer is not { ControlledEntity: { } playerEntity }) return;
|
||||
|
||||
if (StunnedOrNoHands(playerEntity))
|
||||
{
|
||||
StopDragging();
|
||||
}
|
||||
|
||||
if (!CanSeeTable(playerEntity, _table))
|
||||
{
|
||||
StopDragging();
|
||||
@@ -77,8 +78,11 @@ namespace Content.Client.Tabletop
|
||||
// If no entity is being dragged or no viewport is clicked, return
|
||||
if (_draggedEntity == null || _viewport == null) return;
|
||||
|
||||
// Make sure the dragged entity has a draggable component
|
||||
if (!EntityManager.TryGetComponent<TabletopDraggableComponent>(_draggedEntity.Value, out var draggableComponent)) return;
|
||||
if (!CanDrag(playerEntity, _draggedEntity.Value, out var draggableComponent))
|
||||
{
|
||||
StopDragging();
|
||||
return;
|
||||
}
|
||||
|
||||
// If the dragged entity has another dragging player, drop the item
|
||||
// This should happen if the local player is dragging an item, and another player grabs it out of their hand
|
||||
@@ -179,21 +183,7 @@ namespace Content.Client.Tabletop
|
||||
return false;
|
||||
|
||||
// Return if can not see table or stunned/no hands
|
||||
if (!CanSeeTable(playerEntity, _table) || StunnedOrNoHands(playerEntity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var draggedEntity = args.EntityUid;
|
||||
|
||||
// Set the entity being dragged and the viewport under the mouse
|
||||
if (!EntityManager.EntityExists(draggedEntity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure that entity can be dragged
|
||||
if (!EntityManager.HasComponent<TabletopDraggableComponent>(draggedEntity))
|
||||
if (!CanSeeTable(playerEntity, _table) || !CanDrag(playerEntity, args.EntityUid, out _))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -204,7 +194,7 @@ namespace Content.Client.Tabletop
|
||||
return false;
|
||||
}
|
||||
|
||||
StartDragging(draggedEntity, viewport);
|
||||
StartDragging(args.EntityUid, viewport);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
using Content.Shared.Tabletop.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using static Content.Shared.Tabletop.SharedTabletopSystem;
|
||||
|
||||
namespace Content.Server.Tabletop.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedTabletopDraggableComponent))]
|
||||
public sealed class TabletopDraggableComponent : SharedTabletopDraggableComponent
|
||||
{
|
||||
private NetUserId? _draggingPlayer;
|
||||
|
||||
// The player dragging the piece
|
||||
[ViewVariables]
|
||||
public NetUserId? DraggingPlayer
|
||||
{
|
||||
get => _draggingPlayer;
|
||||
set
|
||||
{
|
||||
_draggingPlayer = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
using Content.Server.Tabletop.Components;
|
||||
using Content.Shared.Tabletop;
|
||||
using Content.Shared.Tabletop.Components;
|
||||
using Content.Shared.Tabletop.Events;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
|
||||
|
||||
namespace Content.Server.Tabletop
|
||||
@@ -34,18 +33,7 @@ namespace Content.Server.Tabletop
|
||||
if (!session.Players.ContainsKey(playerSession))
|
||||
return;
|
||||
|
||||
// Return if can not see table or stunned/no hands
|
||||
if (!EntityManager.EntityExists(msg.TableUid))
|
||||
return;
|
||||
|
||||
if (!CanSeeTable(playerEntity, msg.TableUid) || StunnedOrNoHands(playerEntity))
|
||||
return;
|
||||
|
||||
// Check if moved entity exists and has tabletop draggable component
|
||||
if (!EntityManager.EntityExists(msg.MovedEntityUid))
|
||||
return;
|
||||
|
||||
if (!EntityManager.HasComponent<TabletopDraggableComponent>(msg.MovedEntityUid))
|
||||
if (!CanSeeTable(playerEntity, msg.TableUid) || !CanDrag(playerEntity, msg.MovedEntityUid, out _))
|
||||
return;
|
||||
|
||||
// TODO: some permission system, disallow movement if you're not permitted to move the item
|
||||
@@ -63,6 +51,7 @@ namespace Content.Server.Tabletop
|
||||
if (!EntityManager.TryGetComponent<TabletopDraggableComponent?>(dragged, out var draggableComponent)) return;
|
||||
|
||||
draggableComponent.DraggingPlayer = msg.IsDragging ? args.SenderSession.UserId : null;
|
||||
Dirty(draggableComponent);
|
||||
|
||||
if (!EntityManager.TryGetComponent<AppearanceComponent?>(dragged, out var appearance)) return;
|
||||
|
||||
|
||||
@@ -103,10 +103,7 @@ namespace Content.Server.Tabletop
|
||||
|
||||
var gamerUid = (gamer).Owner;
|
||||
|
||||
if (actor.PlayerSession.Status > SessionStatus.Connected || CanSeeTable(gamerUid, gamer.Tabletop)
|
||||
|| !StunnedOrNoHands(gamerUid))
|
||||
continue;
|
||||
|
||||
if (actor.PlayerSession.Status != SessionStatus.InGame || !CanSeeTable(gamerUid, gamer.Tabletop))
|
||||
CloseSessionFor(actor.PlayerSession, gamer.Tabletop);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Tabletop.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows an entity to be dragged around by the mouse. The position is updated for all player while dragging.
|
||||
/// </summary>
|
||||
[NetworkedComponent]
|
||||
public abstract class SharedTabletopDraggableComponent : Component
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Network;
|
||||
|
||||
namespace Content.Shared.Tabletop.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Allows an entity to be dragged around by the mouse. The position is updated for all player while dragging.
|
||||
/// </summary>
|
||||
[NetworkedComponent]
|
||||
[RegisterComponent]
|
||||
public sealed class TabletopDraggableComponent : Component
|
||||
{
|
||||
// The player dragging the piece
|
||||
[ViewVariables]
|
||||
public NetUserId? DraggingPlayer;
|
||||
}
|
||||
@@ -8,7 +8,7 @@ namespace Content.Shared.Tabletop.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// An event that is sent to the server every so often by the client to tell where an entity with a
|
||||
/// <see cref="SharedTabletopDraggableComponent"/> has been moved.
|
||||
/// <see cref="TabletopDraggableComponent"/> has been moved.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class TabletopMoveEvent : EntityEventArgs
|
||||
|
||||
@@ -2,8 +2,10 @@ using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Stunnable;
|
||||
using Content.Shared.Tabletop.Components;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Serialization;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Content.Shared.Tabletop
|
||||
{
|
||||
@@ -32,15 +34,10 @@ namespace Content.Shared.Tabletop
|
||||
/// <param name="table">The table entity to check.</param>
|
||||
protected bool CanSeeTable(EntityUid playerEntity, EntityUid? table)
|
||||
{
|
||||
if (table == null)
|
||||
return false;
|
||||
|
||||
if (EntityManager.GetComponent<TransformComponent>(table.Value).Parent?.Owner is not { } parent)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!EntityManager.HasComponent<MapComponent>(parent) && !EntityManager.HasComponent<IMapGridComponent>(parent))
|
||||
// Table may have been deleted, hence TryComp
|
||||
if (!TryComp(table, out MetaDataComponent? meta)
|
||||
|| meta.EntityLifeStage >= EntityLifeStage.Terminating
|
||||
|| (meta.Flags & MetaDataFlags.InContainer) == MetaDataFlags.InContainer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -48,15 +45,16 @@ namespace Content.Shared.Tabletop
|
||||
return _interactionSystem.InRangeUnobstructed(playerEntity, table.Value) && _actionBlockerSystem.CanInteract(playerEntity, table);
|
||||
}
|
||||
|
||||
protected bool StunnedOrNoHands(EntityUid playerEntity)
|
||||
protected bool CanDrag(EntityUid playerEntity, EntityUid target, [NotNullWhen(true)] out TabletopDraggableComponent? draggable)
|
||||
{
|
||||
var stunned = EntityManager.HasComponent<StunnedComponent>(playerEntity);
|
||||
var hasHand = EntityManager.TryGetComponent<SharedHandsComponent>(playerEntity, out var handsComponent) &&
|
||||
handsComponent.Hands.Count > 0;
|
||||
if (!TryComp(target, out draggable))
|
||||
return false;
|
||||
|
||||
return stunned || !hasHand;
|
||||
// CanSeeTable checks interaction action blockers. So no need to check them here.
|
||||
// If this ever changes, so that ghosts can spectate games, then the check needs to be moved here.
|
||||
|
||||
return TryComp(playerEntity, out SharedHandsComponent? hands) && hands.Hands.Count > 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user