コード例 #1
0
        public void Execute(ClassicBot.ClassicBot bot, string sender, string ogMessage, string[] split)
        {
            _bot = bot;
            if (_isFollowing)
            {
                _isFollowing = false;
                bot.McClient.ClientPlayer.EntityMoved -= ClientPlayerOnEntityMoved;
                _currentlyFollowing = 0;
                bot.McClient.ClientPlayer.SendMessage("Stopped following.");
                return;
            }

            var senderEntity = bot.McClient.ClientPlayer.Entities.Values.FirstOrDefault(a => a.Name == sender);

            if (senderEntity == null)
            {
                bot.McClient.ClientPlayer.SendMessage("Couldn't find you!");
                return;
            }

            _currentlyFollowing = senderEntity.PlayerId;
            _isFollowing        = true;
            bot.McClient.ClientPlayer.SendMessage("Now following!");
            bot.McClient.ClientPlayer.EntityMoved += ClientPlayerOnEntityMoved;
        }
コード例 #2
0
 public CommandHandler(ClassicBot.ClassicBot bot)
 {
     _bot      = bot;
     _commands = new Dictionary <string, ICommand>();
     _commands.Add("!say", new SayCommand());
     _commands.Add("!follow", new FollowCommand());
     _commands.Add("!where", new WhereAmICommand());
     _commands.Add("!export", new ExportCommand());
     _commands.Add("!import", new ImportCommand());
 }
コード例 #3
0
        public void Execute(ClassicBot.ClassicBot bot, string sender, string ogMessage, string[] split)
        {
            var senderEntity = bot.McClient.ClientPlayer.Entities.Values.FirstOrDefault(a => a.Name == sender);

            if (senderEntity == null)
            {
                bot.McClient.ClientPlayer.SendMessage("Couldn't find you!");
                return;
            }

            var locationString     = $"{senderEntity.Position.X} {senderEntity.Position.Y} {senderEntity.Position.Z}";
            var locationStringReal = $"{((ushort)senderEntity.Position.X)/32} {((ushort)senderEntity.Position.Y)/32} {(((ushort)senderEntity.Position.Z)-51)/32}";

            bot.McClient.ClientPlayer.SendMessage("You are located at " + locationString + " EntityCoords.");
            bot.McClient.ClientPlayer.SendMessage("You are located at " + locationStringReal + " RealCoords");
        }
コード例 #4
0
        /// <summary>
        /// Exports blocks to file from between the given coordinates.
        /// </summary>
        /// <param name="coords"></param>
        /// <param name="name"></param>
        /// <param name="bot"></param>
        public static void ExportArea(Vector3S[] coords, string name, ClassicBot.ClassicBot bot)
        {
            short minX = Math.Min(coords[0].X, coords[1].X);
            short minY = Math.Min(coords[0].Y, coords[1].Y);
            short minZ = Math.Min(coords[0].Z, coords[1].Z);
            short maxX = Math.Max(coords[0].X, coords[1].X);
            short maxY = Math.Max(coords[0].Y, coords[1].Y);
            short maxZ = Math.Max(coords[0].Z, coords[1].Z);
            int   sizeX = (maxX - minX) + 1;
            int   sizeY = (maxY - minY) + 1;
            int   sizeZ = (maxZ - minZ) + 1;
            int   indX = 0, indY = 0, indZ = 0;
            var   blocks = new byte[(sizeX * sizeY * sizeZ) + 6]; // -- + 6 for the sizes.

            // -- Place the export size up front.
            var xBytes = BitConverter.GetBytes((short)sizeX);
            var yBytes = BitConverter.GetBytes((short)sizeY);
            var zBytes = BitConverter.GetBytes((short)sizeZ);

            Array.Copy(xBytes, blocks, 2);
            Array.Copy(yBytes, 0, blocks, 2, 2);
            Array.Copy(zBytes, 0, blocks, 4, 2);

            for (int x = minX; x <= maxX; x++)
            {
                for (int y = minY; y <= maxY; y++)
                {
                    for (int z = minZ; z <= maxZ; z++)
                    {
                        int blockIndex = ((indZ * sizeY + indY) * sizeX + indX) + 6;

                        blocks[blockIndex] = bot.McClient.ClientPlayer.World.GetBlockId(x, y, z);
                        indZ++;
                    }
                    indZ = 0;
                    indY++;
                }
                indY = 0;
                indX++;
            }
            if (!Directory.Exists(ExportDirectory))
            {
                Directory.CreateDirectory(ExportDirectory);
            }

            File.WriteAllBytes(Path.Combine(ExportDirectory, name + ".mbot"), blocks);
        }
