コード例 #1
0
 public override void AI()
 {
     projectile.velocity.Y += 0.06f;
     projectile.rotation   += projectile.ai[1];
     OriginExtensions.LinearSmoothing(ref projectile.ai[1], 0, 0.001f);
     Lighting.AddLight(projectile.Center, 0, 0.5f, 0);
     if (Main.rand.Next(100) <= projectile.velocity.Length())
     {
         SpawnDust(0f);
     }
 }
コード例 #2
0
        public override void AI()
        {
            if (projectile.localAI[2] > 0f)
            {
                projectile.localAI[2]--;
                projectile.timeLeft--;
            }
            if (projectile.localAI[0] > 0f)
            {
                projectile.localAI[0]--;
            }
            if (projectile.localAI[0] == 0f && projectile.owner == Main.myPlayer)
            {
                projectile.localAI[0] = 5f;
                float currentTargetDist = projectile.ai[0] > 0?Main.npc[(int)projectile.ai[0] - 1].Distance(projectile.Center):0;
                for (int i = 0; i < Main.maxNPCs; i++)
                {
                    NPC targetOption = Main.npc[i];
                    if (targetOption.CanBeChasedBy())
                    {
                        float newTargetDist = targetOption.Distance(projectile.Center);
                        bool  selectNew     = projectile.ai[0] <= 0f || currentTargetDist > newTargetDist;
                        if (selectNew && (newTargetDist < 240f))
                        {
                            projectile.ai[0]  = i + 1;
                            currentTargetDist = newTargetDist;
                        }
                    }
                }
                if (projectile.ai[0] > 0f)
                {
                    projectile.timeLeft  = 300 - Main.rand.Next(120);
                    projectile.netUpdate = true;
                }
            }
            float scaleFactor = MathHelper.Clamp((30 - projectile.localAI[2]) * 0.04f, 0.1f, 1f);
            Dust  dust        = Dust.NewDustDirect(projectile.Center, 0, 0, 27, 0f, -2f);

            dust.noGravity = true;
            dust.velocity  = projectile.oldVelocity * 0.5f;
            dust.scale     = scaleFactor;
            dust.fadeIn    = 0.5f;
            dust.alpha     = 200;

            int target = (int)projectile.ai[0] - 1;

            if (target >= 0)
            {
                if (Main.npc[target].active)
                {
                    if (projectile.Distance(Main.npc[target].Center) > 1f)
                    {
                        Vector2 dir = projectile.DirectionTo(Main.npc[target].Center);
                        if (dir.HasNaNs())
                        {
                            dir = Vector2.UnitY;
                        }
                        float     angle     = dir.ToRotation();
                        PolarVec2 velocity  = (PolarVec2)projectile.velocity;
                        float     targetVel = projectile.ai[1];
                        bool      changed   = false;
                        if (velocity.R != targetVel)
                        {
                            OriginExtensions.LinearSmoothing(ref velocity.R, targetVel, (targetVel - 0.5f) * 0.1f);
                            changed = true;
                        }
                        if (velocity.Theta != angle)
                        {
                            OriginExtensions.AngularSmoothing(ref velocity.Theta, angle, 0.1f);
                            changed = true;
                        }
                        if (changed)
                        {
                            projectile.velocity = (Vector2)velocity;
                        }
                    }
                    return;
                }
                projectile.ai[0]     = 0f;
                projectile.netUpdate = true;
            }
            else
            {
                PolarVec2 velocity  = (PolarVec2)projectile.velocity;
                float     targetVel = projectile.ai[1];
                bool      changed   = false;
                if (velocity.R != targetVel)
                {
                    OriginExtensions.LinearSmoothing(ref velocity.R, targetVel / 3f, (targetVel - 0.5f) * 0.1f);
                    changed = true;
                }

                if (velocity.Theta != projectile.localAI[1])
                {
                    OriginExtensions.AngularSmoothing(ref velocity.Theta, projectile.localAI[1], (targetVel - 0.5f) * 0.03f);
                    changed = true;
                }
                else
                {
                    projectile.localAI[1] = Main.rand.NextFloat(-MathHelper.Pi, MathHelper.Pi);
                }

                if (changed)
                {
                    projectile.velocity = (Vector2)velocity;
                }
            }
        }