示例#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);
        }
        void Step(PlayerBot bot)
        {
            bot.TargetPos = bot.Pos;
            bot.movement  = true;
            Vec3F32 dir = DirUtils.GetDirVector(bot.Rot.RotY, 0);

            bot.TargetPos.X = bot.Pos.X + (int)(dir.X * bot.movementSpeed);
            bot.TargetPos.Z = bot.Pos.Z + (int)(dir.Z * bot.movementSpeed);
        }
示例#4
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);
        }
示例#5
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;
        }
示例#6
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);
        }
        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);
        }
示例#8
0
        void OnPlayerMove(Player p, Position next, byte yaw, byte pitch)
        {
            string data = playerEffects.FindData(p.name);

            if (data == null)
            {
                return;
            }

            if (rnd.NextDouble() > 0.125f && !data.StartsWith("puff"))
            {
                return;
            }
            float  x          = p.Pos.X * 0.03125f;
            float  y          = (p.Pos.Y + ModelInfo.CalcEyeHeight(p) - Entities.CharacterHeight) * 0.03125f;
            float  z          = p.Pos.Z * 0.03125f;
            float  originX    = x;
            float  originY    = y;
            float  originZ    = z;
            Player notShownTo = null;

            //ugly hack
            if (data.StartsWith("leaf"))
            {
                if (rnd.NextDouble() > 0.5f)
                {
                    return;
                }
                originX += 32;
                originZ += 8;
            }
            else if (data.StartsWith("puff"))
            {
                Random    playerRandom = new Random(p.name.GetHashCode());
                const int cycle        = 4000;
                const int breatheOut   = 1000;
                int       offset       = playerRandom.Next(0, cycle + 1);

                TimeSpan delta  = DateTime.UtcNow - (startTime.AddMilliseconds(offset));
                int      ms     = (int)delta.TotalMilliseconds;
                bool     phase1 = (ms % cycle) < breatheOut;
                if (!phase1)
                {
                    return;
                }


                Vec3F32 dir = DirUtils.GetDirVector(yaw, pitch);
                dir.X     *= 0.3f;
                dir.Y     *= 0.3f;
                dir.Z     *= 0.3f;
                originY    = y;
                x         += dir.X;
                y         += dir.Y;
                z         += dir.Z;
                y         -= 0.15f;
                originY   -= 0.15f;
                notShownTo = p;
            }
            SpawnEffectAt(p.level, data, x, y, z, originX, originY, originZ);
        }