From 11c63112d14828965e69952d7276f0ab594f0098 Mon Sep 17 00:00:00 2001 From: Vera Aguilera Puerto Date: Tue, 9 Nov 2021 12:38:05 +0100 Subject: [PATCH] TabletopSystem uses EntityUid --- Content.Client/Tabletop/TabletopSystem.cs | 40 ++++++++++--------- .../Tabletop/TabletopSystem.Draggable.cs | 6 +-- Content.Server/Tabletop/TabletopSystem.cs | 10 +++-- .../Tabletop/SharedTabletopSystem.cs | 15 ++++--- 4 files changed, 39 insertions(+), 32 deletions(-) diff --git a/Content.Client/Tabletop/TabletopSystem.cs b/Content.Client/Tabletop/TabletopSystem.cs index 102d5cf49b..13ce66372d 100644 --- a/Content.Client/Tabletop/TabletopSystem.cs +++ b/Content.Client/Tabletop/TabletopSystem.cs @@ -33,10 +33,10 @@ namespace Content.Client.Tabletop private const float Delay = 1f / 10; // 10 Hz private float _timePassed; // Time passed since last update sent to the server. - private IEntity? _draggedEntity; // Entity being dragged + private EntityUid? _draggedEntity; // Entity being dragged private ScalingViewport? _viewport; // Viewport currently being used private SS14Window? _window; // Current open tabletop window (only allow one at a time) - private IEntity? _table; // The table entity of the currently open game session + private EntityUid? _table; // The table entity of the currently open game session public override void Initialize() { @@ -51,7 +51,7 @@ namespace Content.Client.Tabletop public override void Update(float frameTime) { // If there is no player entity, return - if (_playerManager.LocalPlayer is not { ControlledEntity: { } playerEntity }) return; + if (_playerManager.LocalPlayer is not { ControlledEntity: { Uid: var playerEntity } }) return; if (StunnedOrNoHands(playerEntity)) { @@ -69,7 +69,7 @@ namespace Content.Client.Tabletop if (_draggedEntity == null || _viewport == null) return; // Make sure the dragged entity has a draggable component - if (!_draggedEntity.TryGetComponent(out var draggableComponent)) return; + if (!EntityManager.TryGetComponent(_draggedEntity.Value, out var draggableComponent)) 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 @@ -88,7 +88,7 @@ namespace Content.Client.Tabletop if (clampedCoords.Equals(MapCoordinates.Nullspace)) return; // Move the entity locally every update - _draggedEntity.Transform.WorldPosition = clampedCoords.Position; + EntityManager.GetComponent(_draggedEntity.Value).WorldPosition = clampedCoords.Position; // Increment total time passed _timePassed += frameTime; @@ -96,7 +96,7 @@ namespace Content.Client.Tabletop // Only send new position to server when Delay is reached if (_timePassed >= Delay && _table != null) { - RaiseNetworkEvent(new TabletopMoveEvent(_draggedEntity.Uid, clampedCoords, _table.Uid)); + RaiseNetworkEvent(new TabletopMoveEvent(_draggedEntity.Value, clampedCoords, _table.Value)); _timePassed -= Delay; } } @@ -112,12 +112,12 @@ namespace Content.Client.Tabletop // Close the currently opened window, if it exists _window?.Close(); - _table = EntityManager.GetEntity(msg.TableUid); + _table = msg.TableUid; // Get the camera entity that the server has created for us - var camera = EntityManager.GetEntity(msg.CameraUid); + var camera = msg.CameraUid; - if (!EntityManager.TryGetComponent(camera.Uid, out var eyeComponent)) + if (!EntityManager.TryGetComponent(camera, out var eyeComponent)) { // If there is no eye, print error and do not open any window Logger.Error("Camera entity does not have eye component!"); @@ -146,7 +146,7 @@ namespace Content.Client.Tabletop { if (_table != null) { - RaiseNetworkEvent(new TabletopStopPlayingEvent(_table.Uid)); + RaiseNetworkEvent(new TabletopStopPlayingEvent(_table.Value)); } StopDragging(); @@ -166,22 +166,24 @@ namespace Content.Client.Tabletop private bool OnMouseDown(in PointerInputCmdHandler.PointerInputCmdArgs args) { // Return if no player entity - if (_playerManager.LocalPlayer is not { ControlledEntity: { } playerEntity }) return false; + if (_playerManager.LocalPlayer is not { ControlledEntity: { Uid : var playerEntityUid } }) return false; // Return if can not see table or stunned/no hands - if (!CanSeeTable(playerEntity, _table) || StunnedOrNoHands(playerEntity)) + if (!CanSeeTable(playerEntityUid, _table) || StunnedOrNoHands(playerEntityUid)) { return false; } + var draggedEntity = args.EntityUid; + // Set the entity being dragged and the viewport under the mouse - if (!EntityManager.TryGetEntity(args.EntityUid, out var draggedEntity)) + if (!EntityManager.EntityExists(draggedEntity)) { return false; } // Make sure that entity can be dragged - if (!EntityManager.HasComponent(draggedEntity.Uid)) + if (!EntityManager.HasComponent(draggedEntity)) { return false; } @@ -211,11 +213,11 @@ namespace Content.Client.Tabletop /// /// The entity that we start dragging. /// The viewport in which we are dragging. - private void StartDragging(IEntity draggedEntity, ScalingViewport viewport) + private void StartDragging(EntityUid draggedEntity, ScalingViewport viewport) { - RaiseNetworkEvent(new TabletopDraggingPlayerChangedEvent(draggedEntity.Uid, _playerManager.LocalPlayer?.UserId)); + RaiseNetworkEvent(new TabletopDraggingPlayerChangedEvent(draggedEntity, _playerManager.LocalPlayer?.UserId)); - if (draggedEntity.TryGetComponent(out var appearance)) + if (EntityManager.TryGetComponent(draggedEntity, out var appearance)) { appearance.SetData(TabletopItemVisuals.Scale, new Vector2(1.25f, 1.25f)); appearance.SetData(TabletopItemVisuals.DrawDepth, (int) DrawDepth.Items + 1); @@ -232,9 +234,9 @@ namespace Content.Client.Tabletop private void StopDragging(bool broadcast = true) { // Set the dragging player on the component to noone - if (broadcast && _draggedEntity != null && _draggedEntity.HasComponent()) + if (broadcast && _draggedEntity != null && EntityManager.HasComponent(_draggedEntity.Value)) { - RaiseNetworkEvent(new TabletopDraggingPlayerChangedEvent(_draggedEntity.Uid, null)); + RaiseNetworkEvent(new TabletopDraggingPlayerChangedEvent(_draggedEntity.Value, null)); } _draggedEntity = null; diff --git a/Content.Server/Tabletop/TabletopSystem.Draggable.cs b/Content.Server/Tabletop/TabletopSystem.Draggable.cs index 86cbe74b47..5d259d4ac3 100644 --- a/Content.Server/Tabletop/TabletopSystem.Draggable.cs +++ b/Content.Server/Tabletop/TabletopSystem.Draggable.cs @@ -25,7 +25,7 @@ namespace Content.Server.Tabletop /// private void OnTabletopMove(TabletopMoveEvent msg, EntitySessionEventArgs args) { - if (args.SenderSession as IPlayerSession is not { AttachedEntity: { } playerEntity } playerSession) + if (args.SenderSession as IPlayerSession is not { AttachedEntityUid: { } playerEntity } playerSession) return; if (!EntityManager.TryGetComponent(msg.TableUid, out TabletopGameComponent? tabletop) || tabletop.Session is not {} session) @@ -36,10 +36,10 @@ namespace Content.Server.Tabletop return; // Return if can not see table or stunned/no hands - if (!EntityManager.TryGetEntity(msg.TableUid, out var table)) + if (!EntityManager.EntityExists(msg.TableUid)) return; - if (!CanSeeTable(playerEntity, table) || StunnedOrNoHands(playerEntity)) + if (!CanSeeTable(playerEntity, msg.TableUid) || StunnedOrNoHands(playerEntity)) return; // Check if moved entity exists and has tabletop draggable component diff --git a/Content.Server/Tabletop/TabletopSystem.cs b/Content.Server/Tabletop/TabletopSystem.cs index 8b2f4fb305..c683e3f1bd 100644 --- a/Content.Server/Tabletop/TabletopSystem.cs +++ b/Content.Server/Tabletop/TabletopSystem.cs @@ -94,7 +94,7 @@ namespace Content.Server.Tabletop foreach (var gamer in EntityManager.EntityQuery()) { - if (!EntityManager.TryGetEntity(gamer.Tabletop, out var table)) + if (!EntityManager.EntityExists(gamer.Tabletop)) continue; if (!gamer.Owner.TryGetComponent(out ActorComponent? actor)) @@ -103,11 +103,13 @@ namespace Content.Server.Tabletop return; }; - if (actor.PlayerSession.Status > SessionStatus.Connected || CanSeeTable(gamer.Owner, table) - || !StunnedOrNoHands(gamer.Owner)) + var gamerUid = gamer.OwnerUid; + + if (actor.PlayerSession.Status > SessionStatus.Connected || CanSeeTable(gamerUid, gamer.Tabletop) + || !StunnedOrNoHands(gamerUid)) continue; - CloseSessionFor(actor.PlayerSession, table.Uid); + CloseSessionFor(actor.PlayerSession, gamer.Tabletop); } } } diff --git a/Content.Shared/Tabletop/SharedTabletopSystem.cs b/Content.Shared/Tabletop/SharedTabletopSystem.cs index 9d34212581..3e395a1543 100644 --- a/Content.Shared/Tabletop/SharedTabletopSystem.cs +++ b/Content.Shared/Tabletop/SharedTabletopSystem.cs @@ -34,9 +34,12 @@ namespace Content.Shared.Tabletop /// /// The player entity to check. /// The table entity to check. - protected bool CanSeeTable(IEntity playerEntity, IEntity? table) + protected bool CanSeeTable(EntityUid playerEntity, EntityUid? table) { - if (table?.Transform.Parent?.Owner is not { } parent) + if (table == null) + return false; + + if (EntityManager.GetComponent(table.Value).Parent?.Owner is not { } parent) { return false; } @@ -46,13 +49,13 @@ namespace Content.Shared.Tabletop return false; } - return _actionBlockerSystem.CanInteract(playerEntity.Uid); + return playerEntity.InRangeUnobstructed(table.Value) && _actionBlockerSystem.CanInteract(playerEntity); } - protected static bool StunnedOrNoHands(IEntity playerEntity) + protected bool StunnedOrNoHands(EntityUid playerEntity) { - var stunned = playerEntity.HasComponent(); - var hasHand = playerEntity.TryGetComponent(out var handsComponent) && + var stunned = EntityManager.HasComponent(playerEntity); + var hasHand = EntityManager.TryGetComponent(playerEntity, out var handsComponent) && handsComponent.Hands.Count > 0; return stunned || !hasHand;