// 37
 private void AITheDestroyer(NPC npc, bool flag)
 {
     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 > 134)
     {
         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 == 134)
     {
         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 = NPC.NewNPC((int)(npc.Position.X + (float)(npc.Width / 2)), (int)(npc.Position.Y + (float)npc.Height), num450, npc.whoAmI);
             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 == 135)
     {
         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 == 134)
         {
             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 < 255; 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 == 134)
     {
         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;
         }
     }
 }
 // 6
 private void AIWorm(NPC npc, bool flag)
 {
     if (npc.target < 0 || npc.target == 255 || Main.players[npc.target].dead)
     {
         npc.TargetClosest(true);
     }
     if (Main.players[npc.target].dead && npc.timeLeft > 10)
     {
         npc.timeLeft = 10;
     }
     if ((npc.Type == 7 || npc.Type == 8 || npc.Type == 10 || npc.Type == 11 || npc.Type == 13 || npc.Type == 14 || npc.Type == 39 || npc.Type == 40) && npc.ai[0] == 0f)
     {
         if (npc.Type == 7 || npc.Type == 10 || npc.Type == 13 || npc.Type == 39)
         {
             npc.ai[2] = (float)Main.rand.Next(8, 13);
             if (npc.Type == 10)
             {
                 npc.ai[2] = (float)Main.rand.Next(4, 7);
             }
             if (npc.Type == 13)
             {
                 npc.ai[2] = (float)Main.rand.Next(45, 56);
             }
             if (npc.Type == 39)
             {
                 npc.ai[2] = (float)Main.rand.Next(12, 19);
             }
             npc.ai[0] = (float)NPC.NewNPC((int)(npc.Position.X + (float)(npc.Width / 2)), (int)(npc.Position.Y + (float)npc.Height), npc.Type + 1, npc.whoAmI);
         }
         else
         {
             if ((npc.Type == 8 || npc.Type == 11 || npc.Type == 14 || npc.Type == 40) && npc.ai[2] > 0f)
             {
                 npc.ai[0] = (float)NPC.NewNPC((int)(npc.Position.X + (float)(npc.Width / 2)), (int)(npc.Position.Y + (float)npc.Height), npc.Type, npc.whoAmI);
             }
             else
             {
                 npc.ai[0] = (float)NPC.NewNPC((int)(npc.Position.X + (float)(npc.Width / 2)), (int)(npc.Position.Y + (float)npc.Height), npc.Type + 1, npc.whoAmI);
             }
         }
         Main.npcs[(int)npc.ai[0]].ai[1] = (float)npc.whoAmI;
         Main.npcs[(int)npc.ai[0]].ai[2] = npc.ai[2] - 1f;
         npc.netUpdate = true;
     }
     if ((npc.Type == 8 || npc.Type == 9 || npc.Type == 11 || npc.Type == 12 || npc.Type == 40 || npc.Type == 41) && (!Main.npcs[(int)npc.ai[1]].Active || Main.npcs[(int)npc.ai[1]].aiStyle != npc.aiStyle))
     {
         npc.life = 0;
         npc.HitEffect(0, 10.0);
         npc.Active = false;
     }
     if ((npc.Type == 7 || npc.Type == 8 || npc.Type == 10 || npc.Type == 11 || npc.Type == 39 || npc.Type == 40) && !Main.npcs[(int)npc.ai[0]].Active)
     {
         npc.life = 0;
         npc.HitEffect(0, 10.0);
         npc.Active = false;
     }
     if (npc.type == NPCType.N13_EATER_OF_WORLDS_HEAD || npc.type == NPCType.N14_EATER_OF_WORLDS_BODY || npc.type == NPCType.N15_EATER_OF_WORLDS_TAIL)
     {
         //If this segment has no segment before or after it, DIE!
         if (!Main.npcs[(int)npc.ai[1]].Active && !Main.npcs[(int)npc.ai[0]].Active)
         {
             npc.life = 0;
             npc.HitEffect(0, 10.0);
             npc.Active = false;
         }
         //If we are a head connected to nothing, DIE!
         if (npc.type == NPCType.N13_EATER_OF_WORLDS_HEAD && !Main.npcs[(int)npc.ai[0]].Active)
         {
             npc.life = 0;
             npc.HitEffect(0, 10.0);
             npc.Active = false;
         }
         //If we are a tail connected to nothing, DIE!
         if (npc.type == NPCType.N15_EATER_OF_WORLDS_TAIL && !Main.npcs[(int)npc.ai[1]].Active)
         {
             npc.life = 0;
             npc.HitEffect(0, 10.0);
             npc.Active = false;
         }
         //If the next segment forward has died, become a head
         if (npc.type == NPCType.N14_EATER_OF_WORLDS_BODY && !Main.npcs[(int)npc.ai[1]].Active)
         {
             npc.type = NPCType.N13_EATER_OF_WORLDS_HEAD;
             int num52 = npc.whoAmI;
             float num53 = (float)npc.life / (float)npc.lifeMax;
             float num54 = npc.ai[0];
             //npc.SetDefaults(npc.Type, -1f);
             //npc = Registries.NPC.Create(npc.Type); WTF!?
             Registries.NPC.SetDefaults(npc, 13); //FIXME: remember to tweak
             npc.Active = true;
             npc.life = (int)((float)npc.lifeMax * num53);
             npc.ai[0] = num54;
             npc.TargetClosest(true);
             npc.netUpdate = true;
             npc.whoAmI = num52;
         }
         //If the next segment behind us has died, become a tail
         if (npc.type == NPCType.N14_EATER_OF_WORLDS_BODY && !Main.npcs[(int)npc.ai[0]].Active)
         {
             npc.type = NPCType.N15_EATER_OF_WORLDS_TAIL;
             int num55 = npc.whoAmI;
             float num56 = (float)npc.life / (float)npc.lifeMax;
             float num57 = npc.ai[1];
             //npc.SetDefaults(npc.Type, -1f);
             //npc = Registries.NPC.Create(npc.Type);
             Registries.NPC.SetDefaults(npc, 14); //FIXME: remember to tweak
             npc.Active = true;
             npc.life = (int)((float)npc.lifeMax * num56);
             npc.ai[1] = num57;
             npc.TargetClosest(true);
             npc.netUpdate = true;
             npc.whoAmI = num55;
         }
         if (npc.life == 0)
         {
             bool flag6 = true;
             for (int l = 0; l < MAX_NPCS; l++)
             {
                 if (Main.npcs[l].Active && (Main.npcs[l].type == NPCType.N13_EATER_OF_WORLDS_HEAD ||
                                              Main.npcs[l].type == NPCType.N14_EATER_OF_WORLDS_BODY ||
                                              Main.npcs[l].type == NPCType.N15_EATER_OF_WORLDS_TAIL))
                 {
                     flag6 = false;
                     break;
                 }
             }
             if (flag6)
             {
                 npc.boss = true;
                 npc.NPCLoot();
             }
         }
     }
     if (!npc.Active)
     {
         NetMessage.SendData(28, -1, -1, "", npc.whoAmI, -1f, 0f, 0f, 0);
     }
     int num58 = (int)(npc.Position.X / 16f) - 1;
     int num59 = (int)((npc.Position.X + (float)npc.Width) / 16f) + 2;
     int num60 = (int)(npc.Position.Y / 16f) - 1;
     int num61 = (int)((npc.Position.Y + (float)npc.Height) / 16f) + 2;
     if (num58 < 0)
     {
         num58 = 0;
     }
     if (num59 > Main.maxTilesX)
     {
         num59 = Main.maxTilesX;
     }
     if (num60 < 0)
     {
         num60 = 0;
     }
     if (num61 > Main.maxTilesY)
     {
         num61 = Main.maxTilesY;
     }
     bool flag7 = false;
     for (int m = num58; m < num59; m++)
     {
         for (int n = num60; n < num61; n++)
         {
             if (Main.tile.At(m, n).Exists && ((Main.tile.At(m, n).Active && (Main.tileSolid[(int)Main.tile.At(m, n).Type] || (Main.tileSolidTop[(int)Main.tile.At(m, n).Type] && Main.tile.At(m, n).FrameY == 0))) || Main.tile.At(m, n).Liquid > 64))
             {
                 Vector2 vector9;
                 vector9.X = (float)(m * 16);
                 vector9.Y = (float)(n * 16);
                 if (npc.Position.X + (float)npc.Width > vector9.X && npc.Position.X < vector9.X + 16f && npc.Position.Y + (float)npc.Height > vector9.Y && npc.Position.Y < vector9.Y + 16f)
                 {
                     flag7 = true;
                     if (Main.rand.Next(40) == 0 && Main.tile.At(m, n).Active)
                     {
                         WorldModify.KillTile(m, n, true, true, false);
                     }
                     //if (Main.tile.At(m, n).Type == 2)
                     //{
                     //    byte arg_4656_0 = Main.tile.At(m, n - 1).Type;
                     //}
                 }
             }
         }
     }
     if (!flag7 && (npc.Type == 7 || npc.Type == 10 || npc.Type == 13 || npc.Type == 39))
     {
         Rectangle rectangle = new Rectangle((int)npc.Position.X, (int)npc.Position.Y, npc.Width, npc.Height);
         int num62 = 1000;
         bool flag8 = true;
         for (int num63 = 0; num63 < 255; num63++)
         {
             if (Main.players[num63].Active)
             {
                 Rectangle rectangle2 = new Rectangle((int)Main.players[num63].Position.X - num62, (int)Main.players[num63].Position.Y - num62, num62 * 2, num62 * 2);
                 if (rectangle.Intersects(rectangle2))
                 {
                     flag8 = false;
                     break;
                 }
             }
         }
         if (flag8)
         {
             flag7 = true;
         }
     }
     float num64 = 8f;
     float num65 = 0.07f;
     if (npc.Type == 10)
     {
         num64 = 6f;
         num65 = 0.05f;
     }
     if (npc.Type == 13)
     {
         num64 = 10f;
         num65 = 0.07f;
     }
     Vector2 vector10 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
     float num66 = Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2) - vector10.X;
     float num67 = Main.players[npc.target].Position.Y + (float)(Main.players[npc.target].Height / 2) - vector10.Y;
     float num68 = (float)Math.Sqrt((double)(num66 * num66 + num67 * num67));
     if (npc.ai[1] > 0f)
     {
         num66 = Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - vector10.X;
         num67 = Main.npcs[(int)npc.ai[1]].Position.Y + (float)(Main.npcs[(int)npc.ai[1]].Height / 2) - vector10.Y;
         npc.rotation = (float)Math.Atan2((double)num67, (double)num66) + 1.57f;
         num68 = (float)Math.Sqrt((double)(num66 * num66 + num67 * num67));
         num68 = (num68 - (float)npc.Width) / num68;
         num66 *= num68;
         num67 *= num68;
         npc.Velocity = default(Vector2);
         npc.Position.X = npc.Position.X + num66;
         npc.Position.Y = npc.Position.Y + num67;
         return;
     }
     if (!flag7)
     {
         npc.TargetClosest(true);
         npc.Velocity.Y = npc.Velocity.Y + 0.11f;
         if (npc.Velocity.Y > num64)
         {
             npc.Velocity.Y = num64;
         }
         if ((double)(Math.Abs(npc.Velocity.X) + Math.Abs(npc.Velocity.Y)) < (double)num64 * 0.4)
         {
             if (npc.Velocity.X < 0f)
             {
                 npc.Velocity.X = npc.Velocity.X - num65 * 1.1f;
             }
             else
             {
                 npc.Velocity.X = npc.Velocity.X + num65 * 1.1f;
             }
         }
         else
         {
             if (npc.Velocity.Y == num64)
             {
                 if (npc.Velocity.X < num66)
                 {
                     npc.Velocity.X = npc.Velocity.X + num65;
                 }
                 else
                 {
                     if (npc.Velocity.X > num66)
                     {
                         npc.Velocity.X = npc.Velocity.X - num65;
                     }
                 }
             }
             else
             {
                 if (npc.Velocity.Y > 4f)
                 {
                     if (npc.Velocity.X < 0f)
                     {
                         npc.Velocity.X = npc.Velocity.X + num65 * 0.9f;
                     }
                     else
                     {
                         npc.Velocity.X = npc.Velocity.X - num65 * 0.9f;
                     }
                 }
             }
         }
     }
     else
     {
         if (npc.soundDelay == 0)
         {
             float num69 = num68 / 40f;
             if (num69 < 10f)
             {
                 num69 = 10f;
             }
             if (num69 > 20f)
             {
                 num69 = 20f;
             }
             npc.soundDelay = (int)num69;
         }
         num68 = (float)Math.Sqrt((double)(num66 * num66 + num67 * num67));
         float num70 = Math.Abs(num66);
         float num71 = Math.Abs(num67);
         num68 = num64 / num68;
         num66 *= num68;
         num67 *= num68;
         if ((npc.Type == 13 || npc.Type == 7) && !Main.players[npc.target].zoneEvil)
         {
             bool flag9 = true;
             for (int num72 = 0; num72 < 255; num72++)
             {
                 if (Main.players[num72].Active && !Main.players[num72].dead && Main.players[num72].zoneEvil)
                 {
                     flag9 = false;
                 }
             }
             if (flag9)
             {
                 if ((double)(npc.Position.Y / 16f) > (Main.rockLayer + (double)Main.maxTilesY) / 2.0)
                 {
                     npc.Active = false;
                     int num73 = (int)npc.ai[0];
                     while (num73 > 0 && num73 < MAX_NPCS && Main.npcs[num73].Active && Main.npcs[num73].aiStyle == npc.aiStyle)
                     {
                         int num74 = (int)Main.npcs[num73].ai[0];
                         Main.npcs[num73].Active = false;
                         npc.life = 0;
                         NetMessage.SendData(23, -1, -1, "", num73, 0f, 0f, 0f, 0);
                         num73 = num74;
                     }
                     NetMessage.SendData(23, -1, -1, "", npc.whoAmI, 0f, 0f, 0f, 0);
                 }
                 num66 = 0f;
                 num67 = num64;
             }
         }
         if ((npc.Velocity.X > 0f && num66 > 0f) || (npc.Velocity.X < 0f && num66 < 0f) || (npc.Velocity.Y > 0f && num67 > 0f) || (npc.Velocity.Y < 0f && num67 < 0f))
         {
             if (npc.Velocity.X < num66)
             {
                 npc.Velocity.X = npc.Velocity.X + num65;
             }
             else
             {
                 if (npc.Velocity.X > num66)
                 {
                     npc.Velocity.X = npc.Velocity.X - num65;
                 }
             }
             if (npc.Velocity.Y < num67)
             {
                 npc.Velocity.Y = npc.Velocity.Y + num65;
             }
             else
             {
                 if (npc.Velocity.Y > num67)
                 {
                     npc.Velocity.Y = npc.Velocity.Y - num65;
                 }
             }
         }
         else
         {
             if (num70 > num71)
             {
                 if (npc.Velocity.X < num66)
                 {
                     npc.Velocity.X = npc.Velocity.X + num65 * 1.1f;
                 }
                 else
                 {
                     if (npc.Velocity.X > num66)
                     {
                         npc.Velocity.X = npc.Velocity.X - num65 * 1.1f;
                     }
                 }
                 if ((double)(Math.Abs(npc.Velocity.X) + Math.Abs(npc.Velocity.Y)) < (double)num64 * 0.5)
                 {
                     if (npc.Velocity.Y > 0f)
                     {
                         npc.Velocity.Y = npc.Velocity.Y + num65;
                     }
                     else
                     {
                         npc.Velocity.Y = npc.Velocity.Y - num65;
                     }
                 }
             }
             else
             {
                 if (npc.Velocity.Y < num67)
                 {
                     npc.Velocity.Y = npc.Velocity.Y + num65 * 1.1f;
                 }
                 else
                 {
                     if (npc.Velocity.Y > num67)
                     {
                         npc.Velocity.Y = npc.Velocity.Y - num65 * 1.1f;
                     }
                 }
                 if ((double)(Math.Abs(npc.Velocity.X) + Math.Abs(npc.Velocity.Y)) < (double)num64 * 0.5)
                 {
                     if (npc.Velocity.X > 0f)
                     {
                         npc.Velocity.X = npc.Velocity.X + num65;
                     }
                     else
                     {
                         npc.Velocity.X = npc.Velocity.X - num65;
                     }
                 }
             }
         }
     }
     npc.rotation = (float)Math.Atan2((double)npc.Velocity.Y, (double)npc.Velocity.X) + 1.57f;
     return;
 }
 // 13
 private void AIMunchyPlant(NPC npc, bool flag)
 {
     if (!Main.tile.At((int)npc.ai[0], (int)npc.ai[1]).Active)
     {
         npc.life = -1;
         npc.HitEffect(0, 10.0);
         npc.Active = false;
         return;
     }
     npc.TargetClosest(true);
     float num133 = 0.035f;
     float num134 = 150f;
     if (npc.Type == 43)
     {
         num134 = 250f;
     }
     npc.ai[2] += 1f;
     if (npc.ai[2] > 300f)
     {
         num134 = (float)((int)((double)num134 * 1.3));
         if (npc.ai[2] > 450f)
         {
             npc.ai[2] = 0f;
         }
     }
     Vector2 vector18 = new Vector2(npc.ai[0] * 16f + 8f, npc.ai[1] * 16f + 8f);
     float num135 = Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2) - (float)(npc.Width / 2) - vector18.X;
     float num136 = Main.players[npc.target].Position.Y + (float)(Main.players[npc.target].Height / 2) - (float)(npc.Height / 2) - vector18.Y;
     float num137 = (float)Math.Sqrt((double)(num135 * num135 + num136 * num136));
     if (num137 > num134)
     {
         num137 = num134 / num137;
         num135 *= num137;
         num136 *= num137;
     }
     if (npc.Position.X < npc.ai[0] * 16f + 8f + num135)
     {
         npc.Velocity.X = npc.Velocity.X + num133;
         if (npc.Velocity.X < 0f && num135 > 0f)
         {
             npc.Velocity.X = npc.Velocity.X + num133 * 1.5f;
         }
     }
     else
     {
         if (npc.Position.X > npc.ai[0] * 16f + 8f + num135)
         {
             npc.Velocity.X = npc.Velocity.X - num133;
             if (npc.Velocity.X > 0f && num135 < 0f)
             {
                 npc.Velocity.X = npc.Velocity.X - num133 * 1.5f;
             }
         }
     }
     if (npc.Position.Y < npc.ai[1] * 16f + 8f + num136)
     {
         npc.Velocity.Y = npc.Velocity.Y + num133;
         if (npc.Velocity.Y < 0f && num136 > 0f)
         {
             npc.Velocity.Y = npc.Velocity.Y + num133 * 1.5f;
         }
     }
     else
     {
         if (npc.Position.Y > npc.ai[1] * 16f + 8f + num136)
         {
             npc.Velocity.Y = npc.Velocity.Y - num133;
             if (npc.Velocity.Y > 0f && num136 < 0f)
             {
                 npc.Velocity.Y = npc.Velocity.Y - num133 * 1.5f;
             }
         }
     }
     if (npc.Type == 43)
     {
         if (npc.Velocity.X > 3f)
         {
             npc.Velocity.X = 3f;
         }
         if (npc.Velocity.X < -3f)
         {
             npc.Velocity.X = -3f;
         }
         if (npc.Velocity.Y > 3f)
         {
             npc.Velocity.Y = 3f;
         }
         if (npc.Velocity.Y < -3f)
         {
             npc.Velocity.Y = -3f;
         }
     }
     else
     {
         if (npc.Velocity.X > 2f)
         {
             npc.Velocity.X = 2f;
         }
         if (npc.Velocity.X < -2f)
         {
             npc.Velocity.X = -2f;
         }
         if (npc.Velocity.Y > 2f)
         {
             npc.Velocity.Y = 2f;
         }
         if (npc.Velocity.Y < -2f)
         {
             npc.Velocity.Y = -2f;
         }
     }
     if (num135 > 0f)
     {
         npc.spriteDirection = 1;
         npc.rotation = (float)Math.Atan2((double)num136, (double)num135);
     }
     if (num135 < 0f)
     {
         npc.spriteDirection = -1;
         npc.rotation = (float)Math.Atan2((double)num136, (double)num135) + 3.14f;
     }
     if (npc.collideX)
     {
         npc.netUpdate = true;
         npc.Velocity.X = npc.oldVelocity.X * -0.7f;
         if (npc.Velocity.X > 0f && npc.Velocity.X < 2f)
         {
             npc.Velocity.X = 2f;
         }
         if (npc.Velocity.X < 0f && npc.Velocity.X > -2f)
         {
             npc.Velocity.X = -2f;
         }
     }
     if (npc.collideY)
     {
         npc.netUpdate = true;
         npc.Velocity.Y = npc.oldVelocity.Y * -0.7f;
         if (npc.Velocity.Y > 0f && npc.Velocity.Y < 2f)
         {
             npc.Velocity.Y = 2f;
         }
         if (npc.Velocity.Y < 0f && npc.Velocity.Y > -2f)
         {
             npc.Velocity.Y = -2f;
             return;
         }
     }
 }
 // 12
 private void AISkeletronHand(NPC npc, bool flag)
 {
     npc.spriteDirection = -(int)npc.ai[0];
     if (!Main.npcs[(int)npc.ai[1]].Active || Main.npcs[(int)npc.ai[1]].aiStyle != 11)
     {
         npc.ai[2] += 10f;
         if (npc.ai[2] > 50f)
         {
             npc.life = -1;
             npc.HitEffect(0, 10.0);
             npc.Active = false;
         }
     }
     if (npc.ai[2] == 0f || npc.ai[2] == 3f)
     {
         if (Main.npcs[(int)npc.ai[1]].ai[1] == 3f && npc.timeLeft > 10)
         {
             npc.timeLeft = 10;
         }
         if (Main.npcs[(int)npc.ai[1]].ai[1] != 0f)
         {
             if (npc.Position.Y > Main.npcs[(int)npc.ai[1]].Position.Y - 100f)
             {
                 if (npc.Velocity.Y > 0f)
                 {
                     npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                 }
                 npc.Velocity.Y = npc.Velocity.Y - 0.07f;
                 if (npc.Velocity.Y > 6f)
                 {
                     npc.Velocity.Y = 6f;
                 }
             }
             else
             {
                 if (npc.Position.Y < Main.npcs[(int)npc.ai[1]].Position.Y - 100f)
                 {
                     if (npc.Velocity.Y < 0f)
                     {
                         npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                     }
                     npc.Velocity.Y = npc.Velocity.Y + 0.07f;
                     if (npc.Velocity.Y < -6f)
                     {
                         npc.Velocity.Y = -6f;
                     }
                 }
             }
             if (npc.Position.X + (float)(npc.Width / 2) > Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 120f * npc.ai[0])
             {
                 if (npc.Velocity.X > 0f)
                 {
                     npc.Velocity.X = npc.Velocity.X * 0.96f;
                 }
                 npc.Velocity.X = npc.Velocity.X - 0.1f;
                 if (npc.Velocity.X > 8f)
                 {
                     npc.Velocity.X = 8f;
                 }
             }
             if (npc.Position.X + (float)(npc.Width / 2) < Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 120f * npc.ai[0])
             {
                 if (npc.Velocity.X < 0f)
                 {
                     npc.Velocity.X = npc.Velocity.X * 0.96f;
                 }
                 npc.Velocity.X = npc.Velocity.X + 0.1f;
                 if (npc.Velocity.X < -8f)
                 {
                     npc.Velocity.X = -8f;
                 }
             }
         }
         else
         {
             npc.ai[3] += 1f;
             if (npc.ai[3] >= 300f)
             {
                 npc.ai[2] += 1f;
                 npc.ai[3] = 0f;
                 npc.netUpdate = true;
             }
             if (npc.Position.Y > Main.npcs[(int)npc.ai[1]].Position.Y + 230f)
             {
                 if (npc.Velocity.Y > 0f)
                 {
                     npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                 }
                 npc.Velocity.Y = npc.Velocity.Y - 0.04f;
                 if (npc.Velocity.Y > 3f)
                 {
                     npc.Velocity.Y = 3f;
                 }
             }
             else
             {
                 if (npc.Position.Y < Main.npcs[(int)npc.ai[1]].Position.Y + 230f)
                 {
                     if (npc.Velocity.Y < 0f)
                     {
                         npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                     }
                     npc.Velocity.Y = npc.Velocity.Y + 0.04f;
                     if (npc.Velocity.Y < -3f)
                     {
                         npc.Velocity.Y = -3f;
                     }
                 }
             }
             if (npc.Position.X + (float)(npc.Width / 2) > Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 200f * npc.ai[0])
             {
                 if (npc.Velocity.X > 0f)
                 {
                     npc.Velocity.X = npc.Velocity.X * 0.96f;
                 }
                 npc.Velocity.X = npc.Velocity.X - 0.07f;
                 if (npc.Velocity.X > 8f)
                 {
                     npc.Velocity.X = 8f;
                 }
             }
             if (npc.Position.X + (float)(npc.Width / 2) < Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 200f * npc.ai[0])
             {
                 if (npc.Velocity.X < 0f)
                 {
                     npc.Velocity.X = npc.Velocity.X * 0.96f;
                 }
                 npc.Velocity.X = npc.Velocity.X + 0.07f;
                 if (npc.Velocity.X < -8f)
                 {
                     npc.Velocity.X = -8f;
                 }
             }
         }
         Vector2 vector15 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
         float num125 = Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 200f * npc.ai[0] - vector15.X;
         float num126 = Main.npcs[(int)npc.ai[1]].Position.Y + 230f - vector15.Y;
         Math.Sqrt((double)(num125 * num125 + num126 * num126));
         npc.rotation = (float)Math.Atan2((double)num126, (double)num125) + 1.57f;
         return;
     }
     if (npc.ai[2] == 1f)
     {
         Vector2 vector16 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
         float num127 = Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 200f * npc.ai[0] - vector16.X;
         float num128 = Main.npcs[(int)npc.ai[1]].Position.Y + 230f - vector16.Y;
         float num129 = (float)Math.Sqrt((double)(num127 * num127 + num128 * num128));
         npc.rotation = (float)Math.Atan2((double)num128, (double)num127) + 1.57f;
         npc.Velocity.X = npc.Velocity.X * 0.95f;
         npc.Velocity.Y = npc.Velocity.Y - 0.1f;
         if (npc.Velocity.Y < -8f)
         {
             npc.Velocity.Y = -8f;
         }
         if (npc.Position.Y < Main.npcs[(int)npc.ai[1]].Position.Y - 200f)
         {
             npc.TargetClosest(true);
             npc.ai[2] = 2f;
             vector16 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
             num127 = Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2) - vector16.X;
             num128 = Main.players[npc.target].Position.Y + (float)(Main.players[npc.target].Height / 2) - vector16.Y;
             num129 = (float)Math.Sqrt((double)(num127 * num127 + num128 * num128));
             num129 = 18f / num129;
             npc.Velocity.X = num127 * num129;
             npc.Velocity.Y = num128 * num129;
             npc.netUpdate = true;
             return;
         }
     }
     else
     {
         if (npc.ai[2] == 2f)
         {
             if (npc.Position.Y > Main.players[npc.target].Position.Y || npc.Velocity.Y < 0f)
             {
                 npc.ai[2] = 3f;
                 return;
             }
         }
         else
         {
             if (npc.ai[2] == 4f)
             {
                 Vector2 vector17 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                 float num130 = Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 200f * npc.ai[0] - vector17.X;
                 float num131 = Main.npcs[(int)npc.ai[1]].Position.Y + 230f - vector17.Y;
                 float num132 = (float)Math.Sqrt((double)(num130 * num130 + num131 * num131));
                 npc.rotation = (float)Math.Atan2((double)num131, (double)num130) + 1.57f;
                 npc.Velocity.Y = npc.Velocity.Y * 0.95f;
                 npc.Velocity.X = npc.Velocity.X + 0.1f * -npc.ai[0];
                 if (npc.Velocity.X < -8f)
                 {
                     npc.Velocity.X = -8f;
                 }
                 if (npc.Velocity.X > 8f)
                 {
                     npc.Velocity.X = 8f;
                 }
                 if (npc.Position.X + (float)(npc.Width / 2) < Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 500f || npc.Position.X + (float)(npc.Width / 2) > Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) + 500f)
                 {
                     npc.TargetClosest(true);
                     npc.ai[2] = 5f;
                     vector17 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                     num130 = Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2) - vector17.X;
                     num131 = Main.players[npc.target].Position.Y + (float)(Main.players[npc.target].Height / 2) - vector17.Y;
                     num132 = (float)Math.Sqrt((double)(num130 * num130 + num131 * num131));
                     num132 = 17f / num132;
                     npc.Velocity.X = num130 * num132;
                     npc.Velocity.Y = num131 * num132;
                     npc.netUpdate = true;
                     return;
                 }
             }
             else
             {
                 if (npc.ai[2] == 5f && ((npc.Velocity.X > 0f && npc.Position.X + (float)(npc.Width / 2) > Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2)) || (npc.Velocity.X < 0f && npc.Position.X + (float)(npc.Width / 2) < Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2))))
                 {
                     npc.ai[2] = 0f;
                     return;
                 }
             }
         }
     }
 }
        // 33 - 1.1.2
        private void AIPrimeSaw(NPC npc, bool flag, Func<Int32, Int32, ITile> TileRefs)
        {
            Vector2 vector42 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
            float num395 = Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 200f * npc.ai[0] - vector42.X;
            float num396 = Main.npcs[(int)npc.ai[1]].Position.Y + 230f - vector42.Y;
            float num397 = (float)Math.Sqrt((double)(num395 * num395 + num396 * num396));
            if (npc.ai[2] != 99f && num397 > 800f)
            {
                npc.ai[2] = 99f;
            }
            else if (num397 < 400f)
            {
                npc.ai[2] = 0f;
            }

            npc.spriteDirection = -(int)npc.ai[0];
            if (!Main.npcs[(int)npc.ai[1]].Active || Main.npcs[(int)npc.ai[1]].aiStyle != 32)
            {
                npc.ai[2] += 10f;
                if (npc.ai[2] > 50f)
                {
                    npc.life = -1;
                    npc.HitEffect(0, 10.0);
                    npc.Active = false;
                }
            }
            if (npc.ai[2] == 99f)
            {
                if (npc.Position.Y > Main.npcs[(int)npc.ai[1]].Position.Y)
                {
                    if (npc.Velocity.Y > 0f)
                    {
                        npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                    }
                    npc.Velocity.Y = npc.Velocity.Y - 0.1f;
                    if (npc.Velocity.Y > 8f)
                    {
                        npc.Velocity.Y = 8f;
                    }
                }
                else if (npc.Position.Y < Main.npcs[(int)npc.ai[1]].Position.Y)
                {
                    if (npc.Velocity.Y < 0f)
                    {
                        npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                    }
                    npc.Velocity.Y = npc.Velocity.Y + 0.1f;
                    if (npc.Velocity.Y < -8f)
                    {
                        npc.Velocity.Y = -8f;
                    }
                }

                if (npc.Position.X + (float)(npc.Width / 2) > Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2))
                {
                    if (npc.Velocity.X > 0f)
                    {
                        npc.Velocity.X = npc.Velocity.X * 0.96f;
                    }
                    npc.Velocity.X = npc.Velocity.X - 0.5f;
                    if (npc.Velocity.X > 12f)
                    {
                        npc.Velocity.X = 12f;
                    }
                }
                if (npc.Position.X + (float)(npc.Width / 2) < Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2))
                {
                    if (npc.Velocity.X < 0f)
                    {
                        npc.Velocity.X = npc.Velocity.X * 0.96f;
                    }
                    npc.Velocity.X = npc.Velocity.X + 0.5f;
                    if (npc.Velocity.X < -12f)
                    {
                        npc.Velocity.X = -12f;
                        return;
                    }
                }
            }
            else if (npc.ai[2] == 0f || npc.ai[2] == 3f)
            {
                if (Main.npcs[(int)npc.ai[1]].ai[1] == 3f && npc.timeLeft > 10)
                {
                    npc.timeLeft = 10;
                }
                if (Main.npcs[(int)npc.ai[1]].ai[1] != 0f)
                {
                    npc.TargetClosest(true);
                    if (Main.players[npc.target].dead)
                    {
                        npc.Velocity.Y = npc.Velocity.Y + 0.1f;
                        if (npc.Velocity.Y > 16f)
                        {
                            npc.Velocity.Y = 16f;
                        }
                    }
                    else
                    {
                        Vector2 vector43 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                        float num398 = Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2) - vector43.X;
                        float num399 = Main.players[npc.target].Position.Y + (float)(Main.players[npc.target].Height / 2) - vector43.Y;
                        float num400 = (float)Math.Sqrt((double)(num398 * num398 + num399 * num399));
                        num400 = 7f / num400;
                        num398 *= num400;
                        num399 *= num400;
                        npc.rotation = (float)Math.Atan2((double)num399, (double)num398) - 1.57f;
                        if (npc.Velocity.X > num398)
                        {
                            if (npc.Velocity.X > 0f)
                            {
                                npc.Velocity.X = npc.Velocity.X * 0.97f;
                            }
                            npc.Velocity.X = npc.Velocity.X - 0.05f;
                        }
                        if (npc.Velocity.X < num398)
                        {
                            if (npc.Velocity.X < 0f)
                            {
                                npc.Velocity.X = npc.Velocity.X * 0.97f;
                            }
                            npc.Velocity.X = npc.Velocity.X + 0.05f;
                        }
                        if (npc.Velocity.Y > num399)
                        {
                            if (npc.Velocity.Y > 0f)
                            {
                                npc.Velocity.Y = npc.Velocity.Y * 0.97f;
                            }
                            npc.Velocity.Y = npc.Velocity.Y - 0.05f;
                        }
                        if (npc.Velocity.Y < num399)
                        {
                            if (npc.Velocity.Y < 0f)
                            {
                                npc.Velocity.Y = npc.Velocity.Y * 0.97f;
                            }
                            npc.Velocity.Y = npc.Velocity.Y + 0.05f;
                        }
                    }
                    npc.ai[3] += 1f;
                    if (npc.ai[3] >= 600f)
                    {
                        npc.ai[2] = 0f;
                        npc.ai[3] = 0f;
                        npc.netUpdate = true;
                    }
                }
                else
                {
                    npc.ai[3] += 1f;
                    if (npc.ai[3] >= 300f)
                    {
                        npc.ai[2] += 1f;
                        npc.ai[3] = 0f;
                        npc.netUpdate = true;
                    }
                    if (npc.Position.Y > Main.npcs[(int)npc.ai[1]].Position.Y + 320f)
                    {
                        if (npc.Velocity.Y > 0f)
                        {
                            npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                        }
                        npc.Velocity.Y = npc.Velocity.Y - 0.04f;
                        if (npc.Velocity.Y > 3f)
                        {
                            npc.Velocity.Y = 3f;
                        }
                    }
                    else if (npc.Position.Y < Main.npcs[(int)npc.ai[1]].Position.Y + 260f)
                    {
                        if (npc.Velocity.Y < 0f)
                        {
                            npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                        }
                        npc.Velocity.Y = npc.Velocity.Y + 0.04f;
                        if (npc.Velocity.Y < -3f)
                        {
                            npc.Velocity.Y = -3f;
                        }
                    }

                    if (npc.Position.X + (float)(npc.Width / 2) > Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2))
                    {
                        if (npc.Velocity.X > 0f)
                        {
                            npc.Velocity.X = npc.Velocity.X * 0.96f;
                        }
                        npc.Velocity.X = npc.Velocity.X - 0.3f;
                        if (npc.Velocity.X > 12f)
                        {
                            npc.Velocity.X = 12f;
                        }
                    }
                    if (npc.Position.X + (float)(npc.Width / 2) < Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 250f)
                    {
                        if (npc.Velocity.X < 0f)
                        {
                            npc.Velocity.X = npc.Velocity.X * 0.96f;
                        }
                        npc.Velocity.X = npc.Velocity.X + 0.3f;
                        if (npc.Velocity.X < -12f)
                        {
                            npc.Velocity.X = -12f;
                        }
                    }
                }
                Vector2 vector44 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                float num401 = Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 200f * npc.ai[0] - vector44.X;
                float num402 = Main.npcs[(int)npc.ai[1]].Position.Y + 230f - vector44.Y;
                Math.Sqrt((double)(num401 * num401 + num402 * num402));
                npc.rotation = (float)Math.Atan2((double)num402, (double)num401) + 1.57f;
                return;
            }
            if (npc.ai[2] == 1f)
            {
                Vector2 vector45 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                float num403 = Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 200f * npc.ai[0] - vector45.X;
                float num404 = Main.npcs[(int)npc.ai[1]].Position.Y + 230f - vector45.Y;
                float num405 = (float)Math.Sqrt((double)(num403 * num403 + num404 * num404));
                npc.rotation = (float)Math.Atan2((double)num404, (double)num403) + 1.57f;
                npc.Velocity.X = npc.Velocity.X * 0.95f;
                npc.Velocity.Y = npc.Velocity.Y - 0.1f;
                if (npc.Velocity.Y < -8f)
                {
                    npc.Velocity.Y = -8f;
                }
                if (npc.Position.Y < Main.npcs[(int)npc.ai[1]].Position.Y - 200f)
                {
                    npc.TargetClosest(true);
                    npc.ai[2] = 2f;
                    vector45 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                    num403 = Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2) - vector45.X;
                    num404 = Main.players[npc.target].Position.Y + (float)(Main.players[npc.target].Height / 2) - vector45.Y;
                    num405 = (float)Math.Sqrt((double)(num403 * num403 + num404 * num404));
                    num405 = 22f / num405;
                    npc.Velocity.X = num403 * num405;
                    npc.Velocity.Y = num404 * num405;
                    npc.netUpdate = true;
                    return;
                }
            }
            else if (npc.ai[2] == 2f)
            {
                if (npc.Position.Y > Main.players[npc.target].Position.Y || npc.Velocity.Y < 0f)
                {
                    npc.ai[2] = 3f;
                    return;
                }
            }
            else if (npc.ai[2] == 4f)
            {
                npc.TargetClosest(true);
                Vector2 vector46 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                float num406 = Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2) - vector46.X;
                float num407 = Main.players[npc.target].Position.Y + (float)(Main.players[npc.target].Height / 2) - vector46.Y;
                float num408 = (float)Math.Sqrt((double)(num406 * num406 + num407 * num407));
                num408 = 7f / num408;
                num406 *= num408;
                num407 *= num408;
                if (npc.Velocity.X > num406)
                {
                    if (npc.Velocity.X > 0f)
                    {
                        npc.Velocity.X = npc.Velocity.X * 0.97f;
                    }
                    npc.Velocity.X = npc.Velocity.X - 0.05f;
                }
                if (npc.Velocity.X < num406)
                {
                    if (npc.Velocity.X < 0f)
                    {
                        npc.Velocity.X = npc.Velocity.X * 0.97f;
                    }
                    npc.Velocity.X = npc.Velocity.X + 0.05f;
                }
                if (npc.Velocity.Y > num407)
                {
                    if (npc.Velocity.Y > 0f)
                    {
                        npc.Velocity.Y = npc.Velocity.Y * 0.97f;
                    }
                    npc.Velocity.Y = npc.Velocity.Y - 0.05f;
                }
                if (npc.Velocity.Y < num407)
                {
                    if (npc.Velocity.Y < 0f)
                    {
                        npc.Velocity.Y = npc.Velocity.Y * 0.97f;
                    }
                    npc.Velocity.Y = npc.Velocity.Y + 0.05f;
                }
                npc.ai[3] += 1f;
                if (npc.ai[3] >= 600f)
                {
                    npc.ai[2] = 0f;
                    npc.ai[3] = 0f;
                    npc.netUpdate = true;
                }
                vector46 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                num406 = Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 200f * npc.ai[0] - vector46.X;
                num407 = Main.npcs[(int)npc.ai[1]].Position.Y + 230f - vector46.Y;
                num408 = (float)Math.Sqrt((double)(num406 * num406 + num407 * num407));
                npc.rotation = (float)Math.Atan2((double)num407, (double)num406) + 1.57f;
                return;
            }
            if (npc.ai[2] == 5f && ((npc.Velocity.X > 0f && npc.Position.X + (float)(npc.Width / 2) > Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2)) || (npc.Velocity.X < 0f && npc.Position.X + (float)(npc.Width / 2) < Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2))))
            {
                npc.ai[2] = 0f;
                return;
            }
        }
        // 7
        private void AIFriendly(NPC npc, bool flag)
        {
            int num75 = (int)(npc.Position.X + (float)(npc.Width / 2)) / 16;
            int num76 = (int)(npc.Position.Y + (float)npc.Height + 1f) / 16;
            if (!npc.townNPC)
            {
                npc.homeTileX = num75;
                npc.homeTileY = num76;
            }
            if (npc.Type == 46 && npc.target == 255)
            {
                npc.TargetClosest(true);
            }
            bool flag10 = false;
            npc.directionY = -1;
            if (npc.direction == 0)
            {
                npc.direction = 1;
            }
            for (int num77 = 0; num77 < 255; num77++)
            {
                if (Main.players[num77].Active && Main.players[num77].talkNPC == npc.whoAmI)
                {
                    flag10 = true;
                    if (npc.ai[0] != 0f)
                    {
                        npc.netUpdate = true;
                    }
                    npc.ai[0] = 0f;
                    npc.ai[1] = 300f;
                    npc.ai[2] = 100f;
                    if (Main.players[num77].Position.X + (float)(Main.players[num77].Width / 2) < npc.Position.X + (float)(npc.Width / 2))
                    {
                        npc.direction = -1;
                    }
                    else
                    {
                        npc.direction = 1;
                    }
                }
            }
            if (npc.ai[3] > 0f)
            {
                npc.life = -1;
                npc.HitEffect(0, 10.0);
                npc.Active = false;
            }
            if (npc.Type == 37)
            {
                npc.homeless = false;
                npc.homeTileX = Main.dungeonX;
                npc.homeTileY = Main.dungeonY;
                if (NPC.downedBoss3)
                {
                    npc.ai[3] = 1f;
                    npc.netUpdate = true;
                }
            }
            if (npc.townNPC && !Main.dayTime && (num75 != npc.homeTileX || num76 != npc.homeTileY) && !npc.homeless)
            {
                bool flag11 = true;
                for (int num78 = 0; num78 < 2; num78++)
                {
                    Rectangle rectangle3 = new Rectangle((int)(npc.Position.X + (float)(npc.Width / 2) - (float)(NPC.sWidth / 2) - (float)NPC.safeRangeX), (int)(npc.Position.Y + (float)(npc.Height / 2) - (float)(NPC.sHeight / 2) - (float)NPC.safeRangeY), NPC.sWidth + NPC.safeRangeX * 2, NPC.sHeight + NPC.safeRangeY * 2);
                    if (num78 == 1)
                    {
                        rectangle3 = new Rectangle(npc.homeTileX * 16 + 8 - NPC.sWidth / 2 - NPC.safeRangeX, npc.homeTileY * 16 + 8 - NPC.sHeight / 2 - NPC.safeRangeY, NPC.sWidth + NPC.safeRangeX * 2, NPC.sHeight + NPC.safeRangeY * 2);
                    }
                    for (int num79 = 0; num79 < 255; num79++)
                    {
                        if (Main.players[num79].Active)
                        {
                            Rectangle rectangle4 = new Rectangle((int)Main.players[num79].Position.X, (int)Main.players[num79].Position.Y, Main.players[num79].Width, Main.players[num79].Height);
                            if (rectangle4.Intersects(rectangle3))
                            {
                                flag11 = false;
                                break;
                            }
                        }
                        if (!flag11)
                        {
                            break;
                        }
                    }
                }
                if (flag11)
                {
                    if (npc.Type == 37 || !Collision.SolidTiles(npc.homeTileX - 1, npc.homeTileX + 1, npc.homeTileY - 3, npc.homeTileY - 1))
                    {
                        npc.Velocity.X = 0f;
                        npc.Velocity.Y = 0f;
                        npc.Position.X = (float)(npc.homeTileX * 16 + 8 - npc.Width / 2);
                        npc.Position.Y = (float)(npc.homeTileY * 16 - npc.Height) - 0.1f;
                        npc.netUpdate = true;
                    }
                    else
                    {
                        npc.homeless = true;
                        WorldModify.QuickFindHome(npc.whoAmI);
                    }
                }
            }
            if (npc.ai[0] == 0f)
            {
                if (npc.ai[2] > 0f)
                {
                    npc.ai[2] -= 1f;
                }
                if (!Main.dayTime && !flag10)
                {
                    if (num75 == npc.homeTileX && num76 == npc.homeTileY)
                    {
                        if (npc.Velocity.X != 0f)
                        {
                            npc.netUpdate = true;
                        }
                        if ((double)npc.Velocity.X > 0.1)
                        {
                            npc.Velocity.X = npc.Velocity.X - 0.1f;
                        }
                        else
                        {
                            if ((double)npc.Velocity.X < -0.1)
                            {
                                npc.Velocity.X = npc.Velocity.X + 0.1f;
                            }
                            else
                            {
                                npc.Velocity.X = 0f;
                            }
                        }
                    }
                    else
                    {
                        if (!flag10)
                        {
                            if (num75 > npc.homeTileX)
                            {
                                npc.direction = -1;
                            }
                            else
                            {
                                npc.direction = 1;
                            }
                            npc.ai[0] = 1f;
                            npc.ai[1] = (float)(200 + Main.rand.Next(200));
                            npc.ai[2] = 0f;
                            npc.netUpdate = true;
                        }
                    }
                }
                else
                {
                    if ((double)npc.Velocity.X > 0.1)
                    {
                        npc.Velocity.X = npc.Velocity.X - 0.1f;
                    }
                    else
                    {
                        if ((double)npc.Velocity.X < -0.1)
                        {
                            npc.Velocity.X = npc.Velocity.X + 0.1f;
                        }
                        else
                        {
                            npc.Velocity.X = 0f;
                        }
                    }
                    if (npc.ai[1] > 0f)
                    {
                        npc.ai[1] -= 1f;
                    }
                    if (npc.ai[1] <= 0f)
                    {
                        npc.ai[0] = 1f;
                        npc.ai[1] = (float)(200 + Main.rand.Next(200));
                        if (npc.Type == 46)
                        {
                            npc.ai[1] += (float)Main.rand.Next(200, 400);
                        }
                        npc.ai[2] = 0f;
                        npc.netUpdate = true;
                    }
                }
                if ((Main.dayTime || (num75 == npc.homeTileX && num76 == npc.homeTileY)))
                {
                    if (num75 < npc.homeTileX - 25 || num75 > npc.homeTileX + 25)
                    {
                        if (npc.ai[2] == 0f)
                        {
                            if (num75 < npc.homeTileX - 50 && npc.direction == -1)
                            {
                                npc.direction = 1;
                                npc.netUpdate = true;
                                return;
                            }
                            if (num75 > npc.homeTileX + 50 && npc.direction == 1)
                            {
                                npc.direction = -1;
                                npc.netUpdate = true;
                                return;
                            }
                        }
                    }
                    else
                    {
                        if (Main.rand.Next(80) == 0 && npc.ai[2] == 0f)
                        {
                            npc.ai[2] = 200f;
                            npc.direction *= -1;
                            npc.netUpdate = true;
                            return;
                        }
                    }
                }
            }
            else
            {
                if (npc.ai[0] == 1f)
                {
                    if (!Main.dayTime && num75 == npc.homeTileX && num76 == npc.homeTileY)
                    {
                        npc.ai[0] = 0f;
                        npc.ai[1] = (float)(200 + Main.rand.Next(200));
                        npc.ai[2] = 60f;
                        npc.netUpdate = true;
                        return;
                    }
                    if (!npc.homeless && (num75 < npc.homeTileX - 35 || num75 > npc.homeTileX + 35))
                    {
                        if (npc.Position.X < (float)(npc.homeTileX * 16) && npc.direction == -1)
                        {
                            npc.direction = 1;
                            npc.netUpdate = true;
                            npc.ai[1] = 0f;
                        }
                        else
                        {
                            if (npc.Position.X > (float)(npc.homeTileX * 16) && npc.direction == 1)
                            {
                                npc.direction = -1;
                                npc.netUpdate = true;
                                npc.ai[1] = 0f;
                            }
                        }
                    }
                    npc.ai[1] -= 1f;
                    if (npc.ai[1] <= 0f)
                    {
                        npc.ai[0] = 0f;
                        npc.ai[1] = (float)(300 + Main.rand.Next(300));
                        if (npc.Type == 46)
                        {
                            npc.ai[1] -= (float)Main.rand.Next(100);
                        }
                        npc.ai[2] = 60f;
                        npc.netUpdate = true;
                    }
                    if (npc.closeDoor && ((npc.Position.X + (float)(npc.Width / 2)) / 16f > (float)(npc.doorX + 2) || (npc.Position.X + (float)(npc.Width / 2)) / 16f < (float)(npc.doorX - 2)))
                    {
                        bool flag12 = WorldModify.CloseDoor(npc.doorX, npc.doorY, false, npc);
                        if (flag12)
                        {
                            npc.closeDoor = false;
                            NetMessage.SendData(19, -1, -1, "", 1, (float)npc.doorX, (float)npc.doorY, (float)npc.direction, 0);
                        }
                        if ((npc.Position.X + (float)(npc.Width / 2)) / 16f > (float)(npc.doorX + 4) || (npc.Position.X + (float)(npc.Width / 2)) / 16f < (float)(npc.doorX - 4) || (npc.Position.Y + (float)(npc.Height / 2)) / 16f > (float)(npc.doorY + 4) || (npc.Position.Y + (float)(npc.Height / 2)) / 16f < (float)(npc.doorY - 4))
                        {
                            npc.closeDoor = false;
                        }
                    }
                    if (npc.Velocity.X < -1f || npc.Velocity.X > 1f)
                    {
                        if (npc.Velocity.Y == 0f)
                        {
                            npc.Velocity *= 0.8f;
                        }
                    }
                    else
                    {
                        if ((double)npc.Velocity.X < 1.15 && npc.direction == 1)
                        {
                            npc.Velocity.X = npc.Velocity.X + 0.07f;
                            if (npc.Velocity.X > 1f)
                            {
                                npc.Velocity.X = 1f;
                            }
                        }
                        else
                        {
                            if (npc.Velocity.X > -1f && npc.direction == -1)
                            {
                                npc.Velocity.X = npc.Velocity.X - 0.07f;
                                if (npc.Velocity.X > 1f)
                                {
                                    npc.Velocity.X = 1f;
                                }
                            }
                        }
                    }
                    if (npc.Velocity.Y == 0f)
                    {
                        if (npc.Position.X == npc.ai[2])
                        {
                            npc.direction *= -1;
                        }
                        npc.ai[2] = -1f;
                        int num80 = (int)((npc.Position.X + (float)(npc.Width / 2) + (float)(15 * npc.direction)) / 16f);
                        int num81 = (int)((npc.Position.Y + (float)npc.Height - 16f) / 16f);

                        if (npc.townNPC && Main.tile.At(num80, num81 - 2).Active && Main.tile.At(num80, num81 - 2).Type == 10 && (Main.rand.Next(10) == 0 || !Main.dayTime))
                        {
                            bool flag13 = WorldModify.OpenDoor(num80, num81 - 2, npc.direction, npc);
                            if (flag13)
                            {
                                npc.closeDoor = true;
                                npc.doorX = num80;
                                npc.doorY = num81 - 2;
                                NetMessage.SendData(19, -1, -1, "", 0, (float)num80, (float)(num81 - 2), (float)npc.direction, 0);
                                npc.netUpdate = true;
                                npc.ai[1] += 80f;
                                return;
                            }
                            if (WorldModify.OpenDoor(num80, num81 - 2, -npc.direction, npc))
                            {
                                npc.closeDoor = true;
                                npc.doorX = num80;
                                npc.doorY = num81 - 2;
                                NetMessage.SendData(19, -1, -1, "", 0, (float)num80, (float)(num81 - 2), (float)(-(float)npc.direction), 0);
                                npc.netUpdate = true;
                                npc.ai[1] += 80f;
                                return;
                            }
                            npc.direction *= -1;
                            npc.netUpdate = true;
                            return;

                        }
                        else
                        {
                            if ((npc.Velocity.X < 0f && npc.spriteDirection == -1) || (npc.Velocity.X > 0f && npc.spriteDirection == 1))
                            {
                                if (Main.tile.At(num80, num81 - 2).Active && Main.tileSolid[(int)Main.tile.At(num80, num81 - 2).Type] && !Main.tileSolidTop[(int)Main.tile.At(num80, num81 - 2).Type])
                                {
                                    if ((npc.direction == 1 && !Collision.SolidTiles(num80 - 2, num80 - 1, num81 - 5, num81 - 1)) || (npc.direction == -1 && !Collision.SolidTiles(num80 + 1, num80 + 2, num81 - 5, num81 - 1)))
                                    {
                                        if (!Collision.SolidTiles(num80, num80, num81 - 5, num81 - 3))
                                        {
                                            npc.Velocity.Y = -6f;
                                            npc.netUpdate = true;
                                        }
                                        else
                                        {
                                            npc.direction *= -1;
                                            npc.netUpdate = true;
                                        }
                                    }
                                    else
                                    {
                                        npc.direction *= -1;
                                        npc.netUpdate = true;
                                    }
                                }
                                else
                                {
                                    if (Main.tile.At(num80, num81 - 1).Active && Main.tileSolid[(int)Main.tile.At(num80, num81 - 1).Type] && !Main.tileSolidTop[(int)Main.tile.At(num80, num81 - 1).Type])
                                    {
                                        if ((npc.direction == 1 && !Collision.SolidTiles(num80 - 2, num80 - 1, num81 - 4, num81 - 1)) || (npc.direction == -1 && !Collision.SolidTiles(num80 + 1, num80 + 2, num81 - 4, num81 - 1)))
                                        {
                                            if (!Collision.SolidTiles(num80, num80, num81 - 4, num81 - 2))
                                            {
                                                npc.Velocity.Y = -5f;
                                                npc.netUpdate = true;
                                            }
                                            else
                                            {
                                                npc.direction *= -1;
                                                npc.netUpdate = true;
                                            }
                                        }
                                        else
                                        {
                                            npc.direction *= -1;
                                            npc.netUpdate = true;
                                        }
                                    }
                                    else
                                    {
                                        if (Main.tile.At(num80, num81).Active && Main.tileSolid[(int)Main.tile.At(num80, num81).Type] && !Main.tileSolidTop[(int)Main.tile.At(num80, num81).Type])
                                        {
                                            if ((npc.direction == 1 && !Collision.SolidTiles(num80 - 2, num80, num81 - 3, num81 - 1)) || (npc.direction == -1 && !Collision.SolidTiles(num80, num80 + 2, num81 - 3, num81 - 1)))
                                            {
                                                npc.Velocity.Y = -3.6f;
                                                npc.netUpdate = true;
                                            }
                                            else
                                            {
                                                npc.direction *= -1;
                                                npc.netUpdate = true;
                                            }
                                        }
                                    }
                                }
                                try
                                {
                                    if (Main.tile.At(num80 - npc.direction, num81 + 4).Exists)
                                    {
                                        if (num75 >= npc.homeTileX - 35 && num75 <= npc.homeTileX + 35 && (!Main.tile.At(num80, num81 + 1).Active || !Main.tileSolid[(int)Main.tile.At(num80, num81 + 1).Type]) && (!Main.tile.At(num80 - npc.direction, num81 + 1).Active || !Main.tileSolid[(int)Main.tile.At(num80 - npc.direction, num81 + 1).Type]) && (!Main.tile.At(num80, num81 + 2).Active || !Main.tileSolid[(int)Main.tile.At(num80, num81 + 2).Type]) && (!Main.tile.At(num80 - npc.direction, num81 + 2).Active || !Main.tileSolid[(int)Main.tile.At(num80 - npc.direction, num81 + 2).Type]) && (!Main.tile.At(num80, num81 + 3).Active || !Main.tileSolid[(int)Main.tile.At(num80, num81 + 3).Type]) && (!Main.tile.At(num80 - npc.direction, num81 + 3).Active || !Main.tileSolid[(int)Main.tile.At(num80 - npc.direction, num81 + 3).Type]) && (!Main.tile.At(num80, num81 + 4).Active || !Main.tileSolid[(int)Main.tile.At(num80, num81 + 4).Type]) && (!Main.tile.At(num80 - npc.direction, num81 + 4).Active || !Main.tileSolid[(int)Main.tile.At(num80 - npc.direction, num81 + 4).Type]) && npc.Type != 46)
                                        {
                                            npc.direction *= -1;
                                            npc.Velocity.X = npc.Velocity.X * -1f;
                                            npc.netUpdate = true;
                                        }
                                    }
                                }
                                catch
                                {
                                }
                                if (npc.Velocity.Y < 0f)
                                {
                                    npc.ai[2] = npc.Position.X;
                                }
                            }
                            if (npc.Velocity.Y < 0f && npc.wet)
                            {
                                npc.Velocity.Y = npc.Velocity.Y * 1.2f;
                            }
                            if (npc.Velocity.Y < 0f && npc.Type == 46)
                            {
                                npc.Velocity.Y = npc.Velocity.Y * 1.2f;
                                return;
                            }
                        }
                    }
                }
            }
        }
        // 35 - 1.1.2
        private void AIPrimeCannon(NPC npc, bool flag, Func<Int32, Int32, ITile> TileRefs)
        {
            npc.spriteDirection = -(int)npc.ai[0];
            if (!Main.npcs[(int)npc.ai[1]].Active || Main.npcs[(int)npc.ai[1]].aiStyle != 32)
            {
                npc.ai[2] += 10f;
                if (npc.ai[2] > 50f)
                {
                    npc.life = -1;
                    npc.HitEffect(0, 10.0);
                    npc.Active = false;
                }
            }
            if (npc.ai[2] == 0f)
            {
                if (Main.npcs[(int)npc.ai[1]].ai[1] == 3f && npc.timeLeft > 10)
                {
                    npc.timeLeft = 10;
                }
                if (Main.npcs[(int)npc.ai[1]].ai[1] != 0f)
                {
                    npc.localAI[0] += 2f;
                    if (npc.Position.Y > Main.npcs[(int)npc.ai[1]].Position.Y - 100f)
                    {
                        if (npc.Velocity.Y > 0f)
                        {
                            npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                        }
                        npc.Velocity.Y = npc.Velocity.Y - 0.07f;
                        if (npc.Velocity.Y > 6f)
                        {
                            npc.Velocity.Y = 6f;
                        }
                    }
                    else if (npc.Position.Y < Main.npcs[(int)npc.ai[1]].Position.Y - 100f)
                    {
                        if (npc.Velocity.Y < 0f)
                        {
                            npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                        }
                        npc.Velocity.Y = npc.Velocity.Y + 0.07f;
                        if (npc.Velocity.Y < -6f)
                        {
                            npc.Velocity.Y = -6f;
                        }
                    }

                    if (npc.Position.X + (float)(npc.Width / 2) > Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 120f * npc.ai[0])
                    {
                        if (npc.Velocity.X > 0f)
                        {
                            npc.Velocity.X = npc.Velocity.X * 0.96f;
                        }
                        npc.Velocity.X = npc.Velocity.X - 0.1f;
                        if (npc.Velocity.X > 8f)
                        {
                            npc.Velocity.X = 8f;
                        }
                    }
                    if (npc.Position.X + (float)(npc.Width / 2) < Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 120f * npc.ai[0])
                    {
                        if (npc.Velocity.X < 0f)
                        {
                            npc.Velocity.X = npc.Velocity.X * 0.96f;
                        }
                        npc.Velocity.X = npc.Velocity.X + 0.1f;
                        if (npc.Velocity.X < -8f)
                        {
                            npc.Velocity.X = -8f;
                        }
                    }
                }
                else
                {
                    npc.ai[3] += 1f;
                    if (npc.ai[3] >= 1100f)
                    {
                        npc.localAI[0] = 0f;
                        npc.ai[2] = 1f;
                        npc.ai[3] = 0f;
                        npc.netUpdate = true;
                    }
                    if (npc.Position.Y > Main.npcs[(int)npc.ai[1]].Position.Y - 150f)
                    {
                        if (npc.Velocity.Y > 0f)
                        {
                            npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                        }
                        npc.Velocity.Y = npc.Velocity.Y - 0.04f;
                        if (npc.Velocity.Y > 3f)
                        {
                            npc.Velocity.Y = 3f;
                        }
                    }
                    else if (npc.Position.Y < Main.npcs[(int)npc.ai[1]].Position.Y - 150f)
                    {
                        if (npc.Velocity.Y < 0f)
                        {
                            npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                        }
                        npc.Velocity.Y = npc.Velocity.Y + 0.04f;
                        if (npc.Velocity.Y < -3f)
                        {
                            npc.Velocity.Y = -3f;
                        }
                    }

                    if (npc.Position.X + (float)(npc.Width / 2) > Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) + 200f)
                    {
                        if (npc.Velocity.X > 0f)
                        {
                            npc.Velocity.X = npc.Velocity.X * 0.96f;
                        }
                        npc.Velocity.X = npc.Velocity.X - 0.2f;
                        if (npc.Velocity.X > 8f)
                        {
                            npc.Velocity.X = 8f;
                        }
                    }
                    if (npc.Position.X + (float)(npc.Width / 2) < Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) + 160f)
                    {
                        if (npc.Velocity.X < 0f)
                        {
                            npc.Velocity.X = npc.Velocity.X * 0.96f;
                        }
                        npc.Velocity.X = npc.Velocity.X + 0.2f;
                        if (npc.Velocity.X < -8f)
                        {
                            npc.Velocity.X = -8f;
                        }
                    }
                }
                Vector2 vector52 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                float num423 = Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 200f * npc.ai[0] - vector52.X;
                float num424 = Main.npcs[(int)npc.ai[1]].Position.Y + 230f - vector52.Y;
                float num425 = (float)Math.Sqrt((double)(num423 * num423 + num424 * num424));
                npc.rotation = (float)Math.Atan2((double)num424, (double)num423) + 1.57f;

                npc.localAI[0] += 1f;
                if (npc.localAI[0] > 140f)
                {
                    npc.localAI[0] = 0f;
                    float num426 = 12f;
                    int num427 = 0;
                    int num428 = 102;
                    num425 = num426 / num425;
                    num423 = -num423 * num425;
                    num424 = -num424 * num425;
                    num423 += (float)Main.rand.Next(-40, 41) * 0.01f;
                    num424 += (float)Main.rand.Next(-40, 41) * 0.01f;
                    vector52.X += num423 * 4f;
                    vector52.Y += num424 * 4f;
                    Projectile.NewProjectile(vector52.X, vector52.Y, num423, num424, num428, num427, 0f, Main.myPlayer);
                    return;
                }
            }
            else if (npc.ai[2] == 1f)
            {
                npc.ai[3] += 1f;
                if (npc.ai[3] >= 300f)
                {
                    npc.localAI[0] = 0f;
                    npc.ai[2] = 0f;
                    npc.ai[3] = 0f;
                    npc.netUpdate = true;
                }
                Vector2 vector53 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                float num429 = Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - vector53.X;
                float num430 = Main.npcs[(int)npc.ai[1]].Position.Y - vector53.Y;
                num430 = Main.players[npc.target].Position.Y + (float)(Main.players[npc.target].Height / 2) - 80f - vector53.Y;
                float num431 = (float)Math.Sqrt((double)(num429 * num429 + num430 * num430));
                num431 = 6f / num431;
                num429 *= num431;
                num430 *= num431;
                if (npc.Velocity.X > num429)
                {
                    if (npc.Velocity.X > 0f)
                    {
                        npc.Velocity.X = npc.Velocity.X * 0.9f;
                    }
                    npc.Velocity.X = npc.Velocity.X - 0.04f;
                }
                if (npc.Velocity.X < num429)
                {
                    if (npc.Velocity.X < 0f)
                    {
                        npc.Velocity.X = npc.Velocity.X * 0.9f;
                    }
                    npc.Velocity.X = npc.Velocity.X + 0.04f;
                }
                if (npc.Velocity.Y > num430)
                {
                    if (npc.Velocity.Y > 0f)
                    {
                        npc.Velocity.Y = npc.Velocity.Y * 0.9f;
                    }
                    npc.Velocity.Y = npc.Velocity.Y - 0.08f;
                }
                if (npc.Velocity.Y < num430)
                {
                    if (npc.Velocity.Y < 0f)
                    {
                        npc.Velocity.Y = npc.Velocity.Y * 0.9f;
                    }
                    npc.Velocity.Y = npc.Velocity.Y + 0.08f;
                }
                npc.TargetClosest(true);
                vector53 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                num429 = Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2) - vector53.X;
                num430 = Main.players[npc.target].Position.Y + (float)(Main.players[npc.target].Height / 2) - vector53.Y;
                num431 = (float)Math.Sqrt((double)(num429 * num429 + num430 * num430));
                npc.rotation = (float)Math.Atan2((double)num430, (double)num429) - 1.57f;

                npc.localAI[0] += 1f;
                if (npc.localAI[0] > 40f)
                {
                    npc.localAI[0] = 0f;
                    float num432 = 10f;
                    int num433 = 0;
                    int num434 = 102;
                    num431 = num432 / num431;
                    num429 *= num431;
                    num430 *= num431;
                    num429 += (float)Main.rand.Next(-40, 41) * 0.01f;
                    num430 += (float)Main.rand.Next(-40, 41) * 0.01f;
                    vector53.X += num429 * 4f;
                    vector53.Y += num430 * 4f;
                    Projectile.NewProjectile(vector53.X, vector53.Y, num429, num430, num434, num433, 0f, Main.myPlayer);
                    return;
                }
            }
        }
        // 36 - 1.1.2
        private void AIPrimeLaser(NPC npc, bool flag, Func<Int32, Int32, ITile> TileRefs)
        {
            npc.spriteDirection = -(int)npc.ai[0];
            if (!Main.npcs[(int)npc.ai[1]].Active || Main.npcs[(int)npc.ai[1]].aiStyle != 32)
            {
                npc.ai[2] += 10f;
                if (npc.ai[2] > 50f)
                {
                    npc.life = -1;
                    npc.HitEffect(0, 10.0);
                    npc.Active = false;
                }
            }
            if (npc.ai[2] == 0f || npc.ai[2] == 3f)
            {
                if (Main.npcs[(int)npc.ai[1]].ai[1] == 3f && npc.timeLeft > 10)
                {
                    npc.timeLeft = 10;
                }
                if (Main.npcs[(int)npc.ai[1]].ai[1] != 0f)
                {
                    npc.localAI[0] += 3f;
                    if (npc.Position.Y > Main.npcs[(int)npc.ai[1]].Position.Y - 100f)
                    {
                        if (npc.Velocity.Y > 0f)
                        {
                            npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                        }
                        npc.Velocity.Y = npc.Velocity.Y - 0.07f;
                        if (npc.Velocity.Y > 6f)
                        {
                            npc.Velocity.Y = 6f;
                        }
                    }
                    else if (npc.Position.Y < Main.npcs[(int)npc.ai[1]].Position.Y - 100f)
                    {
                        if (npc.Velocity.Y < 0f)
                        {
                            npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                        }
                        npc.Velocity.Y = npc.Velocity.Y + 0.07f;
                        if (npc.Velocity.Y < -6f)
                        {
                            npc.Velocity.Y = -6f;
                        }
                    }

                    if (npc.Position.X + (float)(npc.Width / 2) > Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 120f * npc.ai[0])
                    {
                        if (npc.Velocity.X > 0f)
                        {
                            npc.Velocity.X = npc.Velocity.X * 0.96f;
                        }
                        npc.Velocity.X = npc.Velocity.X - 0.1f;
                        if (npc.Velocity.X > 8f)
                        {
                            npc.Velocity.X = 8f;
                        }
                    }
                    if (npc.Position.X + (float)(npc.Width / 2) < Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 120f * npc.ai[0])
                    {
                        if (npc.Velocity.X < 0f)
                        {
                            npc.Velocity.X = npc.Velocity.X * 0.96f;
                        }
                        npc.Velocity.X = npc.Velocity.X + 0.1f;
                        if (npc.Velocity.X < -8f)
                        {
                            npc.Velocity.X = -8f;
                        }
                    }
                }
                else
                {
                    npc.ai[3] += 1f;
                    if (npc.ai[3] >= 800f)
                    {
                        npc.ai[2] += 1f;
                        npc.ai[3] = 0f;
                        npc.netUpdate = true;
                    }
                    if (npc.Position.Y > Main.npcs[(int)npc.ai[1]].Position.Y - 100f)
                    {
                        if (npc.Velocity.Y > 0f)
                        {
                            npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                        }
                        npc.Velocity.Y = npc.Velocity.Y - 0.1f;
                        if (npc.Velocity.Y > 3f)
                        {
                            npc.Velocity.Y = 3f;
                        }
                    }
                    else if (npc.Position.Y < Main.npcs[(int)npc.ai[1]].Position.Y - 100f)
                    {
                        if (npc.Velocity.Y < 0f)
                        {
                            npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                        }
                        npc.Velocity.Y = npc.Velocity.Y + 0.1f;
                        if (npc.Velocity.Y < -3f)
                        {
                            npc.Velocity.Y = -3f;
                        }
                    }

                    if (npc.Position.X + (float)(npc.Width / 2) > Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 180f * npc.ai[0])
                    {
                        if (npc.Velocity.X > 0f)
                        {
                            npc.Velocity.X = npc.Velocity.X * 0.96f;
                        }
                        npc.Velocity.X = npc.Velocity.X - 0.14f;
                        if (npc.Velocity.X > 8f)
                        {
                            npc.Velocity.X = 8f;
                        }
                    }
                    if (npc.Position.X + (float)(npc.Width / 2) < Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 180f * npc.ai[0])
                    {
                        if (npc.Velocity.X < 0f)
                        {
                            npc.Velocity.X = npc.Velocity.X * 0.96f;
                        }
                        npc.Velocity.X = npc.Velocity.X + 0.14f;
                        if (npc.Velocity.X < -8f)
                        {
                            npc.Velocity.X = -8f;
                        }
                    }
                }
                npc.TargetClosest(true);
                Vector2 vector54 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                float num435 = Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2) - vector54.X;
                float num436 = Main.players[npc.target].Position.Y + (float)(Main.players[npc.target].Height / 2) - vector54.Y;
                float num437 = (float)Math.Sqrt((double)(num435 * num435 + num436 * num436));
                npc.rotation = (float)Math.Atan2((double)num436, (double)num435) - 1.57f;

                npc.localAI[0] += 1f;
                if (npc.localAI[0] > 200f)
                {
                    npc.localAI[0] = 0f;
                    float num438 = 8f;
                    int num439 = 25;
                    int num440 = 100;
                    num437 = num438 / num437;
                    num435 *= num437;
                    num436 *= num437;
                    num435 += (float)Main.rand.Next(-40, 41) * 0.05f;
                    num436 += (float)Main.rand.Next(-40, 41) * 0.05f;
                    vector54.X += num435 * 8f;
                    vector54.Y += num436 * 8f;
                    Projectile.NewProjectile(vector54.X, vector54.Y, num435, num436, num440, num439, 0f, Main.myPlayer);
                    return;
                }
            }
            else if (npc.ai[2] == 1f)
            {
                npc.ai[3] += 1f;
                if (npc.ai[3] >= 200f)
                {
                    npc.localAI[0] = 0f;
                    npc.ai[2] = 0f;
                    npc.ai[3] = 0f;
                    npc.netUpdate = true;
                }
                Vector2 vector55 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                float num441 = Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2) - 350f - vector55.X;
                float num442 = Main.players[npc.target].Position.Y + (float)(Main.players[npc.target].Height / 2) - 20f - vector55.Y;
                float num443 = (float)Math.Sqrt((double)(num441 * num441 + num442 * num442));
                num443 = 7f / num443;
                num441 *= num443;
                num442 *= num443;
                if (npc.Velocity.X > num441)
                {
                    if (npc.Velocity.X > 0f)
                    {
                        npc.Velocity.X = npc.Velocity.X * 0.9f;
                    }
                    npc.Velocity.X = npc.Velocity.X - 0.1f;
                }
                if (npc.Velocity.X < num441)
                {
                    if (npc.Velocity.X < 0f)
                    {
                        npc.Velocity.X = npc.Velocity.X * 0.9f;
                    }
                    npc.Velocity.X = npc.Velocity.X + 0.1f;
                }
                if (npc.Velocity.Y > num442)
                {
                    if (npc.Velocity.Y > 0f)
                    {
                        npc.Velocity.Y = npc.Velocity.Y * 0.9f;
                    }
                    npc.Velocity.Y = npc.Velocity.Y - 0.03f;
                }
                if (npc.Velocity.Y < num442)
                {
                    if (npc.Velocity.Y < 0f)
                    {
                        npc.Velocity.Y = npc.Velocity.Y * 0.9f;
                    }
                    npc.Velocity.Y = npc.Velocity.Y + 0.03f;
                }
                npc.TargetClosest(true);
                vector55 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                num441 = Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2) - vector55.X;
                num442 = Main.players[npc.target].Position.Y + (float)(Main.players[npc.target].Height / 2) - vector55.Y;
                num443 = (float)Math.Sqrt((double)(num441 * num441 + num442 * num442));
                npc.rotation = (float)Math.Atan2((double)num442, (double)num441) - 1.57f;
            }
        }
        // 13 - 1.1.2
        private void AIMunchyPlant(NPC npc, bool flag, Func<Int32, Int32, ITile> TileRefs)
        {
            if (!Main.tile.At((int)npc.ai[0], (int)npc.ai[1]).Active)
            {
                npc.life = -1;
                npc.HitEffect(0, 10.0);
                npc.Active = false;
                return;
            }
            npc.TargetClosest(true);
            float num196 = 0.035f;
            float num197 = 150f;

            if (npc.type == NPCType.N43_MAN_EATER)
            {
                num197 = 250f;
            }
            if (npc.type == NPCType.N101_CLINGER)
            {
                num197 = 175f;
            }

            npc.ai[2] += 1f;

            if (npc.ai[2] > 300f)
            {
                num197 = (float)((int)((double)num197 * 1.3));
                if (npc.ai[2] > 450f)
                {
                    npc.ai[2] = 0f;
                }
            }

            Vector2 vector22 = new Vector2(npc.ai[0] * 16f + 8f, npc.ai[1] * 16f + 8f);
            float num198 = Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2) - (float)(npc.Width / 2) - vector22.X;
            float num199 = Main.players[npc.target].Position.Y + (float)(Main.players[npc.target].Height / 2) - (float)(npc.Height / 2) - vector22.Y;
            float num200 = (float)Math.Sqrt((double)(num198 * num198 + num199 * num199));
            if (num200 > num197)
            {
                num200 = num197 / num200;
                num198 *= num200;
                num199 *= num200;
            }
            if (npc.Position.X < npc.ai[0] * 16f + 8f + num198)
            {
                npc.Velocity.X = npc.Velocity.X + num196;
                if (npc.Velocity.X < 0f && num198 > 0f)
                {
                    npc.Velocity.X = npc.Velocity.X + num196 * 1.5f;
                }
            }
            else if (npc.Position.X > npc.ai[0] * 16f + 8f + num198)
            {
                npc.Velocity.X = npc.Velocity.X - num196;
                if (npc.Velocity.X > 0f && num198 < 0f)
                {
                    npc.Velocity.X = npc.Velocity.X - num196 * 1.5f;
                }
            }

            if (npc.Position.Y < npc.ai[1] * 16f + 8f + num199)
            {
                npc.Velocity.Y = npc.Velocity.Y + num196;
                if (npc.Velocity.Y < 0f && num199 > 0f)
                {
                    npc.Velocity.Y = npc.Velocity.Y + num196 * 1.5f;
                }
            }
            else if (npc.Position.Y > npc.ai[1] * 16f + 8f + num199)
            {
                npc.Velocity.Y = npc.Velocity.Y - num196;
                if (npc.Velocity.Y > 0f && num199 < 0f)
                {
                    npc.Velocity.Y = npc.Velocity.Y - num196 * 1.5f;
                }
            }

            if (npc.type == NPCType.N43_MAN_EATER)
            {
                if (npc.Velocity.X > 3f)
                {
                    npc.Velocity.X = 3f;
                }
                if (npc.Velocity.X < -3f)
                {
                    npc.Velocity.X = -3f;
                }
                if (npc.Velocity.Y > 3f)
                {
                    npc.Velocity.Y = 3f;
                }
                if (npc.Velocity.Y < -3f)
                {
                    npc.Velocity.Y = -3f;
                }
            }
            else
            {
                if (npc.Velocity.X > 2f)
                {
                    npc.Velocity.X = 2f;
                }
                if (npc.Velocity.X < -2f)
                {
                    npc.Velocity.X = -2f;
                }
                if (npc.Velocity.Y > 2f)
                {
                    npc.Velocity.Y = 2f;
                }
                if (npc.Velocity.Y < -2f)
                {
                    npc.Velocity.Y = -2f;
                }
            }
            if (num198 > 0f)
            {
                npc.spriteDirection = 1;
                npc.rotation = (float)Math.Atan2((double)num199, (double)num198);
            }
            if (num198 < 0f)
            {
                npc.spriteDirection = -1;
                npc.rotation = (float)Math.Atan2((double)num199, (double)num198) + 3.14f;
            }
            if (npc.collideX)
            {
                npc.netUpdate = true;
                npc.Velocity.X = npc.oldVelocity.X * -0.7f;
                if (npc.Velocity.X > 0f && npc.Velocity.X < 2f)
                {
                    npc.Velocity.X = 2f;
                }
                if (npc.Velocity.X < 0f && npc.Velocity.X > -2f)
                {
                    npc.Velocity.X = -2f;
                }
            }
            if (npc.collideY)
            {
                npc.netUpdate = true;
                npc.Velocity.Y = npc.oldVelocity.Y * -0.7f;
                if (npc.Velocity.Y > 0f && npc.Velocity.Y < 2f)
                {
                    npc.Velocity.Y = 2f;
                }
                if (npc.Velocity.Y < 0f && npc.Velocity.Y > -2f)
                {
                    npc.Velocity.Y = -2f;
                }
            }
            if (npc.type == NPCType.N101_CLINGER && !Main.players[npc.target].dead)
            {
                if (npc.justHit)
                {
                    npc.localAI[0] = 0f;
                }
                npc.localAI[0] += 1f;
                if (npc.localAI[0] >= 120f)
                {
                    if (!Collision.SolidCollision(npc.Position, npc.Width, npc.Height) && Collision.CanHit(npc.Position, npc.Width, npc.Height, Main.players[npc.target].Position, Main.players[npc.target].Width, Main.players[npc.target].Height))
                    {
                        float num201 = 10f;
                        vector22 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                        num198 = Main.players[npc.target].Position.X + (float)Main.players[npc.target].Width * 0.5f - vector22.X + (float)Main.rand.Next(-10, 11);
                        num199 = Main.players[npc.target].Position.Y + (float)Main.players[npc.target].Height * 0.5f - vector22.Y + (float)Main.rand.Next(-10, 11);
                        num200 = (float)Math.Sqrt((double)(num198 * num198 + num199 * num199));
                        num200 = num201 / num200;
                        num198 *= num200;
                        num199 *= num200;
                        int num202 = 22;
                        int num203 = 96;
                        int num204 = Projectile.NewProjectile(vector22.X, vector22.Y, num198, num199, num203, num202, 0f, Main.myPlayer);
                        Main.projectile[num204].timeLeft = 300;
                        npc.localAI[0] = 0f;
                        return;
                    }
                    npc.localAI[0] = 100f;
                    return;
                }
            }
        }
        // 7 - 1.1.2
        private void AIFriendly(NPC npc, bool flag, Func<Int32, Int32, ITile> TileRefs)
        {
            if (npc.type == NPCType.N142_SANTA_CLAUS && !Main.Xmas)
            {
                npc.StrikeNPC(World.Sender, 9999, 0f, 0);
                NetMessage.SendData(28, -1, -1, "", npc.whoAmI, 9999f, 0f, 0f, 0);
            }
            int num129 = (int)(npc.Position.X + (float)(npc.Width / 2)) / 16;
            int num130 = (int)(npc.Position.Y + (float)npc.Height + 1f) / 16;

            if (num129 < 0 || num129 > Main.maxTilesX)
                return;
            else if (num130 < 0 || num130 > Main.maxTilesY)
                return;

            if (npc.type == NPCType.N107_GOBLIN_TINKERER)
            {
                savedGoblin = true;
            }
            if (npc.type == NPCType.N108_WIZARD)
            {
                savedWizard = true;
            }
            if (npc.type == NPCType.N124_MECHANIC)
            {
                savedMech = true;
            }
            if (npc.type == NPCType.N46_BUNNY && npc.target == 255)
            {
                npc.TargetClosest(true);
            }
            bool flag15 = false;
            npc.directionY = -1;
            if (npc.direction == 0)
            {
                npc.direction = 1;
            }
            for (int num131 = 0; num131 < Main.MAX_PLAYERS; num131++)
            {
                if (Main.players[num131].Active && Main.players[num131].talkNPC == npc.whoAmI)
                {
                    flag15 = true;
                    if (npc.ai[0] != 0f)
                    {
                        npc.netUpdate = true;
                    }
                    npc.ai[0] = 0f;
                    npc.ai[1] = 300f;
                    npc.ai[2] = 100f;
                    if (Main.players[num131].Position.X + (float)(Main.players[num131].Width / 2) < npc.Position.X + (float)(npc.Width / 2))
                    {
                        npc.direction = -1;
                    }
                    else
                    {
                        npc.direction = 1;
                    }
                }
            }
            if (npc.ai[3] > 0f)
            {
                npc.life = -1;
                npc.HitEffect(0, 10.0);
                npc.Active = false;
            }
            if (npc.type == NPCType.N37_OLD_MAN)
            {
                npc.homeless = false;
                npc.homeTileX = Main.dungeonX;
                npc.homeTileY = Main.dungeonY;
                if (downedBoss3)
                {
                    npc.ai[3] = 1f;
                    npc.netUpdate = true;
                }
            }
            int num132 = npc.homeTileY;
            if (npc.homeTileY > 0)
            {
                while (!WorldModify.SolidTile(TileRefs, npc.homeTileX, num132) && num132 < Main.maxTilesY - 20)
                {
                    num132++;
                }
            }
            var type = (int)Main.tile.At(num129, num130).Type;
            if (npc.townNPC && (!Main.dayTime || Main.tileDungeon[type]) && (num129 != npc.homeTileX || num130 != num132) && !npc.homeless)
            {
                bool flag16 = true;
                for (int num133 = 0; num133 < 2; num133++)
                {
                    Rectangle rectangle3 = new Rectangle((int)(npc.Position.X + (float)(npc.Width / 2) - (float)(sWidth / 2) - (float)safeRangeX), (int)(npc.Position.Y + (float)(npc.Height / 2) - (float)(sHeight / 2) - (float)safeRangeY), sWidth + safeRangeX * 2, sHeight + safeRangeY * 2);
                    if (num133 == 1)
                    {
                        rectangle3 = new Rectangle(npc.homeTileX * 16 + 8 - sWidth / 2 - safeRangeX, num132 * 16 + 8 - sHeight / 2 - safeRangeY, sWidth + safeRangeX * 2, sHeight + safeRangeY * 2);
                    }
                    for (int num134 = 0; num134 < 255; num134++)
                    {
                        if (Main.players[num134].Active)
                        {
                            Rectangle rectangle4 = new Rectangle((int)Main.players[num134].Position.X, (int)Main.players[num134].Position.Y,
                                Main.players[num134].Width, Main.players[num134].Height);
                            if (rectangle4.Intersects(rectangle3))
                            {
                                flag16 = false;
                                break;
                            }
                        }
                        if (!flag16)
                        {
                            break;
                        }
                    }
                }
                if (flag16)
                {
                    if (npc.type == NPCType.N37_OLD_MAN || !Collision.SolidTiles(npc.homeTileX - 1, npc.homeTileX + 1, num132 - 3, num132 - 1))
                    {
                        npc.Velocity.X = 0f;
                        npc.Velocity.Y = 0f;
                        npc.Position.X = (float)(npc.homeTileX * 16 + 8 - npc.Width / 2);
                        npc.Position.Y = (float)(num132 * 16 - npc.Height) - 0.1f;
                        npc.netUpdate = true;
                    }
                    else
                    {
                        npc.homeless = true;
                        WorldModify.QuickFindHome(TileRefs, npc.whoAmI);
                    }
                }
            }
            if (npc.ai[0] == 0f)
            {
                if (npc.ai[2] > 0f)
                {
                    npc.ai[2] -= 1f;
                }
                if (!Main.dayTime && !flag15 && npc.type != NPCType.N46_BUNNY)
                {
                    if (num129 == npc.homeTileX && num130 == num132)
                    {
                        if (npc.Velocity.X != 0f)
                        {
                            npc.netUpdate = true;
                        }
                        if ((double)npc.Velocity.X > 0.1)
                        {
                            npc.Velocity.X = npc.Velocity.X - 0.1f;
                        }
                        else if ((double)npc.Velocity.X < -0.1)
                        {
                            npc.Velocity.X = npc.Velocity.X + 0.1f;
                        }
                        else
                        {
                            npc.Velocity.X = 0f;
                        }
                    }
                    else if (!flag15)
                    {
                        if (num129 > npc.homeTileX)
                        {
                            npc.direction = -1;
                        }
                        else
                        {
                            npc.direction = 1;
                        }
                        npc.ai[0] = 1f;
                        npc.ai[1] = (float)(200 + Main.rand.Next(200));
                        npc.ai[2] = 0f;
                        npc.netUpdate = true;
                    }
                }
                else
                {
                    if ((double)npc.Velocity.X > 0.1)
                    {
                        npc.Velocity.X = npc.Velocity.X - 0.1f;
                    }
                    else if ((double)npc.Velocity.X < -0.1)
                    {
                        npc.Velocity.X = npc.Velocity.X + 0.1f;
                    }
                    else
                    {
                        npc.Velocity.X = 0f;
                    }

                    if (npc.ai[1] > 0f)
                    {
                        npc.ai[1] -= 1f;
                    }
                    if (npc.ai[1] <= 0f)
                    {
                        npc.ai[0] = 1f;
                        npc.ai[1] = (float)(200 + Main.rand.Next(200));
                        if (npc.type == NPCType.N46_BUNNY)
                        {
                            npc.ai[1] += (float)Main.rand.Next(200, 400);
                        }
                        npc.ai[2] = 0f;
                        npc.netUpdate = true;
                    }
                }
                if ((Main.dayTime || (num129 == npc.homeTileX && num130 == num132)))
                {
                    if (num129 < npc.homeTileX - 25 || num129 > npc.homeTileX + 25)
                    {
                        if (npc.ai[2] == 0f)
                        {
                            if (num129 < npc.homeTileX - 50 && npc.direction == -1)
                            {
                                npc.direction = 1;
                                npc.netUpdate = true;
                                return;
                            }
                            if (num129 > npc.homeTileX + 50 && npc.direction == 1)
                            {
                                npc.direction = -1;
                                npc.netUpdate = true;
                                return;
                            }
                        }
                    }
                    else if (Main.rand.Next(80) == 0 && npc.ai[2] == 0f)
                    {
                        npc.ai[2] = 200f;
                        npc.direction *= -1;
                        npc.netUpdate = true;
                        return;
                    }
                }
            }
            else
            {
                if (npc.ai[0] == 1f)
                {
                    if (!Main.dayTime && num129 == npc.homeTileX && num130 == npc.homeTileY && npc.type != NPCType.N46_BUNNY)
                    {
                        npc.ai[0] = 0f;
                        npc.ai[1] = (float)(200 + Main.rand.Next(200));
                        npc.ai[2] = 60f;
                        npc.netUpdate = true;
                        return;
                    }
                    if (!npc.homeless && !Main.tileDungeon[(int)Main.tile.At(num129, num130).Type] && (num129 < npc.homeTileX - 35 || num129 > npc.homeTileX + 35))
                    {
                        if (npc.Position.X < (float)(npc.homeTileX * 16) && npc.direction == -1)
                        {
                            npc.ai[1] -= 5f;
                        }
                        else if (npc.Position.X > (float)(npc.homeTileX * 16) && npc.direction == 1)
                        {
                            npc.ai[1] -= 5f;
                        }
                    }
                    npc.ai[1] -= 1f;
                    if (npc.ai[1] <= 0f)
                    {
                        npc.ai[0] = 0f;
                        npc.ai[1] = (float)(300 + Main.rand.Next(300));
                        if (npc.type == NPCType.N46_BUNNY)
                        {
                            npc.ai[1] -= (float)Main.rand.Next(100);
                        }
                        npc.ai[2] = 60f;
                        npc.netUpdate = true;
                    }
                    if (npc.closeDoor && ((npc.Position.X + (float)(npc.Width / 2)) / 16f > (float)(npc.doorX + 2) || (npc.Position.X + (float)(npc.Width / 2)) / 16f < (float)(npc.doorX - 2)))
                    {
                        bool flag17 = WorldModify.CloseDoor(TileRefs, null, npc.doorX, npc.doorY, false, npc);
                        if (flag17)
                        {
                            npc.closeDoor = false;
                            NetMessage.SendData(19, -1, -1, "", 1, (float)npc.doorX, (float)npc.doorY, (float)npc.direction, 0);
                        }
                        if ((npc.Position.X + (float)(npc.Width / 2)) / 16f > (float)(npc.doorX + 4) || (npc.Position.X + (float)(npc.Width / 2)) / 16f < (float)(npc.doorX - 4) || (npc.Position.Y + (float)(npc.Height / 2)) / 16f > (float)(npc.doorY + 4) || (npc.Position.Y + (float)(npc.Height / 2)) / 16f < (float)(npc.doorY - 4))
                        {
                            npc.closeDoor = false;
                        }
                    }
                    if (npc.Velocity.X < -1f || npc.Velocity.X > 1f)
                    {
                        if (npc.Velocity.Y == 0f)
                        {
                            npc.Velocity *= 0.8f;
                        }
                    }
                    else if ((double)npc.Velocity.X < 1.15 && npc.direction == 1)
                    {
                        npc.Velocity.X = npc.Velocity.X + 0.07f;
                        if (npc.Velocity.X > 1f)
                        {
                            npc.Velocity.X = 1f;
                        }
                    }
                    else if (npc.Velocity.X > -1f && npc.direction == -1)
                    {
                        npc.Velocity.X = npc.Velocity.X - 0.07f;
                        if (npc.Velocity.X > 1f)
                        {
                            npc.Velocity.X = 1f;
                        }
                    }

                    if (npc.Velocity.Y == 0f)
                    {
                        if (npc.Position.X == npc.ai[2])
                        {
                            npc.direction *= -1;
                        }
                        npc.ai[2] = -1f;
                        int num135 = (int)((npc.Position.X + (float)(npc.Width / 2) + (float)(15 * npc.direction)) / 16f);
                        int num136 = (int)((npc.Position.Y + (float)npc.Height - 16f) / 16f);

                        if (npc.townNPC && Main.tile.At(num135, num136 - 2).Active && Main.tile.At(num135, num136 - 2).Type == 10 &&
                            (Main.rand.Next(10) == 0 || !Main.dayTime))
                        {
                            bool flag18 = WorldModify.OpenDoor(TileRefs, null, num135, num136 - 2, npc.direction, npc);
                            if (flag18)
                            {
                                npc.closeDoor = true;
                                npc.doorX = num135;
                                npc.doorY = num136 - 2;
                                NetMessage.SendData(19, -1, -1, "", 0, (float)num135, (float)(num136 - 2), (float)npc.direction, 0);
                                npc.netUpdate = true;
                                npc.ai[1] += 80f;
                                return;
                            }
                            if (WorldModify.OpenDoor(TileRefs, null, num135, num136 - 2, -npc.direction, npc))
                            {
                                npc.closeDoor = true;
                                npc.doorX = num135;
                                npc.doorY = num136 - 2;
                                NetMessage.SendData(19, -1, -1, "", 0, (float)num135, (float)(num136 - 2), (float)(-(float)npc.direction), 0);
                                npc.netUpdate = true;
                                npc.ai[1] += 80f;
                                return;
                            }
                            npc.direction *= -1;
                            npc.netUpdate = true;
                            return;
                        }
                        else
                        {
                            if ((npc.Velocity.X < 0f && npc.spriteDirection == -1) || (npc.Velocity.X > 0f && npc.spriteDirection == 1))
                            {
                                if (Main.tile.At(num135, num136 - 2).Active && Main.tileSolid[(int)Main.tile.At(num135, num136 - 2).Type] &&
                                    !Main.tileSolidTop[(int)Main.tile.At(num135, num136 - 2).Type])
                                {
                                    if ((npc.direction == 1 && !Collision.SolidTiles(num135 - 2, num135 - 1, num136 - 5, num136 - 1)) ||
                                        (npc.direction == -1 && !Collision.SolidTiles(num135 + 1, num135 + 2, num136 - 5, num136 - 1)))
                                    {
                                        if (!Collision.SolidTiles(num135, num135, num136 - 5, num136 - 3))
                                        {
                                            npc.Velocity.Y = -6f;
                                            npc.netUpdate = true;
                                        }
                                        else
                                        {
                                            npc.direction *= -1;
                                            npc.netUpdate = true;
                                        }
                                    }
                                    else
                                    {
                                        npc.direction *= -1;
                                        npc.netUpdate = true;
                                    }
                                }
                                else
                                {
                                    if (Main.tile.At(num135, num136 - 1).Active && Main.tileSolid[(int)Main.tile.At(num135, num136 - 1).Type] &&
                                        !Main.tileSolidTop[(int)Main.tile.At(num135, num136 - 1).Type])
                                    {
                                        if ((npc.direction == 1 && !Collision.SolidTiles(num135 - 2, num135 - 1, num136 - 4, num136 - 1)) ||
                                            (npc.direction == -1 && !Collision.SolidTiles(num135 + 1, num135 + 2, num136 - 4, num136 - 1)))
                                        {
                                            if (!Collision.SolidTiles(num135, num135, num136 - 4, num136 - 2))
                                            {
                                                npc.Velocity.Y = -5f;
                                                npc.netUpdate = true;
                                            }
                                            else
                                            {
                                                npc.direction *= -1;
                                                npc.netUpdate = true;
                                            }
                                        }
                                        else
                                        {
                                            npc.direction *= -1;
                                            npc.netUpdate = true;
                                        }
                                    }
                                    else if (Main.tile.At(num135, num136).Active && Main.tileSolid[(int)Main.tile.At(num135, num136).Type] &&
                                            !Main.tileSolidTop[(int)Main.tile.At(num135, num136).Type])
                                    {
                                        if ((npc.direction == 1 && !Collision.SolidTiles(num135 - 2, num135, num136 - 3, num136 - 1)) ||
                                            (npc.direction == -1 && !Collision.SolidTiles(num135, num135 + 2, num136 - 3, num136 - 1)))
                                        {
                                            npc.Velocity.Y = -3.6f;
                                            npc.netUpdate = true;
                                        }
                                        else
                                        {
                                            npc.direction *= -1;
                                            npc.netUpdate = true;
                                        }
                                    }
                                }
                                try
                                {
                                    if (num129 >= npc.homeTileX - 35 && num129 <= npc.homeTileX + 35 && (!Main.tile.At(num135, num136 + 1).Active ||
                                        !Main.tileSolid[(int)Main.tile.At(num135, num136 + 1).Type]) && (!Main.tile.At(num135 - npc.direction, num136 + 1).Active ||
                                            !Main.tileSolid[(int)Main.tile.At(num135 - npc.direction, num136 + 1).Type]) && (!Main.tile.At(num135, num136 + 2).Active ||
                                                !Main.tileSolid[(int)Main.tile.At(num135, num136 + 2).Type]) && (!Main.tile.At(num135 - npc.direction, num136 + 2).Active ||
                                                    !Main.tileSolid[(int)Main.tile.At(num135 - npc.direction, num136 + 2).Type]) &&
                                                        (!Main.tile.At(num135, num136 + 3).Active || !Main.tileSolid[(int)Main.tile.At(num135, num136 + 3).Type]) &&
                                                            (!Main.tile.At(num135 - npc.direction, num136 + 3).Active ||
                                                                !Main.tileSolid[(int)Main.tile.At(num135 - npc.direction, num136 + 3).Type]) &&
                                                                    (!Main.tile.At(num135, num136 + 4).Active || !Main.tileSolid[(int)Main.tile.At(num135, num136 + 4).Type]) &&
                                                                        (!Main.tile.At(num135 - npc.direction, num136 + 4).Active ||
                                                                            !Main.tileSolid[(int)Main.tile.At(num135 - npc.direction, num136 + 4).Type])
                                                                                && npc.type != NPCType.N46_BUNNY)
                                    {
                                        npc.direction *= -1;
                                        npc.Velocity.X = npc.Velocity.X * -1f;
                                        npc.netUpdate = true;
                                    }
                                }
                                catch
                                { }

                                if (npc.Velocity.Y < 0f)
                                {
                                    npc.ai[2] = npc.Position.X;
                                }
                            }
                            if (npc.Velocity.Y < 0f && npc.wet)
                            {
                                npc.Velocity.Y = npc.Velocity.Y * 1.2f;
                            }
                            if (npc.Velocity.Y < 0f && npc.type == NPCType.N46_BUNNY)
                            {
                                npc.Velocity.Y = npc.Velocity.Y * 1.2f;
                                return;
                            }
                        }
                    }
                }
            }
        }
        // 6 - 1.1.2
        private void AIWorm(NPC npc, bool flag, Func<Int32, Int32, ITile> TileRefs)
        {
            if (npc.type == NPCType.N117_LEECH_HEAD && npc.localAI[1] == 0f)
            {
                npc.localAI[1] = 1f;
            }
            if (npc.type >= NPCType.N13_EATER_OF_WORLDS_HEAD && npc.type <= NPCType.N15_EATER_OF_WORLDS_TAIL)
            {
                npc.realLife = -1;
            }
            else 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 (Main.players[npc.target].dead && npc.timeLeft > 300)
            {
                npc.timeLeft = 300;
            }

            if (npc.type == NPCType.N87_WYVERN_HEAD && npc.ai[0] == 0f)
            {
                npc.ai[3] = (float)npc.whoAmI;
                npc.realLife = npc.whoAmI;
                int num96 = npc.whoAmI;
                for (int num97 = 0; num97 < 14; num97++)
                {
                    int num98 = 89;
                    if (num97 == 1 || num97 == 8)
                    {
                        num98 = 88;
                    }
                    else if (num97 == 11)
                    {
                        num98 = 90;
                    }
                    else if (num97 == 12)
                    {
                        num98 = 91;
                    }
                    else if (num97 == 13)
                    {
                        num98 = 92;
                    }
                    int num99 = NewNPC((int)(npc.Position.X + (float)(npc.Width / 2)),
                        (int)(npc.Position.Y + (float)npc.Height), num98, npc.whoAmI, true);
                    Main.npcs[num99].ai[3] = (float)npc.whoAmI;
                    Main.npcs[num99].realLife = npc.whoAmI;
                    Main.npcs[num99].ai[1] = (float)num96;
                    Main.npcs[num96].ai[0] = (float)num99;
                    NetMessage.SendData(23, -1, -1, "", num99, 0f, 0f, 0f, 0);
                    num96 = num99;
                }
            }
            if ((npc.type == NPCType.N07_DEVOURER_HEAD || npc.type == NPCType.N08_DEVOURER_BODY || npc.type == NPCType.N10_GIANT_WORM_HEAD ||
                npc.type == NPCType.N11_GIANT_WORM_BODY || npc.type == NPCType.N13_EATER_OF_WORLDS_HEAD || npc.type == NPCType.N14_EATER_OF_WORLDS_BODY ||
                npc.type == NPCType.N39_BONE_SERPENT_HEAD || npc.type == NPCType.N40_BONE_SERPENT_BODY || npc.type == NPCType.N95_DIGGER_HEAD ||
                npc.type == NPCType.N96_DIGGER_BODY || npc.type == NPCType.N98_SEEKER_HEAD || npc.type == NPCType.N99_SEEKER_BODY || npc.type == NPCType.N117_LEECH_HEAD ||
                npc.type == NPCType.N118_LEECH_BODY) && npc.ai[0] == 0f)
            {
                if (npc.type == NPCType.N07_DEVOURER_HEAD || npc.type == NPCType.N10_GIANT_WORM_HEAD || npc.type == NPCType.N13_EATER_OF_WORLDS_HEAD ||
                    npc.type == NPCType.N39_BONE_SERPENT_HEAD || npc.type == NPCType.N95_DIGGER_HEAD || npc.type == NPCType.N98_SEEKER_HEAD ||
                    npc.type == NPCType.N117_LEECH_HEAD)
                {
                    if (npc.type < NPCType.N13_EATER_OF_WORLDS_HEAD || npc.type > NPCType.N15_EATER_OF_WORLDS_TAIL)
                    {
                        npc.ai[3] = (float)npc.whoAmI;
                        npc.realLife = npc.whoAmI;
                    }
                    npc.ai[2] = (float)Main.rand.Next(8, 13);
                    if (npc.type == NPCType.N10_GIANT_WORM_HEAD)
                    {
                        npc.ai[2] = (float)Main.rand.Next(4, 7);
                    }
                    if (npc.type == NPCType.N13_EATER_OF_WORLDS_HEAD)
                    {
                        npc.ai[2] = (float)Main.rand.Next(45, 56);
                    }
                    if (npc.type == NPCType.N39_BONE_SERPENT_HEAD)
                    {
                        npc.ai[2] = (float)Main.rand.Next(12, 19);
                    }
                    if (npc.type == NPCType.N95_DIGGER_HEAD)
                    {
                        npc.ai[2] = (float)Main.rand.Next(6, 12);
                    }
                    if (npc.type == NPCType.N98_SEEKER_HEAD)
                    {
                        npc.ai[2] = (float)Main.rand.Next(20, 26);
                    }
                    if (npc.type == NPCType.N117_LEECH_HEAD)
                    {
                        npc.ai[2] = (float)Main.rand.Next(3, 6);
                    }
                    npc.ai[0] = (float)NewNPC((int)(npc.Position.X + (float)(npc.Width / 2)), (int)(npc.Position.Y + (float)npc.Height),
                        (int)npc.type + 1, npc.whoAmI, true);
                }
                else
                {
                    if ((npc.type == NPCType.N08_DEVOURER_BODY || npc.type == NPCType.N11_GIANT_WORM_BODY || npc.type == NPCType.N14_EATER_OF_WORLDS_BODY ||
                        npc.type == NPCType.N40_BONE_SERPENT_BODY || npc.type == NPCType.N96_DIGGER_BODY || npc.type == NPCType.N99_SEEKER_BODY ||
                        npc.type == NPCType.N118_LEECH_BODY) && npc.ai[2] > 0f)
                    {
                        npc.ai[0] = (float)NewNPC((int)(npc.Position.X + (float)(npc.Width / 2)), (int)(npc.Position.Y + (float)npc.Height),
                            (int)npc.type, npc.whoAmI, true);
                    }
                    else
                    {
                        npc.ai[0] = (float)NewNPC((int)(npc.Position.X + (float)(npc.Width / 2)), (int)(npc.Position.Y + (float)npc.Height),
                            (int)npc.type + 1, npc.whoAmI, true);
                    }
                }
                if (npc.type < NPCType.N13_EATER_OF_WORLDS_HEAD || npc.type > NPCType.N15_EATER_OF_WORLDS_TAIL)
                {
                    Main.npcs[(int)npc.ai[0]].ai[3] = npc.ai[3];
                    Main.npcs[(int)npc.ai[0]].realLife = npc.realLife;
                }
                Main.npcs[(int)npc.ai[0]].ai[1] = (float)npc.whoAmI;
                Main.npcs[(int)npc.ai[0]].ai[2] = npc.ai[2] - 1f;
                npc.netUpdate = true;
            }
            if ((npc.type == NPCType.N08_DEVOURER_BODY || npc.type == NPCType.N09_DEVOURER_TAIL || npc.type == NPCType.N11_GIANT_WORM_BODY ||
                npc.type == NPCType.N12_GIANT_WORM_TAIL || npc.type == NPCType.N40_BONE_SERPENT_BODY || npc.type == NPCType.N41_BONE_SERPENT_TAIL ||
                npc.type == NPCType.N96_DIGGER_BODY || npc.type == NPCType.N97_DIGGER_TAIL || npc.type == NPCType.N99_SEEKER_BODY || npc.type == NPCType.N100_SEEKER_TAIL ||
                (npc.type > NPCType.N87_WYVERN_HEAD && npc.type <= NPCType.N90_WYVERN_BODY_2) ||
                npc.type == NPCType.N118_LEECH_BODY || npc.type == NPCType.N119_LEECH_TAIL) &&
                (!Main.npcs[(int)npc.ai[1]].Active || Main.npcs[(int)npc.ai[1]].aiStyle != npc.aiStyle))
            {
                npc.life = 0;
                npc.HitEffect(0, 10.0);
                npc.Active = false;
            }
            if ((npc.type == NPCType.N07_DEVOURER_HEAD || npc.type == NPCType.N08_DEVOURER_BODY || npc.type == NPCType.N10_GIANT_WORM_HEAD ||
                npc.type == NPCType.N11_GIANT_WORM_BODY || npc.type == NPCType.N39_BONE_SERPENT_HEAD || npc.type == NPCType.N40_BONE_SERPENT_BODY ||
                npc.type == NPCType.N95_DIGGER_HEAD || npc.type == NPCType.N96_DIGGER_BODY || npc.type == NPCType.N98_SEEKER_HEAD || npc.type == NPCType.N99_SEEKER_BODY ||
                (npc.type >= NPCType.N87_WYVERN_HEAD && npc.type < NPCType.N92_WYVERN_TAIL) || npc.type == NPCType.N117_LEECH_HEAD || npc.type == NPCType.N118_LEECH_BODY) &&
                (!Main.npcs[(int)npc.ai[0]].Active || Main.npcs[(int)npc.ai[0]].aiStyle != npc.aiStyle))
            {
                npc.life = 0;
                npc.HitEffect(0, 10.0);
                npc.Active = false;
            }
            if (npc.type == NPCType.N13_EATER_OF_WORLDS_HEAD || npc.type == NPCType.N14_EATER_OF_WORLDS_BODY || npc.type == NPCType.N15_EATER_OF_WORLDS_TAIL)
            {
                if (!Main.npcs[(int)npc.ai[1]].Active && !Main.npcs[(int)npc.ai[0]].Active)
                {
                    npc.life = 0;
                    npc.HitEffect(0, 10.0);
                    npc.Active = false;
                }
                if (npc.type == NPCType.N13_EATER_OF_WORLDS_HEAD && !Main.npcs[(int)npc.ai[0]].Active)
                {
                    npc.life = 0;
                    npc.HitEffect(0, 10.0);
                    npc.Active = false;
                }
                if (npc.type == NPCType.N15_EATER_OF_WORLDS_TAIL && !Main.npcs[(int)npc.ai[1]].Active)
                {
                    npc.life = 0;
                    npc.HitEffect(0, 10.0);
                    npc.Active = false;
                }
                if (npc.type == NPCType.N14_EATER_OF_WORLDS_BODY && (!Main.npcs[(int)npc.ai[1]].Active || Main.npcs[(int)npc.ai[1]].aiStyle != npc.aiStyle))
                {
                    npc.type = NPCType.N13_EATER_OF_WORLDS_HEAD;
                    int num100 = npc.whoAmI;
                    float num101 = (float)npc.life / (float)npc.lifeMax;
                    float num102 = npc.ai[0];
                    npc.SetDefaults((int)npc.type);
                    npc.life = (int)((float)npc.lifeMax * num101);
                    npc.ai[0] = num102;
                    npc.TargetClosest(true);
                    npc.netUpdate = true;
                    npc.whoAmI = num100;
                }
                if (npc.type == NPCType.N14_EATER_OF_WORLDS_BODY && (!Main.npcs[(int)npc.ai[0]].Active || Main.npcs[(int)npc.ai[0]].aiStyle != npc.aiStyle))
                {
                    int num103 = npc.whoAmI;
                    float num104 = (float)npc.life / (float)npc.lifeMax;
                    float num105 = npc.ai[1];
                    npc.SetDefaults((int)npc.type);
                    npc.life = (int)((float)npc.lifeMax * num104);
                    npc.ai[1] = num105;
                    npc.TargetClosest(true);
                    npc.netUpdate = true;
                    npc.whoAmI = num103;
                }
                if (npc.life == 0)
                {
                    bool EoWAlive = false;
                    for (int npcId = 0; npcId < MAX_NPCS; npcId++)
                    {
                        var fNpc = Main.npcs[npcId];

                        if (fNpc.Active)
                        {
                            EoWAlive = (
                                fNpc.type == NPCType.N13_EATER_OF_WORLDS_HEAD ||
                                fNpc.type == NPCType.N14_EATER_OF_WORLDS_BODY ||
                                fNpc.type == NPCType.N15_EATER_OF_WORLDS_TAIL);

                            if (EoWAlive)
                                break;
                        }
                    }

                    if (!EoWAlive)
                    {
                        npc.boss = true;
                        npc.NPCLoot();
                    }
                }
            }
            if (!npc.Active)
            {
                NetMessage.SendData(28, -1, -1, "", npc.whoAmI, -1f, 0f, 0f, 0);
            }

            int num107 = (int)(npc.Position.X / 16f) - 1;
            int num108 = (int)((npc.Position.X + (float)npc.Width) / 16f) + 2;
            int num109 = (int)(npc.Position.Y / 16f) - 1;
            int num110 = (int)((npc.Position.Y + (float)npc.Height) / 16f) + 2;
            if (num107 < 0)
            {
                num107 = 0;
            }
            if (num108 > Main.maxTilesX)
            {
                num108 = Main.maxTilesX;
            }
            if (num109 < 0)
            {
                num109 = 0;
            }
            if (num110 > Main.maxTilesY)
            {
                num110 = Main.maxTilesY;
            }
            bool flag11 = false;
            if (npc.type >= NPCType.N87_WYVERN_HEAD && npc.type <= NPCType.N92_WYVERN_TAIL)
            {
                flag11 = true;
            }
            if (!flag11)
            {
                for (int num111 = num107; num111 < num108; num111++)
                {
                    for (int num112 = num109; num112 < num110; num112++)
                    {
                        if (((Main.tile.At(num111, num112).Active && (Main.tileSolid[(int)Main.tile.At(num111, num112).Type] ||
                            (Main.tileSolidTop[(int)Main.tile.At(num111, num112).Type] && Main.tile.At(num111, num112).FrameY == 0))) ||
                                Main.tile.At(num111, num112).Liquid > 64))
                        {
                            Vector2 vector13;
                            vector13.X = (float)(num111 * 16);
                            vector13.Y = (float)(num112 * 16);
                            if (npc.Position.X + (float)npc.Width > vector13.X && npc.Position.X < vector13.X + 16f && npc.Position.Y + (float)npc.Height > vector13.Y && npc.Position.Y < vector13.Y + 16f)
                            {
                                flag11 = true;
                                if (Main.rand.Next(100) == 0 && npc.type != NPCType.N117_LEECH_HEAD && Main.tile.At(num111, num112).Active)
                                {
                                    WorldModify.KillTile(TileRefs, null, num111, num112, true, true);
                                }
                            }
                        }
                    }
                }
            }
            if (!flag11 && (npc.type == NPCType.N07_DEVOURER_HEAD || npc.type == NPCType.N10_GIANT_WORM_HEAD || npc.type == NPCType.N13_EATER_OF_WORLDS_HEAD ||
                npc.type == NPCType.N39_BONE_SERPENT_HEAD || npc.type == NPCType.N95_DIGGER_HEAD || npc.type == NPCType.N98_SEEKER_HEAD || npc.type == NPCType.N117_LEECH_HEAD))
            {
                Rectangle rectangle = new Rectangle((int)npc.Position.X, (int)npc.Position.Y, npc.Width, npc.Height);
                int num113 = 1000;
                bool flag12 = true;
                for (int num114 = 0; num114 < 255; num114++)
                {
                    if (Main.players[num114].Active)
                    {
                        Rectangle rectangle2 = new Rectangle((int)Main.players[num114].Position.X - num113, (int)Main.players[num114].Position.Y - num113, num113 * 2, num113 * 2);
                        if (rectangle.Intersects(rectangle2))
                        {
                            flag12 = false;
                            break;
                        }
                    }
                }
                if (flag12)
                {
                    flag11 = true;
                }
            }
            if (npc.type >= NPCType.N87_WYVERN_HEAD && npc.type <= NPCType.N92_WYVERN_TAIL)
            {
                if (npc.Velocity.X < 0f)
                {
                    npc.spriteDirection = 1;
                }
                else if (npc.Velocity.X > 0f)
                {
                    npc.spriteDirection = -1;
                }
            }
            float num115 = 8f;
            float num116 = 0.07f;
            if (npc.type == NPCType.N95_DIGGER_HEAD)
            {
                num115 = 5.5f;
                num116 = 0.045f;
            }
            if (npc.type == NPCType.N10_GIANT_WORM_HEAD)
            {
                num115 = 6f;
                num116 = 0.05f;
            }
            if (npc.type == NPCType.N13_EATER_OF_WORLDS_HEAD)
            {
                num115 = 10f;
                num116 = 0.07f;
            }
            if (npc.type == NPCType.N87_WYVERN_HEAD)
            {
                num115 = 11f;
                num116 = 0.25f;
            }
            if (npc.type == NPCType.N117_LEECH_HEAD && Main.WallOfFlesh >= 0)
            {
                float num117 = (float)Main.npcs[Main.WallOfFlesh].life / (float)Main.npcs[Main.WallOfFlesh].lifeMax;
                if ((double)num117 < 0.5)
                {
                    num115 += 1f;
                    num116 += 0.1f;
                }
                if ((double)num117 < 0.25)
                {
                    num115 += 1f;
                    num116 += 0.1f;
                }
                if ((double)num117 < 0.1)
                {
                    num115 += 2f;
                    num116 += 0.1f;
                }
            }
            Vector2 vector14 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
            float num118 = Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2);
            float num119 = Main.players[npc.target].Position.Y + (float)(Main.players[npc.target].Height / 2);
            num118 = (float)((int)(num118 / 16f) * 16);
            num119 = (float)((int)(num119 / 16f) * 16);
            vector14.X = (float)((int)(vector14.X / 16f) * 16);
            vector14.Y = (float)((int)(vector14.Y / 16f) * 16);
            num118 -= vector14.X;
            num119 -= vector14.Y;
            float num120 = (float)Math.Sqrt((double)(num118 * num118 + num119 * num119));
            if (npc.ai[1] > 0f && npc.ai[1] < (float)Main.npcs.Length)
            {
                try
                {
                    vector14 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                    num118 = Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - vector14.X;
                    num119 = Main.npcs[(int)npc.ai[1]].Position.Y + (float)(Main.npcs[(int)npc.ai[1]].Height / 2) - vector14.Y;
                }
                catch
                { }

                npc.rotation = (float)Math.Atan2((double)num119, (double)num118) + 1.57f;
                num120 = (float)Math.Sqrt((double)(num118 * num118 + num119 * num119));
                int num121 = npc.Width;
                if (npc.type >= NPCType.N87_WYVERN_HEAD && npc.type <= NPCType.N92_WYVERN_TAIL)
                {
                    num121 = 42;
                }
                num120 = (num120 - (float)num121) / num120;
                num118 *= num120;
                num119 *= num120;
                npc.Velocity = default(Vector2);
                npc.Position.X = npc.Position.X + num118;
                npc.Position.Y = npc.Position.Y + num119;
                if (npc.type >= NPCType.N87_WYVERN_HEAD && npc.type <= NPCType.N92_WYVERN_TAIL)
                {
                    if (num118 < 0f)
                    {
                        npc.spriteDirection = 1;
                        return;
                    }
                    if (num118 > 0f)
                    {
                        npc.spriteDirection = -1;
                        return;
                    }
                }
            }
            else if (!flag11)
            {
                npc.TargetClosest(true);
                npc.Velocity.Y = npc.Velocity.Y + 0.11f;
                if (npc.Velocity.Y > num115)
                {
                    npc.Velocity.Y = num115;
                }
                if ((double)(Math.Abs(npc.Velocity.X) + Math.Abs(npc.Velocity.Y)) < (double)num115 * 0.4)
                {
                    if (npc.Velocity.X < 0f)
                    {
                        npc.Velocity.X = npc.Velocity.X - num116 * 1.1f;
                    }
                    else
                    {
                        npc.Velocity.X = npc.Velocity.X + num116 * 1.1f;
                    }
                }
                else if (npc.Velocity.Y == num115)
                {
                    if (npc.Velocity.X < num118)
                    {
                        npc.Velocity.X = npc.Velocity.X + num116;
                    }
                    else if (npc.Velocity.X > num118)
                    {
                        npc.Velocity.X = npc.Velocity.X - num116;
                    }
                }
                else if (npc.Velocity.Y > 4f)
                {
                    if (npc.Velocity.X < 0f)
                    {
                        npc.Velocity.X = npc.Velocity.X + num116 * 0.9f;
                    }
                    else
                    {
                        npc.Velocity.X = npc.Velocity.X - num116 * 0.9f;
                    }
                }
            }
            else
            {
                if (npc.type != NPCType.N87_WYVERN_HEAD && npc.type != NPCType.N117_LEECH_HEAD && npc.soundDelay == 0)
                {
                    float num122 = num120 / 40f;
                    if (num122 < 10f)
                    {
                        num122 = 10f;
                    }
                    if (num122 > 20f)
                    {
                        num122 = 20f;
                    }
                    npc.soundDelay = (int)num122;
                }
                num120 = (float)Math.Sqrt((double)(num118 * num118 + num119 * num119));
                float num123 = Math.Abs(num118);
                float num124 = Math.Abs(num119);
                float num125 = num115 / num120;
                num118 *= num125;
                num119 *= num125;
                if ((npc.type == NPCType.N13_EATER_OF_WORLDS_HEAD || npc.type == NPCType.N07_DEVOURER_HEAD) && !Main.players[npc.target].zoneEvil)
                {
                    bool flag13 = true;
                    for (int num126 = 0; num126 < 255; num126++)
                    {
                        if (Main.players[num126].Active && !Main.players[num126].dead && Main.players[num126].zoneEvil)
                        {
                            flag13 = false;
                        }
                    }
                    if (flag13 & !npc.MadeSpawn)
                    {
                        if ((double)(npc.Position.Y / 16f) > (Main.rockLayer + (double)Main.maxTilesY) / 2.0)
                        {
                            npc.Active = false;
                            int num127 = (int)npc.ai[0];
                            while (num127 > 0 && num127 < 200 && Main.npcs[num127].Active && Main.npcs[num127].aiStyle == npc.aiStyle)
                            {
                                int num128 = (int)Main.npcs[num127].ai[0];
                                Main.npcs[num127].Active = false;
                                npc.life = 0;

                                NetMessage.SendData(23, -1, -1, "", num127);

                                num127 = num128;
                            }

                            NetMessage.SendData(23, -1, -1, "", npc.whoAmI);
                        }
                        num118 = 0f;
                        num119 = num115;
                    }
                }
                bool flag14 = false;
                if (npc.type == NPCType.N87_WYVERN_HEAD)
                {
                    if (((npc.Velocity.X > 0f && num118 < 0f) || (npc.Velocity.X < 0f && num118 > 0f) || (npc.Velocity.Y > 0f && num119 < 0f) || (npc.Velocity.Y < 0f && num119 > 0f)) && Math.Abs(npc.Velocity.X) + Math.Abs(npc.Velocity.Y) > num116 / 2f && num120 < 300f)
                    {
                        flag14 = true;
                        if (Math.Abs(npc.Velocity.X) + Math.Abs(npc.Velocity.Y) < num115)
                        {
                            npc.Velocity *= 1.1f;
                        }
                    }
                    if (npc.Position.Y > Main.players[npc.target].Position.Y || (double)(Main.players[npc.target].Position.Y / 16f) > Main.worldSurface || Main.players[npc.target].dead)
                    {
                        flag14 = true;
                        if (Math.Abs(npc.Velocity.X) < num115 / 2f)
                        {
                            if (npc.Velocity.X == 0f)
                            {
                                npc.Velocity.X = npc.Velocity.X - (float)npc.direction;
                            }
                            npc.Velocity.X = npc.Velocity.X * 1.1f;
                        }
                        else if (npc.Velocity.Y > -num115)
                        {
                            npc.Velocity.Y = npc.Velocity.Y - num116;
                        }
                    }
                }
                if (!flag14)
                {
                    if ((npc.Velocity.X > 0f && num118 > 0f) || (npc.Velocity.X < 0f && num118 < 0f) || (npc.Velocity.Y > 0f && num119 > 0f) || (npc.Velocity.Y < 0f && num119 < 0f))
                    {
                        if (npc.Velocity.X < num118)
                        {
                            npc.Velocity.X = npc.Velocity.X + num116;
                        }
                        else if (npc.Velocity.X > num118)
                        {
                            npc.Velocity.X = npc.Velocity.X - num116;
                        }

                        if (npc.Velocity.Y < num119)
                        {
                            npc.Velocity.Y = npc.Velocity.Y + num116;
                        }
                        else if (npc.Velocity.Y > num119)
                        {
                            npc.Velocity.Y = npc.Velocity.Y - num116;
                        }

                        if ((double)Math.Abs(num119) < (double)num115 * 0.2 && ((npc.Velocity.X > 0f && num118 < 0f) || (npc.Velocity.X < 0f && num118 > 0f)))
                        {
                            if (npc.Velocity.Y > 0f)
                            {
                                npc.Velocity.Y = npc.Velocity.Y + num116 * 2f;
                            }
                            else
                            {
                                npc.Velocity.Y = npc.Velocity.Y - num116 * 2f;
                            }
                        }
                        if ((double)Math.Abs(num118) < (double)num115 * 0.2 && ((npc.Velocity.Y > 0f && num119 < 0f) || (npc.Velocity.Y < 0f && num119 > 0f)))
                        {
                            if (npc.Velocity.X > 0f)
                            {
                                npc.Velocity.X = npc.Velocity.X + num116 * 2f;
                            }
                            else
                            {
                                npc.Velocity.X = npc.Velocity.X - num116 * 2f;
                            }
                        }
                    }
                    else if (num123 > num124)
                    {
                        if (npc.Velocity.X < num118)
                        {
                            npc.Velocity.X = npc.Velocity.X + num116 * 1.1f;
                        }
                        else if (npc.Velocity.X > num118)
                        {
                            npc.Velocity.X = npc.Velocity.X - num116 * 1.1f;
                        }
                        if ((double)(Math.Abs(npc.Velocity.X) + Math.Abs(npc.Velocity.Y)) < (double)num115 * 0.5)
                        {
                            if (npc.Velocity.Y > 0f)
                            {
                                npc.Velocity.Y = npc.Velocity.Y + num116;
                            }
                            else
                            {
                                npc.Velocity.Y = npc.Velocity.Y - num116;
                            }
                        }
                    }
                    else
                    {
                        if (npc.Velocity.Y < num119)
                        {
                            npc.Velocity.Y = npc.Velocity.Y + num116 * 1.1f;
                        }
                        else if (npc.Velocity.Y > num119)
                        {
                            npc.Velocity.Y = npc.Velocity.Y - num116 * 1.1f;
                        }

                        if ((double)(Math.Abs(npc.Velocity.X) + Math.Abs(npc.Velocity.Y)) < (double)num115 * 0.5)
                        {
                            if (npc.Velocity.X > 0f)
                            {
                                npc.Velocity.X = npc.Velocity.X + num116;
                            }
                            else
                            {
                                npc.Velocity.X = npc.Velocity.X - num116;
                            }
                        }
                    }
                }
            }

            npc.rotation = (float)Math.Atan2((double)npc.Velocity.Y, (double)npc.Velocity.X) + 1.57f;
            if (npc.type == NPCType.N07_DEVOURER_HEAD || npc.type == NPCType.N10_GIANT_WORM_HEAD ||
                npc.type == NPCType.N13_EATER_OF_WORLDS_HEAD || npc.type == NPCType.N39_BONE_SERPENT_HEAD || npc.type == NPCType.N95_DIGGER_HEAD ||
                npc.type == NPCType.N98_SEEKER_HEAD || npc.type == NPCType.N117_LEECH_HEAD)
            {
                if (flag11)
                {
                    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;
                }
            }
        }
        // 12 - 1.1.2
        private void AISkeletronHand(NPC npc, bool flag, Func<Int32, Int32, ITile> TileRefs)
        {
            npc.spriteDirection = -(int)npc.ai[0];
            if (!Main.npcs[(int)npc.ai[1]].Active || Main.npcs[(int)npc.ai[1]].aiStyle != 11)
            {
                npc.ai[2] += 10f;
                if (npc.ai[2] > 50f)
                {
                    npc.life = -1;
                    npc.HitEffect(0, 10.0);
                    npc.Active = false;
                }
            }
            if (npc.ai[2] == 0f || npc.ai[2] == 3f)
            {
                if (Main.npcs[(int)npc.ai[1]].ai[1] == 3f && npc.timeLeft > 10)
                {
                    npc.timeLeft = 10;
                }
                if (Main.npcs[(int)npc.ai[1]].ai[1] != 0f)
                {
                    if (npc.Position.Y > Main.npcs[(int)npc.ai[1]].Position.Y - 100f)
                    {
                        if (npc.Velocity.Y > 0f)
                        {
                            npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                        }
                        npc.Velocity.Y = npc.Velocity.Y - 0.07f;
                        if (npc.Velocity.Y > 6f)
                        {
                            npc.Velocity.Y = 6f;
                        }
                    }
                    else if (npc.Position.Y < Main.npcs[(int)npc.ai[1]].Position.Y - 100f)
                    {
                        if (npc.Velocity.Y < 0f)
                        {
                            npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                        }
                        npc.Velocity.Y = npc.Velocity.Y + 0.07f;
                        if (npc.Velocity.Y < -6f)
                        {
                            npc.Velocity.Y = -6f;
                        }
                    }

                    if (npc.Position.X + (float)(npc.Width / 2) > Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 120f * npc.ai[0])
                    {
                        if (npc.Velocity.X > 0f)
                        {
                            npc.Velocity.X = npc.Velocity.X * 0.96f;
                        }
                        npc.Velocity.X = npc.Velocity.X - 0.1f;
                        if (npc.Velocity.X > 8f)
                        {
                            npc.Velocity.X = 8f;
                        }
                    }
                    if (npc.Position.X + (float)(npc.Width / 2) < Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 120f * npc.ai[0])
                    {
                        if (npc.Velocity.X < 0f)
                        {
                            npc.Velocity.X = npc.Velocity.X * 0.96f;
                        }
                        npc.Velocity.X = npc.Velocity.X + 0.1f;
                        if (npc.Velocity.X < -8f)
                        {
                            npc.Velocity.X = -8f;
                        }
                    }
                }
                else
                {
                    npc.ai[3] += 1f;
                    if (npc.ai[3] >= 300f)
                    {
                        npc.ai[2] += 1f;
                        npc.ai[3] = 0f;
                        npc.netUpdate = true;
                    }
                    if (npc.Position.Y > Main.npcs[(int)npc.ai[1]].Position.Y + 230f)
                    {
                        if (npc.Velocity.Y > 0f)
                        {
                            npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                        }
                        npc.Velocity.Y = npc.Velocity.Y - 0.04f;
                        if (npc.Velocity.Y > 3f)
                        {
                            npc.Velocity.Y = 3f;
                        }
                    }
                    else if (npc.Position.Y < Main.npcs[(int)npc.ai[1]].Position.Y + 230f)
                    {
                        if (npc.Velocity.Y < 0f)
                        {
                            npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                        }
                        npc.Velocity.Y = npc.Velocity.Y + 0.04f;
                        if (npc.Velocity.Y < -3f)
                        {
                            npc.Velocity.Y = -3f;
                        }
                    }

                    if (npc.Position.X + (float)(npc.Width / 2) > Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 200f * npc.ai[0])
                    {
                        if (npc.Velocity.X > 0f)
                        {
                            npc.Velocity.X = npc.Velocity.X * 0.96f;
                        }
                        npc.Velocity.X = npc.Velocity.X - 0.07f;
                        if (npc.Velocity.X > 8f)
                        {
                            npc.Velocity.X = 8f;
                        }
                    }
                    if (npc.Position.X + (float)(npc.Width / 2) < Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 200f * npc.ai[0])
                    {
                        if (npc.Velocity.X < 0f)
                        {
                            npc.Velocity.X = npc.Velocity.X * 0.96f;
                        }
                        npc.Velocity.X = npc.Velocity.X + 0.07f;
                        if (npc.Velocity.X < -8f)
                        {
                            npc.Velocity.X = -8f;
                        }
                    }
                }
                Vector2 vector19 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                float num188 = Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 200f * npc.ai[0] - vector19.X;
                float num189 = Main.npcs[(int)npc.ai[1]].Position.Y + 230f - vector19.Y;
                Math.Sqrt((double)(num188 * num188 + num189 * num189));
                npc.rotation = (float)Math.Atan2((double)num189, (double)num188) + 1.57f;
                return;
            }
            if (npc.ai[2] == 1f)
            {
                Vector2 vector20 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                float num190 = Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 200f * npc.ai[0] - vector20.X;
                float num191 = Main.npcs[(int)npc.ai[1]].Position.Y + 230f - vector20.Y;
                float num192 = (float)Math.Sqrt((double)(num190 * num190 + num191 * num191));
                npc.rotation = (float)Math.Atan2((double)num191, (double)num190) + 1.57f;
                npc.Velocity.X = npc.Velocity.X * 0.95f;
                npc.Velocity.Y = npc.Velocity.Y - 0.1f;
                if (npc.Velocity.Y < -8f)
                {
                    npc.Velocity.Y = -8f;
                }
                if (npc.Position.Y < Main.npcs[(int)npc.ai[1]].Position.Y - 200f)
                {
                    npc.TargetClosest(true);
                    npc.ai[2] = 2f;
                    vector20 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                    num190 = Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2) - vector20.X;
                    num191 = Main.players[npc.target].Position.Y + (float)(Main.players[npc.target].Height / 2) - vector20.Y;
                    num192 = (float)Math.Sqrt((double)(num190 * num190 + num191 * num191));
                    num192 = 18f / num192;
                    npc.Velocity.X = num190 * num192;
                    npc.Velocity.Y = num191 * num192;
                    npc.netUpdate = true;
                    return;
                }
            }
            else if (npc.ai[2] == 2f && npc.Position.Y > Main.players[npc.target].Position.Y || npc.Velocity.Y < 0f)
            {
                npc.ai[2] = 3f;
                return;
            }
            else if (npc.ai[2] == 4f)
            {
                Vector2 vector21 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                float num193 = Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 200f * npc.ai[0] - vector21.X;
                float num194 = Main.npcs[(int)npc.ai[1]].Position.Y + 230f - vector21.Y;
                float num195 = (float)Math.Sqrt((double)(num193 * num193 + num194 * num194));
                npc.rotation = (float)Math.Atan2((double)num194, (double)num193) + 1.57f;
                npc.Velocity.Y = npc.Velocity.Y * 0.95f;
                npc.Velocity.X = npc.Velocity.X + 0.1f * -npc.ai[0];
                if (npc.Velocity.X < -8f)
                {
                    npc.Velocity.X = -8f;
                }
                if (npc.Velocity.X > 8f)
                {
                    npc.Velocity.X = 8f;
                }
                if (npc.Position.X + (float)(npc.Width / 2) < Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 500f || npc.Position.X + (float)(npc.Width / 2) > Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) + 500f)
                {
                    npc.TargetClosest(true);
                    npc.ai[2] = 5f;
                    vector21 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                    num193 = Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2) - vector21.X;
                    num194 = Main.players[npc.target].Position.Y + (float)(Main.players[npc.target].Height / 2) - vector21.Y;
                    num195 = (float)Math.Sqrt((double)(num193 * num193 + num194 * num194));
                    num195 = 17f / num195;
                    npc.Velocity.X = num193 * num195;
                    npc.Velocity.Y = num194 * num195;
                    npc.netUpdate = true;
                    return;
                }
            }
            else if (npc.ai[2] == 5f && ((npc.Velocity.X > 0f && npc.Position.X + (float)(npc.Width / 2) > Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2)) || (npc.Velocity.X < 0f && npc.Position.X + (float)(npc.Width / 2) < Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2))))
            {
                npc.ai[2] = 0f;
                return;
            }
        }
        // 34 - 1.1.2
        private void AIPrimeVice(NPC npc, bool flag, Func<Int32, Int32, ITile> TileRefs)
        {
            npc.spriteDirection = -(int)npc.ai[0];
            Vector2 vector47 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
            float num409 = Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 200f * npc.ai[0] - vector47.X;
            float num410 = Main.npcs[(int)npc.ai[1]].Position.Y + 230f - vector47.Y;
            float num411 = (float)Math.Sqrt((double)(num409 * num409 + num410 * num410));

            if (npc.ai[2] != 99f && num411 > 800f)
            {
                npc.ai[2] = 99f;
            }
            else if (num411 < 400f)
            {
                npc.ai[2] = 0f;
            }

            if (!Main.npcs[(int)npc.ai[1]].Active || Main.npcs[(int)npc.ai[1]].aiStyle != 32)
            {
                npc.ai[2] += 10f;
                if (npc.ai[2] > 50f)
                {
                    npc.life = -1;
                    npc.HitEffect(0, 10.0);
                    npc.Active = false;
                }
            }
            if (npc.ai[2] == 99f)
            {
                if (npc.Position.Y > Main.npcs[(int)npc.ai[1]].Position.Y)
                {
                    if (npc.Velocity.Y > 0f)
                    {
                        npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                    }
                    npc.Velocity.Y = npc.Velocity.Y - 0.1f;
                    if (npc.Velocity.Y > 8f)
                    {
                        npc.Velocity.Y = 8f;
                    }
                }
                else if (npc.Position.Y < Main.npcs[(int)npc.ai[1]].Position.Y)
                {
                    if (npc.Velocity.Y < 0f)
                    {
                        npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                    }
                    npc.Velocity.Y = npc.Velocity.Y + 0.1f;
                    if (npc.Velocity.Y < -8f)
                    {
                        npc.Velocity.Y = -8f;
                    }
                }

                if (npc.Position.X + (float)(npc.Width / 2) > Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2))
                {
                    if (npc.Velocity.X > 0f)
                    {
                        npc.Velocity.X = npc.Velocity.X * 0.96f;
                    }
                    npc.Velocity.X = npc.Velocity.X - 0.5f;
                    if (npc.Velocity.X > 12f)
                    {
                        npc.Velocity.X = 12f;
                    }
                }
                if (npc.Position.X + (float)(npc.Width / 2) < Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2))
                {
                    if (npc.Velocity.X < 0f)
                    {
                        npc.Velocity.X = npc.Velocity.X * 0.96f;
                    }
                    npc.Velocity.X = npc.Velocity.X + 0.5f;
                    if (npc.Velocity.X < -12f)
                    {
                        npc.Velocity.X = -12f;
                        return;
                    }
                }
            }
            else if (npc.ai[2] == 0f || npc.ai[2] == 3f)
            {
                if (Main.npcs[(int)npc.ai[1]].ai[1] == 3f && npc.timeLeft > 10)
                {
                    npc.timeLeft = 10;
                }
                if (Main.npcs[(int)npc.ai[1]].ai[1] != 0f)
                {
                    npc.TargetClosest(true);
                    npc.TargetClosest(true);
                    if (Main.players[npc.target].dead)
                    {
                        npc.Velocity.Y = npc.Velocity.Y + 0.1f;
                        if (npc.Velocity.Y > 16f)
                        {
                            npc.Velocity.Y = 16f;
                        }
                    }
                    else
                    {
                        Vector2 vector48 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                        float num412 = Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2) - vector48.X;
                        float num413 = Main.players[npc.target].Position.Y + (float)(Main.players[npc.target].Height / 2) - vector48.Y;
                        float num414 = (float)Math.Sqrt((double)(num412 * num412 + num413 * num413));
                        num414 = 12f / num414;
                        num412 *= num414;
                        num413 *= num414;
                        npc.rotation = (float)Math.Atan2((double)num413, (double)num412) - 1.57f;
                        if (Math.Abs(npc.Velocity.X) + Math.Abs(npc.Velocity.Y) < 2f)
                        {
                            npc.rotation = (float)Math.Atan2((double)num413, (double)num412) - 1.57f;
                            npc.Velocity.X = num412;
                            npc.Velocity.Y = num413;
                            npc.netUpdate = true;
                        }
                        else
                        {
                            npc.Velocity *= 0.97f;
                        }
                        npc.ai[3] += 1f;
                        if (npc.ai[3] >= 600f)
                        {
                            npc.ai[2] = 0f;
                            npc.ai[3] = 0f;
                            npc.netUpdate = true;
                        }
                    }
                }
                else
                {
                    npc.ai[3] += 1f;
                    if (npc.ai[3] >= 600f)
                    {
                        npc.ai[2] += 1f;
                        npc.ai[3] = 0f;
                        npc.netUpdate = true;
                    }
                    if (npc.Position.Y > Main.npcs[(int)npc.ai[1]].Position.Y + 300f)
                    {
                        if (npc.Velocity.Y > 0f)
                        {
                            npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                        }
                        npc.Velocity.Y = npc.Velocity.Y - 0.1f;
                        if (npc.Velocity.Y > 3f)
                        {
                            npc.Velocity.Y = 3f;
                        }
                    }
                    else if (npc.Position.Y < Main.npcs[(int)npc.ai[1]].Position.Y + 230f)
                    {
                        if (npc.Velocity.Y < 0f)
                        {
                            npc.Velocity.Y = npc.Velocity.Y * 0.96f;
                        }
                        npc.Velocity.Y = npc.Velocity.Y + 0.1f;
                        if (npc.Velocity.Y < -3f)
                        {
                            npc.Velocity.Y = -3f;
                        }
                    }

                    if (npc.Position.X + (float)(npc.Width / 2) > Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) + 250f)
                    {
                        if (npc.Velocity.X > 0f)
                        {
                            npc.Velocity.X = npc.Velocity.X * 0.94f;
                        }
                        npc.Velocity.X = npc.Velocity.X - 0.3f;
                        if (npc.Velocity.X > 9f)
                        {
                            npc.Velocity.X = 9f;
                        }
                    }
                    if (npc.Position.X + (float)(npc.Width / 2) < Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2))
                    {
                        if (npc.Velocity.X < 0f)
                        {
                            npc.Velocity.X = npc.Velocity.X * 0.94f;
                        }
                        npc.Velocity.X = npc.Velocity.X + 0.2f;
                        if (npc.Velocity.X < -8f)
                        {
                            npc.Velocity.X = -8f;
                        }
                    }
                }
                Vector2 vector49 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                float num415 = Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 200f * npc.ai[0] - vector49.X;
                float num416 = Main.npcs[(int)npc.ai[1]].Position.Y + 230f - vector49.Y;
                Math.Sqrt((double)(num415 * num415 + num416 * num416));
                npc.rotation = (float)Math.Atan2((double)num416, (double)num415) + 1.57f;
                return;
            }
            if (npc.ai[2] == 1f)
            {
                if (npc.Velocity.Y > 0f)
                {
                    npc.Velocity.Y = npc.Velocity.Y * 0.9f;
                }
                Vector2 vector50 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                float num417 = Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 280f * npc.ai[0] - vector50.X;
                float num418 = Main.npcs[(int)npc.ai[1]].Position.Y + 230f - vector50.Y;
                float num419 = (float)Math.Sqrt((double)(num417 * num417 + num418 * num418));
                npc.rotation = (float)Math.Atan2((double)num418, (double)num417) + 1.57f;
                npc.Velocity.X = (npc.Velocity.X * 5f + Main.npcs[(int)npc.ai[1]].Velocity.X) / 6f;
                npc.Velocity.X = npc.Velocity.X + 0.5f;
                npc.Velocity.Y = npc.Velocity.Y - 0.5f;
                if (npc.Velocity.Y < -9f)
                {
                    npc.Velocity.Y = -9f;
                }
                if (npc.Position.Y < Main.npcs[(int)npc.ai[1]].Position.Y - 280f)
                {
                    npc.TargetClosest(true);
                    npc.ai[2] = 2f;
                    vector50 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                    num417 = Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2) - vector50.X;
                    num418 = Main.players[npc.target].Position.Y + (float)(Main.players[npc.target].Height / 2) - vector50.Y;
                    num419 = (float)Math.Sqrt((double)(num417 * num417 + num418 * num418));
                    num419 = 20f / num419;
                    npc.Velocity.X = num417 * num419;
                    npc.Velocity.Y = num418 * num419;
                    npc.netUpdate = true;
                    return;
                }
            }
            else if (npc.ai[2] == 2f)
            {
                if (npc.Position.Y > Main.players[npc.target].Position.Y || npc.Velocity.Y < 0f)
                {
                    if (npc.ai[3] >= 4f)
                    {
                        npc.ai[2] = 3f;
                        npc.ai[3] = 0f;
                        return;
                    }
                    npc.ai[2] = 1f;
                    npc.ai[3] += 1f;
                    return;
                }
            }
            else if (npc.ai[2] == 4f)
            {
                Vector2 vector51 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                float num420 = Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 200f * npc.ai[0] - vector51.X;
                float num421 = Main.npcs[(int)npc.ai[1]].Position.Y + 230f - vector51.Y;
                float num422 = (float)Math.Sqrt((double)(num420 * num420 + num421 * num421));
                npc.rotation = (float)Math.Atan2((double)num421, (double)num420) + 1.57f;
                npc.Velocity.Y = (npc.Velocity.Y * 5f + Main.npcs[(int)npc.ai[1]].Velocity.Y) / 6f;
                npc.Velocity.X = npc.Velocity.X + 0.5f;
                if (npc.Velocity.X > 12f)
                {
                    npc.Velocity.X = 12f;
                }
                if (npc.Position.X + (float)(npc.Width / 2) < Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) - 500f || npc.Position.X + (float)(npc.Width / 2) > Main.npcs[(int)npc.ai[1]].Position.X + (float)(Main.npcs[(int)npc.ai[1]].Width / 2) + 500f)
                {
                    npc.TargetClosest(true);
                    npc.ai[2] = 5f;
                    vector51 = new Vector2(npc.Position.X + (float)npc.Width * 0.5f, npc.Position.Y + (float)npc.Height * 0.5f);
                    num420 = Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2) - vector51.X;
                    num421 = Main.players[npc.target].Position.Y + (float)(Main.players[npc.target].Height / 2) - vector51.Y;
                    num422 = (float)Math.Sqrt((double)(num420 * num420 + num421 * num421));
                    num422 = 17f / num422;
                    npc.Velocity.X = num420 * num422;
                    npc.Velocity.Y = num421 * num422;
                    npc.netUpdate = true;
                    return;
                }
            }
            else if (npc.ai[2] == 5f && npc.Position.X + (float)(npc.Width / 2) < Main.players[npc.target].Position.X + (float)(Main.players[npc.target].Width / 2) - 100f)
            {
                if (npc.ai[3] >= 4f)
                {
                    npc.ai[2] = 0f;
                    npc.ai[3] = 0f;
                    return;
                }
                npc.ai[2] = 4f;
                npc.ai[3] += 1f;
                return;
            }
        }