Beispiel #1
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;
        }
Beispiel #2
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;
        }
        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);
        }