Ejemplo n.º 1
0
        private bool HandleDrop(ICommonSession session, GridCoordinates coords, EntityUid uid)
        {
            var ent = ((IPlayerSession)session).AttachedEntity;

            if (ent == null || !ent.IsValid())
            {
                return(false);
            }

            if (!ent.TryGetComponent(out HandsComponent handsComp))
            {
                return(false);
            }

            if (handsComp.GetActiveHand == null)
            {
                return(false);
            }

            if (coords.InRange(_mapManager, ent.Transform.GridPosition, InteractionSystem.InteractionRange))
            {
                handsComp.Drop(handsComp.ActiveIndex, coords);
            }
            else
            {
                var entCoords = ent.Transform.GridPosition.Position;
                var entToDesiredDropCoords = coords.Position - entCoords;
                var clampedDropCoords      = ((entToDesiredDropCoords.Normalized * InteractionSystem.InteractionRange) + entCoords);

                handsComp.Drop(handsComp.ActiveIndex, new GridCoordinates(clampedDropCoords, coords.GridID));
            }

            return(true);
        }
        public void TryMoveTo(GridCoordinates from, GridCoordinates to)
        {
            if (_puller == null || ControlledComponent == null)
            {
                return;
            }

            var mapManager = IoCManager.Resolve <IMapManager>();

            if (!from.InRange(mapManager, to, SharedInteractionSystem.InteractionRange))
            {
                return;
            }

            ControlledComponent.WakeBody();

            var dist = _puller.Owner.Transform.GridPosition.Position - to.Position;

            if (Math.Sqrt(dist.LengthSquared) > DistBeforeStopPull ||
                Math.Sqrt(dist.LengthSquared) < 0.25f)
            {
                return;
            }

            _movingTo = to;
        }
Ejemplo n.º 3
0
        private bool HandleDrop(ICommonSession session, GridCoordinates coords, EntityUid uid)
        {
            var ent = ((IPlayerSession)session).AttachedEntity;

            if (ent == null || !ent.IsValid())
            {
                return(false);
            }

            if (!ent.TryGetComponent(out HandsComponent handsComp))
            {
                return(false);
            }

            if (coords.InRange(_mapManager, ent.Transform.GridPosition, InteractionSystem.InteractionRange))
            {
                handsComp.Drop(handsComp.ActiveIndex, coords);
            }
            else
            {
                handsComp.Drop(handsComp.ActiveIndex);
            }

            return(true);
        }
