208 lines
8.1 KiB
C#
208 lines
8.1 KiB
C#
using CalamityMod.Events;
|
|
using CalamityMod.Projectiles.Enemy;
|
|
using CalamityMod.World;
|
|
using Microsoft.Xna.Framework;
|
|
using Terraria;
|
|
using Terraria.ID;
|
|
using Terraria.Localization;
|
|
using Terraria.ModLoader;
|
|
|
|
namespace CalamityMod.NPCs.DesertScourge
|
|
{
|
|
public class DesertScourgeBody : ModNPC
|
|
{
|
|
public override LocalizedText DisplayName => CalamityUtils.GetText("NPCs.DesertScourgeHead.DisplayName");
|
|
public override void SetStaticDefaults()
|
|
{
|
|
this.HideFromBestiary();
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
NPC.GetNPCDamage();
|
|
NPC.width = 32;
|
|
NPC.height = 36;
|
|
NPC.defense = 6;
|
|
NPC.DR_NERD(0.05f);
|
|
|
|
NPC.LifeMaxNERB(2500, 3000, 1650000);
|
|
if (Main.getGoodWorld)
|
|
NPC.lifeMax *= 4;
|
|
|
|
double HPBoost = CalamityConfig.Instance.BossHealthBoost * 0.01;
|
|
NPC.lifeMax += (int)(NPC.lifeMax * HPBoost);
|
|
NPC.aiStyle = -1;
|
|
AIType = -1;
|
|
NPC.knockBackResist = 0f;
|
|
NPC.alpha = 255;
|
|
NPC.boss = true;
|
|
NPC.behindTiles = true;
|
|
NPC.noGravity = true;
|
|
NPC.noTileCollide = true;
|
|
NPC.canGhostHeal = false;
|
|
NPC.HitSound = SoundID.NPCHit1;
|
|
NPC.DeathSound = SoundID.NPCDeath1;
|
|
NPC.netAlways = true;
|
|
NPC.dontCountMe = true;
|
|
|
|
if (BossRushEvent.BossRushActive)
|
|
NPC.scale *= 1.25f;
|
|
else if (CalamityWorld.death)
|
|
NPC.scale *= 1.2f;
|
|
else if (CalamityWorld.revenge)
|
|
NPC.scale *= 1.15f;
|
|
else if (Main.expertMode)
|
|
NPC.scale *= 1.1f;
|
|
|
|
if (Main.getGoodWorld)
|
|
NPC.scale *= 0.4f;
|
|
|
|
NPC.Calamity().VulnerableToCold = true;
|
|
NPC.Calamity().VulnerableToSickness = true;
|
|
NPC.Calamity().VulnerableToWater = true;
|
|
}
|
|
|
|
public override bool? DrawHealthBar(byte hbPosition, ref float scale, ref Vector2 position)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
if (NPC.ai[2] > 0f)
|
|
NPC.realLife = (int)NPC.ai[2];
|
|
|
|
if (NPC.target < 0 || NPC.target == Main.maxPlayers || Main.player[NPC.target].dead || !Main.player[NPC.target].active)
|
|
NPC.TargetClosest();
|
|
|
|
bool shouldDespawn = true;
|
|
for (int i = 0; i < Main.maxNPCs; i++)
|
|
{
|
|
if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType<DesertScourgeHead>())
|
|
{
|
|
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;
|
|
}
|
|
|
|
if (Main.player[NPC.target].dead)
|
|
NPC.TargetClosest(false);
|
|
|
|
Vector2 segmentTilePos = new Vector2(NPC.position.X + (float)NPC.width * 0.5f, NPC.position.Y + (float)NPC.height * 0.5f);
|
|
float playerXPos = Main.player[NPC.target].position.X + (float)(Main.player[NPC.target].width / 2);
|
|
float playerYPos = Main.player[NPC.target].position.Y + (float)(Main.player[NPC.target].height / 2);
|
|
playerXPos = (float)((int)(playerXPos / 16f) * 16);
|
|
playerYPos = (float)((int)(playerYPos / 16f) * 16);
|
|
segmentTilePos.X = (float)((int)(segmentTilePos.X / 16f) * 16);
|
|
segmentTilePos.Y = (float)((int)(segmentTilePos.Y / 16f) * 16);
|
|
playerXPos -= segmentTilePos.X;
|
|
playerYPos -= segmentTilePos.Y;
|
|
float playerDistance = (float)System.Math.Sqrt((double)(playerXPos * playerXPos + playerYPos * playerYPos));
|
|
if (NPC.ai[1] > 0f && NPC.ai[1] < (float)Main.npc.Length)
|
|
{
|
|
try
|
|
{
|
|
segmentTilePos = new Vector2(NPC.position.X + (float)NPC.width * 0.5f, NPC.position.Y + (float)NPC.height * 0.5f);
|
|
playerXPos = Main.npc[(int)NPC.ai[1]].position.X + (float)(Main.npc[(int)NPC.ai[1]].width / 2) - segmentTilePos.X;
|
|
playerYPos = Main.npc[(int)NPC.ai[1]].position.Y + (float)(Main.npc[(int)NPC.ai[1]].height / 2) - segmentTilePos.Y;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
NPC.rotation = (float)System.Math.Atan2((double)playerYPos, (double)playerXPos) + 1.57f;
|
|
playerDistance = (float)System.Math.Sqrt((double)(playerXPos * playerXPos + playerYPos * playerYPos));
|
|
playerDistance = (playerDistance - (float)(NPC.width)) / playerDistance;
|
|
playerXPos *= playerDistance;
|
|
playerYPos *= playerDistance;
|
|
NPC.velocity = Vector2.Zero;
|
|
NPC.position.X = NPC.position.X + playerXPos;
|
|
NPC.position.Y = NPC.position.Y + playerYPos;
|
|
|
|
if (playerXPos < 0f)
|
|
NPC.spriteDirection = 1;
|
|
else if (playerXPos > 0f)
|
|
NPC.spriteDirection = -1;
|
|
}
|
|
}
|
|
|
|
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)
|
|
{
|
|
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>("ScourgeBody").Type, NPC.scale);
|
|
Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity * randomSpread * Main.rand.NextFloat(), Mod.Find<ModGore>("ScourgeBody2").Type, NPC.scale);
|
|
Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity * randomSpread * Main.rand.NextFloat(), Mod.Find<ModGore>("ScourgeBody3").Type, NPC.scale);
|
|
}
|
|
for (int k = 0; k < 10; k++)
|
|
Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Blood, hit.HitDirection, -1f, 0, default, 1f);
|
|
}
|
|
}
|
|
public override void OnHitByProjectile(Projectile projectile, NPC.HitInfo hit, int damageDone)
|
|
{
|
|
// Sometimes "Deflect" projectiles in gfb into water blasts.
|
|
if (Main.rand.NextBool(20) && Main.zenithWorld)
|
|
{
|
|
if (Main.netMode != NetmodeID.Server)
|
|
{
|
|
Vector2 velocity = new Vector2(-projectile.velocity.X, -projectile.velocity.Y);
|
|
velocity.Normalize();
|
|
Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center, velocity * 4, ModContent.ProjectileType<HorsWaterBlast>(), projectile.damage, 1f, Main.myPlayer);
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void ApplyDifficultyAndPlayerScaling(int numPlayers, float balance, float bossAdjustment)
|
|
{
|
|
NPC.lifeMax = (int)(NPC.lifeMax * 0.8f * balance);
|
|
}
|
|
|
|
public override void OnHitPlayer(Player target, Player.HurtInfo hurtInfo)
|
|
{
|
|
if (hurtInfo.Damage > 0)
|
|
target.AddBuff(BuffID.Bleeding, 240, true);
|
|
}
|
|
|
|
public override Color? GetAlpha(Color drawColor)
|
|
{
|
|
if (Main.zenithWorld)
|
|
{
|
|
Color lightColor = Color.MediumBlue * drawColor.A;
|
|
return lightColor * NPC.Opacity;
|
|
}
|
|
else return null;
|
|
}
|
|
}
|
|
}
|