Files
CalamityModPublic/NPCs/NormalNPCs/CosmicElemental.cs
T
2023-04-12 20:13:32 -05:00

132 lines
4.9 KiB
C#

using CalamityMod.Buffs.DamageOverTime;
using CalamityMod.Items.Placeables.Banners;
using CalamityMod.World;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.GameContent;
using Terraria.GameContent.Bestiary;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.Utilities;
namespace CalamityMod.NPCs.NormalNPCs
{
public class CosmicElemental : ModNPC
{
public override void SetStaticDefaults()
{
// DisplayName.SetDefault("Cosmic Elemental");
Main.npcFrameCount[NPC.type] = 11;
NPCID.Sets.NPCBestiaryDrawModifiers value = new NPCID.Sets.NPCBestiaryDrawModifiers(0);
value.Position.Y -= 6f;
value.PortraitPositionYOverride = -32f;
NPCID.Sets.NPCBestiaryDrawOffset[Type] = value;
}
public override void SetDefaults()
{
NPC.npcSlots = 0.5f;
NPC.aiStyle = NPCAIStyleID.GraniteElemental;
NPC.damage = 20;
NPC.width = NPC.height = 30;
NPC.defense = 10;
NPC.lifeMax = 25;
NPC.knockBackResist = 0.5f;
NPC.value = Item.buyPrice(0, 0, 3, 0);
NPC.HitSound = SoundID.NPCHit7;
NPC.DeathSound = SoundID.NPCDeath6;
Banner = NPC.type;
BannerItem = ModContent.ItemType<CosmicElementalBanner>();
NPC.Calamity().VulnerableToSickness = false;
}
public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry)
{
bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] {
BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.Caverns,
// Will move to localization whenever that is cleaned up.
new FlavorTextBestiaryInfoElement("A curious construct, and though its origins are unknown, it has been decidedly proven that the core of its body leads to somewhere not of our world.")
});
}
public override void FindFrame(int frameHeight)
{
NPC.frameCounter++;
if (NPC.frameCounter > 6)
{
NPC.frame.Y += frameHeight;
NPC.frameCounter = 0;
}
if (NPC.ai[0] == -1f)
{
if (NPC.frame.Y >= frameHeight * 11)
NPC.frame.Y = frameHeight * 10;
else if (NPC.frame.Y <= frameHeight * 5)
NPC.frame.Y = frameHeight * 6;
NPC.rotation += NPC.velocity.X * 0.2f;
}
else
{
if (NPC.frame.Y >= frameHeight * 6)
NPC.frame.Y = 0;
NPC.rotation = NPC.velocity.X * 0.1f;
}
}
public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor)
{
Texture2D texture = TextureAssets.Npc[NPC.type].Value;
int height = texture.Height / Main.npcFrameCount[NPC.type];
int width = texture.Width;
SpriteEffects spriteEffects = SpriteEffects.None;
if (NPC.spriteDirection == -1)
{
spriteEffects = SpriteEffects.FlipHorizontally;
}
Main.spriteBatch.Draw(texture, NPC.Center - screenPos + new Vector2(0f, NPC.gfxOffY), NPC.frame, NPC.GetAlpha(drawColor), NPC.rotation, new Vector2(width / 2f, height / 2f), NPC.scale, spriteEffects, 0f);
return false;
}
public override float SpawnChance(NPCSpawnInfo spawnInfo)
{
if (spawnInfo.PlayerSafe || spawnInfo.Player.Calamity().ZoneAbyss || spawnInfo.Player.Calamity().ZoneSunkenSea)
{
return 0f;
}
return SpawnCondition.Cavern.Chance * 0.01f;
}
public override void OnHitPlayer(Player target, Player.HurtInfo hurtInfo)
{
int debuffType = CalamityWorld.getFixedBoi ? ModContent.BuffType<GodSlayerInferno>() : BuffID.Confused;
if (hurtInfo.Damage > 0)
target.AddBuff(debuffType, 180, true);
}
public override void HitEffect(NPC.HitInfo hit)
{
for (int k = 0; k < 5; k++)
{
Dust.NewDust(NPC.position, NPC.width, NPC.height, 70, hit.HitDirection, -1f, 0, default, 1f);
}
if (NPC.life <= 0)
{
for (int k = 0; k < 20; k++)
{
Dust.NewDust(NPC.position, NPC.width, NPC.height, 70, hit.HitDirection, -1f, 0, default, 1f);
}
}
}
public override void ModifyNPCLoot(NPCLoot npcLoot)
{
npcLoot.Add(ItemID.BoneSword, 20);
npcLoot.Add(ItemID.Starfury, 50);
npcLoot.Add(ItemID.EnchantedSword, 50);
npcLoot.Add(ItemID.Terragrim, 100);
}
}
}