/// <summary> /// Move an entity which is dragged by the user, but check if they are allowed to do so and to these coordinates /// </summary> private void OnTabletopMove(TabletopMoveEvent msg, EntitySessionEventArgs args) { if (args.SenderSession as IPlayerSession is not { AttachedEntity : { } playerEntity } playerSession) { return; } if (!EntityManager.TryGetComponent(msg.TableUid, out TabletopGameComponent? tabletop) || tabletop.Session is not { } session) { return; } // Check if player is actually playing at this table if (!session.Players.ContainsKey(playerSession)) { return; } 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 // Move the entity and dirty it (we use the map ID from the entity so noone can try to be funny and move the item to another map) var transform = EntityManager.GetComponent <TransformComponent>(msg.MovedEntityUid); var entityCoordinates = new EntityCoordinates(_mapManager.GetMapEntityId(transform.MapID), msg.Coordinates.Position); transform.Coordinates = entityCoordinates; }
/// <summary> /// Move an entity which is dragged by the user, but check if they are allowed to do so and to these coordinates /// </summary> private void OnTabletopMove(TabletopMoveEvent msg, EntitySessionEventArgs args) { if (args.SenderSession as IPlayerSession is not { AttachedEntity : { } playerEntity } playerSession) { return; } if (!EntityManager.TryGetComponent(msg.TableUid, out TabletopGameComponent? tabletop) || tabletop.Session is not { } session) { return; } // Check if player is actually playing at this table if (!session.Players.ContainsKey(playerSession)) { return; } // Return if can not see table or stunned/no hands if (!EntityManager.TryGetEntity(msg.TableUid, out var table)) { return; } if (!CanSeeTable(playerEntity, table) || StunnedOrNoHands(playerEntity)) { return; } // Check if moved entity exists and has tabletop draggable component if (!EntityManager.TryGetEntity(msg.MovedEntityUid, out var movedEntity)) { return; } if (!EntityManager.HasComponent <TabletopDraggableComponent>(movedEntity.Uid)) { return; } // TODO: some permission system, disallow movement if you're not permitted to move the item // Move the entity and dirty it (we use the map ID from the entity so noone can try to be funny and move the item to another map) var transform = EntityManager.GetComponent <ITransformComponent>(movedEntity.Uid); var entityCoordinates = new EntityCoordinates(_mapManager.GetMapEntityId(transform.MapID), msg.Coordinates.Position); transform.Coordinates = entityCoordinates; movedEntity.Dirty(); }