126 lines
4.5 KiB
C#
126 lines
4.5 KiB
C#
using CalamityMod.Items.Placeables.Banners;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using Terraria;
|
|
using Terraria.GameContent;
|
|
using Terraria.GameContent.Bestiary;
|
|
using Terraria.GameContent.ItemDropRules;
|
|
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;
|
|
}
|
|
|
|
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 player, int damage, bool crit)
|
|
{
|
|
if (damage > 0)
|
|
player.AddBuff(BuffID.Confused, 180, true);
|
|
}
|
|
|
|
public override void HitEffect(int hitDirection, double damage)
|
|
{
|
|
for (int k = 0; k < 5; k++)
|
|
{
|
|
Dust.NewDust(NPC.position, NPC.width, NPC.height, 70, 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, 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);
|
|
}
|
|
}
|
|
}
|