Files
CalamityModPublic/NPCs/Signus/CosmicLantern.cs
T

194 lines
7.9 KiB
C#

using System.IO;
using CalamityMod.Events;
using CalamityMod.NPCs.CalamityAIs.CalamityRegularEnemyAIs;
using CalamityMod.World;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Content;
using Terraria;
using Terraria.GameContent;
using Terraria.GameContent.Bestiary;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.NPCs.Signus
{
public class CosmicLantern : ModNPC
{
public static Asset<Texture2D> GlowTexture;
public override void SetStaticDefaults()
{
Main.npcFrameCount[NPC.type] = 4;
NPCID.Sets.TrailingMode[NPC.type] = 1;
NPCID.Sets.BossBestiaryPriority.Add(Type);
if (!Main.dedServ)
{
GlowTexture = ModContent.Request<Texture2D>(Texture + "Glow", AssetRequestMode.AsyncLoad);
}
}
public override void SetDefaults()
{
NPC.aiStyle = -1;
AIType = -1;
NPC.GetNPCDamage();
NPC.width = 25;
NPC.height = 25;
NPC.defense = 50;
NPC.lifeMax = 25;
NPC.alpha = 255;
NPC.knockBackResist = 0.85f;
NPC.noGravity = true;
NPC.dontTakeDamage = true;
NPC.chaseable = false;
NPC.noTileCollide = true;
NPC.HitSound = SoundID.NPCHit53;
NPC.DeathSound = SoundID.NPCDeath44;
NPC.Calamity().VulnerableToSickness = false;
// Scale stats in Expert and Master
CalamityGlobalNPC.AdjustExpertModeStatScaling(NPC);
CalamityGlobalNPC.AdjustMasterModeStatScaling(NPC);
}
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)
{
// Set damage
NPC.damage = NPC.defDamage;
NPC.alpha = 0;
int lightDust = Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.TreasureSparkle, 0f, 0f, 0, default, 0.25f);
Main.dust[lightDust].velocity *= 0.1f;
Main.dust[lightDust].noGravity = true;
}
else
{
// Avoid cheap bullshit
NPC.damage = 0;
}
bool revenge = CalamityWorld.revenge;
float playerDistNormMult = revenge ? 24f : 22f;
if (BossRushEvent.BossRushActive)
playerDistNormMult = 30f;
CalamityRegularEnemyAI.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 halfSizeTexture = new Vector2((float)(TextureAssets.Npc[NPC.type].Value.Width / 2), (float)(TextureAssets.Npc[NPC.type].Value.Height / Main.npcFrameCount[NPC.type] / 2));
int afterimageAmt = 5;
if (CalamityConfig.Instance.Afterimages)
{
for (int i = 1; i < afterimageAmt; i += 2)
{
Color afterimageColor = drawColor;
afterimageColor = Color.Lerp(afterimageColor, Color.White, 0.5f);
afterimageColor = NPC.GetAlpha(afterimageColor);
afterimageColor *= (float)(afterimageAmt - i) / 15f;
Vector2 afterimagePos = NPC.oldPos[i] + new Vector2((float)NPC.width, (float)NPC.height) / 2f - screenPos;
afterimagePos -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[NPC.type])) * NPC.scale / 2f;
afterimagePos += halfSizeTexture * NPC.scale + new Vector2(0f, NPC.gfxOffY);
spriteBatch.Draw(texture2D15, afterimagePos, NPC.frame, afterimageColor, NPC.rotation, halfSizeTexture, NPC.scale, spriteEffects, 0f);
}
}
Vector2 drawLocation = NPC.Center - screenPos;
drawLocation -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[NPC.type])) * NPC.scale / 2f;
drawLocation += halfSizeTexture * NPC.scale + new Vector2(0f, NPC.gfxOffY);
spriteBatch.Draw(texture2D15, drawLocation, NPC.frame, NPC.GetAlpha(drawColor), NPC.rotation, halfSizeTexture, NPC.scale, spriteEffects, 0f);
texture2D15 = GlowTexture.Value;
Color cyanLerp = Color.Lerp(Color.White, Color.Cyan, 0.5f);
if (CalamityConfig.Instance.Afterimages)
{
for (int j = 1; j < afterimageAmt; j++)
{
Color flameAfterimageColor = cyanLerp;
flameAfterimageColor = Color.Lerp(flameAfterimageColor, Color.White, 0.5f);
flameAfterimageColor = NPC.GetAlpha(flameAfterimageColor);
flameAfterimageColor *= (float)(afterimageAmt - j) / 15f;
Vector2 flameAfterimagePos = NPC.oldPos[j] + new Vector2((float)NPC.width, (float)NPC.height) / 2f - screenPos;
flameAfterimagePos -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[NPC.type])) * NPC.scale / 2f;
flameAfterimagePos += halfSizeTexture * NPC.scale + new Vector2(0f, NPC.gfxOffY);
spriteBatch.Draw(texture2D15, flameAfterimagePos, NPC.frame, flameAfterimageColor, NPC.rotation, halfSizeTexture, NPC.scale, spriteEffects, 0f);
}
}
spriteBatch.Draw(texture2D15, drawLocation, NPC.frame, cyanLerp, NPC.rotation, halfSizeTexture, 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, DustID.TreasureSparkle, hit.HitDirection, -1f, 0, default, 1f);
}
}
}
}
}