Esempio n. 1
0
 public override string Run(McTcpClient handler, string command)
 {
     if (Settings.TerrainAndMovements)
     {
         string[] args = getArgs(command);
         if (args.Length == 1)
         {
             string dirStr = getArg(command).Trim().ToLower();
             Direction direction;
             switch (dirStr)
             {
                 case "up": direction = Direction.Up; break;
                 case "down": direction = Direction.Down; break;
                 case "east": direction = Direction.East; break;
                 case "west": direction = Direction.West; break;
                 case "north": direction = Direction.North; break;
                 case "south": direction = Direction.South; break;
                 case "get": return handler.GetCurrentLocation().ToString();
                 default: return "Unknown direction '" + dirStr + "'.";
             }
             if (Movement.CanMove(handler.GetWorld(), handler.GetCurrentLocation(), direction))
             {
                 handler.MoveTo(Movement.Move(handler.GetCurrentLocation(), direction));
                 return "Moving " + dirStr + '.';
             }
             else return "Cannot move in that direction.";
         }
         else if (args.Length == 3)
         {
             try
             {
                 int x = int.Parse(args[0]);
                 int y = int.Parse(args[1]);
                 int z = int.Parse(args[2]);
                 Location goal = new Location(x, y, z);
                 if (handler.MoveTo(goal))
                     return "Walking to " + goal;
                 return "Failed to compute path to " + goal;
             }
             catch (FormatException) { return CMDDesc; }
         }
         else return CMDDesc;
     }
     else return "Please enable terrainandmovements in config to use this command.";
 }
 public override string Run(McTcpClient handler, string command, Dictionary <string, object> localVars)
 {
     //IMinecraftCom handlerProtocol;
     string[] args = getArgs(command);
     if (args.Length == 3)
     {
         int      x     = int.Parse(args[0]);
         int      y     = int.Parse(args[1]);
         int      z     = int.Parse(args[2]);
         Location start = new Location(x, y, z);
         try
         {
             ConsoleIO.WriteLine("Calculating path to " + start.ToString());
             if (!handler.MoveTo(start))
             {
                 return("Failed to compute path to " + start);
             }
             ConsoleIO.WriteLine("Moving to " + start.ToString());
             while (handler.path != null && handler.path.Count > 0)
             {
                 Thread.Sleep(100);
             }
             Thread.Sleep(200);
             Location tLoc;
             //第一条
             tLoc = new Location(x, y, z);
             for (int i = 1; i < 9; i++)
             {
                 DigSide(handler, false, tLoc, i);
                 Thread.Sleep(100);
                 MoveTo(handler, tLoc + new Location(-i, 0, 0));
                 Thread.Sleep(200);
             }
             MoveTo(handler, tLoc + new Location(-8, 0, 0));
             Thread.Sleep(100);
             //一 二转角
             ChangeDIRup(handler, false, tLoc);
             //第二条
             tLoc += new Location(-8, 0, 3);
             for (int i = 0; i < 9; i++)
             {
                 DigSide(handler, true, tLoc, i);
                 Thread.Sleep(100);
                 MoveTo(handler, tLoc + new Location(i, 0, 0));
                 Thread.Sleep(200);
             }
             MoveTo(handler, tLoc + new Location(8, 0, 0));
             Thread.Sleep(100);
             //二 三转角
             ChangeDIRup(handler, true, tLoc);
             //第三条
             tLoc += new Location(8, 0, 3);
             for (int i = 0; i < 8; i++)
             {
                 DigSide(handler, false, tLoc, i);
                 Thread.Sleep(100);
                 MoveTo(handler, tLoc + new Location(-i, 0, 0));
                 Thread.Sleep(200);
             }
             DigSide(handler, true, tLoc + new Location(-8, 0, 0), 0);
             //三与下层 交界
             DigSide(handler, false, tLoc + new Location(-8, -1, 0), 0);
             Thread.Sleep(100);
             MoveTo(handler, tLoc + new Location(-8, -1, 0));
             Thread.Sleep(200);
             //下层 第一条
             tLoc += new Location(-8, -1, 0);
             for (int i = 0; i < 9; i++)
             {
                 DigSide(handler, true, tLoc, i);
                 Thread.Sleep(100);
                 MoveTo(handler, tLoc + new Location(i, 0, 0));
                 Thread.Sleep(200);
             }
             MoveTo(handler, tLoc + new Location(8, 0, 0));
             Thread.Sleep(100);
             //下层 一 二转角
             ChangeDIRdown(handler, true, tLoc);
             //第二条
             tLoc += new Location(8, 0, -3);
             for (int i = 0; i < 9; i++)
             {
                 DigSide(handler, false, tLoc, i);
                 Thread.Sleep(100);
                 MoveTo(handler, tLoc + new Location(-i, 0, 0));
                 Thread.Sleep(200);
             }
             MoveTo(handler, tLoc + new Location(-8, 0, 0));
             Thread.Sleep(100);
             //下层 二 三转角
             ChangeDIRdown(handler, false, tLoc);
             //第三条
             tLoc += new Location(-8, 0, -3);
             for (int i = 0; i < 8; i++)
             {
                 DigSide(handler, true, tLoc, i);
                 Thread.Sleep(100);
                 MoveTo(handler, tLoc + new Location(i, 0, 0));
                 Thread.Sleep(200);
             }
             DigSide(handler, true, tLoc + new Location(8, 0, 0), 0);
             //下下层 交界
             DigSide(handler, false, tLoc + new Location(8, -1, 0), 0);
             Thread.Sleep(100);
             MoveTo(handler, tLoc + new Location(8, -1, 0));
             Thread.Sleep(200);
             return("Done!");
         }
         catch (FormatException) { return(CMDDesc); }
     }
     else
     {
         return(CMDDesc);
     }
 }
        public override string Run(McTcpClient handler, string command, Dictionary <string, object> localVars)
        {
            string[] args   = getArgs(command);
            string   argStr = getArg(command).Trim().ToLower();

            if (argStr == "on")
            {
                handler.SetTerrainEnabled(true);
                return("Enabling Terrain and Movements on next server login, respawn or world change.");
            }
            else if (argStr == "off")
            {
                handler.SetTerrainEnabled(false);
                return("Disabling Terrain and Movements.");
            }
            else if (handler.GetTerrainEnabled())
            {
                if (args.Length == 1)
                {
                    Direction direction;
                    switch (argStr)
                    {
                    case "up": direction = Direction.Up; break;

                    case "down": direction = Direction.Down; break;

                    case "east": direction = Direction.East; break;

                    case "west": direction = Direction.West; break;

                    case "north": direction = Direction.North; break;

                    case "south": direction = Direction.South; break;

                    case "get": return(handler.GetCurrentLocation().ToString());

                    default: return("Unknown direction '" + argStr + "'.");
                    }
                    if (Movement.CanMove(handler.GetWorld(), handler.GetCurrentLocation(), direction))
                    {
                        handler.MoveTo(Movement.Move(handler.GetCurrentLocation(), direction));
                        return("Moving " + argStr + '.');
                    }
                    else
                    {
                        return("Cannot move in that direction.");
                    }
                }
                else if (args.Length == 3)
                {
                    try
                    {
                        int      x    = int.Parse(args[0]);
                        int      y    = int.Parse(args[1]);
                        int      z    = int.Parse(args[2]);
                        Location goal = new Location(x, y, z);
                        if (handler.MoveTo(goal))
                        {
                            return("Walking to " + goal);
                        }
                        return("Failed to compute path to " + goal);
                    }
                    catch (FormatException) { return(CMDDesc); }
                }
                else
                {
                    return(CMDDesc);
                }
            }
            else
            {
                return("Please enable terrainandmovements to use this command.");
            }
        }
