public int movementVariance = 60; //how far from the center point to move. public override void AI() { npc.defDamage = isAwakened ? 200 : 180; if (Body == null) { NPC npcBody = Main.npc[(int)npc.ai[0]]; if (npcBody.type == mod.NPCType("Yamata") || npcBody.type == mod.NPCType("YamataA")) { Body = (Yamata)npcBody.modNPC; } } if (Body == null) { return; } npc.alpha = Body.npc.alpha; if (npc.alpha > 0) { npc.damage = 0; } else { npc.damage = npc.defDamage; } npc.TargetClosest(); Player targetPlayer = Main.player[npc.target]; if (targetPlayer == null || !targetPlayer.active || targetPlayer.dead) { targetPlayer = null; //deliberately set to null } float playerDistance = targetPlayer == null ? 99999f : Vector2.Distance(targetPlayer.Center, npc.Center); if (!Body.npc.active) { if (Main.netMode != NetmodeID.MultiplayerClient) //force a kill to prevent 'ghost hands' { npc.life = 0; npc.checkDead(); npc.netUpdate = true; killedbyplayer = false; } return; } Vector2 nextTarget = Body.npc.Center + new Vector2(leftHead ? -distFromBodyX : distFromBodyX, -distFromBodyY) + new Vector2(npc.ai[2], npc.ai[3]); float dist = Vector2.Distance(nextTarget, npc.Center); if (YamataHead.EATTHELITTLEMAGGOT && playerDistance < 300f) { BaseAI.AIFlier(npc, ref customAI, true, .5f, .8f, 5, 5, false, 300); } else if (dist < 40f) { npc.velocity *= 0.9f; if (Math.Abs(npc.velocity.X) < 0.05f) { npc.velocity.X = 0f; } if (Math.Abs(npc.velocity.Y) < 0.05f) { npc.velocity.Y = 0f; } } else { npc.velocity = Vector2.Normalize(nextTarget - npc.Center); npc.velocity *= 20f; } npc.position += Body.npc.position - Body.npc.oldPosition; npc.spriteDirection = -1; if (Body.TeleportMe1) { Body.TeleportMe1 = false; npc.Center = Body.npc.Center; return; } if (Body.TeleportMe2) { Body.TeleportMe2 = false; npc.Center = Body.npc.Center; return; } if (Body.TeleportMe3) { Body.TeleportMe3 = false; npc.Center = Body.npc.Center; for (int i = 0; i < 5; ++i) { Main.PlaySound(SoundID.Item, (int)npc.Center.X, (int)npc.Center.Y, 20); Vector2 dir = Vector2.Normalize(targetPlayer.Center - npc.Center); dir *= 5f; Projectile.NewProjectile(npc.Center.X, npc.Center.Y, dir.X, dir.Y, isAwakened ? mod.ProjectileType("YamataABreath") : mod.ProjectileType("YamataBreath"), npc.damage / 4, 0f, Main.myPlayer); } return; } if (Body.TeleportMe4) { Body.TeleportMe4 = false; npc.Center = Body.npc.Center; return; } if (Body.TeleportMe5) { Body.TeleportMe5 = false; npc.Center = Body.npc.Center; return; } if (Body.TeleportMe6) { Body.TeleportMe6 = false; npc.Center = Body.npc.Center; return; } if (Main.netMode != NetmodeID.MultiplayerClient && !YamataHead.EATTHELITTLEMAGGOT) { if (npc.alpha <= 0) { npc.ai[1]++;; } int aiTimerFire = npc.whoAmI % 3 == 0 ? 50 : npc.whoAmI % 2 == 0 ? 150 : 100; if (leftHead) { aiTimerFire += 30; } if (targetPlayer != null && npc.ai[1] == aiTimerFire) { fireAttack = true; for (int i = 0; i < 5; ++i) { Main.PlaySound(SoundID.Item, (int)npc.Center.X, (int)npc.Center.Y, 20); Vector2 dir = Vector2.Normalize(targetPlayer.Center - npc.Center); dir *= 5f; Projectile.NewProjectile(npc.Center.X, npc.Center.Y, dir.X, dir.Y, isAwakened ? mod.ProjectileType("YamataABreath") : mod.ProjectileType("YamataBreath"), npc.damage / 4, 0f, Main.myPlayer); } } else if (npc.ai[1] >= 200) //pick random spot to move head to { fireAttack = false; npc.ai[1] = 0; npc.ai[2] = Main.rand.Next(-movementVariance, movementVariance); npc.ai[3] = Main.rand.Next(-movementVariance, movementVariance); npc.netUpdate = true; } } }
public override void AI() { int attackpower = 130; if (Main.expertMode) { damage = npc.damage / 4; } else { damage = npc.damage / 2; } if (Body == null) { NPC npcBody = Main.npc[(int)npc.ai[0]]; if (npcBody.type == mod.NPCType("Yamata") || npcBody.type == mod.NPCType("YamataA")) { Body = npcBody; yamata = (Yamata)npcBody.modNPC; } } if (Body == null) { return; } if (!Body.active) { if (Main.netMode != NetmodeID.MultiplayerClient) //force a kill to prevent 'ghost hands' { npc.life = 0; npc.checkDead(); npc.netUpdate = true; } return; } npc.realLife = Body.whoAmI; npc.timeLeft = 100; npc.TargetClosest(true); Player player = Main.player[npc.target]; npc.alpha = Body.alpha; if (npc.alpha > 0) { npc.damage = 0; } else { npc.damage = attackpower; } Laugh(); int roarSound = ModLoader.GetMod("AAMod").GetSoundSlot(SoundType.Item, "Sounds/Sounds/YamataRoar"); Vector2 PlayerDistance = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); float num433 = 6f; float PlayerPosX = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2) - PlayerDistance.X; float PlayerPosY = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2) - PlayerDistance.Y; float PlayerPos = (float)Math.Sqrt(PlayerPosX * PlayerPosX + PlayerPosY * PlayerPosY); PlayerPos = num433 / PlayerPos; PlayerPosX *= PlayerPos; PlayerPosY *= PlayerPos; PlayerPosY += Main.rand.Next(-40, 41) * 0.01f; PlayerPosX += Main.rand.Next(-40, 41) * 0.01f; PlayerPosY += npc.velocity.Y * 0.5f; PlayerPosX += npc.velocity.X * 0.5f; PlayerDistance.X -= PlayerPosX * 1f; PlayerDistance.Y -= PlayerPosY * 1f; if (npc.alpha <= 0) { internalAI[2]++; } if (internalAI[2] == 399) { QuoteSaid = false; Main.PlaySound(roarSound, npc.Center); internalAI[1] = Main.rand.Next(4); } if (internalAI[2] >= 400) { Attacks(internalAI[1]); } if (internalAI[2] >= 600) { EATTHELITTLEMAGGOT = false; internalAI[2] = 0; } if (npc.ai[3] == 1) { attackCounter++; if (attackCounter > 10) { attackFrame++; attackCounter = 0; } if (attackFrame >= 3) { attackFrame = 2; } } if (!player.active || player.dead || !Body.active) { npc.TargetClosest(false); player = Main.player[npc.target]; if (!player.active || player.dead || !Body.active) { if (npc.timeLeft > 10) { npc.timeLeft = 10; } return; } } fireTimer++; if (fireTimer >= 240 && npc.ai[3] == 0) { Main.PlaySound(roarSound, npc.Center); npc.ai[3] = 1; fireTimer = 0; } projDamage = npc.damage / 6; if (npc.ai[3] == 1) { attackTimer++; if (Main.rand.Next(3) == 0) { if (attackTimer == 40) { Main.PlaySound(SoundID.Item, (int)npc.Center.X, (int)npc.Center.Y, 20); int proj2 = Projectile.NewProjectile(npc.Center.X + Main.rand.Next(-20, 20), npc.Center.Y + Main.rand.Next(-20, 20), npc.velocity.X * 2f, npc.velocity.Y * 2f, mod.ProjectileType("YamataBomb"), projDamage, 0, Main.myPlayer); Main.projectile[proj2].damage = projDamage; attackTimer = 0; attackFrame = 0; attackCounter = 0; } if (attackTimer >= 80) { npc.ai[3] = 0; } } else { if (attackTimer == 8 || attackTimer == 16 || attackTimer == 24 || attackTimer == 32 || attackTimer == 40 || attackTimer == 48 || attackTimer == 56 || attackTimer == 64 || attackTimer == 72 || attackTimer == 79) { Main.PlaySound(SoundID.Item, (int)npc.Center.X, (int)npc.Center.Y, 20); for (int i = 0; i < 5; ++i) { if (Main.netMode != NetmodeID.MultiplayerClient) { Projectile.NewProjectile(PlayerDistance.X, PlayerDistance.Y, PlayerPosX * 2f, PlayerPosY * 2f, mod.ProjectileType("YamataBreath"), projDamage, 0f, Main.myPlayer); } } } if (attackTimer >= 80) { npc.ai[3] = 0; attackTimer = 0; attackFrame = 0; attackCounter = 0; } } } Vector2 moveTo = new Vector2(Body.Center.X + npc.ai[1], Body.Center.Y - (130f + npc.ai[2])) - npc.Center; npc.velocity = moveTo * moveSpeedBoost; npc.rotation = 0; npc.position += Body.position - Body.oldPosition; if (Yamata.TeleportMeBitch) { Yamata.TeleportMeBitch = false; npc.Center = yamata.npc.Center; return; } }