Files
CalamityModPublic/NPCs/NormalNPCs/ImpiousImmolator.cs
T
mountaindrew10 2d1d2b352b 1 - Rev changes enemy AIs now.
2 - Death changes some enemies to be harder than current Death.
3 - Added buff for Trinket of Chi team regen.
2022-12-20 02:17:06 -06:00

287 lines
11 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using CalamityMod.Dusts;
using CalamityMod.Items.Materials;
using CalamityMod.Items.Placeables.Banners;
using CalamityMod.Items.Weapons.Summon;
using CalamityMod.Projectiles.Enemy;
using CalamityMod.World;
using Microsoft.Xna.Framework;
using System;
using System.IO;
using Terraria;
using Terraria.GameContent.Bestiary;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.Utilities;
namespace CalamityMod.NPCs.NormalNPCs
{
public class ImpiousImmolator : ModNPC
{
public bool hasBeenHit = false;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Impious Immolator");
Main.npcFrameCount[NPC.type] = 4;
}
public override void SetDefaults()
{
NPC.noGravity = true;
NPC.lavaImmune = true;
NPC.damage = 0;
NPC.width = 60;
NPC.height = 60;
NPC.defense = 30;
NPC.lifeMax = 5775;
NPC.aiStyle = -1;
AIType = -1;
NPC.value = Item.buyPrice(0, 0, 50, 0);
NPC.HitSound = SoundID.NPCHit5;
NPC.DeathSound = SoundID.NPCDeath7;
NPC.knockBackResist = 0.2f;
Banner = NPC.type;
BannerItem = ModContent.ItemType<ImpiousImmolatorBanner>();
NPC.Calamity().VulnerableToHeat = false;
NPC.Calamity().VulnerableToCold = true;
NPC.Calamity().VulnerableToSickness = false;
NPC.Calamity().VulnerableToWater = true;
}
public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry)
{
bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] {
BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.TheHallow,
BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.TheUnderworld,
// Will move to localization whenever that is cleaned up.
new FlavorTextBestiaryInfoElement("A burning spirit, with no regard or acknowledgment for its surroundings. Anyone who intrudes upon the Profaned Goddess’ holy grounds will be turned to ash.")
});
}
public override void SendExtraAI(BinaryWriter writer)
{
writer.Write(hasBeenHit);
writer.Write(NPC.chaseable);
}
public override void ReceiveExtraAI(BinaryReader reader)
{
hasBeenHit = reader.ReadBoolean();
NPC.chaseable = reader.ReadBoolean();
}
public override void AI()
{
NPC.spriteDirection = (NPC.direction > 0) ? 1 : -1;
NPC.noGravity = true;
if (NPC.direction == 0)
{
NPC.TargetClosest(true);
}
if (NPC.justHit)
{
hasBeenHit = true;
}
NPC.chaseable = hasBeenHit;
if (!NPC.wet)
{
bool flag14 = hasBeenHit;
NPC.TargetClosest(false);
if ((Main.player[NPC.target].wet || Main.player[NPC.target].dead) && flag14)
{
flag14 = false;
}
if (!flag14)
{
if (NPC.collideX)
{
NPC.velocity.X = NPC.velocity.X * -1f;
NPC.direction *= -1;
NPC.netUpdate = true;
}
if (NPC.collideY)
{
NPC.netUpdate = true;
if (NPC.velocity.Y > 0f)
{
NPC.velocity.Y = Math.Abs(NPC.velocity.Y) * -1f;
NPC.directionY = -1;
NPC.ai[0] = -1f;
}
else if (NPC.velocity.Y < 0f)
{
NPC.velocity.Y = Math.Abs(NPC.velocity.Y);
NPC.directionY = 1;
NPC.ai[0] = 1f;
}
}
}
if (flag14)
{
NPC.TargetClosest(true);
NPC.velocity.X = NPC.velocity.X + (float)NPC.direction * 0.2f;
NPC.velocity.Y = NPC.velocity.Y + (float)NPC.directionY * 0.2f;
float velocityMax = CalamityWorld.death ? 16f : CalamityWorld.revenge ? 14f : 12f;
if (NPC.velocity.X > velocityMax)
{
NPC.velocity.X = velocityMax;
}
if (NPC.velocity.X < -velocityMax)
{
NPC.velocity.X = -velocityMax;
}
if (NPC.velocity.Y > velocityMax)
{
NPC.velocity.Y = velocityMax;
}
if (NPC.velocity.Y < -velocityMax)
{
NPC.velocity.Y = -velocityMax;
}
NPC.localAI[0] += 1f;
if (Main.netMode != NetmodeID.MultiplayerClient && NPC.localAI[0] >= (CalamityWorld.death ? 50f : CalamityWorld.revenge ? 70f : 90f))
{
NPC.localAI[0] = 0f;
if (Collision.CanHit(NPC.position, NPC.width, NPC.height, Main.player[NPC.target].position, Main.player[NPC.target].width, Main.player[NPC.target].height))
{
float speed = 12f;
Vector2 vector = new Vector2(NPC.position.X + (float)NPC.width * 0.5f, NPC.position.Y + (float)(NPC.height / 2));
float num6 = Main.player[NPC.target].position.X + (float)Main.player[NPC.target].width * 0.5f - vector.X + (float)Main.rand.Next(-20, 21);
float num7 = Main.player[NPC.target].position.Y + (float)Main.player[NPC.target].height * 0.5f - vector.Y + (float)Main.rand.Next(-20, 21);
float num8 = (float)Math.Sqrt((double)(num6 * num6 + num7 * num7));
num8 = speed / num8;
num6 *= num8;
num7 *= num8;
int damage = 55;
if (Main.expertMode)
{
damage = 42;
}
int beam = Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center.X, NPC.Center.Y, num6, num7, ModContent.ProjectileType<FlameBurstHostile>(), damage, 0f, Main.myPlayer, 0f, 0f);
Main.projectile[beam].tileCollide = true;
}
}
}
else
{
NPC.velocity.X = NPC.velocity.X + (float)NPC.direction * 0.1f;
if (NPC.velocity.X < -3f || NPC.velocity.X > 3f)
{
NPC.velocity.X = NPC.velocity.X * 0.95f;
}
if (NPC.ai[0] == -1f)
{
NPC.velocity.Y = NPC.velocity.Y - 0.01f;
if ((double)NPC.velocity.Y < -0.3)
{
NPC.ai[0] = 1f;
}
}
else
{
NPC.velocity.Y = NPC.velocity.Y + 0.01f;
if ((double)NPC.velocity.Y > 0.3)
{
NPC.ai[0] = -1f;
}
}
}
int num258 = (int)(NPC.position.X + (float)(NPC.width / 2)) / 16;
int num259 = (int)(NPC.position.Y + (float)(NPC.height / 2)) / 16;
if (Main.tile[num258, num259 - 1].LiquidAmount < 128) //problem?
{
if (Main.tile[num258, num259 + 1].HasTile)
{
NPC.ai[0] = -1f;
}
else if (Main.tile[num258, num259 + 2].HasTile)
{
NPC.ai[0] = -1f;
}
}
if ((double)NPC.velocity.Y > 0.4 || (double)NPC.velocity.Y < -0.4)
{
NPC.velocity.Y = NPC.velocity.Y * 0.95f;
}
}
else
{
if (NPC.velocity.Y == 0f)
{
NPC.velocity.X = NPC.velocity.X * 0.94f;
if ((double)NPC.velocity.X > -0.2 && (double)NPC.velocity.X < 0.2)
{
NPC.velocity.X = 0f;
}
}
NPC.velocity.Y = NPC.velocity.Y + 0.3f;
if (NPC.velocity.Y > 5f)
{
NPC.velocity.Y = 5f;
}
NPC.ai[0] = 1f;
}
NPC.rotation = NPC.velocity.Y * (float)NPC.direction * 0.1f;
if ((double)NPC.rotation < -0.1)
{
NPC.rotation = -0.1f;
}
if ((double)NPC.rotation > 0.1)
{
NPC.rotation = 0.1f;
}
}
public override bool? CanBeHitByProjectile(Projectile projectile)
{
if (projectile.minion && !projectile.Calamity().overridesMinionDamagePrevention)
{
return hasBeenHit;
}
return null;
}
public override void FindFrame(int frameHeight)
{
NPC.frameCounter += hasBeenHit ? 0.25f : 0.125f;
NPC.frameCounter %= Main.npcFrameCount[NPC.type];
int frame = (int)NPC.frameCounter;
NPC.frame.Y = frame * frameHeight;
}
public override float SpawnChance(NPCSpawnInfo spawnInfo)
{
if (spawnInfo.PlayerSafe || !NPC.downedMoonlord)
{
return 0f;
}
if (SpawnCondition.Underworld.Chance > 0f)
{
return SpawnCondition.Underworld.Chance / 4f;
}
return SpawnCondition.OverworldHallow.Chance / 4f;
}
public override void ModifyNPCLoot(NPCLoot npcLoot)
{
npcLoot.Add(ModContent.ItemType<UnholyEssence>(), 1, 2, 4);
npcLoot.Add(ModContent.ItemType<EnergyStaff>(), 15);
}
public override void HitEffect(int hitDirection, double damage)
{
for (int k = 0; k < 5; k++)
{
Dust.NewDust(NPC.position, NPC.width, NPC.height, (int)CalamityDusts.ProfanedFire, hitDirection, -1f, 0, default, 1f);
}
if (NPC.life <= 0)
{
for (int k = 0; k < 25; k++)
{
Dust.NewDust(NPC.position, NPC.width, NPC.height, (int)CalamityDusts.ProfanedFire, hitDirection, -1f, 0, default, 1f);
}
}
}
}
}