コード例 #1
0
        static bool MoveTowards(PlayerBot bot, Player p, Metadata meta)
        {
            if (p == null)
            {
                return(false);
            }
            int dist = (int)(0.875 * 32);

            int dx = p.Pos.X - bot.Pos.X, dy = p.Pos.Y - bot.Pos.Y, dz = p.Pos.Z - bot.Pos.Z;

            bot.TargetPos = p.Pos;
            bot.movement  = true;

            Vec3F32 dir = new Vec3F32(dx, dy, dz);

            dir = Vec3F32.Normalise(dir);
            Orientation rot = bot.Rot;

            DirUtils.GetYawPitch(dir, out rot.RotY, out rot.HeadX);


            MobAI.SetDirectionalSpeeds(bot);

            dx = Math.Abs(dx); dy = Math.Abs(dy); dz = Math.Abs(dz);
            if (InRange(p, bot, dist))
            {
                p.Message("%cInfect");
            }

            bot.Rot = rot;


            return(dx <= 8 && dy <= 16 && dz <= 8);
        }
コード例 #2
0
        static bool MoveTowards(PlayerBot bot, Player p, Metadata meta)
        {
            if (p == null)
            {
                return(false);
            }

            int dx = p.Pos.X - bot.Pos.X, dy = p.Pos.Y - bot.Pos.Y, dz = p.Pos.Z - bot.Pos.Z;

            bot.TargetPos = p.Pos;
            bot.movement  = true;

            Vec3F32 dir = new Vec3F32(dx, dy, dz);

            dir = Vec3F32.Normalise(dir);
            Orientation rot = bot.Rot;

            DirUtils.GetYawPitch(dir, out rot.RotY, out rot.HeadX);

            MobAI.SetDirectionalSpeeds(bot);

            p.Message("I am facing: %b" + MobAI.CalculateCardinal(bot));

            p.Message("sp " + bot.movementSpeed);

            //p.Message("The block in front of me is: %b");

            dx = Math.Abs(dx); dy = Math.Abs(dy); dz = Math.Abs(dz);

            bot.Rot = rot;

            return(dx <= 8 && dy <= 16 && dz <= 8);
        }
コード例 #3
0
        static bool MoveTowards(PlayerBot bot, Player p, Metadata meta)
        {
            if (p == null)
            {
                return(false);
            }

            int dx = p.Pos.X - bot.Pos.X, dy = p.Pos.Y - bot.Pos.Y, dz = p.Pos.Z - bot.Pos.Z;

            bot.TargetPos = p.Pos;
            bot.movement  = true;

            Vec3F32 dir = new Vec3F32(dx, dy, dz);

            dir = Vec3F32.Normalise(dir);
            Orientation rot = bot.Rot;

            DirUtils.GetYawPitch(dir, out rot.RotY, out rot.HeadX);

            MobAI.SetDirectionalSpeeds(bot);

            dx = Math.Abs(dx); dy = Math.Abs(dy); dz = Math.Abs(dz);

            if (bot.Model == "creeper")
            {
                if (dx < (3 * 32) && dz < (3 * 32))
                {
                    if (meta.explodeTime == 0)
                    {
                        meta.explodeTime = 10;
                    }
                }
                else
                {
                    meta.explodeTime = 0;
                }
            }

            else
            {
                if ((dx <= 8 && dy <= 16 && dz <= 8))
                {
                    HitPlayer(bot, p, rot);
                }
            }

            bot.Rot = rot;


            return(dx <= 8 && dy <= 16 && dz <= 8);
        }
コード例 #4
0
        /// <summary>
        /// Face bot towards target position.
        /// </summary>
        /// <param name="bot"></param>

        public static void FaceTowards(PlayerBot bot)
        {
            int dstHeight = ModelInfo.CalcEyeHeight(bot);

            int     dx = (bot.TargetPos.X) - bot.Pos.X, dy = bot.Rot.RotY, dz = (bot.TargetPos.Z) - bot.Pos.Z;
            Vec3F32 dir = new Vec3F32(dx, dy, dz);

            dir = Vec3F32.Normalise(dir);

            Orientation rot = bot.Rot;

            DirUtils.GetYawPitch(dir, out rot.RotY, out rot.HeadX);
            bot.Rot = rot;
        }
