Terraria.Projectile.AI_062 C# (CSharp) Method

AI_062() private method

private AI_062 ( ) : void
return void
        private void AI_062()
        {
            if (type == 373)
            {
                if (Main.player[owner].dead)
                    Main.player[owner].hornetMinion = false;
                if (Main.player[owner].hornetMinion)
                    timeLeft = 2;
            }
            if (type == 375)
            {
                if (Main.player[owner].dead)
                    Main.player[owner].impMinion = false;
                if (Main.player[owner].impMinion)
                    timeLeft = 2;
            }
            if (type == 407)
            {
                if (Main.player[owner].dead)
                    Main.player[owner].sharknadoMinion = false;
                if (Main.player[owner].sharknadoMinion)
                    timeLeft = 2;
            }
            if (type == 423)
            {
                if (Main.player[owner].dead)
                    Main.player[owner].UFOMinion = false;
                if (Main.player[owner].UFOMinion)
                    timeLeft = 2;
            }
            if (type == 613)
            {
                if (Main.player[owner].dead)
                    Main.player[owner].stardustMinion = false;
                if (Main.player[owner].stardustMinion)
                    timeLeft = 2;
                Lighting.AddLight(Center, 0.2f, 0.6f, 0.7f);
                if (localAI[1] > 0.0)
                    --localAI[1];
            }
            if (type == 423)
            {
                if (ai[0] == 2.0)
                {
                    --ai[1];
                    tileCollide = false;
                    if (ai[1] > 3.0)
                    {
                        int index = Dust.NewDust(Center, 0, 0, 220 + Main.rand.Next(2), velocity.X, velocity.Y, 100, new Color(), 1f);
                        Main.dust[index].scale = (float)(0.5 + Main.rand.NextDouble() * 0.300000011920929);
                        Main.dust[index].velocity /= 2.5f;
                        Main.dust[index].noGravity = true;
                        Main.dust[index].noLight = true;
                        Main.dust[index].frame.Y = 80;
                    }
                    if (ai[1] != 0.0)
                        return;
                    ai[1] = 30f;
                    ai[0] = 0.0f;
                    Projectile projectile = this;
                    Vector2 vector2 = projectile.velocity / 5f;
                    projectile.velocity = vector2;
                    velocity.Y = 0.0f;
                    extraUpdates = 0;
                    numUpdates = 0;
                    netUpdate = true;
                    extraUpdates = 0;
                    numUpdates = 0;
                }
                if (extraUpdates > 1)
                    extraUpdates = 0;
                if (numUpdates > 1)
                    numUpdates = 0;
            }
            if (type == 613)
            {
                if (ai[0] == 2.0)
                {
                    --ai[1];
                    tileCollide = false;
                    if (ai[1] > 3.0)
                    {
                        if (numUpdates < 20)
                        {
                            for (int index = 0; index < 3; ++index)
                            {
                                Dust dust = Main.dust[Dust.NewDust(position, width, height, 229, 0.0f, 0.0f, 0, new Color(), 1f)];
                                dust.noGravity = true;
                                dust.position = Center;
                                dust.velocity *= 3f;
                                dust.velocity += velocity * 3f;
                                dust.fadeIn = 1f;
                            }
                        }
                        float num1 = (float)(2.0 - numUpdates / 30.0);
                        if (scale > 0.0)
                        {
                            float num2 = 2f;
                            for (int index = 0; (double)index < num2; ++index)
                            {
                                Dust dust = Main.dust[Dust.NewDust(position, width, height, 229, 0.0f, 0.0f, 0, new Color(), 1f)];
                                dust.noGravity = true;
                                dust.position = Center + Utils.RotatedBy(Vector2.UnitY, numUpdates * 0.104719758033752 + whoAmI * 0.785398185253143 + 1.57079637050629, new Vector2()) * (height / 2) - velocity * ((float)index / num2);
                                dust.velocity = velocity / 3f;
                                dust.fadeIn = num1 / 2f;
                                dust.scale = num1;
                            }
                        }
                    }
                    if (ai[1] != 0.0)
                        return;
                    ai[1] = 30f;
                    ai[0] = 0.0f;
                    Projectile projectile = this;
                    Vector2 vector2 = projectile.velocity / 5f;
                    projectile.velocity = vector2;
                    velocity.Y = 0.0f;
                    extraUpdates = 0;
                    numUpdates = 0;
                    netUpdate = true;
                    float num = 15f;
                    for (int index = 0; index < num; ++index)
                    {
                        Dust dust = Main.dust[Dust.NewDust(position, width, height, 229, 0.0f, 0.0f, 0, new Color(), 1f)];
                        dust.noGravity = true;
                        dust.position = Center - velocity * 5f;
                        dust.velocity *= 3f;
                        dust.velocity += velocity * 3f;
                        dust.fadeIn = 1f;
                        if (Main.rand.Next(3) != 0)
                        {
                            dust.fadeIn = 2f;
                            dust.scale = 2f;
                            dust.velocity /= 8f;
                        }
                    }
                    for (int index = 0; index < num; ++index)
                    {
                        Dust dust = Main.dust[Dust.NewDust(position, width, height, 229, 0.0f, 0.0f, 0, new Color(), 1f)];
                        dust.noGravity = true;
                        dust.position = Center;
                        dust.velocity *= 3f;
                        dust.velocity += velocity * 3f;
                        dust.fadeIn = 1f;
                        if (Main.rand.Next(3) != 0)
                        {
                            dust.fadeIn = 2f;
                            dust.scale = 2f;
                            dust.velocity /= 8f;
                        }
                    }
                    extraUpdates = 0;
                    numUpdates = 0;
                }
                if (extraUpdates > 1)
                    extraUpdates = 0;
                if (numUpdates > 1)
                    numUpdates = 0;
            }
            if (type == 423 && localAI[0] > 0.0)
                --localAI[0];
            if (type == 613 && localAI[0] > 0.0)
                --localAI[0];
            float num3 = 0.05f;
            float num4 = width;
            if (type == 407)
            {
                num3 = 0.1f;
                num4 *= 2f;
            }
            for (int index = 0; index < 1000; ++index)
            {
                if (index != whoAmI && Main.projectile[index].active && (Main.projectile[index].owner == owner && Main.projectile[index].type == type) && Math.Abs(position.X - Main.projectile[index].position.X) + Math.Abs(position.Y - Main.projectile[index].position.Y) < num4)
                {
                    if (position.X < Main.projectile[index].position.X)
                        velocity.X -= num3;
                    else
                        velocity.X += num3;
                    if (position.Y < Main.projectile[index].position.Y)
                        velocity.Y -= num3;
                    else
                        velocity.Y += num3;
                }
            }
            Vector2 vector2_1 = position;
            float num5 = 400f;
            if (type == 423)
                num5 = 300f;
            if (type == 613)
                num5 = 300f;
            bool flag = false;
            int ai1 = -1;
            tileCollide = true;
            if (type == 407)
            {
                tileCollide = false;
                if (Collision.SolidCollision(position, width, height))
                {
                    alpha += 20;
                    if (alpha > 150)
                        alpha = 150;
                }
                else
                {
                    alpha -= 50;
                    if (alpha < 60)
                        alpha = 60;
                }
            }
            if (type == 407 || type == 613 || type == 423)
            {
                Vector2 center = Main.player[owner].Center;
                Vector2 vector2_2 = new Vector2(0.5f);
                if (type == 423)
                    vector2_2.Y = 0.0f;
                for (int index = 0; index < 200; ++index)
                {
                    NPC npc = Main.npc[index];
                    if (npc.CanBeChasedBy(this, false))
                    {
                        Vector2 vector2_3 = npc.position + npc.Size * vector2_2;
                        float num1 = Vector2.Distance(vector2_3, center);
                        if ((Vector2.Distance(center, vector2_1) > num1 && num1 < num5 || !flag) && Collision.CanHitLine(position, width, height, npc.position, npc.width, npc.height))
                        {
                            num5 = num1;
                            vector2_1 = vector2_3;
                            flag = true;
                            ai1 = index;
                        }
                    }
                }
            }
            else
            {
                for (int index = 0; index < 200; ++index)
                {
                    NPC npc = Main.npc[index];
                    if (npc.CanBeChasedBy(this, false))
                    {
                        float num1 = Vector2.Distance(npc.Center, Center);
                        if ((Vector2.Distance(Center, vector2_1) > num1 && num1 < num5 || !flag) && Collision.CanHitLine(position, width, height, npc.position, npc.width, npc.height))
                        {
                            num5 = num1;
                            vector2_1 = npc.Center;
                            flag = true;
                            ai1 = index;
                        }
                    }
                }
            }
            int num7 = 500;
            if (flag)
                num7 = 1000;
            if (flag && type == 423)
                num7 = 1200;
            if (flag && type == 613)
                num7 = 1350;
            Player player = Main.player[owner];
            if (Vector2.Distance(player.Center, Center) > num7)
            {
                ai[0] = 1f;
                netUpdate = true;
            }
            if (ai[0] == 1.0)
                tileCollide = false;
            if (flag && ai[0] == 0.0)
            {
                Vector2 vector2_2 = vector2_1 - Center;
                float num1 = vector2_2.Length();
                vector2_2.Normalize();
                if (type == 423)
                {
                    Vector2 vector2_3 = vector2_1 - Vector2.UnitY * 80f;
                    int index = (int)vector2_3.Y / 16;
                    if (index < 0)
                        index = 0;
                    Tile tile1 = Main.tile[(int)vector2_3.X / 16, index];
                    if (tile1 != null && tile1.active() && (Main.tileSolid[tile1.type] && !Main.tileSolidTop[tile1.type]))
                    {
                        vector2_3 += Vector2.UnitY * 16f;
                        Tile tile2 = Main.tile[(int)vector2_3.X / 16, (int)vector2_3.Y / 16];
                        if (tile2 != null && tile2.active() && (Main.tileSolid[tile2.type] && !Main.tileSolidTop[tile2.type]))
                            vector2_3 += Vector2.UnitY * 16f;
                    }
                    vector2_2 = vector2_3 - Center;
                    num1 = vector2_2.Length();
                    vector2_2.Normalize();
                    if (num1 > 300.0 && num1 <= 800.0 && localAI[0] == 0.0)
                    {
                        ai[0] = 2f;
                        ai[1] = (int)(num1 / 10.0);
                        extraUpdates = (int)ai[1];
                        velocity = vector2_2 * 10f;
                        localAI[0] = 60f;
                        return;
                    }
                }
                if (type == 613)
                {
                    Vector2 vector2_3 = vector2_1;
                    Vector2 vector2_4 = Center - vector2_3;
                    if (vector2_4 == Vector2.Zero)
                        vector2_4 = -Vector2.UnitY;
                    vector2_4.Normalize();
                    Vector2 vector2_5 = vector2_3 + vector2_4 * 60f;
                    int index = (int)vector2_5.Y / 16;
                    if (index < 0)
                        index = 0;
                    Tile tile1 = Main.tile[(int)vector2_5.X / 16, index];
                    if (tile1 != null && tile1.active() && (Main.tileSolid[tile1.type] && !Main.tileSolidTop[tile1.type]))
                    {
                        vector2_5 += Vector2.UnitY * 16f;
                        Tile tile2 = Main.tile[(int)vector2_5.X / 16, (int)vector2_5.Y / 16];
                        if (tile2 != null && tile2.active() && (Main.tileSolid[tile2.type] && !Main.tileSolidTop[tile2.type]))
                            vector2_5 += Vector2.UnitY * 16f;
                    }
                    vector2_2 = vector2_5 - Center;
                    num1 = vector2_2.Length();
                    vector2_2.Normalize();
                    if (num1 > 400.0 && num1 <= 800.0 && localAI[0] == 0.0)
                    {
                        ai[0] = 2f;
                        ai[1] = (float)(int)(num1 / 10.0);
                        extraUpdates = (int)ai[1];
                        velocity = vector2_2 * 10f;
                        localAI[0] = 60f;
                        return;
                    }
                }
                if (type == 407)
                {
                    if (num1 > 400.0)
                    {
                        float num2 = 2f;
                        vector2_2 *= num2;
                        velocity = (velocity * 20f + vector2_2) / 21f;
                    }
                    else
                    {
                        Projectile projectile = this;
                        Vector2 vector2_3 = projectile.velocity * 0.96f;
                        projectile.velocity = vector2_3;
                    }
                }
                if (num1 > 200.0)
                {
                    float num2 = 6f;
                    Vector2 vector2_3 = vector2_2 * num2;
                    velocity.X = (float)((velocity.X * 40.0 + vector2_3.X) / 41.0);
                    velocity.Y = (float)((velocity.Y * 40.0 + vector2_3.Y) / 41.0);
                }
                else if (type == 423 || type == 613)
                {
                    if (num1 > 70.0 && num1 < 130.0)
                    {
                        float num2 = 7f;
                        if (num1 < 100.0)
                            num2 = -3f;
                        Vector2 vector2_3 = vector2_2 * num2;
                        velocity = (velocity * 20f + vector2_3) / 21f;
                        if (Math.Abs(vector2_3.X) > Math.Abs(vector2_3.Y))
                            velocity.X = (float)((velocity.X * 10.0 + vector2_3.X) / 11.0);
                    }
                    else
                    {
                        Projectile projectile = this;
                        Vector2 vector2_3 = projectile.velocity * 0.97f;
                        projectile.velocity = vector2_3;
                    }
                }
                else if (type == 375)
                {
                    if (num1 < 150.0)
                    {
                        float num2 = 4f;
                        Vector2 vector2_3 = vector2_2 * -num2;
                        velocity.X = (float)((velocity.X * 40.0 + vector2_3.X) / 41.0);
                        velocity.Y = (float)((velocity.Y * 40.0 + vector2_3.Y) / 41.0);
                    }
                    else
                    {
                        Projectile projectile = this;
                        Vector2 vector2_3 = projectile.velocity * 0.97f;
                        projectile.velocity = vector2_3;
                    }
                }
                else if (velocity.Y > -1.0)
                    velocity.Y -= 0.1f;
            }
            else
            {
                if (!Collision.CanHitLine(Center, 1, 1, Main.player[owner].Center, 1, 1))
                    ai[0] = 1f;
                float num1 = 6f;
                if (ai[0] == 1.0)
                    num1 = 15f;
                if (type == 407)
                    num1 = 9f;
                Vector2 center = Center;
                Vector2 vector2_2 = player.Center - center + new Vector2(0.0f, -60f);
                if (type == 407)
                    vector2_2 += new Vector2(0.0f, 40f);
                if (type == 375)
                {
                    ai[1] = 3600f;
                    netUpdate = true;
                    vector2_2 = player.Center - center;
                    int num2 = 1;
                    for (int index = 0; index < whoAmI; ++index)
                    {
                        if (Main.projectile[index].active && Main.projectile[index].owner == owner && Main.projectile[index].type == type)
                            ++num2;
                    }
                    vector2_2.X -= (10 * Main.player[owner].direction);
                    vector2_2.X -= (num2 * 40 * Main.player[owner].direction);
                    vector2_2.Y -= 10f;
                }
                float num8 = vector2_2.Length();
                if (num8 > 200.0 && num1 < 9.0)
                    num1 = 9f;
                if (type == 375)
                    num1 = (int)(num1 * 0.75);
                if (num8 < 100.0 && ai[0] == 1.0 && !Collision.SolidCollision(position, width, height))
                {
                    ai[0] = 0.0f;
                    netUpdate = true;
                }
                if (num8 > 2000.0)
                {
                    position.X = Main.player[owner].Center.X - (width / 2);
                    position.Y = Main.player[owner].Center.Y - (width / 2);
                }
                if (type == 375)
                {
                    if (num8 > 10.0)
                    {
                        vector2_2.Normalize();
                        if (num8 < 50.0)
                            num1 /= 2f;
                        vector2_2 *= num1;
                        velocity = (velocity * 20f + vector2_2) / 21f;
                    }
                    else
                    {
                        direction = Main.player[owner].direction;
                        Projectile projectile = this;
                        Vector2 vector2_3 = projectile.velocity * 0.9f;
                        projectile.velocity = vector2_3;
                    }
                }
                else if (type == 407)
                {
                    if (Math.Abs(vector2_2.X) > 40.0 || Math.Abs(vector2_2.Y) > 10.0)
                    {
                        vector2_2.Normalize();
                        vector2_2 *= num1;
                        vector2_2 *= new Vector2(1.25f, 0.65f);
                        velocity = (velocity * 20f + vector2_2) / 21f;
                    }
                    else
                    {
                        if (velocity.X == 0.0 && velocity.Y == 0.0)
                        {
                            velocity.X = -0.15f;
                            velocity.Y = -0.05f;
                        }
                        Projectile projectile = this;
                        Vector2 vector2_3 = projectile.velocity * 1.01f;
                        projectile.velocity = vector2_3;
                    }
                }
                else if (num8 > 70.0)
                {
                    vector2_2.Normalize();
                    vector2_2 *= num1;
                    velocity = (velocity * 20f + vector2_2) / 21f;
                }
                else
                {
                    if (velocity.X == 0.0 && velocity.Y == 0.0)
                    {
                        velocity.X = -0.15f;
                        velocity.Y = -0.05f;
                    }
                    Projectile projectile = this;
                    Vector2 vector2_3 = projectile.velocity * 1.01f;
                    projectile.velocity = vector2_3;
                }
            }
            rotation = velocity.X * 0.05f;
            ++frameCounter;
            if (type == 373)
            {
                if (frameCounter > 1)
                {
                    ++frame;
                    frameCounter = 0;
                }
                if (frame > 2)
                    frame = 0;
            }
            if (type == 375)
            {
                if (frameCounter >= 16)
                    frameCounter = 0;
                frame = frameCounter / 4;
                if (ai[1] > 0.0 && ai[1] < 16.0)
                    frame += 4;
                if (Main.rand.Next(6) == 0)
                {
                    int index = Dust.NewDust(new Vector2(position.X, position.Y), width, height, 6, 0.0f, 0.0f, 100, new Color(), 2f);
                    Main.dust[index].velocity *= 0.3f;
                    Main.dust[index].noGravity = true;
                    Main.dust[index].noLight = true;
                }
            }
            if (type == 407)
            {
                int num1 = 2;
                if (frameCounter >= 6 * num1)
                    frameCounter = 0;
                frame = frameCounter / num1;
                if (Main.rand.Next(5) == 0)
                {
                    int index = Dust.NewDust(new Vector2(position.X, position.Y), width, height, 217, 0.0f, 0.0f, 100, new Color(), 2f);
                    Main.dust[index].velocity *= 0.3f;
                    Main.dust[index].noGravity = true;
                    Main.dust[index].noLight = true;
                }
            }
            if (type == 423 || type == 613)
            {
                int num1 = 3;
                if (frameCounter >= 4 * num1)
                    frameCounter = 0;
                frame = frameCounter / num1;
            }
            if (velocity.X > 0.0)
                spriteDirection = direction = -1;
            else if (velocity.X < 0.0)
                spriteDirection = direction = 1;
            if (type == 373)
            {
                if (ai[1] > 0.0)
                    ai[1] += Main.rand.Next(1, 4);
                if (ai[1] > 90.0)
                {
                    ai[1] = 0.0f;
                    netUpdate = true;
                }
            }
            else if (type == 375)
            {
                if (ai[1] > 0.0)
                {
                    ++ai[1];
                    if (Main.rand.Next(3) == 0)
                        ++ai[1];
                }
                if (ai[1] > Main.rand.Next(180, 900))
                {
                    ai[1] = 0.0f;
                    netUpdate = true;
                }
            }
            else if (type == 407)
            {
                if (ai[1] > 0.0)
                {
                    ++ai[1];
                    if (Main.rand.Next(3) != 0)
                        ++ai[1];
                }
                if (ai[1] > 60.0)
                {
                    ai[1] = 0.0f;
                    netUpdate = true;
                }
            }
            else if (type == 423)
            {
                if (ai[1] > 0.0)
                {
                    ++ai[1];
                    if (Main.rand.Next(3) != 0)
                        ++ai[1];
                }
                if (ai[1] > 30.0)
                {
                    ai[1] = 0.0f;
                    netUpdate = true;
                }
            }
            else if (type == 613)
            {
                if (ai[1] > 0.0)
                {
                    ++ai[1];
                    if (Main.rand.Next(3) != 0)
                        ++ai[1];
                }
                if (ai[1] > 60.0)
                {
                    ai[1] = 0.0f;
                    netUpdate = true;
                }
            }
            if (ai[0] != 0.0)
                return;
            float num9 = 0.0f;
            int Type = 0;
            if (type == 373)
            {
                num9 = 10f;
                Type = 374;
            }
            else if (type == 375)
            {
                num9 = 11f;
                Type = 376;
            }
            else if (type == 407)
            {
                num9 = 14f;
                Type = 408;
            }
            else if (type == 423)
            {
                num9 = 4f;
                Type = 433;
            }
            else if (type == 613)
            {
                num9 = 14f;
                Type = 614;
            }
            if (!flag)
                return;
            if (type == 375)
            {
                if ((vector2_1 - Center).X > 0.0)
                    spriteDirection = direction = -1;
                else if ((vector2_1 - Center).X < 0.0)
                    spriteDirection = direction = 1;
            }
            if (type == 407 && Collision.SolidCollision(position, width, height))
                return;
            if (type == 423)
            {
                if (Math.Abs(Utils.ToRotation(vector2_1 - Center) - 1.570796f) > 0.785398185253143)
                {
                    Projectile projectile = this;
                    Vector2 vector2_2 = projectile.velocity + Vector2.Normalize(vector2_1 - Center - Vector2.UnitY * 80f);
                    projectile.velocity = vector2_2;
                }
                else
                {
                    if ((vector2_1 - Center).Length() > 400.0 || ai[1] != 0.0)
                        return;
                    ++ai[1];
                    if (Main.myPlayer != owner)
                        return;
                    Vector2 vector2_2 = vector2_1 - Center;
                    vector2_2.Normalize();
                    Vector2 vector2_3 = vector2_2 * num9;
                    NewProjectile(Center.X, Center.Y, vector2_3.X, vector2_3.Y, Type, damage, 0.0f, Main.myPlayer, 0.0f, 0.0f);
                    netUpdate = true;
                }
            }
            else if (ai[1] == 0.0 && type == 613)
            {
                if ((double)(vector2_1 - Center).Length() > 500.0 || ai[1] != 0.0)
                    return;
                ++ai[1];
                if (Main.myPlayer == owner)
                {
                    Vector2 vector2_2 = vector2_1 - Center;
                    vector2_2.Normalize();
                    Vector2 vector2_3 = vector2_2 * num9;
                    int index = NewProjectile(Center.X, Center.Y, vector2_3.X, vector2_3.Y, Type, damage, 0.0f, Main.myPlayer, 0.0f, ai1);
                    Main.projectile[index].timeLeft = 300;
                    Main.projectile[index].netUpdate = true;
                    Projectile projectile = this;
                    Vector2 vector2_4 = projectile.velocity - vector2_3 / 3f;
                    projectile.velocity = vector2_4;
                    netUpdate = true;
                }
                for (int index1 = 0; index1 < 5; ++index1)
                {
                    int num1 = width / 4;
                    Vector2 vector2_2 = Utils.ToRotationVector2((float)Main.rand.NextDouble() * 6.283185f) * Main.rand.Next(24, 41) / 8f;
                    int index2 = Dust.NewDust(Center - Vector2.One * num1, num1 * 2, num1 * 2, 88, 0.0f, 0.0f, 0, new Color(), 1f);
                    Dust dust = Main.dust[index2];
                    Vector2 vector2_3 = Vector2.Normalize(dust.position - Center);
                    dust.position = Center + vector2_3 * num1 * scale - new Vector2(4f);
                    dust.velocity = index1 >= 30 ? 2f * vector2_3 * Main.rand.Next(45, 91) / 10f : vector2_3 * dust.velocity.Length() * 2f;
                    dust.noGravity = true;
                    dust.scale = 0.7f + Utils.NextFloat(Main.rand);
                }
            }
            else
            {
                if (ai[1] != 0.0)
                    return;
                ++ai[1];
                if (Main.myPlayer != owner)
                    return;
                Vector2 vector2_2 = vector2_1 - Center;
                vector2_2.Normalize();
                Vector2 vector2_3 = vector2_2 * num9;
                int index = NewProjectile(Center.X, Center.Y, vector2_3.X, vector2_3.Y, Type, damage, 0.0f, Main.myPlayer, 0.0f, 0.0f);
                Main.projectile[index].timeLeft = 300;
                Main.projectile[index].netUpdate = true;
                netUpdate = true;
            }
        }