Files
CalamityModPublic/NPCs/Abyss/Bloatfish.cs
T
2022-12-18 22:48:15 -08:00

226 lines
8.1 KiB
C#

using System;
using CalamityMod.BiomeManagers;
using CalamityMod.Buffs.DamageOverTime;
using CalamityMod.Items.Materials;
using CalamityMod.Items.Placeables;
using CalamityMod.Items.Placeables.Banners;
using Terraria;
using Terraria.GameContent.Bestiary;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.Utilities;
namespace CalamityMod.NPCs.Abyss
{
public class Bloatfish : ModNPC
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Bloatfish");
Main.npcFrameCount[NPC.type] = 4;
}
public override void SetDefaults()
{
NPC.noGravity = true;
NPC.lavaImmune = true;
NPC.damage = 5;
NPC.width = 74;
NPC.height = 94;
NPC.defense = 100;
NPC.lifeMax = 7200;
NPC.aiStyle = -1;
AIType = -1;
NPC.value = Item.buyPrice(0, 0, 30, 0);
NPC.HitSound = SoundID.NPCHit1;
NPC.DeathSound = SoundID.NPCDeath1;
NPC.knockBackResist = 0.9f;
Banner = NPC.type;
BannerItem = ModContent.ItemType<BloatfishBanner>();
NPC.Calamity().VulnerableToHeat = false;
NPC.Calamity().VulnerableToSickness = true;
NPC.Calamity().VulnerableToElectricity = true;
NPC.Calamity().VulnerableToWater = false;
SpawnModBiomes = new int[1] { ModContent.GetInstance<AbyssLayer4Biome>().Type };
}
public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry)
{
bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] {
// Will move to localization whenever that is cleaned up.
new FlavorTextBestiaryInfoElement("Heavy, large fish which can easily resist the crushing pressure of the depths and any weapon which might attempt to pierce its tough skin.")
});
}
public override void AI()
{
NPC.spriteDirection = (NPC.direction > 0) ? 1 : -1;
NPC.noGravity = true;
if (NPC.direction == 0)
{
NPC.TargetClosest(true);
}
if (NPC.wet)
{
NPC.TargetClosest(false);
if (NPC.collideX)
{
NPC.velocity.X = NPC.velocity.X * -1f;
NPC.direction *= -1;
NPC.netUpdate = true;
}
if (NPC.collideY)
{
NPC.netUpdate = true;
if (NPC.velocity.Y > 0f)
{
NPC.velocity.Y = Math.Abs(NPC.velocity.Y) * -1f;
NPC.directionY = -1;
NPC.ai[0] = -1f;
}
else if (NPC.velocity.Y < 0f)
{
NPC.velocity.Y = Math.Abs(NPC.velocity.Y);
NPC.directionY = 1;
NPC.ai[0] = 1f;
}
}
NPC.velocity.X = NPC.velocity.X + (float)NPC.direction * 0.1f;
if (NPC.velocity.X < -0.2f || NPC.velocity.X > 0.2f)
{
NPC.velocity.X = NPC.velocity.X * 0.95f;
}
if (NPC.ai[0] == -1f)
{
NPC.velocity.Y = NPC.velocity.Y - 0.01f;
if ((double)NPC.velocity.Y < -0.3)
{
NPC.ai[0] = 1f;
}
}
else
{
NPC.velocity.Y = NPC.velocity.Y + 0.01f;
if ((double)NPC.velocity.Y > 0.3)
{
NPC.ai[0] = -1f;
}
}
int num258 = (int)(NPC.position.X + (float)(NPC.width / 2)) / 16;
int num259 = (int)(NPC.position.Y + (float)(NPC.height / 2)) / 16;
if (Main.tile[num258, num259 - 1].LiquidAmount > 128)
{
if (Main.tile[num258, num259 + 1].HasTile)
{
NPC.ai[0] = -1f;
}
else if (Main.tile[num258, num259 + 2].HasTile)
{
NPC.ai[0] = -1f;
}
}
if ((double)NPC.velocity.Y > 0.4 || (double)NPC.velocity.Y < -0.4)
{
NPC.velocity.Y = NPC.velocity.Y * 0.95f;
}
}
else
{
if (NPC.velocity.Y == 0f)
{
NPC.velocity.X = NPC.velocity.X * 0.94f;
if ((double)NPC.velocity.X > -0.2 && (double)NPC.velocity.X < 0.2)
{
NPC.velocity.X = 0f;
}
}
NPC.velocity.Y = NPC.velocity.Y + 0.3f;
if (NPC.velocity.Y > 3f)
{
NPC.velocity.Y = 3f;
}
NPC.ai[0] = 1f;
}
NPC.rotation = NPC.velocity.Y * (float)NPC.direction * 0.1f;
if ((double)NPC.rotation < -0.2)
{
NPC.rotation = -0.2f;
}
if ((double)NPC.rotation > 0.2)
{
NPC.rotation = 0.2f;
return;
}
}
public override void ModifyHitByProjectile(Projectile projectile, ref int damage, ref float knockback, ref bool crit, ref int hitDirection)
{
if ((projectile.penetrate == -1 || projectile.penetrate > 1) && !projectile.minion)
{
projectile.penetrate = 1;
}
}
public override void OnHitPlayer(Player player, int damage, bool crit)
{
if (damage > 0)
player.AddBuff(ModContent.BuffType<CrushDepth>(), 300, true);
}
public override void FindFrame(int frameHeight)
{
if (!NPC.wet && !NPC.IsABestiaryIconDummy)
{
NPC.frameCounter = 0.0;
return;
}
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().ZoneAbyssLayer4 && spawnInfo.Water && NPC.CountNPCS(ModContent.NPCType<Bloatfish>()) < 3)
{
return SpawnCondition.CaveJellyfish.Chance * 0.3f;
}
return 0f;
}
public override void ModifyNPCLoot(NPCLoot npcLoot)
{
npcLoot.Add(ModContent.ItemType<Voidstone>(), 1, 10, 20);
var postClone = npcLoot.DefineConditionalDropSet(DropHelper.PostCal());
postClone.Add(DropHelper.NormalVsExpertQuantity(ModContent.ItemType<DepthCells>(), 2, 5, 7, 7, 10));
}
public override void HitEffect(int hitDirection, double damage)
{
for (int k = 0; k < 5; k++)
{
Dust.NewDust(NPC.position, NPC.width, NPC.height, 5, hitDirection, -1f, 0, default, 1f);
}
if (NPC.life <= 0)
{
for (int k = 0; k < 50; k++)
{
Dust.NewDust(NPC.position, NPC.width, NPC.height, 5, hitDirection, -1f, 0, default, 1f);
}
if (Main.netMode != NetmodeID.Server)
{
Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("Bloatfish").Type, NPC.scale);
Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("Bloatfish2").Type, NPC.scale);
Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("Bloatfish3").Type, NPC.scale);
}
}
if (NPC.scale < 2f)
{
NPC.scale += 0.05f;
}
}
}
}