Ejemplo n.º 4
0
 /// <summary>
 ///     Gets all players inside of a circle.
 /// </summary>
 /// <param name="worldPos">Position of the circle in world-space.</param>
 /// <param name="range">Radius of the circle in world units.</param>
 /// <returns></returns>
 public List <IPlayerSession> GetPlayersInRange(GridCoordinates worldPos, int range)
 {
     _sessionsLock.EnterReadLock();
     //TODO: This needs to be moved to the PVS system.
     try
     {
         return
             (_sessions.Values.Where(x => x.AttachedEntity != null &&
                                     worldPos.InRange(_mapManager, x.AttachedEntity.Transform.GridPosition, range))
              .Cast <IPlayerSession>()
              .ToList());
     }
     finally
     {
         _sessionsLock.ExitReadLock();
     }
 }
        private bool HandleDrop(ICommonSession session, GridCoordinates coords, EntityUid uid)
        {
            var ent = ((IPlayerSession)session).AttachedEntity;

            if (ent == null || !ent.IsValid())
            {
                return(false);
            }

            if (!ent.TryGetComponent(out HandsComponent handsComp))
            {
                return(false);
            }

            if (handsComp.GetActiveHand == null)
            {
                return(false);
            }

            var dir        = (coords.Position - ent.Transform.GridPosition.Position);
            var ray        = new CollisionRay(ent.Transform.GridPosition.Position, dir.Normalized, (int)CollisionGroup.Impassable);
            var rayResults = IoCManager.Resolve <IPhysicsManager>().IntersectRay(ent.Transform.MapID, ray, dir.Length, ent);

            if (!rayResults.DidHitObject)
            {
                if (coords.InRange(_mapManager, ent.Transform.GridPosition, InteractionSystem.InteractionRange))
                {
                    handsComp.Drop(handsComp.ActiveIndex, coords);
                }
                else
                {
                    var entCoords = ent.Transform.GridPosition.Position;
                    var entToDesiredDropCoords = coords.Position - entCoords;
                    var clampedDropCoords      = ((entToDesiredDropCoords.Normalized * InteractionSystem.InteractionRange) + entCoords);

                    handsComp.Drop(handsComp.ActiveIndex, new GridCoordinates(clampedDropCoords, coords.GridID));
                }
            }
            else
            {
                handsComp.Drop(handsComp.ActiveIndex, ent.Transform.GridPosition);
            }

            return(true);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Checks that these coordinates are within a certain distance without any
        ///     entity that matches the collision mask obstructing them.
        ///     If the <paramref name="range"/> is zero or negative,
        ///     this method will only check if nothing obstructs the two sets of coordinates..
        /// </summary>
        /// <param name="mapManager">Map manager containing the two GridIds.</param>
        /// <param name="coords">Set of coordinates to use.</param>
        /// <param name="otherCoords">Other set of coordinates to use.</param>
        /// <param name="range">maximum distance between the two sets of coordinates.</param>
        /// <param name="collisionMask">the mask to check for collisions</param>
        /// <param name="ignoredEnt">the entity to be ignored when checking for collisions.</param>
        /// <returns>True if the two points are within a given range without being obstructed.</returns>
        public bool InRangeUnobstructed(GridCoordinates coords, GridCoordinates otherCoords, float range = InteractionRange, int collisionMask = (int)CollisionGroup.Impassable, IEntity ignoredEnt = null)
        {
            if (range > 0f && !coords.InRange(_mapManager, otherCoords, range))
            {
                return(false);
            }

            var dir = (otherCoords.Position - coords.Position);

            if (!(dir.Length > 0f))
            {
                return(true);
            }
            var ray        = new CollisionRay(coords.Position, dir.Normalized, collisionMask);
            var rayResults = _physicsManager.IntersectRay(_mapManager.GetGrid(coords.GridID).ParentMapId, ray, dir.Length, ignoredEnt);

            return(!rayResults.DidHitObject);
        }
Ejemplo n.º 7
0
        void TryStartStructureConstruction(GridCoordinates loc, string prototypeName, Angle angle, int ack)
        {
            var prototype = _prototypeManager.Index <ConstructionPrototype>(prototypeName);

            var transform = Owner.Transform;

            if (!loc.InRange(_mapManager, transform.GridPosition, InteractionSystem.InteractionRange))
            {
                return;
            }

            if (prototype.Stages.Count < 2)
            {
                throw new InvalidOperationException($"Prototype '{prototypeName}' does not have enough stages.");
            }

            var stage0 = prototype.Stages[0];

            if (!(stage0.Forward is ConstructionStepMaterial matStep))
            {
                throw new NotImplementedException();
            }

            // Try to find the stack with the material in the user's hand.
            var hands      = Owner.GetComponent <HandsComponent>();
            var activeHand = hands.GetActiveHand?.Owner;

            if (activeHand == null)
            {
                return;
            }

            if (!activeHand.TryGetComponent(out StackComponent stack) || !ConstructionComponent.MaterialStackValidFor(matStep, stack))
            {
                return;
            }

            if (!stack.Use(matStep.Amount))
            {
                return;
            }

            // OK WE'RE GOOD CONSTRUCTION STARTED.
            _entitySystemManager.GetEntitySystem <AudioSystem>().Play("/Audio/items/deconstruct.ogg", loc);
            if (prototype.Stages.Count == 2)
            {
                // Exactly 2 stages, so don't make an intermediate frame.
                var ent = _serverEntityManager.SpawnEntityAt(prototype.Result, loc);
                ent.Transform.LocalRotation = angle;
            }
            else
            {
                var frame        = _serverEntityManager.SpawnEntityAt("structureconstructionframe", loc);
                var construction = frame.GetComponent <ConstructionComponent>();
                construction.Init(prototype);
                frame.Transform.LocalRotation = angle;
            }

            var msg = new AckStructureConstructionMessage(ack);

            SendNetworkMessage(msg);
        }
Ejemplo n.º 8
0
 public bool InRange(GridCoordinates from, GridCoordinates to)
 {
     return(from.InRange(_mapManager, to, 15));
 }