Files
CalamityModPublic/NPCs/Abyss/GulperEelBody.cs
T

191 lines
8.0 KiB
C#

using CalamityMod.Buffs.DamageOverTime;
using CalamityMod.Items.Placeables.Banners;
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.Abyss
{
[LongDistanceNetSync(SyncWith = typeof(GulperEelHead))]
public class GulperEelBody : ModNPC
{
public override LocalizedText DisplayName => CalamityUtils.GetText("NPCs.GulperEelHead.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.damage = 90; //70
NPC.width = 40; //36
NPC.height = 48;
NPC.defense = 30;
NPC.lifeMax = 60000;
NPC.aiStyle = -1; //new
AIType = -1; //new
NPC.knockBackResist = 0f;
NPC.alpha = 255;
NPC.behindTiles = true;
NPC.noGravity = true;
NPC.noTileCollide = true;
NPC.HitSound = SoundID.NPCHit9;
NPC.DeathSound = SoundID.NPCDeath13;
NPC.netAlways = true;
NPC.dontCountMe = true;
NPC.chaseable = false;
Banner = ModContent.NPCType<GulperEelHead>();
BannerItem = ModContent.ItemType<GulperEelBanner>();
NPC.Calamity().VulnerableToHeat = false;
NPC.Calamity().VulnerableToSickness = true;
NPC.Calamity().VulnerableToElectricity = true;
NPC.Calamity().VulnerableToWater = false;
// Scale stats in Expert and Master
CalamityGlobalNPC.AdjustExpertModeStatScaling(NPC);
CalamityGlobalNPC.AdjustMasterModeStatScaling(NPC);
}
public override bool? DrawHealthBar(byte hbPosition, ref float scale, ref Vector2 position)
{
return false;
}
public override void AI()
{
// Avoid cheap bullshit
NPC.damage = 0;
if (NPC.ai[2] > 0f)
NPC.realLife = (int)NPC.ai[2];
// Check if other segments are still alive, if not, die
bool shouldDespawn = true;
foreach (NPC n in Main.ActiveNPCs)
{
if (n.type == ModContent.NPCType<GulperEelHead>())
{
shouldDespawn = false;
break;
}
}
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;
}
if (Main.npc[(int)NPC.ai[1]].alpha < 128)
{
NPC.alpha -= 42;
if (NPC.alpha < 0)
NPC.alpha = 0;
}
Vector2 segmentPosition = new Vector2(NPC.position.X + (float)NPC.width * 0.5f, NPC.position.Y + (float)NPC.height * 0.5f);
float targetXDirection = Main.player[NPC.target].position.X + (float)(Main.player[NPC.target].width / 2);
float targetYDirection = Main.player[NPC.target].position.Y + (float)(Main.player[NPC.target].height / 2);
targetXDirection = (float)((int)(targetXDirection / 16f) * 16);
targetYDirection = (float)((int)(targetYDirection / 16f) * 16);
segmentPosition.X = (float)((int)(segmentPosition.X / 16f) * 16);
segmentPosition.Y = (float)((int)(segmentPosition.Y / 16f) * 16);
targetXDirection -= segmentPosition.X;
targetYDirection -= segmentPosition.Y;
float targetDistance = (float)System.Math.Sqrt((double)(targetXDirection * targetXDirection + targetYDirection * targetYDirection));
if (NPC.ai[1] > 0f && NPC.ai[1] < (float)Main.npc.Length)
{
try
{
segmentPosition = new Vector2(NPC.position.X + (float)NPC.width * 0.5f, NPC.position.Y + (float)NPC.height * 0.5f);
targetXDirection = Main.npc[(int)NPC.ai[1]].position.X + (float)(Main.npc[(int)NPC.ai[1]].width / 2) - segmentPosition.X;
targetYDirection = Main.npc[(int)NPC.ai[1]].position.Y + (float)(Main.npc[(int)NPC.ai[1]].height / 2) - segmentPosition.Y;
}
catch
{
}
NPC.rotation = (float)System.Math.Atan2((double)targetYDirection, (double)targetXDirection) + 1.57f;
targetDistance = (float)System.Math.Sqrt((double)(targetXDirection * targetXDirection + targetYDirection * targetYDirection));
int segmentWidth = NPC.width;
targetDistance = (targetDistance - (float)segmentWidth) / targetDistance;
targetXDirection *= targetDistance;
targetYDirection *= targetDistance;
NPC.velocity = Vector2.Zero;
NPC.position.X = NPC.position.X + targetXDirection;
NPC.position.Y = NPC.position.Y + targetYDirection;
if (targetXDirection < 0f)
NPC.spriteDirection = -1;
else if (targetXDirection > 0f)
NPC.spriteDirection = 1;
}
}
public override void PostDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor)
{
SpriteEffects spriteEffects = SpriteEffects.None;
if (NPC.spriteDirection == 1)
{
spriteEffects = SpriteEffects.FlipHorizontally;
}
Vector2 center = new Vector2(NPC.Center.X, NPC.Center.Y);
Vector2 halfSizeTexture = new Vector2((float)(TextureAssets.Npc[NPC.type].Value.Width / 2), (float)(TextureAssets.Npc[NPC.type].Value.Height / Main.npcFrameCount[NPC.type] / 2));
Vector2 vector = center - screenPos;
vector -= new Vector2((float)GlowTexture.Value.Width, (float)(GlowTexture.Value.Height / Main.npcFrameCount[NPC.type])) * 1f / 2f;
vector += halfSizeTexture * 1f + new Vector2(0f, NPC.gfxOffY);
Color color = new Color(127 - NPC.alpha, 127 - NPC.alpha, 127 - NPC.alpha, 0).MultiplyRGBA(Color.White);
Main.spriteBatch.Draw(GlowTexture.Value, vector,
new Microsoft.Xna.Framework.Rectangle?(NPC.frame), color, NPC.rotation, halfSizeTexture, 1f, spriteEffects, 0f);
}
public override bool CheckActive()
{
return false;
}
public override void HitEffect(NPC.HitInfo hit)
{
for (int k = 0; k < 3; k++)
{
Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Blood, hit.HitDirection, -1f, 0, default, 1f);
}
if (NPC.life <= 0)
{
for (int k = 0; k < 10; k++)
{
Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Blood, hit.HitDirection, -1f, 0, default, 1f);
}
if (Main.netMode != NetmodeID.Server)
{
Gore.NewGore(NPC.GetSource_Death(), NPC.Center, NPC.velocity, Mod.Find<ModGore>("GulperEel2").Type, 1f);
Gore.NewGore(NPC.GetSource_Death(), NPC.Center, NPC.velocity, Mod.Find<ModGore>("GulperEel3").Type, 1f);
}
}
}
public override void OnHitPlayer(Player target, Player.HurtInfo hurtInfo)
{
if (hurtInfo.Damage > 0)
target.AddBuff(ModContent.BuffType<CrushDepth>(), 120, true);
}
}
}