Esempio n. 4
0
        public override string Run(McTcpClient handler, string command)
        {
            if (Settings.TerrainAndMovements)
            {
                string[] args = getArgs(command);
                if (args.Length == 1)
                {
                    string    dirStr = getArg(command).Trim().ToLower();
                    Direction direction;
                    switch (dirStr)
                    {
                    case "up": direction = Direction.Up; break;

                    case "down": direction = Direction.Down; break;

                    case "east": direction = Direction.East; break;

                    case "west": direction = Direction.West; break;

                    case "north": direction = Direction.North; break;

                    case "south": direction = Direction.South; break;

                    case "get": return(handler.GetCurrentLocation().ToString());

                    default: return("Unknown direction '" + dirStr + "'.");
                    }
                    if (Movement.CanMove(handler.GetWorld(), handler.GetCurrentLocation(), direction))
                    {
                        handler.MoveTo(Movement.Move(handler.GetCurrentLocation(), direction));
                        return("Moving " + dirStr + '.');
                    }
                    else
                    {
                        return("Cannot move in that direction.");
                    }
                }
                else if (args.Length == 3)
                {
                    try
                    {
                        int      x    = int.Parse(args[0]);
                        int      y    = int.Parse(args[1]);
                        int      z    = int.Parse(args[2]);
                        Location goal = new Location(x, y, z);
                        if (handler.MoveTo(goal))
                        {
                            return("Walking to " + goal);
                        }
                        return("Failed to compute path to " + goal);
                    }
                    catch (FormatException) { return(CMDDesc); }
                }
                else
                {
                    return(CMDDesc);
                }
            }
            else
            {
                return("Please enable terrainandmovements in config to use this command.");
            }
        }