Ejemplo n.º 1
0
        public override bool Invoke(ulong steamId, long playerId, string messageText)
        {
            var match = Regex.Match(messageText, @"/stopall(?:\s{1,}(?<RANGE>[^\s]*)){0,1}", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                var    strRange = match.Groups["RANGE"].Captures.Count > 0 ? match.Groups["RANGE"].Captures[0].Value : "100";
                double range    = 100;
                double.TryParse(strRange, out range);
                range = Math.Abs(range);

                Vector3D destination;
                if (MyAPIGateway.Session.CameraController is MySpectator)
                {
                    destination = MyAPIGateway.Session.Camera.WorldMatrix.Translation;
                }
                else
                {
                    var playerEntity = MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity;
                    destination = playerEntity.WorldAABB.Center;
                }
                var sphere     = new BoundingSphereD(destination, range);
                var entityList = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);

                entityList = entityList.Where(e =>
                                              (e is IMyFloatingObject) ||
                                              (e is IMyCharacter) ||
                                              (e is IMyCubeGrid)).ToList();

                int counter = 0;
                foreach (var item in entityList)
                {
                    // Check for null physics and IsPhantom, to prevent picking up primitives.
                    if (item.Physics != null && !item.Physics.IsPhantom)
                    {
                        if (MyAPIGateway.Multiplayer.MultiplayerActive)
                        {
                            MessageSyncEntity.Process(item, SyncEntityType.Stop);
                        }
                        else
                        {
                            item.Stop();
                        }
                        counter++;
                    }
                }

                MyAPIGateway.Utilities.ShowMessage("Stopped", "{0} items within {1:N}m.", counter, range);
                return(true);
            }

            return(false);
        }
        public static void CollectObjects(ulong steamId, Vector3D destination, double range)
        {
            var sphere       = new BoundingSphereD(destination, range);
            var floatingList = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);

            //floatingList = floatingList.Where(e => (e is Sandbox.ModAPI.IMyFloatingObject) || (e is Sandbox.ModAPI.IMyCharacter)).ToList();
            floatingList = floatingList.Where(e => (e is IMyFloatingObject) || (e is Sandbox.Game.Entities.MyInventoryBagEntity)).ToList();

            _instance._timer100.Stop();
            _instance._workQueue.Clear();
            for (var i = 0; i < floatingList.Count; i++)
            {
                var item = floatingList[i];

                // Check for null physics and IsPhantom, to prevent picking up primitives.
                if (item.Physics != null && !item.Physics.IsPhantom)
                {
                    if (item is IMyCharacter)
                    {
                        var character = item.GetObjectBuilder() as MyObjectBuilder_Character;
                        if (!character.Health.HasValue || character.Health.Value > 0) // ignore living players
                        {
                            // TODO: not working currently. It causes body duplicates?

                            //item.Physics.ClearSpeed();
                            //_workQueue.Enqueue(delegate() { item.SetPosition(destination); });
                        }
                    }
                    else if (item is IMyFloatingObject || item is Sandbox.Game.Entities.MyInventoryBagEntity)
                    {
                        // Need to queue the objects, and relocate them over a number of frames, otherwise if they
                        // are all moved simultaneously to the same point in space, they will become stuck.

                        _instance._workQueue.Enqueue(delegate()
                        {
                            //item.SyncObject.UpdatePosition(); // causes Null exception.

                            if (item.Physics != null)
                            {
                                MessageSyncEntity.Process(item, SyncEntityType.Position | SyncEntityType.Stop, destination);
                            }
                        });
                    }
                }
            }
            if (_instance._workQueue.Count > 0)
            {
                _instance._timer100.Start();
            }
        }
Ejemplo n.º 3
0
        public override bool Invoke(ulong steamId, long playerId, string messageText)
        {
            var match = Regex.Match(messageText, @"/to\s{1,}(?<X>[+-]?((\d+(\.\d*)?)|(\.\d+)))\s{1,}(?<Y>[+-]?((\d+(\.\d*)?)|(\.\d+)))\s{1,}(?<Z>[+-]?((\d+(\.\d*)?)|(\.\d+)))", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                var offset = new Vector3D(
                    double.Parse(match.Groups["X"].Value, CultureInfo.InvariantCulture),
                    double.Parse(match.Groups["Y"].Value, CultureInfo.InvariantCulture),
                    double.Parse(match.Groups["Z"].Value, CultureInfo.InvariantCulture));

                var currentPosition = MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.GetPosition();

                // Use the player to determine direction of offset.
                var worldMatrix = MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.WorldMatrix;
                var position    = worldMatrix.Translation + worldMatrix.Right * offset.X + worldMatrix.Up * offset.Y + worldMatrix.Backward * offset.Z;

                if (MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.Parent == null)
                {
                    // Move the player only.
                    MessageSyncEntity.Process(MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity, SyncEntityType.Position, position);
                }
                else
                {
                    // Move the ship the player is piloting.
                    var cubeGrid = MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.GetTopMostParent();
                    currentPosition = cubeGrid.GetPosition();
                    var grids       = cubeGrid.GetAttachedGrids();
                    var worldOffset = position - MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.GetPosition();

                    foreach (var grid in grids)
                    {
                        MessageSyncEntity.Process(grid, SyncEntityType.Position, grid.GetPosition() + worldOffset);
                    }
                }

                // save teleport in history
                MessageSaveTeleportHistory.SaveToHistory(playerId, currentPosition);
                return(true);
            }

            return(false);
        }
        public override bool Invoke(ulong steamId, long playerId, string messageText)
        {
            var match = Regex.Match(messageText, @"/((j)|(jump))\s{1,}(?<D>[+-]?((\d+(\.\d*)?)|(\.\d+)))", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                var distance = double.Parse(match.Groups["D"].Value, CultureInfo.InvariantCulture);

                // Use the player to determine direction of offset.
                var entity          = MyAPIGateway.Session.Player.Controller.ControlledEntity;
                var currentPosition = entity.Entity.GetPosition();

                if (entity.Entity.Parent == null)
                {
                    // Move the player only.
                    // Use player HeadMatrix to calculate direction of Jump.
                    // Dead center of player cross hairs, except in thrid person where the view can be shifted with ALT.
                    var worldMatrix = entity.GetHeadMatrix(true, true, false, false);
                    var position    = entity.Entity.GetPosition() + (worldMatrix.Forward * distance);
                    MessageSyncEntity.Process(entity.Entity, SyncEntityType.Position, position);
                }
                else
                {
                    // Move the ship the player is piloting.
                    var cubeGrid = entity.Entity.GetTopMostParent();
                    var grids    = cubeGrid.GetAttachedGrids();

                    // Use cockpit/chair WorldMatrix to calculate direction of Jump.
                    var worldOffset = (entity.Entity.WorldMatrix.Forward * distance);
                    foreach (var grid in grids)
                    {
                        MessageSyncEntity.Process(grid, SyncEntityType.Position, grid.GetPosition() + worldOffset);
                    }
                }

                // save teleport in history
                MessageSaveTeleportHistory.SaveToHistory(playerId, currentPosition);
                return(true);
            }

            return(false);
        }