public virtual void OnUpdateNavigation()
        {
            TotalTicks++;

            if (NoPath())
            {
                return;
            }

            if (CanNavigate())
            {
                PathFollow();
            }

            if (NoPath())
            {
                return;
            }

            Vec3D vec3d = CurrentPath.GetCurrentNodeVec3d(TheEntity);

            if (vec3d == null)
            {
                return;
            }
            else
            {
                TheEntity.GetMoveHelper().SetMoveTo(vec3d.XCoord, vec3d.YCoord, vec3d.ZCoord, Speed);
                return;
            }
        }
Beispiel #2
0
        public override void UpdateEntityActionState()
        {
            Profiler.StartSection("ai");

            if (FleeingTick > 0)
            {
                FleeingTick--;
            }

            HasAttacked = IsMovementCeased();
            float f = 16F;

            if (EntityToAttack == null)
            {
                EntityToAttack = FindPlayerToAttack();

                if (EntityToAttack != null)
                {
                    PathToEntity = WorldObj.GetPathEntityToEntity(this, EntityToAttack, f, true, false, false, true);
                }
            }
            else if (!EntityToAttack.IsEntityAlive())
            {
                EntityToAttack = null;
            }
            else
            {
                float f1 = EntityToAttack.GetDistanceToEntity(this);

                if (CanEntityBeSeen(EntityToAttack))
                {
                    AttackEntity(EntityToAttack, f1);
                }
                else
                {
                    AttackBlockedEntity(EntityToAttack, f1);
                }
            }

            Profiler.EndSection();

            if (!HasAttacked && EntityToAttack != null && (PathToEntity == null || Rand.Next(20) == 0))
            {
                PathToEntity = WorldObj.GetPathEntityToEntity(this, EntityToAttack, f, true, false, false, true);
            }
            else if (!HasAttacked && (PathToEntity == null && Rand.Next(180) == 0 || Rand.Next(120) == 0 || FleeingTick > 0) && EntityAge < 100)
            {
                UpdateWanderPath();
            }

            int  i     = MathHelper2.Floor_double(BoundingBox.MinY + 0.5D);
            bool flag  = IsInWater();
            bool flag1 = HandleLavaMovement();

            RotationPitch = 0.0F;

            if (PathToEntity == null || Rand.Next(100) == 0)
            {
                base.UpdateEntityActionState();
                PathToEntity = null;
                return;
            }

            Profiler.StartSection("followpath");
            Vec3D vec3d = PathToEntity.GetCurrentNodeVec3d(this);

            for (double d = Width * 2.0F; vec3d != null && vec3d.SquareDistanceTo(PosX, vec3d.YCoord, PosZ) < d * d;)
            {
                PathToEntity.IncrementPathIndex();

                if (PathToEntity.IsFinished())
                {
                    vec3d        = null;
                    PathToEntity = null;
                }
                else
                {
                    vec3d = PathToEntity.GetCurrentNodeVec3d(this);
                }
            }

            IsJumping = false;

            if (vec3d != null)
            {
                double d1 = vec3d.XCoord - PosX;
                double d2 = vec3d.ZCoord - PosZ;
                double d3 = vec3d.YCoord - (double)i;
                float  f2 = (float)((Math.Atan2(d2, d1) * 180D) / Math.PI) - 90F;
                float  f3 = f2 - RotationYaw;
                MoveForward = MoveSpeed;

                for (; f3 < -180F; f3 += 360F)
                {
                }

                for (; f3 >= 180F; f3 -= 360F)
                {
                }

                if (f3 > 30F)
                {
                    f3 = 30F;
                }

                if (f3 < -30F)
                {
                    f3 = -30F;
                }

                RotationYaw += f3;

                if (HasAttacked && EntityToAttack != null)
                {
                    double d4 = EntityToAttack.PosX - PosX;
                    double d5 = EntityToAttack.PosZ - PosZ;
                    float  f5 = RotationYaw;
                    RotationYaw = (float)((Math.Atan2(d5, d4) * 180D) / Math.PI) - 90F;
                    float f4 = (((f5 - RotationYaw) + 90F) * (float)Math.PI) / 180F;
                    MoveStrafing = -MathHelper2.Sin(f4) * MoveForward * 1.0F;
                    MoveForward  = MathHelper2.Cos(f4) * MoveForward * 1.0F;
                }

                if (d3 > 0.0F)
                {
                    IsJumping = true;
                }
            }

            if (EntityToAttack != null)
            {
                FaceEntity(EntityToAttack, 30F, 30F);
            }

            if (IsCollidedHorizontally && !HasPath())
            {
                IsJumping = true;
            }

            if (Rand.NextFloat() < 0.8F && (flag || flag1))
            {
                IsJumping = true;
            }

            Profiler.EndSection();
        }