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

199 lines
7.4 KiB
C#

using CalamityMod.BiomeManagers;
using CalamityMod.Items.Materials;
using CalamityMod.Items.Placeables.Banners;
using CalamityMod.Projectiles.Enemy;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.IO;
using Terraria;
using Terraria.GameContent;
using Terraria.GameContent.Bestiary;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.Utilities;
using Terraria.Audio;
namespace CalamityMod.NPCs.Abyss
{
public class ToxicMinnow : ModNPC
{
public override void SetStaticDefaults()
{
Main.npcFrameCount[NPC.type] = 4;
NPCID.Sets.NPCBestiaryDrawModifiers value = new NPCID.Sets.NPCBestiaryDrawModifiers(0)
{
Scale = 0.8f,
};
NPCID.Sets.NPCBestiaryDrawOffset[Type] = value;
}
public override void SetDefaults()
{
NPC.noGravity = true;
NPC.damage = 20;
NPC.width = 80;
NPC.height = 40;
NPC.defense = 20;
NPC.lifeMax = 240;
NPC.aiStyle = -1;
AIType = -1;
NPC.value = Item.buyPrice(0, 0, 5, 0);
NPC.HitSound = SoundID.NPCHit1;
NPC.DeathSound = SoundID.NPCDeath1;
NPC.knockBackResist = 0.15f;
Banner = NPC.type;
BannerItem = ModContent.ItemType<ToxicMinnowBanner>();
NPC.chaseable = false;
NPC.Calamity().VulnerableToHeat = false;
NPC.Calamity().VulnerableToSickness = false;
NPC.Calamity().VulnerableToElectricity = true;
NPC.Calamity().VulnerableToWater = false;
SpawnModBiomes = new int[2] { ModContent.GetInstance<AbyssLayer1Biome>().Type, ModContent.GetInstance<AbyssLayer2Biome>().Type };
}
public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry)
{
bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[]
{
new FlavorTextBestiaryInfoElement("Mods.CalamityMod.Bestiary.ToxicMinnow")
});
}
public override void SendExtraAI(BinaryWriter writer)
{
writer.Write(NPC.chaseable);
}
public override void ReceiveExtraAI(BinaryReader reader)
{
NPC.chaseable = reader.ReadBoolean();
}
public override void AI()
{
CalamityAI.PassiveSwimmingAI(NPC, Mod, 2, 0f, 0f, 0f, 0f, 0f, 0.1f);
}
public override bool? CanBeHitByProjectile(Projectile projectile)
{
if (projectile.minion && !projectile.Calamity().overridesMinionDamagePrevention)
{
return NPC.chaseable;
}
return null;
}
public override bool CheckDead()
{
SoundEngine.PlaySound(SoundID.NPCDeath14, NPC.Center);
NPC.position.X = NPC.position.X + (float)(NPC.width / 2);
NPC.position.Y = NPC.position.Y + (float)(NPC.height / 2);
NPC.width = NPC.height = 40;
NPC.position.X = NPC.position.X - (float)(NPC.width / 2);
NPC.position.Y = NPC.position.Y - (float)(NPC.height / 2);
if (Main.netMode != NetmodeID.MultiplayerClient)
{
Vector2 valueBoom = new Vector2(NPC.position.X + (float)NPC.width * 0.5f, NPC.position.Y + (float)NPC.height * 0.5f);
float spreadBoom = 15f * 0.0174f;
double startAngleBoom = Math.Atan2(NPC.velocity.X, NPC.velocity.Y) - spreadBoom / 2;
double deltaAngleBoom = spreadBoom / 8f;
double offsetAngleBoom;
int iBoom;
int damageBoom = 30;
for (iBoom = 0; iBoom < 5; iBoom++)
{
int projectileType = ModContent.ProjectileType<ToxicMinnowCloud>();
offsetAngleBoom = startAngleBoom + deltaAngleBoom * (iBoom + iBoom * iBoom) / 2f + 32f * iBoom;
Projectile.NewProjectile(NPC.GetSource_FromAI(), valueBoom.X, valueBoom.Y, (float)(Math.Sin(offsetAngleBoom) * 6f), (float)(Math.Cos(offsetAngleBoom) * 6f), projectileType, damageBoom, 0f, Main.myPlayer, 0f, 0f);
Projectile.NewProjectile(NPC.GetSource_FromAI(), valueBoom.X, valueBoom.Y, (float)(-Math.Sin(offsetAngleBoom) * 6f), (float)(-Math.Cos(offsetAngleBoom) * 6f), projectileType, damageBoom, 0f, Main.myPlayer, 0f, 0f);
}
}
NPC.netUpdate = true;
return true;
}
public override void PostDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor)
{
if (!NPC.IsABestiaryIconDummy)
{
Texture2D tex = ModContent.Request<Texture2D>("CalamityMod/NPCs/Abyss/ToxicMinnowGlow").Value;
var effects = NPC.direction == -1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
Main.EntitySpriteDraw(tex, NPC.Center - Main.screenPosition + new Vector2(0, NPC.gfxOffY + 4),
NPC.frame, Color.White * 0.5f, NPC.rotation, NPC.frame.Size() / 2f, NPC.scale, effects, 0);
}
}
public override void OnHitPlayer(Player target, Player.HurtInfo hurtInfo)
{
if (hurtInfo.Damage > 0)
target.AddBuff(BuffID.Poisoned, 240, true);
}
public override void FindFrame(int frameHeight)
{
if (!NPC.wet && !NPC.IsABestiaryIconDummy)
{
NPC.frameCounter = 0.0;
return;
}
if (NPC.IsABestiaryIconDummy)
{
NPC.frameCounter += 1;
if (NPC.frameCounter > 6.0)
{
NPC.frame.Y = NPC.frame.Y + frameHeight;
NPC.frameCounter = 0.0;
}
if (NPC.frame.Y >= frameHeight * 4)
{
NPC.frame.Y = 0;
}
}
else
{
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().ZoneAbyssLayer1 && spawnInfo.Water)
{
return SpawnCondition.OceanMonster.Chance * 1.5f;
}
if (spawnInfo.Player.Calamity().ZoneAbyssLayer2 && spawnInfo.Water)
{
return SpawnCondition.CaveJellyfish.Chance * 2.0f;
}
return 0f;
}
public override void ModifyNPCLoot(NPCLoot npcLoot)
{
var postClone = npcLoot.DefineConditionalDropSet(DropHelper.PostCal());
postClone.Add(DropHelper.NormalVsExpertQuantity(ModContent.ItemType<DepthCells>(), 2, 2, 3, 4, 6));
}
public override void HitEffect(NPC.HitInfo hit)
{
for (int k = 0; k < 5; k++)
{
Dust.NewDust(NPC.position, NPC.width, NPC.height, 40, 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, 40, hit.HitDirection, -1f, 0, default, 1f);
}
}
}
}
}