176 lines
7.0 KiB
C#
176 lines
7.0 KiB
C#
using CalamityMod.Buffs.DamageOverTime;
|
|
using CalamityMod.Items.Materials;
|
|
using CalamityMod.Items.Placeables.Banners;
|
|
using CalamityMod.Items.Weapons.Ranged;
|
|
using CalamityMod.Projectiles.Enemy;
|
|
using CalamityMod.World;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using System;
|
|
using System.IO;
|
|
using Terraria;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
|
|
namespace CalamityMod.NPCs.Abyss
|
|
{
|
|
public class ToxicMinnow : ModNPC
|
|
{
|
|
public override void SetStaticDefaults()
|
|
{
|
|
DisplayName.SetDefault("Toxic Minnow");
|
|
Main.npcFrameCount[npc.type] = 4;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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()
|
|
{
|
|
Main.PlaySound(SoundID.NPCDeath14, npc.position);
|
|
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;
|
|
int boom1 = Projectile.NewProjectile(valueBoom.X, valueBoom.Y, (float)(Math.Sin(offsetAngleBoom) * 6f), (float)(Math.Cos(offsetAngleBoom) * 6f), projectileType, damageBoom, 0f, Main.myPlayer, 0f, 0f);
|
|
int boom2 = Projectile.NewProjectile(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, 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)(Main.npcTexture[npc.type].Width / 2), (float)(Main.npcTexture[npc.type].Height / Main.npcFrameCount[npc.type] / 2));
|
|
Vector2 vector = center - Main.screenPosition;
|
|
vector -= new Vector2((float)ModContent.GetTexture("CalamityMod/NPCs/Abyss/ToxicMinnowGlow").Width, (float)(ModContent.GetTexture("CalamityMod/NPCs/Abyss/ToxicMinnowGlow").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.LightGreen);
|
|
Main.spriteBatch.Draw(ModContent.GetTexture("CalamityMod/NPCs/Abyss/ToxicMinnowGlow"), vector,
|
|
new Microsoft.Xna.Framework.Rectangle?(npc.frame), color, npc.rotation, vector11, 1f, spriteEffects, 0f);
|
|
}
|
|
|
|
public override void OnHitPlayer(Player player, int damage, bool crit)
|
|
{
|
|
player.AddBuff(BuffID.Poisoned, 120, true);
|
|
}
|
|
|
|
public override void FindFrame(int frameHeight)
|
|
{
|
|
if (!npc.wet)
|
|
{
|
|
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().ZoneAbyssLayer1 && spawnInfo.water)
|
|
{
|
|
return SpawnCondition.CaveJellyfish.Chance * 0.6f;
|
|
}
|
|
if (spawnInfo.player.Calamity().ZoneAbyssLayer2 && spawnInfo.water)
|
|
{
|
|
return SpawnCondition.CaveJellyfish.Chance * 0.9f;
|
|
}
|
|
if (spawnInfo.player.Calamity().ZoneAbyssLayer3 && spawnInfo.water)
|
|
{
|
|
return SpawnCondition.CaveJellyfish.Chance * 0.6f;
|
|
}
|
|
return 0f;
|
|
}
|
|
|
|
public override void NPCLoot()
|
|
{
|
|
int minCells = Main.expertMode ? 4 : 2;
|
|
int maxCells = Main.expertMode ? 6 : 3;
|
|
DropHelper.DropItemCondition(npc, ModContent.ItemType<DepthCells>(), CalamityWorld.downedCalamitas, 0.5f, minCells, maxCells);
|
|
}
|
|
|
|
public override void HitEffect(int hitDirection, double damage)
|
|
{
|
|
for (int k = 0; k < 5; k++)
|
|
{
|
|
Dust.NewDust(npc.position, npc.width, npc.height, 40, 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, hitDirection, -1f, 0, default, 1f);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|