Files
CalamityModPublic/NPCs/SunkenSea/SeaMinnow.cs
T
Mortis3 4a856851d1 Localization stuffs
localized (hopefully) every npc in calamity that needs it
2023-07-20 10:11:57 -04:00

221 lines
7.7 KiB
C#

using CalamityMod.BiomeManagers;
using CalamityMod.Items.Placeables.Banners;
using CalamityMod.Items.Critters;
using System;
using Terraria;
using Terraria.GameContent.Bestiary;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.Utilities;
namespace CalamityMod.NPCs.SunkenSea
{
public class SeaMinnow : ModNPC
{
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.damage = 0;
NPC.width = 36;
NPC.height = 22;
NPC.defense = 0;
NPC.lifeMax = 5;
NPC.aiStyle = -1;
AIType = -1;
NPC.HitSound = SoundID.NPCHit1;
NPC.DeathSound = SoundID.NPCDeath1;
Banner = NPC.type;
BannerItem = ModContent.ItemType<SeaMinnowBanner>();
NPC.chaseable = false;
NPC.catchItem = (short)ModContent.ItemType<SeaMinnowItem>();
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.SeaMinnow")
});
}
public override void AI()
{
CalamityAI.PassiveSwimmingAI(NPC, Mod, 3, 150f, 0.25f, 0.15f, 6f, 6f, 0.05f);
NPC.spriteDirection = (NPC.direction > 0) ? 1 : -1;
NPC.noGravity = true;
bool flag14 = false;
if (NPC.direction == 0)
{
NPC.TargetClosest(true);
}
if (NPC.wet)
{
NPC.TargetClosest(false);
if (Main.player[NPC.target].wet && !Main.player[NPC.target].dead &&
(Main.player[NPC.target].Center - NPC.Center).Length() < 150f)
{
flag14 = true;
}
if ((!Main.player[NPC.target].wet || Main.player[NPC.target].dead) && flag14)
{
flag14 = false;
}
if (!flag14)
{
if (NPC.collideX || NPC.velocity.X == 0f)
{
NPC.velocity.X = NPC.velocity.X * -3f;
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) * -3f;
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;
}
}
}
if (flag14)
{
NPC.TargetClosest(true);
NPC.velocity.X = NPC.velocity.X - (float)NPC.direction * 0.25f;
NPC.velocity.Y = NPC.velocity.Y - (float)NPC.directionY * 0.15f;
if (NPC.velocity.X > 6f)
{
NPC.velocity.X = 6f;
}
if (NPC.velocity.X < -6f)
{
NPC.velocity.X = -6f;
}
if (NPC.velocity.Y > 6f)
{
NPC.velocity.Y = 6f;
}
if (NPC.velocity.Y < -6f)
{
NPC.velocity.Y = -6f;
}
NPC.direction *= -1;
}
else
{
NPC.velocity.X = NPC.velocity.X + (float)NPC.direction * 0.1f;
if (NPC.velocity.X < -2.5f || NPC.velocity.X > 2.5f)
{
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 > 10f)
{
NPC.velocity.Y = 10f;
}
NPC.ai[0] = 1f;
}
NPC.rotation = NPC.velocity.X * 0.05f;
if ((double)NPC.rotation < -0.1)
{
NPC.rotation = -0.1f;
}
if ((double)NPC.rotation > 0.1)
{
NPC.rotation = 0.1f;
return;
}
}
public override void FindFrame(int frameHeight)
{
if (!NPC.wet && !NPC.IsABestiaryIconDummy)
{
NPC.frameCounter = 0.0;
return;
}
NPC.frameCounter += 0.075f;
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 * 0.6f;
}
return 0f;
}
public override void HitEffect(NPC.HitInfo hit)
{
for (int k = 0; k < 5; k++)
{
Dust.NewDust(NPC.position, NPC.width, NPC.height, 68, hit.HitDirection, -1f, 0, default, 1f);
}
}
}
}