224 lines
7.9 KiB
C#
224 lines
7.9 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 CalamityMod.World;
|
|
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()
|
|
{
|
|
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[]
|
|
{
|
|
new FlavorTextBestiaryInfoElement("Mods.CalamityMod.Bestiary.Bloatfish")
|
|
});
|
|
}
|
|
|
|
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 npcTileX = (int)(NPC.position.X + (float)(NPC.width / 2)) / 16;
|
|
int npcTileY = (int)(NPC.position.Y + (float)(NPC.height / 2)) / 16;
|
|
if (Main.tile[npcTileX, npcTileY - 1].LiquidAmount > 128)
|
|
{
|
|
if (Main.tile[npcTileX, npcTileY + 1].HasTile)
|
|
{
|
|
NPC.ai[0] = -1f;
|
|
}
|
|
else if (Main.tile[npcTileX, npcTileY + 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 NPC.HitModifiers modifiers)
|
|
{
|
|
if ((projectile.penetrate == -1 || projectile.penetrate > 1) && !projectile.minion)
|
|
{
|
|
projectile.penetrate = 1;
|
|
}
|
|
}
|
|
|
|
public override void OnHitPlayer(Player target, Player.HurtInfo hurtInfo)
|
|
{
|
|
if (hurtInfo.Damage > 0)
|
|
target.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 Main.remixWorld ? 4.5f : SpawnCondition.CaveJellyfish.Chance * 0.5f;
|
|
|
|
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(NPC.HitInfo hit)
|
|
{
|
|
for (int k = 0; k < 5; k++)
|
|
{
|
|
Dust.NewDust(NPC.position, NPC.width, NPC.height, 5, hit.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, hit.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 || Main.zenithWorld)
|
|
{
|
|
NPC.scale += 0.05f;
|
|
}
|
|
}
|
|
}
|
|
}
|