Ejemplo n.º 1
0
        // /admin movefrom x y z x y z radius
        public override bool HandleCommand(ulong userId, string[] words)
        {
            if (words.Count() < 2)
            {
                Communication.SendPrivateInformation(userId, GetHelp());
                return(true);
            }

            string sourceName = words[0];
            float  distance   = 50f;

            // TODO Allow quotes so we can do distance?
            bool parse = false;

            if (words.Count() > 2)
            {
                parse = float.TryParse(words[words.Count() - 1], out distance);
            }

            string targetName;

            if (parse)
            {
                targetName = string.Join(" ", words.Skip(1).Take(words.Count() - 2).ToArray());
            }
            else
            {
                targetName = string.Join(" ", words.Skip(1).ToArray());
            }

            Vector3D  position;
            IMyEntity entity = Player.FindControlledEntity(targetName);

            if (entity == null)
            {
                entity = CubeGrids.Find(targetName);
                if (entity == null)
                {
                    Communication.SendPrivateInformation(userId, string.Format("Can not find user or grid with the name: {0}", targetName));
                    return(true);
                }
            }

            position = entity.GetPosition();

            Communication.SendPrivateInformation(userId, string.Format("Trying to move {0} to within {1}m of {2}.  This may take about 20 seconds.", sourceName, distance, targetName));
            Vector3D startPosition = MathUtility.RandomPositionFromPoint((Vector3)position, distance);

            if (!Player.Move(sourceName, startPosition))
            {
                Communication.SendPrivateInformation(userId, string.Format("Can not move user: {0} (Is user in a cockpit or not in game?)", sourceName));
                return(true);
            }

            Communication.SendPrivateInformation(userId, string.Format("Moved {0} to within {1}m of {2}", sourceName, (int)Math.Round(Vector3D.Distance(startPosition, position)), targetName));
            return(true);
        }
Ejemplo n.º 2
0
        // /admin movefrom x y z x y z radius
        public override bool HandleCommand(ulong userId, string[] words)
        {
            if (words.Count() < 2)
            {
                Communication.SendPrivateInformation(userId, GetHelp());
                return(true);
            }

            string sourceName = words[0];
            float  distance   = 50f;

            // TODO Allow quotes so we can do distance?
            bool parse = false;

            if (words.Count() > 2)
            {
                parse = float.TryParse(words[words.Count() - 1], out distance);
            }

            string targetName;

            if (parse)
            {
                targetName = string.Join(" ", words.Skip(1).Take(words.Count() - 2).ToArray());
            }
            else
            {
                targetName = string.Join(" ", words.Skip(1).ToArray());
            }

            Communication.SendPrivateInformation(userId, $"Moving {sourceName} to within {distance}m of {targetName}.");

            Vector3D position;
            MyEntity entity = (MyEntity)Player.FindControlledEntity(targetName);

            if (entity == null)
            {
                entity = CubeGrids.Find(targetName);
                if (entity == null)
                {
                    Communication.SendPrivateInformation(userId, $"Can not find user or grid with the name: {targetName}");
                    return(true);
                }
                position = entity.PositionComp.GetPosition();
            }
            else
            {
                position = entity.PositionComp.GetPosition();
            }

            MyEntity gridToMove = CubeGrids.Find(sourceName);

            if (gridToMove == null)
            {
                Communication.SendPrivateInformation(userId, $"Unable to find: {sourceName}");
                return(true);
            }
            Vector3D?testPos = null;

            Wrapper.GameAction(() => testPos = MyEntities.FindFreePlace(position, (float)gridToMove.PositionComp.WorldAABB.Extents.Max(  ) + distance));

            if (testPos == null)
            {
                Communication.SendPrivateInformation(userId, $"Could not find valid location to move: {sourceName}. Try increasing distance.");
                return(true);
            }

            Wrapper.GameAction(() => gridToMove.PositionComp.SetPosition(testPos.Value));

            Communication.SendPrivateInformation(userId, $"Moved {sourceName} to within {(int)Math.Round( Vector3D.Distance(testPos.Value, position ) )}m of {targetName}");
            return(true);
        }