コード例 #5
0
        static bool MoveTowards(PlayerBot bot, Player p, Metadata meta)
        {
            if (p == null)
            {
                return(false);
            }
            int dist = (int)(0.875 * 32);

            int dx = p.Pos.X - bot.Pos.X, dy = p.Pos.Y - bot.Pos.Y, dz = p.Pos.Z - bot.Pos.Z;

            bot.TargetPos = p.Pos;
            bot.movement  = true;

            Vec3F32 dir = new Vec3F32(dx, dy, dz);

            dir = Vec3F32.Normalise(dir);
            Orientation rot = bot.Rot;

            DirUtils.GetYawPitch(dir, out rot.RotY, out rot.HeadX);

            MobAI.SetDirectionalSpeeds(bot);

            dx = Math.Abs(dx); dy = Math.Abs(dy); dz = Math.Abs(dz);
            //if (InRange(p, bot, dist)) p.Message("%cInfect");

            bot.Rot = rot;

            if (dx < (5 * 32) && dz < (5 * 32)) // 5 block reach
            {
                Random rnd = new Random();
                // This code serves as a sort of 'CPS mechanism' to ensure that the bot does not perfectly delete every single block
                int chance = rnd.Next(0, 4); // 33% chance of deleting the block
                if (chance < 3)
                {
                    bot.level.UpdateBlock(Player.Console, (ushort)(p.Pos.X / 32), (ushort)((p.Pos.Y / 32) - 2), (ushort)(p.Pos.Z / 32), Block.Air);

                    if ((p.Pos.Y / 32) > lastY)
                    {
                        bot.level.UpdateBlock(Player.Console, (ushort)(p.Pos.X / 32), (ushort)((p.Pos.Y / 32) - 3), (ushort)(p.Pos.Z / 32), Block.Air);
                    }
                }

                lastY = (p.Pos.Y / 32);
            }

            return(dx <= 8 && dy <= 16 && dz <= 8);
        }
コード例 #6
0
        public static void HitPlayer(PlayerBot bot, Player p, Orientation rot)
        {
            // Send player backwards if hit
            // Code "borrowed" from PvP plugin

            int srcHeight = ModelInfo.CalcEyeHeight(bot);
            int dstHeight = ModelInfo.CalcEyeHeight(p);
            int dx2 = bot.Pos.X - p.Pos.X, dy2 = (bot.Pos.Y + srcHeight) - (p.Pos.Y + dstHeight), dz2 = bot.Pos.Z - p.Pos.Z;

            Vec3F32 dir2 = new Vec3F32(dx2, dy2, dz2);

            if (dir2.Length > 0)
            {
                dir2 = Vec3F32.Normalise(dir2);
            }

            float mult    = 1 / ModelInfo.GetRawScale(p.Model);
            float plScale = ModelInfo.GetRawScale(p.Model);

            float VelocityY = 1.0117f * mult;

            if (dir2.Length <= 0)
            {
                VelocityY = 0;
            }

            if (p.Supports(CpeExt.VelocityControl))
            {
                // Intensity of force is in part determined by model scale
                p.Send(Packet.VelocityControl((-dir2.X * mult) * 0.57f, VelocityY, (-dir2.Z * mult) * 0.57f, 0, 1, 0));
            }

            // If we are very close to a player, switch from trying to look
            // at them to just facing the opposite direction to them

            rot.RotY = (byte)(p.Rot.RotY + 128);
            bot.Rot  = rot;
        }
コード例 #7
0
        static bool MoveTowards(PlayerBot bot, Player p)
        {
            int dx = p.Pos.X - bot.Pos.X, dy = p.Pos.Y - bot.Pos.Y, dz = p.Pos.Z - bot.Pos.Z;

            bot.TargetPos = p.Pos;
            bot.movement  = true;

            Vec3F32 dir = new Vec3F32(dx, dy, dz);

            dir = Vec3F32.Normalise(dir);
            Orientation rot = bot.Rot;

            DirUtils.GetYawPitch(dir, out rot.RotY, out rot.HeadX);

            // If we are very close to a player, switch from trying to look
            // at them to just facing the opposite direction to them
            if (Math.Abs(dx) < 4 && Math.Abs(dz) < 4)
            {
                rot.RotY = (byte)(p.Rot.RotY + 128);
            }
            bot.Rot = rot;

            return(dx <= 8 && dy <= 16 && dz <= 8);
        }