示例#1
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);
        }