Ejemplo n.º 3
0
        // /admin movefrom x y z x y z radius
        public override bool HandleCommand(ulong userId, string[] words)
        {
            if (words.Count() < 2)
            {
                Communication.SendPrivateInformation(userId, GetHelp());
                return(true);
            }

            string sourceName = words[0];
            float  distance   = 50f;

            // TODO Allow quotes so we can do distance?
            bool parse = false;

            if (words.Count() > 2)
            {
                parse = float.TryParse(words[words.Count() - 1], out distance);
            }
            if (distance < 10)
            {
                Communication.SendPrivateInformation(userId, string.Format("Minimum distance is 10m"));
                distance = 10;
            }

            string targetName;

            if (parse)
            {
                targetName = string.Join(" ", words.Skip(1).Take(words.Count() - 2).ToArray());
            }
            else
            {
                targetName = string.Join(" ", words.Skip(1).ToArray());
            }

            IMyEntity entity = Player.FindControlledEntity(targetName);

            if (entity == null)
            {
                entity = CubeGrids.Find(targetName);
                if (entity == null)
                {
                    Communication.SendPrivateInformation(userId, string.Format("Can not find user or grid with the name: {0}", targetName));
                    return(true);
                }
            }

            Vector3D position = entity.GetPosition();

            Communication.SendPrivateInformation(userId, string.Format("Trying to move {0} to within {1}m of {2}.  This may take about 20 seconds.", sourceName, distance, targetName));
            Vector3D startPosition = MathUtility.RandomPositionFromPoint((Vector3)position, distance);

            //make sure we aren't moving the player inside a planet or something
            int             tryCount       = 0;
            BoundingSphereD positionSphere = new BoundingSphereD(startPosition, 5);

            while (MyAPIGateway.Entities.GetIntersectionWithSphere(ref positionSphere) != null)
            {
                startPosition  = MathUtility.RandomPositionFromPoint((Vector3)position, distance);
                positionSphere = new BoundingSphereD(startPosition, 5);

                tryCount++;
                if (tryCount > 20)
                {
                    Communication.SendPrivateInformation(userId, string.Format("Could not find valid location to move player: {0}. Try increasing distance.", sourceName));
                    return(true);
                }
            }

            //it's much better to have the client move the player, so we're doing that
            ulong steamId = PlayerMap.Instance.GetSteamIdFromPlayerName(sourceName);

            //send blank move type to pop the user out of any seat they're in
            Communication.MoveMessage(steamId, " ", startPosition);

            /*
             * if (!Player.Move(sourceName, startPosition))
             *          {
             *                  Communication.SendPrivateInformation(userId, string.Format("Can not move user: {0} (Is user in a cockpit or not in game?)", sourceName));
             *                  return true;
             *          }
             */

            Communication.SendPrivateInformation(userId, string.Format("Moved {0} to within {1}m of {2}", sourceName, (int)Math.Round(Vector3D.Distance(startPosition, position)), targetName));
            return(true);
        }
        // /admin movefrom x y z x y z radius
        public override bool HandleCommand(ulong userId, string[] words)
        {
            if (words.Count() < 2)
            {
                Communication.SendPrivateInformation(userId, GetHelp());
                return(true);
            }

            string sourceName = words[0];
            float  distance   = 50f;

            // TODO Allow quotes so we can do distance?
            bool parse = false;

            if (words.Count() > 2)
            {
                parse = float.TryParse(words[words.Count() - 1], out distance);
            }

            List <IMyPlayer> players = new List <IMyPlayer>();

            MyAPIGateway.Players.GetPlayers(players, x => x.DisplayName.Contains(sourceName, StringComparison.CurrentCultureIgnoreCase));
            if (players[0] == null)
            {
                Communication.SendPrivateInformation(userId, $"Couldn't find player with name {sourceName}.");
                return(true);
            }
            var controlledEntity = players[0].Controller.ControlledEntity;

            //kick the player out of their cockpit if they're in one
            if (controlledEntity is MyShipController)
            {
                Wrapper.GameAction(() => ((MyShipController)controlledEntity).RemoveUsers(false));
            }

            string targetName;

            if (parse)
            {
                targetName = string.Join(" ", words.Skip(1).Take(words.Count() - 2).ToArray());
            }
            else
            {
                targetName = string.Join(" ", words.Skip(1).ToArray());
            }

            IMyEntity entity = Player.FindControlledEntity(targetName);

            if (entity == null)
            {
                entity = CubeGrids.Find(targetName);
                if (entity == null)
                {
                    Communication.SendPrivateInformation(userId, $"Can not find user or grid with the name: {targetName}");
                    return(true);
                }
            }

            Vector3D position = entity.GetPosition();

            Communication.SendPrivateInformation(userId, $"Trying to move {sourceName} to within {distance}m of {targetName}.");
            Vector3D startPosition = MathUtility.RandomPositionFromPoint((Vector3)position, distance);

            //make sure we aren't moving the player inside a planet or something
            Vector3D?testPos = null;

            Wrapper.GameAction(() => testPos = MyEntities.FindFreePlace(startPosition, 2.5f + distance));

            if (testPos == null)
            {
                Communication.SendPrivateInformation(userId, $"Could not find valid location to move player: {sourceName}. Try increasing distance.");
                return(true);
            }

            //server controls movement now
            Wrapper.GameAction(() => ((MyEntity)players[0].Controller.ControlledEntity).PositionComp.SetPosition(testPos.Value));

            Communication.SendPrivateInformation(userId, string.Format("Moved {0} to within {1}m of {2}", sourceName, (int)Math.Round(Vector3D.Distance(startPosition, position)), targetName));
            return(true);
        }
        // /admin movefrom x y z x y z radius
        public override bool HandleCommand(ulong userId, string[] words)
        {
            if (words.Count() < 2)
            {
                Communication.SendPrivateInformation(userId, GetHelp());
                return(true);
            }

            string sourceName = words[0];
            float  distance   = 50f;

            // TODO Allow quotes so we can do distance?
            bool parse = false;

            if (words.Count() > 2)
            {
                parse = float.TryParse(words[words.Count() - 1], out distance);
            }

            string targetName;

            if (parse)
            {
                targetName = string.Join(" ", words.Skip(1).Take(words.Count() - 2).ToArray());
            }
            else
            {
                targetName = string.Join(" ", words.Skip(1).ToArray());
            }

            Communication.SendPrivateInformation(userId, string.Format("Moving {0} to within {1}m of {2}.  This may take about 20 seconds.", sourceName, distance, targetName));

            Vector3D  position;
            IMyEntity entity = Player.FindControlledEntity(targetName);

            if (entity == null)
            {
                entity = CubeGrids.Find(targetName);
                if (entity == null)
                {
                    Communication.SendPrivateInformation(userId, string.Format("Can not find user or grid with the name: {0}", targetName));
                    return(true);
                }
                position = entity.GetPosition();
            }
            else
            {
                position = entity.GetPosition();
            }

            Vector3D  startPosition = MathUtility.RandomPositionFromPoint((Vector3)position, distance);
            IMyEntity gridToMove    = CubeGrids.Find(sourceName);

            if (gridToMove == null)
            {
                Communication.SendPrivateInformation(userId, string.Format("Unable to find: {0}", sourceName));
                return(true);
            }

            Communication.MoveMessage(0, "normal", startPosition.X, startPosition.Y, startPosition.Z, gridToMove.EntityId);

            //Wrapper.GameAction( ( ) =>
            //{
            //    gridToMove.GetTopMostParent( ).SetPosition( startPosition );
            //    Log.Info( string.Format( "Moving '{0}' from {1} to {2}", gridToMove.DisplayName, gridToMove.GetPosition( ), startPosition ) );
            // MyMultiplayer.ReplicateImmediatelly( MyExternalReplicable.FindByObject( gridToMove.GetTopMostParent() ) );
            //} );

            /*
             *          Thread.Sleep(5000);
             *
             *          Wrapper.GameAction(() =>
             *          {
             *              MyAPIGateway.Entities.RemoveFromClosedEntities(entity);
             *              Log.Info(string.Format("Removing '{0}' for move", entity.DisplayName));
             *          });
             *
             *          Thread.Sleep(10000);
             *
             *          Wrapper.GameAction(() =>
             *          {
             *              gridBuilder.PositionAndOrientation = new MyPositionAndOrientation(startPosition, gridBuilder.PositionAndOrientation.Value.Forward, gridBuilder.PositionAndOrientation.Value.Up);
             *              Log.Info(string.Format("Adding '{0}' for move", gridBuilder.DisplayName));
             *              SectorObjectManager.Instance.AddEntity(new CubeGridEntity(gridBuilder));
             *          });*/

            Communication.SendPrivateInformation(userId, string.Format("Moved {0} to within {1}m of {2}", sourceName, (int)Math.Round(Vector3D.Distance(startPosition, position)), targetName));
            return(true);
        }