コード例 #1
0
        // 37 - 1.1.2
        private void AITheDestroyer(NPC npc, bool flag, Func<Int32, Int32, ITile> TileRefs)
        {
            if (npc.ai[3] > 0f)
            {
                npc.realLife = (int)npc.ai[3];
            }
            if (npc.target < 0 || npc.target == 255 || Main.players[npc.target].dead)
            {
                npc.TargetClosest(true);
            }
            if (npc.type > NPCType.N134_THE_DESTROYER)
            {
                bool flag34 = false;
                if (npc.ai[1] <= 0f)
                {
                    flag34 = true;
                }
                else
                {
                    if (Main.npcs[(int)npc.ai[1]].life <= 0)
                    {
                        flag34 = true;
                    }
                }
                if (flag34)
                {
                    npc.life = 0;
                    npc.HitEffect(0, 10.0);
                    npc.CheckDead();
                }
            }
            if (npc.ai[0] == 0f && npc.type == NPCType.N134_THE_DESTROYER)
            {
                npc.ai[3] = (float)npc.whoAmI;
                npc.realLife = npc.whoAmI;
                int num447 = npc.whoAmI;
                int num448 = 80;
                for (int num449 = 0; num449 <= num448; num449++)
                {
                    int num450 = 135;
                    if (num449 == num448)
                    {
                        num450 = 136;
                    }
                    int num451 = NewNPC((int)(npc.Position.X + (float)(npc.Width / 2)), (int)(npc.Position.Y + (float)npc.Height), num450, npc.whoAmI, Main.stopSpawns);
                    Main.npcs[num451].ai[3] = (float)npc.whoAmI;
                    Main.npcs[num451].realLife = npc.whoAmI;
                    Main.npcs[num451].ai[1] = (float)num447;
                    Main.npcs[num447].ai[0] = (float)num451;
                    NetMessage.SendData(23, -1, -1, "", num451, 0f, 0f, 0f, 0);
                    num447 = num451;
                }
            }
            if (npc.type == NPCType.N135_THE_DESTROYER_BODY)
            {
                npc.localAI[0] += (float)Main.rand.Next(4);
                if (npc.localAI[0] >= (float)Main.rand.Next(1400, 26000))
                {
                    npc.localAI[0] = 0f;
                    npc.TargetClosest(true);
                    if (Collision.CanHit(npc.Position, npc.Width, npc.Height, Main.players[npc.target].Position, Main.players[npc.target].Width, Main.players[npc.target].Height))
                    {
                        float num452 = 8f;
                        Vector2 vector56 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)(npc.Height / 2));
                        float num453 = Main.players[npc.target].Position.X + (float)Main.players[npc.target].Width * 0.5f - vector56.X + (float)Main.rand.Next(-20, 21);
                        float num454 = Main.players[npc.target].Position.Y + (float)Main.players[npc.target].Height * 0.5f - vector56.Y + (float)Main.rand.Next(-20, 21);
                        float num455 = (float)Math.Sqrt((double)(num453 * num453 + num454 * num454));
                        num455 = num452 / num455;
                        num453 *= num455;
                        num454 *= num455;
                        num453 += (float)Main.rand.Next(-20, 21) * 0.05f;
                        num454 += (float)Main.rand.Next(-20, 21) * 0.05f;
                        int num456 = 22;
                        int num457 = 100;
                        vector56.X += num453 * 5f;
                        vector56.Y += num454 * 5f;
                        int num458 = Projectile.NewProjectile(vector56.X, vector56.Y, num453, num454, num457, num456, 0f, Main.myPlayer);
                        Main.projectile[num458].timeLeft = 300;
                        npc.netUpdate = true;
                    }
                }
            }

            int num459 = (int)(npc.Position.X / 16f) - 1;
            int num460 = (int)((npc.Position.X + (float)npc.Width) / 16f) + 2;
            int num461 = (int)(npc.Position.Y / 16f) - 1;
            int num462 = (int)((npc.Position.Y + (float)npc.Height) / 16f) + 2;
            if (num459 < 0)
            {
                num459 = 0;
            }
            if (num460 > Main.maxTilesX)
            {
                num460 = Main.maxTilesX;
            }
            if (num461 < 0)
            {
                num461 = 0;
            }
            if (num462 > Main.maxTilesY)
            {
                num462 = Main.maxTilesY;
            }
            bool flag35 = false;
            if (!flag35)
            {
                for (int num463 = num459; num463 < num460; num463++)
                {
                    for (int num464 = num461; num464 < num462; num464++)
                    {
                        if (((Main.tile.At(num463, num464).Active && (Main.tileSolid[(int)Main.tile.At(num463, num464).Type] ||
                            (Main.tileSolidTop[(int)Main.tile.At(num463, num464).Type] && Main.tile.At(num463, num464).FrameY == 0))) ||
                            Main.tile.At(num463, num464).Liquid > 64))
                        {
                            Vector2 vector57;
                            vector57.X = (float)(num463 * 16);
                            vector57.Y = (float)(num464 * 16);
                            if (npc.Position.X + (float)npc.Width > vector57.X && npc.Position.X < vector57.X + 16f && npc.Position.Y + (float)npc.Height > vector57.Y && npc.Position.Y < vector57.Y + 16f)
                            {
                                flag35 = true;
                                break;
                            }
                        }
                    }
                }
            }
            if (!flag35)
            {
                npc.localAI[1] = 1f;
                if (npc.type == NPCType.N134_THE_DESTROYER)
                {
                    Rectangle rectangle11 = new Rectangle((int)npc.Position.X, (int)npc.Position.Y, npc.Width, npc.Height);
                    int num465 = 1000;
                    bool flag36 = true;
                    if (npc.Position.Y > Main.players[npc.target].Position.Y)
                    {
                        for (int num466 = 0; num466 < Main.MAX_PLAYERS; num466++)
                        {
                            if (Main.players[num466].Active)
                            {
                                Rectangle rectangle12 = new Rectangle((int)Main.players[num466].Position.X - num465, (int)Main.players[num466].Position.Y - num465, num465 * 2, num465 * 2);
                                if (rectangle11.Intersects(rectangle12))
                                {
                                    flag36 = false;
                                    break;
                                }
                            }
                        }
                        if (flag36)
                        {
                            flag35 = true;
                        }
                    }
                }
            }
            else
            {
                npc.localAI[1] = 0f;
            }
            float num467 = 16f;
            if (Main.dayTime || Main.players[npc.target].dead)
            {
                flag35 = false;
                npc.Velocity.Y = npc.Velocity.Y + 1f;
                if ((double)npc.Position.Y > Main.worldSurface * 16.0)
                {
                    npc.Velocity.Y = npc.Velocity.Y + 1f;
                    num467 = 32f;
                }
                if ((double)npc.Position.Y > Main.rockLayer * 16.0)
                {
                    for (int num468 = 0; num468 < 200; num468++)
                    {
                        if (Main.npcs[num468].aiStyle == npc.aiStyle)
                        {
                            Main.npcs[num468].Active = false;
                        }
                    }
                }
            }
            float num469 = 0.1f;
            float num470 = 0.15f;
            Vector2 vector58 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
            float num471 = Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2);
            float num472 = Main.players[npc.target].Position.Y + (float)(Main.players[npc.target].Height / 2);
            num471 = (float)((int)(num471 / 16f) * 16);
            num472 = (float)((int)(num472 / 16f) * 16);
            vector58.X = (float)((int)(vector58.X / 16f) * 16);
            vector58.Y = (float)((int)(vector58.Y / 16f) * 16);
            num471 -= vector58.X;
            num472 -= vector58.Y;
            float num473 = (float)Math.Sqrt((double)(num471 * num471 + num472 * num472));
            if (npc.ai[1] > 0f && npc.ai[1] < (float)Main.npcs.Length)
            {
                try
                {
                    vector58 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                    num471 = Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - vector58.X;
                    num472 = Main.npcs[(int)npc.ai[1]].Position.Y + (float)(Main.npcs[(int)npc.ai[1]].Height / 2) - vector58.Y;
                }
                catch
                { }

                npc.rotation = (float)Math.Atan2((double)num472, (double)num471) + 1.57f;
                num473 = (float)Math.Sqrt((double)(num471 * num471 + num472 * num472));
                int num474 = (int)(44f * npc.scale);
                num473 = (num473 - (float)num474) / num473;
                num471 *= num473;
                num472 *= num473;
                npc.Velocity = default(Vector2);
                npc.Position.X = npc.Position.X + num471;
                npc.Position.Y = npc.Position.Y + num472;
                return;
            }
            if (!flag35)
            {
                npc.TargetClosest(true);
                npc.Velocity.Y = npc.Velocity.Y + 0.15f;
                if (npc.Velocity.Y > num467)
                {
                    npc.Velocity.Y = num467;
                }
                if ((double)(Math.Abs(npc.Velocity.X) + Math.Abs(npc.Velocity.Y)) < (double)num467 * 0.4)
                {
                    if (npc.Velocity.X < 0f)
                    {
                        npc.Velocity.X = npc.Velocity.X - num469 * 1.1f;
                    }
                    else
                    {
                        npc.Velocity.X = npc.Velocity.X + num469 * 1.1f;
                    }
                }
                else if (npc.Velocity.Y == num467)
                {
                    if (npc.Velocity.X < num471)
                    {
                        npc.Velocity.X = npc.Velocity.X + num469;
                    }
                    else if (npc.Velocity.X > num471)
                    {
                        npc.Velocity.X = npc.Velocity.X - num469;
                    }
                }
                else if (npc.Velocity.Y > 4f)
                {
                    if (npc.Velocity.X < 0f)
                    {
                        npc.Velocity.X = npc.Velocity.X + num469 * 0.9f;
                    }
                    else
                    {
                        npc.Velocity.X = npc.Velocity.X - num469 * 0.9f;
                    }
                }
            }
            else
            {
                if (npc.soundDelay == 0)
                {
                    float num475 = num473 / 40f;
                    if (num475 < 10f)
                    {
                        num475 = 10f;
                    }
                    if (num475 > 20f)
                    {
                        num475 = 20f;
                    }
                    npc.soundDelay = (int)num475;
                }
                num473 = (float)Math.Sqrt((double)(num471 * num471 + num472 * num472));
                float num476 = Math.Abs(num471);
                float num477 = Math.Abs(num472);
                float num478 = num467 / num473;
                num471 *= num478;
                num472 *= num478;
                if (((npc.Velocity.X > 0f && num471 > 0f) || (npc.Velocity.X < 0f && num471 < 0f)) && ((npc.Velocity.Y > 0f && num472 > 0f) || (npc.Velocity.Y < 0f && num472 < 0f)))
                {
                    if (npc.Velocity.X < num471)
                    {
                        npc.Velocity.X = npc.Velocity.X + num470;
                    }
                    else if (npc.Velocity.X > num471)
                    {
                        npc.Velocity.X = npc.Velocity.X - num470;
                    }
                    if (npc.Velocity.Y < num472)
                    {
                        npc.Velocity.Y = npc.Velocity.Y + num470;
                    }
                    else if (npc.Velocity.Y > num472)
                    {
                        npc.Velocity.Y = npc.Velocity.Y - num470;
                    }
                }
                if ((npc.Velocity.X > 0f && num471 > 0f) || (npc.Velocity.X < 0f && num471 < 0f) || (npc.Velocity.Y > 0f && num472 > 0f) || (npc.Velocity.Y < 0f && num472 < 0f))
                {
                    if (npc.Velocity.X < num471)
                    {
                        npc.Velocity.X = npc.Velocity.X + num469;
                    }
                    else if (npc.Velocity.X > num471)
                    {
                        npc.Velocity.X = npc.Velocity.X - num469;
                    }
                    if (npc.Velocity.Y < num472)
                    {
                        npc.Velocity.Y = npc.Velocity.Y + num469;
                    }
                    else if (npc.Velocity.Y > num472)
                    {
                        npc.Velocity.Y = npc.Velocity.Y - num469;
                    }
                    if ((double)Math.Abs(num472) < (double)num467 * 0.2 && ((npc.Velocity.X > 0f && num471 < 0f) || (npc.Velocity.X < 0f && num471 > 0f)))
                    {
                        if (npc.Velocity.Y > 0f)
                        {
                            npc.Velocity.Y = npc.Velocity.Y + num469 * 2f;
                        }
                        else
                        {
                            npc.Velocity.Y = npc.Velocity.Y - num469 * 2f;
                        }
                    }
                    if ((double)Math.Abs(num471) < (double)num467 * 0.2 && ((npc.Velocity.Y > 0f && num472 < 0f) || (npc.Velocity.Y < 0f && num472 > 0f)))
                    {
                        if (npc.Velocity.X > 0f)
                        {
                            npc.Velocity.X = npc.Velocity.X + num469 * 2f;
                        }
                        else
                        {
                            npc.Velocity.X = npc.Velocity.X - num469 * 2f;
                        }
                    }
                }
                else if (num476 > num477)
                {
                    if (npc.Velocity.X < num471)
                    {
                        npc.Velocity.X = npc.Velocity.X + num469 * 1.1f;
                    }
                    else if (npc.Velocity.X > num471)
                    {
                        npc.Velocity.X = npc.Velocity.X - num469 * 1.1f;
                    }
                    if ((double)(Math.Abs(npc.Velocity.X) + Math.Abs(npc.Velocity.Y)) < (double)num467 * 0.5)
                    {
                        if (npc.Velocity.Y > 0f)
                        {
                            npc.Velocity.Y = npc.Velocity.Y + num469;
                        }
                        else
                        {
                            npc.Velocity.Y = npc.Velocity.Y - num469;
                        }
                    }
                }
                else
                {
                    if (npc.Velocity.Y < num472)
                    {
                        npc.Velocity.Y = npc.Velocity.Y + num469 * 1.1f;
                    }
                    else if (npc.Velocity.Y > num472)
                    {
                        npc.Velocity.Y = npc.Velocity.Y - num469 * 1.1f;
                    }
                    if ((double)(Math.Abs(npc.Velocity.X) + Math.Abs(npc.Velocity.Y)) < (double)num467 * 0.5)
                    {
                        if (npc.Velocity.X > 0f)
                        {
                            npc.Velocity.X = npc.Velocity.X + num469;
                        }
                        else
                        {
                            npc.Velocity.X = npc.Velocity.X - num469;
                        }
                    }
                }
            }
            npc.rotation = (float)Math.Atan2((double)npc.Velocity.Y, (double)npc.Velocity.X) + 1.57f;
            if (npc.type == NPCType.N134_THE_DESTROYER)
            {
                if (flag35)
                {
                    if (npc.localAI[0] != 1f)
                    {
                        npc.netUpdate = true;
                    }
                    npc.localAI[0] = 1f;
                }
                else
                {
                    if (npc.localAI[0] != 0f)
                    {
                        npc.netUpdate = true;
                    }
                    npc.localAI[0] = 0f;
                }
                if (((npc.Velocity.X > 0f && npc.oldVelocity.X < 0f) || (npc.Velocity.X < 0f && npc.oldVelocity.X > 0f) || (npc.Velocity.Y > 0f && npc.oldVelocity.Y < 0f) || (npc.Velocity.Y < 0f && npc.oldVelocity.Y > 0f)) && !npc.justHit)
                {
                    npc.netUpdate = true;
                    return;
                }
            }
        }