170 lines
6.4 KiB
C#
170 lines
6.4 KiB
C#
using CalamityMod.BiomeManagers;
|
|
using CalamityMod.Items.Placeables.Banners;
|
|
using CalamityMod.Items.Critters;
|
|
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;
|
|
using Terraria.ModLoader.Utilities;
|
|
using CalamityMod.Items.Fishing.SunkenSeaCatches;
|
|
namespace CalamityMod.NPCs.SunkenSea
|
|
{
|
|
public class BabyGhostBell : ModNPC
|
|
{
|
|
public bool hasBeenHit = false;
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
Main.npcFrameCount[NPC.type] = 4;
|
|
Main.npcCatchable[NPC.type] = true;
|
|
NPCID.Sets.CountsAsCritter[NPC.type] = true;
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
NPC.npcSlots = 0.1f;
|
|
NPC.noGravity = true;
|
|
NPC.chaseable = false;
|
|
NPC.aiStyle = -1;
|
|
AIType = -1;
|
|
NPC.damage = 0;
|
|
NPC.width = 28;
|
|
NPC.height = 36;
|
|
NPC.defense = 0;
|
|
NPC.lifeMax = 5;
|
|
NPC.knockBackResist = 1f;
|
|
NPC.alpha = 100;
|
|
NPC.HitSound = SoundID.NPCHit25;
|
|
NPC.DeathSound = SoundID.NPCDeath28;
|
|
Banner = NPC.type;
|
|
BannerItem = ModContent.ItemType<BabyGhostBellBanner>();
|
|
NPC.catchItem = (short)ModContent.ItemType<BabyGhostBellItem>();
|
|
SpawnModBiomes = new int[1] { ModContent.GetInstance<SunkenSeaBiome>().Type };
|
|
}
|
|
|
|
public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry)
|
|
{
|
|
bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[]
|
|
{
|
|
new FlavorTextBestiaryInfoElement("Mods.CalamityMod.Bestiary.BabyGhostBell")
|
|
});
|
|
}
|
|
|
|
public override void SendExtraAI(BinaryWriter writer)
|
|
{
|
|
writer.Write(NPC.chaseable);
|
|
writer.Write(hasBeenHit);
|
|
}
|
|
|
|
public override void ReceiveExtraAI(BinaryReader reader)
|
|
{
|
|
NPC.chaseable = reader.ReadBoolean();
|
|
hasBeenHit = reader.ReadBoolean();
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
if (NPC.localAI[0] == 0f && Main.netMode != NetmodeID.MultiplayerClient)
|
|
{
|
|
if (Main.rand.NextBool(20))
|
|
NPC.catchItem = (short)ModContent.ItemType<RustedJingleBell>();
|
|
NPC.localAI[0] = 1f;
|
|
NPC.velocity.Y = -3f;
|
|
NPC.netUpdate = true;
|
|
}
|
|
if (Main.rand.Next(8) < 1 && NPC.catchItem == (short)ModContent.ItemType<RustedJingleBell>())
|
|
{
|
|
int dust = Dust.NewDust(NPC.position - new Vector2(2f, 2f), NPC.width + 4, NPC.height + 4, 68, NPC.velocity.X * 0.4f, NPC.velocity.Y * 0.4f, 200, default, 1f);
|
|
Main.dust[dust].noGravity = true;
|
|
Main.dust[dust].velocity *= 1.1f;
|
|
Main.dust[dust].velocity.Y += 0.25f;
|
|
Main.dust[dust].noLight = true;
|
|
if (Main.rand.NextBool(2))
|
|
{
|
|
Main.dust[dust].noGravity = false;
|
|
Main.dust[dust].scale *= 0.5f;
|
|
}
|
|
}
|
|
Lighting.AddLight(NPC.Center, 0f, (255 - NPC.alpha) * 1f / 255f, (255 - NPC.alpha) * 1f / 255f);
|
|
if (NPC.wet)
|
|
{
|
|
NPC.noGravity = true;
|
|
if (NPC.velocity.Y < 0f)
|
|
{
|
|
NPC.velocity.Y += 0.1f;
|
|
}
|
|
if (NPC.velocity.Y > 0f)
|
|
{
|
|
NPC.velocity.Y = 0f;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
NPC.noGravity = false;
|
|
}
|
|
}
|
|
|
|
public override bool? CanBeHitByProjectile(Projectile projectile)
|
|
{
|
|
if (projectile.minion && !projectile.Calamity().overridesMinionDamagePrevention)
|
|
{
|
|
return hasBeenHit;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public override void FindFrame(int frameHeight)
|
|
{
|
|
NPC.frameCounter += 0.15f;
|
|
NPC.frameCounter %= Main.npcFrameCount[NPC.type];
|
|
int frame = (int)NPC.frameCounter;
|
|
NPC.frame.Y = frame * frameHeight;
|
|
}
|
|
|
|
public override float SpawnChance(NPCSpawnInfo spawnInfo)
|
|
{
|
|
if (spawnInfo.Player.Calamity().ZoneSunkenSea && spawnInfo.Water && !spawnInfo.Player.Calamity().clamity)
|
|
{
|
|
return SpawnCondition.CaveJellyfish.Chance * 1.5f;
|
|
}
|
|
return 0f;
|
|
}
|
|
|
|
public override void PostDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor)
|
|
{
|
|
SpriteEffects spriteEffects = SpriteEffects.None;
|
|
if (NPC.spriteDirection == 1)
|
|
{
|
|
spriteEffects = SpriteEffects.FlipHorizontally;
|
|
}
|
|
Vector2 center = new Vector2(NPC.Center.X, NPC.Center.Y);
|
|
Vector2 vector11 = new Vector2((float)(TextureAssets.Npc[NPC.type].Value.Width / 2), (float)(TextureAssets.Npc[NPC.type].Value.Height / Main.npcFrameCount[NPC.type] / 2));
|
|
Vector2 vector = center - screenPos;
|
|
vector -= new Vector2((float)ModContent.Request<Texture2D>("CalamityMod/NPCs/SunkenSea/BabyGhostBellGlow").Value.Width, (float)(ModContent.Request<Texture2D>("CalamityMod/NPCs/SunkenSea/BabyGhostBellGlow").Value.Height / Main.npcFrameCount[NPC.type])) * 1f / 2f;
|
|
vector += vector11 * 1f + new Vector2(0f, 4f + NPC.gfxOffY);
|
|
Color color = new Color(127 - NPC.alpha, 127 - NPC.alpha, 127 - NPC.alpha, 0).MultiplyRGBA(Microsoft.Xna.Framework.Color.LightBlue);
|
|
Main.spriteBatch.Draw(ModContent.Request<Texture2D>("CalamityMod/NPCs/SunkenSea/BabyGhostBellGlow").Value, vector,
|
|
new Microsoft.Xna.Framework.Rectangle?(NPC.frame), color, NPC.rotation, vector11, 1f, spriteEffects, 0f);
|
|
}
|
|
|
|
public override void HitEffect(NPC.HitInfo hit)
|
|
{
|
|
for (int k = 0; k < 2; k++)
|
|
{
|
|
Dust.NewDust(NPC.position, NPC.width, NPC.height, 68, hit.HitDirection, -1f, 0, default, 1f);
|
|
}
|
|
if (NPC.life <= 0)
|
|
{
|
|
for (int k = 0; k < 10; k++)
|
|
{
|
|
Dust.NewDust(NPC.position, NPC.width, NPC.height, 68, hit.HitDirection, -1f, 0, default, 1f);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|