Files
CalamityModPublic/NPCs/Providence/ProvSpawnOffense.cs
T
ben-tk b745894036 Almost all debuff immunities/vulnerabilities are now centralized in NPCStats.cs
This is called in GlobalNPC SetDefaults.
Added a few comments explaining some stuff.
Created a list for confusion weak enemies so they are also initialized in GlobalNPC SetDefaults.
2020-12-14 22:44:26 -05:00

297 lines
12 KiB
C#

using CalamityMod.Buffs.DamageOverTime;
using CalamityMod.Buffs.StatDebuffs;
using CalamityMod.Dusts;
using CalamityMod.Events;
using CalamityMod.Projectiles.Boss;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.NPCs.Providence
{
[AutoloadBossHead]
public class ProvSpawnOffense : ModNPC
{
public int dustTimer = 3;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("A Profaned Guardian");
Main.npcFrameCount[npc.type] = 6;
NPCID.Sets.TrailingMode[npc.type] = 1;
}
public override void SetDefaults()
{
npc.Calamity().canBreakPlayerDefense = true;
npc.npcSlots = 1f;
npc.aiStyle = -1;
npc.GetNPCDamage();
npc.width = 100;
npc.height = 80;
npc.defense = 40;
npc.DR_NERD(0.3f);
npc.lifeMax = 31875; // Old HP - 42500
if (BossRushEvent.BossRushActive)
{
npc.lifeMax = 400000;
}
double HPBoost = CalamityConfig.Instance.BossHealthBoost * 0.01;
npc.lifeMax += (int)(npc.lifeMax * HPBoost);
npc.knockBackResist = 0f;
npc.noGravity = true;
npc.noTileCollide = true;
aiType = -1;
npc.HitSound = SoundID.NPCHit52;
npc.DeathSound = SoundID.NPCDeath55;
}
public override void FindFrame(int frameHeight)
{
npc.frameCounter += 0.15f;
npc.frameCounter %= Main.npcFrameCount[npc.type];
int frame = (int)npc.frameCounter;
npc.frame.Y = frame * frameHeight;
}
public override void AI()
{
CalamityGlobalNPC.holyBossAttacker = npc.whoAmI;
bool fireDust = (double)npc.life <= (double)npc.lifeMax * 0.5;
bool expertMode = Main.expertMode;
Vector2 vectorCenter = npc.Center;
npc.TargetClosest(false);
Player player = Main.player[npc.target];
if (CalamityGlobalNPC.holyBoss < 0 || !Main.npc[CalamityGlobalNPC.holyBoss].active)
{
npc.active = false;
npc.netUpdate = true;
return;
}
npc.dontTakeDamage = Main.npc[CalamityGlobalNPC.holyBoss].dontTakeDamage;
if (Math.Sign(npc.velocity.X) != 0)
{
npc.spriteDirection = -Math.Sign(npc.velocity.X);
}
npc.spriteDirection = Math.Sign(npc.velocity.X);
float num1005 = 20f;
float num1006 = 0.111111117f * num1005;
int num1009 = (npc.ai[0] == 2f) ? 2 : 1;
int num1010 = (npc.ai[0] == 2f) ? 80 : 60;
for (int num1011 = 0; num1011 < 2; num1011++)
{
if (Main.rand.Next(3) < num1009)
{
int num1012 = Dust.NewDust(vectorCenter - new Vector2((float)num1010), num1010 * 2, num1010 * 2, (int)CalamityDusts.ProfanedFire, npc.velocity.X * 0.5f, npc.velocity.Y * 0.5f, 90, default, 0.5f);
Main.dust[num1012].noGravity = true;
Main.dust[num1012].velocity *= 0.2f;
Main.dust[num1012].fadeIn = 1f;
}
}
if (npc.ai[0] == 0f)
{
float scaleFactor6 = 10f;
Vector2 center5 = player.Center;
Vector2 vector126 = center5 - vectorCenter;
Vector2 vector127 = vector126 - Vector2.UnitY * 300f;
float num1013 = vector126.Length();
vector126 = Vector2.Normalize(vector126) * scaleFactor6;
vector127 = Vector2.Normalize(vector127) * scaleFactor6;
bool flag64 = Collision.CanHit(vectorCenter, 1, 1, player.Center, 1, 1);
if (npc.ai[3] >= 120f)
{
flag64 = true;
}
float num1014 = 8f;
flag64 = flag64 && vector126.ToRotation() > 3.14159274f / num1014 && vector126.ToRotation() < 3.14159274f - 3.14159274f / num1014;
if (num1013 > 800f || !flag64)
{
npc.velocity.X = (npc.velocity.X * (num1005 - 1f) + vector127.X) / num1005;
npc.velocity.Y = (npc.velocity.Y * (num1005 - 1f) + vector127.Y) / num1005;
if (!flag64)
{
npc.ai[3] += 1f;
if (npc.ai[3] == 120f)
{
npc.netUpdate = true;
}
}
else
{
npc.ai[3] = 0f;
}
}
else
{
npc.ai[0] = 1f;
npc.ai[2] = vector126.X;
npc.ai[3] = vector126.Y;
npc.netUpdate = true;
}
}
else if (npc.ai[0] == 1f)
{
npc.velocity *= 0.8f;
npc.ai[1] += 1f;
if (npc.ai[1] >= 5f)
{
npc.ai[0] = 2f;
npc.ai[1] = 0f;
npc.netUpdate = true;
Vector2 velocity = new Vector2(npc.ai[2], npc.ai[3]);
velocity.Normalize();
velocity *= 10f;
npc.velocity = velocity;
}
}
else if (npc.ai[0] == 2f)
{
if (Main.netMode != NetmodeID.MultiplayerClient)
{
dustTimer--;
if (fireDust && dustTimer <= 0)
{
Main.PlaySound(SoundID.Item20, npc.position);
int type = ModContent.ProjectileType<FlareDust>();
int damage = npc.GetProjectileDamage(type);
Vector2 vector173 = Vector2.Normalize(player.Center - vectorCenter) * (float)(npc.width + 20) / 2f + vectorCenter;
int projectile = Projectile.NewProjectile((int)vector173.X, (int)vector173.Y, (float)(npc.direction * 2), 4f, type, damage, 0f, Main.myPlayer, 2f, 0f);
Main.projectile[projectile].timeLeft = 120;
Main.projectile[projectile].velocity.X = 0f;
Main.projectile[projectile].velocity.Y = 0f;
dustTimer = 3;
}
}
npc.ai[1] += 1f;
bool flag65 = vectorCenter.Y + 50f > player.Center.Y;
if ((npc.ai[1] >= 90f && flag65) || npc.velocity.Length() < 8f)
{
npc.ai[0] = 3f;
npc.ai[1] = 45f;
npc.ai[2] = 0f;
npc.ai[3] = 0f;
npc.velocity /= 2f;
npc.netUpdate = true;
}
else
{
Vector2 center7 = player.Center;
Vector2 vec2 = center7 - vectorCenter;
vec2.Normalize();
if (vec2.HasNaNs())
{
vec2 = new Vector2((float)npc.direction, 0f);
}
npc.velocity = (npc.velocity * (num1005 - 1f) + vec2 * (npc.velocity.Length() + num1006)) / num1005;
}
}
else if (npc.ai[0] == 3f)
{
npc.ai[1] -= 1f;
if (npc.ai[1] <= 0f)
{
npc.ai[0] = 0f;
npc.ai[1] = 0f;
npc.netUpdate = true;
}
npc.velocity *= 0.98f;
}
}
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
SpriteEffects spriteEffects = SpriteEffects.None;
if (npc.spriteDirection == 1)
spriteEffects = SpriteEffects.FlipHorizontally;
Texture2D texture2D15 = Main.npcTexture[npc.type];
Vector2 vector11 = new Vector2((float)(Main.npcTexture[npc.type].Width / 2), (float)(Main.npcTexture[npc.type].Height / Main.npcFrameCount[npc.type] / 2));
Color color36 = Color.White;
float amount9 = 0.5f;
int num153 = 5;
if (npc.ai[0] == 2f)
num153 = 10;
if (CalamityConfig.Instance.Afterimages)
{
for (int num155 = 1; num155 < num153; num155 += 2)
{
Color color38 = lightColor;
color38 = Color.Lerp(color38, color36, amount9);
color38 = npc.GetAlpha(color38);
color38 *= (float)(num153 - num155) / 15f;
Vector2 vector41 = npc.oldPos[num155] + new Vector2((float)npc.width, (float)npc.height) / 2f - Main.screenPosition;
vector41 -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[npc.type])) * npc.scale / 2f;
vector41 += vector11 * npc.scale + new Vector2(0f, 4f + npc.gfxOffY);
spriteBatch.Draw(texture2D15, vector41, npc.frame, color38, npc.rotation, vector11, npc.scale, spriteEffects, 0f);
}
}
Vector2 vector43 = npc.Center - Main.screenPosition;
vector43 -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[npc.type])) * npc.scale / 2f;
vector43 += vector11 * npc.scale + new Vector2(0f, 4f + npc.gfxOffY);
spriteBatch.Draw(texture2D15, vector43, npc.frame, npc.GetAlpha(lightColor), npc.rotation, vector11, npc.scale, spriteEffects, 0f);
texture2D15 = ModContent.GetTexture("CalamityMod/NPCs/ProfanedGuardians/ProfanedGuardianBossGlow");
Color color37 = Color.Lerp(Color.White, Color.Yellow, 0.5f);
if (CalamityConfig.Instance.Afterimages)
{
for (int num163 = 1; num163 < num153; num163++)
{
Color color41 = color37;
color41 = Color.Lerp(color41, color36, amount9);
color41 = npc.GetAlpha(color41);
color41 *= (float)(num153 - num163) / 15f;
Vector2 vector44 = npc.oldPos[num163] + new Vector2((float)npc.width, (float)npc.height) / 2f - Main.screenPosition;
vector44 -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[npc.type])) * npc.scale / 2f;
vector44 += vector11 * npc.scale + new Vector2(0f, 4f + npc.gfxOffY);
spriteBatch.Draw(texture2D15, vector44, npc.frame, color41, npc.rotation, vector11, npc.scale, spriteEffects, 0f);
}
}
spriteBatch.Draw(texture2D15, vector43, npc.frame, color37, npc.rotation, vector11, npc.scale, spriteEffects, 0f);
return false;
}
public override bool CheckActive()
{
return false;
}
public override bool CanHitPlayer(Player target, ref int cooldownSlot)
{
cooldownSlot = 1;
return true;
}
public override void OnHitPlayer(Player player, int damage, bool crit)
{
player.AddBuff(ModContent.BuffType<HolyFlames>(), 300, true);
}
public override void HitEffect(int hitDirection, double damage)
{
for (int k = 0; k < 3; k++)
{
Dust.NewDust(npc.position, npc.width, npc.height, (int)CalamityDusts.ProfanedFire, hitDirection, -1f, 0, default, 1f);
}
if (npc.life <= 0)
{
Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/ProfanedGuardianBossGores/ProfanedGuardianBossA"), 1f);
Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/ProfanedGuardianBossGores/ProfanedGuardianBossA2"), 1f);
Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/ProfanedGuardianBossGores/ProfanedGuardianBossA3"), 1f);
Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/ProfanedGuardianBossGores/ProfanedGuardianBossA4"), 1f);
for (int k = 0; k < 30; k++)
{
Dust.NewDust(npc.position, npc.width, npc.height, (int)CalamityDusts.ProfanedFire, hitDirection, -1f, 0, default, 1f);
}
}
}
}
}