237 lines
9.9 KiB
C#
237 lines
9.9 KiB
C#
using System.IO;
|
|
using CalamityMod.Buffs.DamageOverTime;
|
|
using CalamityMod.Dusts;
|
|
using CalamityMod.Events;
|
|
using CalamityMod.World;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using ReLogic.Content;
|
|
using Terraria;
|
|
using Terraria.GameContent;
|
|
using Terraria.ID;
|
|
using Terraria.Localization;
|
|
using Terraria.ModLoader;
|
|
namespace CalamityMod.NPCs.DevourerofGods
|
|
{
|
|
[LongDistanceNetSync(SyncWith = typeof(CosmicGuardianHead))]
|
|
public class CosmicGuardianTail : ModNPC
|
|
{
|
|
public int invinceTime = 180;
|
|
public override LocalizedText DisplayName => CalamityUtils.GetText("NPCs.CosmicGuardianHead.DisplayName");
|
|
|
|
public static Asset<Texture2D> GlowTexture;
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
this.HideFromBestiary();
|
|
if (!Main.dedServ)
|
|
{
|
|
GlowTexture = ModContent.Request<Texture2D>(Texture + "Glow", AssetRequestMode.AsyncLoad);
|
|
}
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
NPC.GetNPCDamage();
|
|
NPC.width = 30;
|
|
NPC.height = 50;
|
|
NPC.defense = 70;
|
|
NPC.lifeMax = 50000;
|
|
NPC.aiStyle = -1;
|
|
AIType = -1;
|
|
NPC.knockBackResist = 0f;
|
|
NPC.Opacity = 0f;
|
|
NPC.behindTiles = true;
|
|
NPC.noGravity = true;
|
|
NPC.noTileCollide = true;
|
|
NPC.HitSound = SoundID.NPCHit4;
|
|
NPC.DeathSound = SoundID.NPCDeath14;
|
|
NPC.netAlways = true;
|
|
NPC.dontCountMe = true;
|
|
|
|
// Scale stats in Expert and Master
|
|
CalamityGlobalNPC.AdjustExpertModeStatScaling(NPC);
|
|
CalamityGlobalNPC.AdjustMasterModeStatScaling(NPC);
|
|
}
|
|
|
|
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 bool? DrawHealthBar(byte hbPosition, ref float scale, ref Vector2 position)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
if (invinceTime > 0)
|
|
{
|
|
invinceTime--;
|
|
NPC.damage = 0;
|
|
NPC.dontTakeDamage = true;
|
|
}
|
|
else
|
|
{
|
|
NPC.damage = NPC.defDamage;
|
|
NPC.dontTakeDamage = false;
|
|
}
|
|
|
|
if (NPC.ai[2] > 0f)
|
|
NPC.realLife = (int)NPC.ai[2];
|
|
|
|
// Check if other segments are still alive, if not, die
|
|
bool shouldDespawn = !NPC.AnyNPCs(ModContent.NPCType<CosmicGuardianHead>());
|
|
if (!shouldDespawn)
|
|
{
|
|
if (NPC.ai[1] <= 0f)
|
|
shouldDespawn = true;
|
|
else if (Main.npc[(int)NPC.ai[1]].life <= 0)
|
|
shouldDespawn = true;
|
|
}
|
|
if (shouldDespawn)
|
|
{
|
|
NPC.life = 0;
|
|
NPC.HitEffect(0, 10.0);
|
|
NPC.checkDead();
|
|
NPC.active = false;
|
|
}
|
|
|
|
NPC.Opacity = Main.npc[(int)NPC.ai[2]].Opacity;
|
|
|
|
Vector2 segmentPosition = NPC.Center;
|
|
float targetX = Main.player[NPC.target].position.X + (Main.player[NPC.target].width / 2);
|
|
float targetY = Main.player[NPC.target].position.Y + (Main.player[NPC.target].height / 2);
|
|
targetX = (int)(targetX / 16f) * 16;
|
|
targetY = (int)(targetY / 16f) * 16;
|
|
segmentPosition.X = (int)(segmentPosition.X / 16f) * 16;
|
|
segmentPosition.Y = (int)(segmentPosition.Y / 16f) * 16;
|
|
targetX -= segmentPosition.X;
|
|
targetY -= segmentPosition.Y;
|
|
float targetDistance = (float)System.Math.Sqrt(targetX * targetX + targetY * targetY);
|
|
if (NPC.ai[1] > 0f && NPC.ai[1] < Main.npc.Length)
|
|
{
|
|
try
|
|
{
|
|
segmentPosition = NPC.Center;
|
|
targetX = Main.npc[(int)NPC.ai[1]].position.X + (Main.npc[(int)NPC.ai[1]].width / 2) - segmentPosition.X;
|
|
targetY = Main.npc[(int)NPC.ai[1]].position.Y + (Main.npc[(int)NPC.ai[1]].height / 2) - segmentPosition.Y;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
NPC.rotation = (float)System.Math.Atan2(targetY, targetX) + 1.57f;
|
|
targetDistance = (float)System.Math.Sqrt(targetX * targetX + targetY * targetY);
|
|
int segmentWidth = NPC.width;
|
|
targetDistance = (targetDistance - segmentWidth) / targetDistance;
|
|
targetX *= targetDistance;
|
|
targetY *= targetDistance;
|
|
NPC.velocity = Vector2.Zero;
|
|
NPC.position.X = NPC.position.X + targetX;
|
|
NPC.position.Y = NPC.position.Y + targetY;
|
|
}
|
|
|
|
// Calculate contact damage based on velocity
|
|
float segmentVelocity = BossRushEvent.BossRushActive ? 30f : CalamityWorld.revenge ? 25f : 23f;
|
|
float minimalContactDamageVelocity = segmentVelocity * 0.25f;
|
|
float minimalDamageVelocity = segmentVelocity * 0.5f;
|
|
float bodyAndTailVelocity = (NPC.position - NPC.oldPosition).Length();
|
|
if (bodyAndTailVelocity <= minimalContactDamageVelocity)
|
|
{
|
|
NPC.damage = 0;
|
|
}
|
|
else
|
|
{
|
|
float velocityDamageScalar = MathHelper.Clamp((bodyAndTailVelocity - minimalContactDamageVelocity) / minimalDamageVelocity, 0f, 1f);
|
|
NPC.damage = (int)MathHelper.Lerp(0f, NPC.defDamage, velocityDamageScalar);
|
|
}
|
|
}
|
|
|
|
public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor)
|
|
{
|
|
SpriteEffects spriteEffects = SpriteEffects.None;
|
|
if (NPC.spriteDirection == 1)
|
|
spriteEffects = SpriteEffects.FlipHorizontally;
|
|
|
|
Texture2D texture2D15 = TextureAssets.Npc[NPC.type].Value;
|
|
Vector2 halfSizeTexture = new Vector2((float)(TextureAssets.Npc[NPC.type].Value.Width / 2), (float)(TextureAssets.Npc[NPC.type].Value.Height / 2));
|
|
|
|
Vector2 drawLocation = NPC.Center - screenPos;
|
|
drawLocation -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height)) * NPC.scale / 2f;
|
|
drawLocation += halfSizeTexture * NPC.scale + new Vector2(0f, NPC.gfxOffY);
|
|
spriteBatch.Draw(texture2D15, drawLocation, NPC.frame, NPC.GetAlpha(drawColor), NPC.rotation, halfSizeTexture, NPC.scale, spriteEffects, 0f);
|
|
|
|
texture2D15 = GlowTexture.Value;
|
|
Color glowmaskColor = Color.Lerp(Color.White, Color.Cyan, 0.5f);
|
|
|
|
spriteBatch.Draw(texture2D15, drawLocation, NPC.frame, glowmaskColor, NPC.rotation, halfSizeTexture, NPC.scale, spriteEffects, 0f);
|
|
|
|
return false;
|
|
}
|
|
|
|
public override bool CanHitPlayer(Player target, ref int cooldownSlot)
|
|
{
|
|
cooldownSlot = ImmunityCooldownID.Bosses;
|
|
return NPC.Opacity >= 1f && invinceTime <= 0;
|
|
}
|
|
|
|
public override void HitEffect(NPC.HitInfo hit)
|
|
{
|
|
if (NPC.life <= 0)
|
|
{
|
|
if (Main.netMode != NetmodeID.Server)
|
|
{
|
|
float randomSpread = Main.rand.Next(-200, 201) / 100f;
|
|
Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity * randomSpread * Main.rand.NextFloat(), Mod.Find<ModGore>("DoT2").Type, 1f);
|
|
Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity * randomSpread * Main.rand.NextFloat(), Mod.Find<ModGore>("DoT3").Type, 1f);
|
|
Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity * randomSpread * Main.rand.NextFloat(), Mod.Find<ModGore>("DoT4").Type, 1f);
|
|
Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity * randomSpread * Main.rand.NextFloat(), Mod.Find<ModGore>("DoT5").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 i = 0; i < 10; i++)
|
|
{
|
|
int cosmiliteDust = Dust.NewDust(NPC.position, NPC.width, NPC.height, (int)CalamityDusts.PurpleCosmilite, 0f, 0f, 100, default, 2f);
|
|
Main.dust[cosmiliteDust].velocity *= 3f;
|
|
if (Main.rand.NextBool())
|
|
{
|
|
Main.dust[cosmiliteDust].scale = 0.5f;
|
|
Main.dust[cosmiliteDust].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f;
|
|
}
|
|
}
|
|
for (int j = 0; j < 20; j++)
|
|
{
|
|
int cosmiliteDust2 = Dust.NewDust(NPC.position, NPC.width, NPC.height, (int)CalamityDusts.PurpleCosmilite, 0f, 0f, 100, default, 3f);
|
|
Main.dust[cosmiliteDust2].noGravity = true;
|
|
Main.dust[cosmiliteDust2].velocity *= 5f;
|
|
cosmiliteDust2 = Dust.NewDust(NPC.position, NPC.width, NPC.height, (int)CalamityDusts.PurpleCosmilite, 0f, 0f, 100, default, 2f);
|
|
Main.dust[cosmiliteDust2].velocity *= 2f;
|
|
}
|
|
}
|
|
}
|
|
|
|
public override bool CheckActive()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public override void OnHitPlayer(Player target, Player.HurtInfo hurtInfo)
|
|
{
|
|
if (hurtInfo.Damage > 0)
|
|
target.AddBuff(ModContent.BuffType<GodSlayerInferno>(), 60, true);
|
|
}
|
|
}
|
|
}
|