public override void AI() { Player player = Main.player[npc.target]; float lifeRatio = (float)npc.life / npc.lifeMax; int jumpHeight = Main.rand.Next(5); npc.TargetClosest(true); Vector2 range = npc.Center - player.Center; range.Normalize(); if (npc.velocity.Y == 0) { npc.velocity.X = 0f; } if (!player.active || player.dead) { npc.ai[1] = 0; npc.ai[2] = 0; npc.TargetClosest(false); npc.noTileCollide = true; npc.velocity.Y++; } if (npc.velocity.Y > 0 && npc.position.Y < player.Center.Y - (npc.height + 125) && !npc.collideX && !npc.collideY) { npc.noTileCollide = true; } else { npc.noTileCollide = false; } if (npc.ai[0] == 0) { trail = false; npc.ai[2]++; if (npc.ai[2] >= 600) { npc.ai[0] = 1; npc.ai[1] = 0; npc.ai[2] = 0; } npc.ai[1]++; if (npc.ai[1] >= 180 && npc.velocity.Y == 0) { if (npc.Center.X >= player.Center.X) { npc.velocity.X -= 5; } if (npc.Center.X <= player.Center.X) { npc.velocity.X += 5; } if (jumpHeight < 3) { npc.velocity.Y -= 12; } else { npc.velocity.Y -= 11; } npc.ai[1] = 0; } } if (npc.ai[0] == 1) { trail = false; text = false; npc.ai[2]++; if (npc.ai[2] >= 70 && lifeRatio >= 0.5 || npc.ai[2] >= 130 && lifeRatio < 0.5) { npc.ai[0] = 2; npc.ai[1] = 0; npc.ai[2] = 0; } npc.ai[1]++; if (npc.ai[1] == 60 && !text) { CombatText.NewText(new Rectangle((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height), new Color(20, 100, 100), "Releasing Missiles"); text = true; } if (npc.ai[1] >= 60 && npc.velocity.Y == 0) { for (int i = 0; i < 10; i++) { Main.PlaySound(SoundID.Item61, npc.Center); int p = Projectile.NewProjectile(npc.Center.X + Main.rand.Next(-60, 60), npc.Center.Y + Main.rand.Next(-60, 60), Main.rand.NextFloat(-5.3f, 5.3f), Main.rand.NextFloat(-5.3f, 5.3f), ModContent.ProjectileType <CyborgMissile>(), NPCUtils.RealDamage(20, 1.5f), 1, Main.myPlayer, 0, 0); if (Main.projectile[p].velocity == Vector2.Zero) { Main.projectile[p].velocity = new Vector2(2.5f, 2.5f); } if (Main.projectile[p].velocity.X <2.5f && Math.Sign(Main.projectile[p].velocity.X) == Math.Sign(1) || Main.projectile[p].velocity.X> -2.5f && Math.Sign(Main.projectile[p].velocity.X) == Math.Sign(-1)) { Main.projectile[p].velocity.X *= 2.35f; } } npc.ai[1] = 0; } } if (npc.ai[0] == 2) { trail = false; npc.ai[2]++; if (npc.ai[2] >= 480) { npc.ai[0] = 3; npc.ai[1] = 0; npc.ai[2] = 0; } npc.ai[1]++; if (npc.ai[1] >= 120 && npc.velocity.Y == 0) { if (npc.Center.X >= player.Center.X) { npc.velocity.X -= 5; } if (npc.Center.X <= player.Center.X) { npc.velocity.X += 5; } if (jumpHeight < 3) { npc.velocity.Y -= 12; } else { npc.velocity.Y -= 11; } npc.ai[1] = 0; } } if (npc.ai[0] == 3) { trail = true; if (!exploded) { npc.position.Y = player.Center.Y - 600f; npc.position.X = player.Center.X - npc.width * 0.5f; npc.velocity.X = 0; for (int z = 0; z < 30; z++) { Dust.NewDust(npc.position, npc.width, npc.height, DustID.Electric, 0f, 0f, 0, default, 2f);
public override void AI() { npc.spriteDirection = npc.direction; Player player = Main.player[npc.target]; float lifeRatio = (float)npc.life / npc.lifeMax; npc.TargetClosest(true); if (!player.active || player.dead) { npc.TargetClosest(false); npc.velocity.Y -= 2000; } if (player.ZoneDungeon) { npc.damage = 50; npc.defense = 32; } else { npc.damage = 36; npc.defense = 24; } npc.ai[0]++; if (npc.ai[0] < 120 || (npc.ai[0] > 120 && npc.ai[0] < 890) || (npc.ai[0] > 1060 && npc.ai[0] < 1100) || (npc.ai[0] > 1380 && npc.ai[0] < 1980)) { swordLaunch = false; float value12 = (float)Math.Cos(Main.GlobalTime % 2.4f / 2.4f * 6.28318548f) * 60f; if (npc.Center.X >= player.Center.X && speedX >= -37) { speedX--; } else if (npc.Center.X <= player.Center.X && speedX <= 37) { speedX++; } npc.velocity.X = speedX * 0.16f; npc.rotation = npc.velocity.X * 0.04f; if (npc.Center.Y >= player.Center.Y - 80f + value12 && speedY >= -20) { speedY--; } else if (npc.Center.Y <= player.Center.Y - 80f + value12 && speedY <= 20) { speedY++; } npc.velocity.Y = speedY * 0.12f; } if (npc.ai[0] > 900 && npc.ai[0] < 1050) { npc.velocity = Vector2.Zero; if (npc.ai[0] % 15 == 0) { if (!swordLaunch && lifeRatio >= 0.5f) { for (int i = 0; i < 2; i++) { Main.PlaySound(SoundID.Item20, npc.Center); int p = Projectile.NewProjectile(npc.Center.X + Main.rand.Next(-60, 60), npc.Center.Y + Main.rand.Next(-60, 60), Main.rand.NextFloat(-5.3f, 5.3f), Main.rand.NextFloat(-5.3f, 5.3f), ModContent.ProjectileType <RuneWarriorSword>(), NPCUtils.RealDamage(38, 1.5f), 1, Main.myPlayer, 0, 0); if (Main.projectile[p].velocity == Vector2.Zero) { Main.projectile[p].velocity = new Vector2(2.25f, 2.25f); } if ((Main.projectile[p].velocity.X < 2.25f && Math.Sign(Main.projectile[p].velocity.X) == Math.Sign(1)) || (Main.projectile[p].velocity.X > -2.25f && Math.Sign(Main.projectile[p].velocity.X) == Math.Sign(-1))) { Main.projectile[p].velocity.X *= 2.15f; } swordLaunch = true; } } if (!swordLaunch && lifeRatio <= 0.5f) { for (int i = 0; i < 4; i++) { Main.PlaySound(SoundID.Item20, npc.Center); int p = Projectile.NewProjectile(npc.Center.X + Main.rand.Next(-60, 60), npc.Center.Y + Main.rand.Next(-60, 60), Main.rand.NextFloat(-5.3f, 5.3f), Main.rand.NextFloat(-5.3f, 5.3f), ModContent.ProjectileType <RuneWarriorSword>(), NPCUtils.RealDamage(38, 1.5f), 1, Main.myPlayer, 0, 0); if (Main.projectile[p].velocity == Vector2.Zero) { Main.projectile[p].velocity = new Vector2(2.25f, 2.25f); } if ((Main.projectile[p].velocity.X < 2.25f && Math.Sign(Main.projectile[p].velocity.X) == Math.Sign(1)) || (Main.projectile[p].velocity.X > -2.25f && Math.Sign(Main.projectile[p].velocity.X) == Math.Sign(-1))) { Main.projectile[p].velocity.X *= 2.15f; } swordLaunch = true; } } } } if (npc.ai[0] >= 1120 && npc.ai[0] < 1370) { swordLaunch = false; npc.direction = Math.Sign(player.Center.X - npc.Center.X); if (npc.ai[0] < 1280) { npc.ai[1] = 0; npc.ai[2] = 0; Vector2 playerCenter = player.Center; playerCenter.X += (npc.Center.X < player.Center.X) ? -240 : 240; playerCenter.Y -= 15; float vel = MathHelper.Clamp(npc.Distance(playerCenter) / 12, 8, 30); npc.velocity = Vector2.Lerp(npc.velocity, npc.DirectionTo(playerCenter) * vel, 0.08f); } else { npc.rotation = npc.velocity.X * 0.02f; if (npc.ai[0] < 1320) { npc.velocity.X = -npc.spriteDirection; npc.velocity.Y = 0; } else if (npc.ai[0] == 1320 || npc.ai[0] == 1360) { Main.PlaySound(new LegacySoundStyle(SoundID.Roar, 0), npc.Center); npc.velocity.X = MathHelper.Clamp(Math.Abs((player.Center.X - npc.Center.X) / 10), 20, 26) * npc.spriteDirection; npc.netUpdate = true; } else if (npc.direction != npc.spriteDirection || npc.ai[1] > 0) { npc.ai[1]++; npc.velocity.X = MathHelper.Lerp(npc.velocity.X, 0, 0.06f); } } } if (npc.ai[0] > 2000) { npc.ai[0] = 0; npc.ai[1] = 0; npc.ai[2] = 0; npc.netUpdate = true; } }
public override bool PreAI() { var exposedBodies = Main.npc.Where(x => x.active && (x.type == ModContent.NPCType <FungalDiggerBody>() || x.type == ModContent.NPCType <FungalDiggerTail>()) && x.localAI[0] > 0).Count(); if (Main.netMode != NetmodeID.MultiplayerClient) { if (exposedBodies < 7 && Main.rand.NextBool(50) || (++npc.localAI[1] % 60 == 0 && Main.rand.NextBool(50))) { if (!Exposed) { npc.localAI[0] = 1; npc.netUpdate = true; } } if (exposedBodies > 10 || (npc.localAI[1] % 60 == 0 && Main.rand.NextBool(50))) { if (Exposed) { npc.localAI[0] = 0; npc.netUpdate = true; } } if (npc.localAI[2] >= 601) { npc.localAI[2] = 0f; } } if (Exposed) { npc.defense = 22; npc.dontTakeDamage = false; } Player player = Main.player[npc.target]; if (Head.ai[2] == 1) { if (Main.netMode != NetmodeID.MultiplayerClient) { if (--npc.ai[3] == 0) { Main.PlaySound(SoundID.Item, (int)npc.position.X, (int)npc.position.Y, 9); npc.TargetClosest(true); npc.netUpdate = true; if (Main.rand.NextBool(2)) { float num941 = 1f; Vector2 vector104 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height / 2); float num942 = player.position.X + player.width * 0.5f - vector104.X + Main.rand.Next(-20, 21); float num943 = player.position.Y + player.height * 0.5f - vector104.Y + Main.rand.Next(-20, 21); float num944 = (float)Math.Sqrt(num942 * num942 + num943 * num943); num944 = num941 / num944; num942 *= num944; num943 *= num944; num942 += Main.rand.Next(-10, 11) * 0.0125f; num943 += Main.rand.Next(-10, 11) * 0.0125f; int num946 = ModContent.ProjectileType <GlowingMushroom>(); vector104.X += num942 * 4f; vector104.Y += num943 * 2.5f; int num947 = Projectile.NewProjectile(vector104.X, vector104.Y, num942, num943, num946, NPCUtils.RealDamage(25, 1.25f), 0f, Main.myPlayer, 0f, 0f); Main.projectile[num947].timeLeft = 350; } } } if (Main.netMode == NetmodeID.MultiplayerClient) { if (--npc.ai[3] == 0) { Main.PlaySound(SoundID.Item, (int)npc.position.X, (int)npc.position.Y, 9); } } } else { npc.ai[3] = Main.rand.Next(175, 190); } if (!Main.npc[(int)npc.ai[1]].active) { npc.life = 0; npc.HitEffect(0, 10.0); npc.active = false; } if (npc.ai[2] > 0) { npc.realLife = (int)npc.ai[2]; } if (npc.target < 0 || npc.target == byte.MaxValue || Main.player[npc.target].dead) { npc.TargetClosest(true); } if (Main.player[npc.target].dead && npc.timeLeft > 300) { npc.timeLeft = 300; } if (npc.ai[1] < (double)Main.npc.Length) { Vector2 npcCenter = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); float dirX = Main.npc[(int)npc.ai[1]].position.X + Main.npc[(int)npc.ai[1]].width / 2 - npcCenter.X; float dirY = Main.npc[(int)npc.ai[1]].position.Y + Main.npc[(int)npc.ai[1]].height / 2 - npcCenter.Y; npc.rotation = (float)Math.Atan2(dirY, dirX) + 1.57f; float length = (float)Math.Sqrt(dirX * dirX + dirY * dirY); float dist = (length - (float)npc.width) / length; float posX = dirX * dist; float posY = dirY * dist; npc.velocity = Vector2.Zero; npc.position.X = npc.position.X + posX; npc.position.Y = npc.position.Y + posY; } return(true); }
public override void AI() { Player player = Main.player[npc.target]; int parent = NPC.FindFirstNPC(ModContent.NPCType <FungalDiggerHead>()); if (parent < 0 || parent >= Main.npc.Length) { npc.active = false; return; } if (!Main.npc[(int)npc.ai[1]].active) { npc.life = 0; npc.HitEffect(0, 10.0); npc.active = false; } if (Main.npc[parent].ai[2] != 1) { if (Main.netMode != NetmodeID.MultiplayerClient) { npc.localAI[0] += Main.expertMode ? 2f : 1f; if (npc.localAI[0] >= 200f) { npc.localAI[0] = 0f; npc.TargetClosest(true); if (Collision.CanHit(npc.position, npc.width, npc.height, player.position, player.width, player.height)) { Main.PlaySound(SoundID.Item, (int)npc.Center.X, (int)npc.Center.Y, 12); float num941 = 4f; Vector2 vector104 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height / 2)); float num942 = player.position.X + (player.width * 0.5f) - vector104.X + Main.rand.Next(-20, 21); float num943 = player.position.Y + (player.height * 0.5f) - vector104.Y + Main.rand.Next(-20, 21); float num944 = (float)Math.Sqrt((num942 * num942) + (num943 * num943)); num944 = num941 / num944; num942 *= num944; num943 *= num944; vector104.X += num942 * 5f; vector104.Y += num943 * 5f; int num947 = Projectile.NewProjectile(vector104.X, vector104.Y, num942, num943, ModContent.ProjectileType <GlowingMushroom>(), NPCUtils.RealDamage(24, 1.5f), 0f, Main.myPlayer, 0f, 0f); Main.projectile[num947].timeLeft = 300; npc.netUpdate = true; } } } if (Main.netMode == NetmodeID.MultiplayerClient) { npc.localAI[0] += Main.expertMode ? 2f : 1f; if (npc.localAI[0] >= 200f) { npc.localAI[0] = 0f; if (Collision.CanHit(npc.position, npc.width, npc.height, player.position, player.width, player.height)) { Main.PlaySound(SoundID.Item, (int)npc.Center.X, (int)npc.Center.Y, 12); } } } } else { npc.localAI[0] = 0; } if (npc.ai[2] > 0) { npc.realLife = (int)npc.ai[2]; } if (npc.target < 0 || npc.target == byte.MaxValue || Main.player[npc.target].dead) { npc.TargetClosest(true); } if (npc.ai[1] < (double)Main.npc.Length) { Vector2 npcCenter = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height * 0.5f)); float dirX = Main.npc[(int)npc.ai[1]].position.X + (Main.npc[(int)npc.ai[1]].width / 2) - npcCenter.X; float dirY = Main.npc[(int)npc.ai[1]].position.Y + (Main.npc[(int)npc.ai[1]].height / 2) - npcCenter.Y; npc.rotation = (float)Math.Atan2(dirY, dirX) + 1.57f; float length = (float)Math.Sqrt((dirX * dirX) + (dirY * dirY)); float dist = (length - npc.width) / length; float posX = dirX * dist; float posY = dirY * dist; npc.velocity = Vector2.Zero; npc.position.X += posX; npc.position.Y += posY; } }