Files
CalamityModPublic/NPCs/Signus/CosmicLantern.cs
T

179 lines
7.3 KiB
C#

using CalamityMod.Events;
using CalamityMod.World;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.IO;
using Terraria;
using Terraria.GameContent;
using Terraria.GameContent.Bestiary;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.NPCs.Signus
{
public class CosmicLantern : ModNPC
{
public override void SetStaticDefaults()
{
Main.npcFrameCount[NPC.type] = 4;
NPCID.Sets.TrailingMode[NPC.type] = 1;
NPCID.Sets.BossBestiaryPriority.Add(Type);
}
public override void SetDefaults()
{
NPC.aiStyle = -1;
AIType = -1;
NPC.GetNPCDamage();
NPC.width = 25;
NPC.height = 25;
NPC.defense = 50;
NPC.lifeMax = 25;
double HPBoost = CalamityConfig.Instance.BossHealthBoost * 0.01;
NPC.lifeMax += (int)(NPC.lifeMax * HPBoost);
NPC.alpha = 255;
NPC.knockBackResist = 0.85f;
NPC.noGravity = true;
NPC.dontTakeDamage = true;
NPC.chaseable = false;
NPC.canGhostHeal = false;
NPC.noTileCollide = true;
NPC.HitSound = SoundID.NPCHit53;
NPC.DeathSound = SoundID.NPCDeath44;
NPC.Calamity().VulnerableToSickness = false;
}
public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry)
{
int associatedNPCType = ModContent.NPCType<Signus>();
bestiaryEntry.UIInfoProvider = new CommonEnemyUICollectionInfoProvider(ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[associatedNPCType], quickUnlock: true);
bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[]
{
BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.TheUnderworld,
new FlavorTextBestiaryInfoElement("Mods.CalamityMod.Bestiary.CosmicLantern")
});
}
public override void SendExtraAI(BinaryWriter writer)
{
writer.Write(NPC.dontTakeDamage);
}
public override void ReceiveExtraAI(BinaryReader reader)
{
NPC.dontTakeDamage = reader.ReadBoolean();
}
public override void FindFrame(int frameHeight)
{
if (NPC.IsABestiaryIconDummy)
NPC.Opacity = 1f;
NPC.frameCounter += 0.15f;
NPC.frameCounter %= Main.npcFrameCount[NPC.type];
int frame = (int)NPC.frameCounter;
NPC.frame.Y = frame * frameHeight;
}
public override void AI()
{
if (CalamityGlobalNPC.signus < 0 || !Main.npc[CalamityGlobalNPC.signus].active)
{
NPC.life = 0;
NPC.HitEffect();
NPC.active = false;
NPC.netUpdate = true;
return;
}
Lighting.AddLight((int)((NPC.position.X + (float)(NPC.width / 2)) / 16f), (int)((NPC.position.Y + (float)(NPC.height / 2)) / 16f), 0.3f, 0.3f, 0.3f);
NPC.alpha -= 3;
if (NPC.alpha < 0)
{
NPC.alpha = 0;
int num1262 = Dust.NewDust(NPC.position, NPC.width, NPC.height, 204, 0f, 0f, 0, default, 0.25f);
Main.dust[num1262].velocity *= 0.1f;
Main.dust[num1262].noGravity = true;
}
bool revenge = CalamityWorld.revenge;
float playerDistNormMult = revenge ? 24f : 22f;
if (BossRushEvent.BossRushActive)
playerDistNormMult = 30f;
CalamityAI.DungeonSpiritAI(NPC, Mod, playerDistNormMult, 0f, true);
}
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 vector11 = new Vector2((float)(TextureAssets.Npc[NPC.type].Value.Width / 2), (float)(TextureAssets.Npc[NPC.type].Value.Height / Main.npcFrameCount[NPC.type] / 2));
Color color36 = Color.White;
float amount9 = 0.5f;
int num153 = 5;
if (CalamityConfig.Instance.Afterimages)
{
for (int num155 = 1; num155 < num153; num155 += 2)
{
Color color38 = drawColor;
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 - screenPos;
vector41 -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[NPC.type])) * NPC.scale / 2f;
vector41 += vector11 * NPC.scale + new Vector2(0f, NPC.gfxOffY);
spriteBatch.Draw(texture2D15, vector41, NPC.frame, color38, NPC.rotation, vector11, NPC.scale, spriteEffects, 0f);
}
}
Vector2 vector43 = NPC.Center - screenPos;
vector43 -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[NPC.type])) * NPC.scale / 2f;
vector43 += vector11 * NPC.scale + new Vector2(0f, NPC.gfxOffY);
spriteBatch.Draw(texture2D15, vector43, NPC.frame, NPC.GetAlpha(drawColor), NPC.rotation, vector11, NPC.scale, spriteEffects, 0f);
texture2D15 = ModContent.Request<Texture2D>("CalamityMod/NPCs/Signus/CosmicLanternGlow").Value;
Color color37 = Color.Lerp(Color.White, Color.Cyan, 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 - screenPos;
vector44 -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[NPC.type])) * NPC.scale / 2f;
vector44 += vector11 * NPC.scale + new Vector2(0f, 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 CanHitPlayer(Player target, ref int cooldownSlot)
{
return NPC.alpha == 0;
}
public override void HitEffect(NPC.HitInfo hit)
{
if (NPC.life <= 0)
{
for (int k = 0; k < 10; k++)
{
Dust.NewDust(NPC.position, NPC.width, NPC.height, 204, hit.HitDirection, -1f, 0, default, 1f);
}
}
}
}
}