コード例 #5
0
        public void Execute(ClassicBot.ClassicBot bot, string sender, string ogMessage, string[] split)
        {
            if (_importMode)
            {
                bot.McClient.ClientPlayer.SendMessage("Import mode cancelled.");
                bot.McClient.ClientPlayer.BlockPlaced -= ClientPlayerOnBlockPlaced;
                _importMode = false;
                return;
            }

            if (split.Length < 2)
            {
                bot.McClient.ClientPlayer.SendMessage("Please provide an import name.");
                return;
            }

            _importName = split[1];
            _bot        = bot;
            bot.McClient.ClientPlayer.SendMessage("Place an iron ore to import.");
            bot.McClient.ClientPlayer.BlockPlaced += ClientPlayerOnBlockPlaced;
            _importMode = true;
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: TheDireMaster/ClassicBot
        static void Main(string[] args)
        {
            _cbot               = new ClassicBot.ClassicBot("umby24", "127.0.0.1", 13337);
            _cbot.InfoMessage  += CbotOnInfoMessage;
            _cbot.DebugMessage += CbotOnDebugMessage;
            _cbot.ErrorMessage += CbotOnErrorMessage;
            _cbot.OnMessage    += CbotOnOnMessage;
            _cbot.McClient.ClientPlayer.LevelFinished += WorldOnLevelFinished;
            _commander = new CommandHandler(_cbot);
            var input = "";

            _cbot.Connect();

            while (input != "EXIT")
            {
                input = Console.ReadLine().Trim();

                if (input != "EXIT")
                {
                    _cbot.McClient.ClientPlayer.SendMessage(input);
                }
            }
        }
コード例 #7
0
        public void Execute(ClassicBot.ClassicBot bot, string sender, string ogMessage, string[] split)
        {
            if (_exportMode)
            {
                bot.McClient.ClientPlayer.SendMessage("Export mode cancelled.");
                bot.McClient.ClientPlayer.BlockPlaced -= ClientPlayerOnBlockPlaced;
                _exportMode = false;
                return;
            }

            if (split.Length < 2)
            {
                bot.McClient.ClientPlayer.SendMessage("Please provide an export name.");
                return;
            }

            _exportName = split[1];

            _bot         = bot;
            ExportCoords = new Vector3S[2];
            bot.McClient.ClientPlayer.SendMessage("Place 2 Iron-ore markers to mark the export area.");
            bot.McClient.ClientPlayer.BlockPlaced += ClientPlayerOnBlockPlaced;
        }
コード例 #8
0
        public static void ImportArea(Vector3S start, string name, ClassicBot.ClassicBot bot)
        {
            var pathTo = Path.Combine(ExportDirectory, name + ".mbot");

            if (!File.Exists(pathTo))
            {
                bot.McClient.ClientPlayer.SendMessage("That export does not exist.");
                return;
            }

            byte[] blocks = File.ReadAllBytes(pathTo);
            int    sizeX = 0, sizeY = 0, sizeZ = 0;

            // -- get the sizes out.
            sizeX = BitConverter.ToInt16(blocks, 0);
            sizeY = BitConverter.ToInt16(blocks, 2);
            sizeZ = BitConverter.ToInt16(blocks, 4);

            for (int x = 0; x < sizeX; x++)
            {
                for (int y = 0; y < sizeY; y++)
                {
                    for (int z = 0; z < sizeZ; z++)
                    {
                        var blockIndex    = ((z * sizeY + y) * sizeX + x) + 6;
                        var placeLocation = new Vector3S {
                            X = (short)(start.X + x),
                            Y = (short)(start.Y + y),
                            Z = (short)(start.Z + z)
                        };

                        bot.McClient.ClientPlayer.PlaceBlock(placeLocation, blocks[blockIndex]);
                    }
                }
            }
        }
コード例 #9
0
        public void Execute(ClassicBot.ClassicBot bot, string sender, string ogMessage, string[] split)
        {
            var minusCmd = string.Join(" ", split.Skip(1).ToArray());

            bot.McClient.ClientPlayer.SendMessage(minusCmd);
        }
コード例 #10
0
 public void Execute(ClassicBot.ClassicBot bot, string sender, string ogMessage, string[] split)
 {
 }