426 lines
17 KiB
C#
426 lines
17 KiB
C#
using CalamityMod.Buffs.DamageOverTime;
|
|
using CalamityMod.Dusts;
|
|
using CalamityMod.Events;
|
|
using CalamityMod.World;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using System;
|
|
using System.IO;
|
|
using Terraria;
|
|
using Terraria.GameContent;
|
|
using Terraria.GameContent.Bestiary;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
|
|
namespace CalamityMod.NPCs.DevourerofGods
|
|
{
|
|
public class CosmicGuardianHead : ModNPC
|
|
{
|
|
private bool tail = false;
|
|
private const int minLength = 10;
|
|
private const int maxLength = 11;
|
|
private int invinceTime = 180;
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
NPCID.Sets.BossBestiaryPriority.Add(Type);
|
|
NPCID.Sets.NPCBestiaryDrawModifiers value = new NPCID.Sets.NPCBestiaryDrawModifiers(0)
|
|
{
|
|
Scale = 0.75f,
|
|
PortraitScale = 0.75f,
|
|
CustomTexturePath = "CalamityMod/ExtraTextures/Bestiary/CosmicGuardian_Bestiary",
|
|
PortraitPositionXOverride = 40,
|
|
PortraitPositionYOverride = 40
|
|
};
|
|
value.Position.X += 62f;
|
|
value.Position.Y += 35f;
|
|
NPCID.Sets.NPCBestiaryDrawOffset[Type] = value;
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
NPC.Calamity().canBreakPlayerDefense = true;
|
|
NPC.GetNPCDamage();
|
|
NPC.width = 64;
|
|
NPC.height = 76;
|
|
NPC.defense = 40;
|
|
NPC.lifeMax = 50000;
|
|
double HPBoost = CalamityConfig.Instance.BossHealthBoost * 0.01;
|
|
NPC.lifeMax += (int)(NPC.lifeMax * HPBoost);
|
|
NPC.aiStyle = -1;
|
|
AIType = -1;
|
|
NPC.knockBackResist = 0f;
|
|
NPC.Opacity = 0f;
|
|
NPC.behindTiles = true;
|
|
NPC.noGravity = true;
|
|
NPC.noTileCollide = true;
|
|
NPC.canGhostHeal = false;
|
|
NPC.HitSound = SoundID.NPCHit4;
|
|
NPC.DeathSound = SoundID.NPCDeath14;
|
|
NPC.netAlways = true;
|
|
}
|
|
|
|
public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry)
|
|
{
|
|
int associatedNPCType = ModContent.NPCType<DevourerofGodsHead>();
|
|
bestiaryEntry.UIInfoProvider = new CommonEnemyUICollectionInfoProvider(ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[associatedNPCType], quickUnlock: true);
|
|
|
|
bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[]
|
|
{
|
|
new FlavorTextBestiaryInfoElement("Mods.CalamityMod.Bestiary.CosmicGuardian")
|
|
});
|
|
}
|
|
|
|
public override void SendExtraAI(BinaryWriter writer)
|
|
{
|
|
writer.Write(invinceTime);
|
|
writer.Write(NPC.dontTakeDamage);
|
|
}
|
|
|
|
public override void ReceiveExtraAI(BinaryReader reader)
|
|
{
|
|
invinceTime = reader.ReadInt32();
|
|
NPC.dontTakeDamage = reader.ReadBoolean();
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
if (invinceTime > 0)
|
|
{
|
|
invinceTime--;
|
|
NPC.damage = 0;
|
|
NPC.dontTakeDamage = true;
|
|
}
|
|
else
|
|
{
|
|
NPC.damage = NPC.defDamage;
|
|
NPC.dontTakeDamage = false;
|
|
}
|
|
|
|
Vector2 vector = NPC.Center;
|
|
|
|
if (NPC.ai[2] > 0f)
|
|
NPC.realLife = (int)NPC.ai[2];
|
|
|
|
if (Main.netMode != NetmodeID.MultiplayerClient)
|
|
{
|
|
if (!tail && NPC.ai[0] == 0f)
|
|
{
|
|
int Previous = NPC.whoAmI;
|
|
for (int segmentSpawn = 0; segmentSpawn < maxLength; segmentSpawn++)
|
|
{
|
|
int segment;
|
|
if (segmentSpawn >= 0 && segmentSpawn < minLength)
|
|
{
|
|
segment = NPC.NewNPC(NPC.GetSource_FromAI(), (int)NPC.position.X + (NPC.width / 2), (int)NPC.position.Y + (NPC.height / 2), ModContent.NPCType<CosmicGuardianBody>(), NPC.whoAmI);
|
|
}
|
|
else
|
|
{
|
|
segment = NPC.NewNPC(NPC.GetSource_FromAI(), (int)NPC.position.X + (NPC.width / 2), (int)NPC.position.Y + (NPC.height / 2), ModContent.NPCType<CosmicGuardianTail>(), NPC.whoAmI);
|
|
}
|
|
Main.npc[segment].realLife = NPC.whoAmI;
|
|
Main.npc[segment].ai[2] = NPC.whoAmI;
|
|
Main.npc[segment].ai[1] = Previous;
|
|
Main.npc[Previous].ai[0] = segment;
|
|
NPC.netUpdate = true;
|
|
Previous = segment;
|
|
}
|
|
tail = true;
|
|
}
|
|
if (!NPC.active && Main.netMode == NetmodeID.Server)
|
|
{
|
|
NetMessage.SendData(MessageID.DamageNPC, -1, -1, null, NPC.whoAmI, -1f, 0f, 0f, 0, 0, 0);
|
|
}
|
|
}
|
|
|
|
if (CalamityGlobalNPC.DoGHead < 0 || !Main.npc[CalamityGlobalNPC.DoGHead].active)
|
|
{
|
|
NPC.velocity.Y -= 4f;
|
|
|
|
if ((double)NPC.position.Y < Main.topWorld + 16f)
|
|
{
|
|
for (int a = 0; a < Main.maxNPCs; a++)
|
|
{
|
|
if (Main.npc[a].type == NPC.type || Main.npc[a].type == ModContent.NPCType<CosmicGuardianBody>() || Main.npc[a].type == ModContent.NPCType<CosmicGuardianTail>())
|
|
Main.npc[a].active = false;
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
Player player = Main.player[Main.npc[CalamityGlobalNPC.DoGHead].target];
|
|
|
|
bool increaseSpeed = Vector2.Distance(player.Center, vector) > CalamityGlobalNPC.CatchUpDistance200Tiles;
|
|
bool increaseSpeedMore = Vector2.Distance(player.Center, vector) > CalamityGlobalNPC.CatchUpDistance350Tiles;
|
|
|
|
NPC.Opacity = Main.npc[CalamityGlobalNPC.DoGHead].Opacity;
|
|
|
|
// Fly up and despawn if DoG enters phase 2 and isn't in the final Cosmic Guardian spawn phase.
|
|
bool flyAwayAndDespawn = (Main.npc[CalamityGlobalNPC.DoGHead].life / (float)Main.npc[CalamityGlobalNPC.DoGHead].lifeMax < 0.6f && Main.npc[CalamityGlobalNPC.DoGHead].life / (float)Main.npc[CalamityGlobalNPC.DoGHead].lifeMax > 0.2f) || Main.npc[CalamityGlobalNPC.DoGHead].life <= 1;
|
|
if (flyAwayAndDespawn)
|
|
{
|
|
// Prevents them from doing damage while despawning.
|
|
NPC.Opacity = 0.99f;
|
|
|
|
NPC.velocity.Y -= 4f;
|
|
|
|
if ((double)NPC.position.Y < Main.topWorld + 16f)
|
|
{
|
|
for (int a = 0; a < Main.maxNPCs; a++)
|
|
{
|
|
if (Main.npc[a].type == NPC.type || Main.npc[a].type == ModContent.NPCType<CosmicGuardianBody>() || Main.npc[a].type == ModContent.NPCType<CosmicGuardianTail>())
|
|
Main.npc[a].active = false;
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
Vector2 vector18 = new Vector2(NPC.position.X + NPC.width * 0.5f, NPC.position.Y + NPC.height * 0.5f);
|
|
float num191 = Main.npc[CalamityGlobalNPC.DoGHead].position.X + (Main.npc[CalamityGlobalNPC.DoGHead].width / 2);
|
|
float num192 = Main.npc[CalamityGlobalNPC.DoGHead].position.Y + (Main.npc[CalamityGlobalNPC.DoGHead].height / 2);
|
|
float num188 = BossRushEvent.BossRushActive ? 30f : CalamityWorld.revenge ? 25f : 23f;
|
|
float num189 = BossRushEvent.BossRushActive ? 0.9f : CalamityWorld.revenge ? 0.75f : 0.23f;
|
|
|
|
if (increaseSpeedMore)
|
|
num189 *= 4f;
|
|
else if (increaseSpeed)
|
|
num189 *= 2f;
|
|
|
|
for (int num52 = 0; num52 < Main.maxNPCs; num52++)
|
|
{
|
|
if (Main.npc[num52].active && (Main.npc[num52].type == NPC.type || Main.npc[num52].type == ModContent.NPCType<DevourerofGodsHead>()) && num52 != NPC.whoAmI)
|
|
{
|
|
Vector2 vector4 = Main.npc[num52].Center - NPC.Center;
|
|
if (vector4.Length() < 400f)
|
|
{
|
|
vector4.Normalize();
|
|
vector4 *= 400f;
|
|
num191 -= vector4.X;
|
|
num192 -= vector4.Y;
|
|
}
|
|
}
|
|
}
|
|
|
|
float num48 = num188 * 1.3f;
|
|
float num49 = num188 * 0.7f;
|
|
float num50 = NPC.velocity.Length();
|
|
if (num50 > 0f)
|
|
{
|
|
if (num50 > num48)
|
|
{
|
|
NPC.velocity.Normalize();
|
|
NPC.velocity *= num48;
|
|
}
|
|
else if (num50 < num49)
|
|
{
|
|
NPC.velocity.Normalize();
|
|
NPC.velocity *= num49;
|
|
}
|
|
}
|
|
|
|
num191 = (int)(num191 / 16f) * 16;
|
|
num192 = (int)(num192 / 16f) * 16;
|
|
vector18.X = (int)(vector18.X / 16f) * 16;
|
|
vector18.Y = (int)(vector18.Y / 16f) * 16;
|
|
num191 -= vector18.X;
|
|
num192 -= vector18.Y;
|
|
float num193 = (float)Math.Sqrt(num191 * num191 + num192 * num192);
|
|
float num196 = Math.Abs(num191);
|
|
float num197 = Math.Abs(num192);
|
|
float num198 = num188 / num193;
|
|
num191 *= num198;
|
|
num192 *= num198;
|
|
if ((NPC.velocity.X > 0f && num191 > 0f) || (NPC.velocity.X < 0f && num191 < 0f) || (NPC.velocity.Y > 0f && num192 > 0f) || (NPC.velocity.Y < 0f && num192 < 0f))
|
|
{
|
|
if (NPC.velocity.X < num191)
|
|
{
|
|
NPC.velocity.X = NPC.velocity.X + num189;
|
|
}
|
|
else
|
|
{
|
|
if (NPC.velocity.X > num191)
|
|
{
|
|
NPC.velocity.X = NPC.velocity.X - num189;
|
|
}
|
|
}
|
|
if (NPC.velocity.Y < num192)
|
|
{
|
|
NPC.velocity.Y = NPC.velocity.Y + num189;
|
|
}
|
|
else
|
|
{
|
|
if (NPC.velocity.Y > num192)
|
|
{
|
|
NPC.velocity.Y = NPC.velocity.Y - num189;
|
|
}
|
|
}
|
|
if (Math.Abs(num192) < num188 * 0.2 && ((NPC.velocity.X > 0f && num191 < 0f) || (NPC.velocity.X < 0f && num191 > 0f)))
|
|
{
|
|
if (NPC.velocity.Y > 0f)
|
|
{
|
|
NPC.velocity.Y = NPC.velocity.Y + num189 * 2f;
|
|
}
|
|
else
|
|
{
|
|
NPC.velocity.Y = NPC.velocity.Y - num189 * 2f;
|
|
}
|
|
}
|
|
if (Math.Abs(num191) < num188 * 0.2 && ((NPC.velocity.Y > 0f && num192 < 0f) || (NPC.velocity.Y < 0f && num192 > 0f)))
|
|
{
|
|
if (NPC.velocity.X > 0f)
|
|
{
|
|
NPC.velocity.X = NPC.velocity.X + num189 * 2f; //changed from 2
|
|
}
|
|
else
|
|
{
|
|
NPC.velocity.X = NPC.velocity.X - num189 * 2f; //changed from 2
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (num196 > num197)
|
|
{
|
|
if (NPC.velocity.X < num191)
|
|
{
|
|
NPC.velocity.X = NPC.velocity.X + num189 * 1.1f; //changed from 1.1
|
|
}
|
|
else if (NPC.velocity.X > num191)
|
|
{
|
|
NPC.velocity.X = NPC.velocity.X - num189 * 1.1f; //changed from 1.1
|
|
}
|
|
if ((Math.Abs(NPC.velocity.X) + Math.Abs(NPC.velocity.Y)) < num188 * 0.5)
|
|
{
|
|
if (NPC.velocity.Y > 0f)
|
|
{
|
|
NPC.velocity.Y = NPC.velocity.Y + num189;
|
|
}
|
|
else
|
|
{
|
|
NPC.velocity.Y = NPC.velocity.Y - num189;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (NPC.velocity.Y < num192)
|
|
{
|
|
NPC.velocity.Y = NPC.velocity.Y + num189 * 1.1f;
|
|
}
|
|
else if (NPC.velocity.Y > num192)
|
|
{
|
|
NPC.velocity.Y = NPC.velocity.Y - num189 * 1.1f;
|
|
}
|
|
if ((Math.Abs(NPC.velocity.X) + Math.Abs(NPC.velocity.Y)) < num188 * 0.5)
|
|
{
|
|
if (NPC.velocity.X > 0f)
|
|
{
|
|
NPC.velocity.X = NPC.velocity.X + num189;
|
|
}
|
|
else
|
|
{
|
|
NPC.velocity.X = NPC.velocity.X - num189;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
NPC.rotation = (float)Math.Atan2(NPC.velocity.Y, NPC.velocity.X) + 1.57f;
|
|
}
|
|
|
|
public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor)
|
|
{
|
|
if (NPC.IsABestiaryIconDummy)
|
|
NPC.Opacity = 1f;
|
|
|
|
SpriteEffects spriteEffects = SpriteEffects.None;
|
|
if (NPC.spriteDirection == 1)
|
|
spriteEffects = SpriteEffects.FlipHorizontally;
|
|
|
|
Texture2D texture2D15 = TextureAssets.Npc[NPC.type].Value;
|
|
Vector2 vector11 = new Vector2((float)(TextureAssets.Npc[NPC.type].Value.Width / 2), (float)(TextureAssets.Npc[NPC.type].Value.Height / 2));
|
|
|
|
Vector2 vector43 = NPC.Center - screenPos;
|
|
vector43 -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height)) * NPC.scale / 2f;
|
|
vector43 += vector11 * NPC.scale + new Vector2(0f, NPC.gfxOffY);
|
|
spriteBatch.Draw(texture2D15, vector43, NPC.frame, NPC.GetAlpha(drawColor), NPC.rotation, vector11, NPC.scale, spriteEffects, 0f);
|
|
|
|
texture2D15 = ModContent.Request<Texture2D>("CalamityMod/NPCs/DevourerofGods/CosmicGuardianHeadGlow").Value;
|
|
Color color37 = Color.Lerp(Color.White, Color.Fuchsia, 0.5f);
|
|
|
|
spriteBatch.Draw(texture2D15, vector43, NPC.frame, color37, NPC.rotation, vector11, NPC.scale, spriteEffects, 0f);
|
|
|
|
texture2D15 = ModContent.Request<Texture2D>("CalamityMod/NPCs/DevourerofGods/CosmicGuardianHeadGlow2").Value;
|
|
color37 = Color.Lerp(Color.White, Color.Cyan, 0.5f);
|
|
|
|
spriteBatch.Draw(texture2D15, vector43, NPC.frame, color37, NPC.rotation, vector11, NPC.scale, spriteEffects, 0f);
|
|
|
|
return false;
|
|
}
|
|
|
|
public override void OnKill()
|
|
{
|
|
int heartAmt = Main.rand.Next(3) + 3;
|
|
for (int i = 0; i < heartAmt; i++)
|
|
Item.NewItem(NPC.GetSource_Loot(), (int)NPC.position.X, (int)NPC.position.Y, NPC.width, NPC.height, ItemID.Heart);
|
|
}
|
|
|
|
public override bool CanHitPlayer(Player target, ref int cooldownSlot)
|
|
{
|
|
cooldownSlot = ImmunityCooldownID.Bosses;
|
|
return NPC.Opacity >= 1f && invinceTime <= 0;
|
|
}
|
|
|
|
public override bool? DrawHealthBar(byte hbPosition, ref float scale, ref Vector2 position)
|
|
{
|
|
scale = 1.5f;
|
|
return null;
|
|
}
|
|
|
|
public override bool CheckActive()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public override void HitEffect(NPC.HitInfo hit)
|
|
{
|
|
if (NPC.life <= 0)
|
|
{
|
|
if (Main.netMode != NetmodeID.Server)
|
|
{
|
|
Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("DoT").Type, 1f);
|
|
}
|
|
NPC.position.X = NPC.position.X + (float)(NPC.width / 2);
|
|
NPC.position.Y = NPC.position.Y + (float)(NPC.height / 2);
|
|
NPC.width = 50;
|
|
NPC.height = 50;
|
|
NPC.position.X = NPC.position.X - (float)(NPC.width / 2);
|
|
NPC.position.Y = NPC.position.Y - (float)(NPC.height / 2);
|
|
for (int num621 = 0; num621 < 15; num621++)
|
|
{
|
|
int num622 = Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, (int)CalamityDusts.PurpleCosmilite, 0f, 0f, 100, default, 2f);
|
|
Main.dust[num622].velocity *= 3f;
|
|
if (Main.rand.NextBool(2))
|
|
{
|
|
Main.dust[num622].scale = 0.5f;
|
|
Main.dust[num622].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f;
|
|
}
|
|
}
|
|
for (int num623 = 0; num623 < 30; num623++)
|
|
{
|
|
int num624 = Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, (int)CalamityDusts.PurpleCosmilite, 0f, 0f, 100, default, 3f);
|
|
Main.dust[num624].noGravity = true;
|
|
Main.dust[num624].velocity *= 5f;
|
|
num624 = Dust.NewDust(new Vector2(NPC.position.X, NPC.position.Y), NPC.width, NPC.height, (int)CalamityDusts.PurpleCosmilite, 0f, 0f, 100, default, 2f);
|
|
Main.dust[num624].velocity *= 2f;
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void OnHitPlayer(Player target, Player.HurtInfo hurtInfo)
|
|
{
|
|
if (hurtInfo.Damage > 0)
|
|
target.AddBuff(ModContent.BuffType<GodSlayerInferno>(), 180, true);
|
|
}
|
|
}
|
|
}
|