Files
ForgottenWawiTech/Content/NPCs/OriginalNeptune/Neptune.cs
T
2025-11-21 14:14:57 +00:00

143 lines
5.0 KiB
C#

using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
using Terraria.Chat;
using Terraria.Localization;
using Terraria.GameContent.ItemDropRules;
using ForgottenWawiTech.Content.Items.TreasureBags;
namespace ForgottenWawiTech.Content.NPCs.OriginalNeptune
{
[AutoloadBossHead]
public class Neptune : ModNPC
{
public override void SetStaticDefaults()
{
// DisplayName.SetDefault("Original Neptune");
Main.npcFrameCount[NPC.type] = 1;
}
public override void SetDefaults()
{
NPC.width = 40;
NPC.height = 40;
NPC.damage = 1786;
NPC.defense = 290;
NPC.lifeMax = 1000000;
NPC.HitSound = SoundID.NPCHit1;
NPC.DeathSound = SoundID.NPCDeath1;
NPC.knockBackResist = 0f;
NPC.boss = true;
NPC.aiStyle = -1;
NPC.value = Item.buyPrice(0, 1, 0, 0);
}
public override void AI()
{
// Phased boss AI: at 50% HP spawn Raccoon. Neptune becomes invulnerable and does not attack
// until Raccoon is defeated, then move to Phase 2.
NPC.TargetClosest(false);
Player target = Main.player[NPC.target];
if (!target.active || target.dead)
{
NPC.timeLeft = 300;
return;
}
int phase = (int)NPC.ai[0]; // 0 = phase 1 (initial), 1 = waiting for raccoon, 2 = phase 2
int flags = (int)NPC.ai[1]; // bitflags: bit0 = raccoon spawned
// Phase 0: before Raccoon summoned
if (phase == 0)
{
// If at or below 50% life and raccoon hasn't been spawned, spawn it and enter waiting state
if (NPC.life <= NPC.lifeMax / 2 && (flags & 1) == 0)
{
flags |= 1;
NPC.ai[1] = flags;
// Make Neptune invulnerable and enter waiting phase
NPC.dontTakeDamage = true;
NPC.ai[0] = 1;
NPC.netUpdate = true;
string announce = "A mischievous raccoon scurries into the battlefield!";
}
// Simple approach movement when not waiting
if (NPC.ai[0] == 0)
{
Vector2 dir = (target.Center - NPC.Center);
if (dir.Length() > 8f)
{
dir.Normalize();
NPC.velocity = Vector2.Lerp(NPC.velocity, dir * 3f, 0.02f);
}
}
}
// Phase 1: waiting for Raccoon to be defeated
else if (phase == 1)
{
bool raccoonAlive = false;
int raccoonType = ModContent.NPCType<Raccoon>();
for (int i = 0; i < Main.maxNPCs; i++)
{
NPC check = Main.npc[i];
if (check.active && check.type == raccoonType)
{
raccoonAlive = true;
break;
}
}
// Stay invulnerable and idle until raccoon is gone
if (!raccoonAlive)
{
NPC.dontTakeDamage = false;
NPC.ai[0] = 2; // enter Phase 2
NPC.netUpdate = true;
}
else
{
// idle drift while waiting
NPC.velocity *= 0.98f;
}
}
// Phase 2+: normal behaviour (placeholder movement)
else
{
Vector2 dir = (target.Center - NPC.Center);
if (dir.Length() > 8f)
{
dir.Normalize();
NPC.velocity = Vector2.Lerp(NPC.velocity, dir * 4f, 0.02f);
}
NPC.spriteDirection = NPC.direction = (target.Center.X < NPC.Center.X) ? -1 : 1;
}
}
public override void OnKill()
{
/* // Spawn NeptuneNPC when killed
if (Main.netMode != NetmodeID.MultiplayerClient)
{
NPC.NewNPC(NPC.GetSource_Death(), (int)NPC.Center.X, (int)NPC.Center.Y, ModContent.NPCType<NeptuneNPC>());
}
else
{
NetMessage.SendData(MessageID.SpawnNPC, number: ModContent.NPCType<NeptuneNPC>(), number2: NPC.whoAmI);
} */
// Set a world flag or similar to indicate Neptune has been defeated
WorldDefeatedBosses.Neptune = true;
// Immediate sync of world flags
WorldDefeatedBosses.Sync(ModContent.GetInstance<ForgottenWawiTech>());
}
public override void ModifyNPCLoot(NPCLoot npcLoot)
{
npcLoot.Add(ItemDropRule.BossBag(ModContent.ItemType<NeptuneBossBag>()));
}
}
}