328 lines
12 KiB
C#
328 lines
12 KiB
C#
using CalamityMod.Buffs.DamageOverTime;
|
|
using CalamityMod.Items.Materials;
|
|
using CalamityMod.Items.Placeables.Banners;
|
|
using CalamityMod.World;
|
|
using Microsoft.Xna.Framework;
|
|
using System;
|
|
using System.IO;
|
|
using Terraria;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
|
|
namespace CalamityMod.NPCs.Abyss
|
|
{
|
|
public class OarfishHead : ModNPC
|
|
{
|
|
private Vector2 patrolSpot = Vector2.Zero;
|
|
public bool detectsPlayer = false;
|
|
public const int minLength = 40;
|
|
public const int maxLength = 41;
|
|
public float speed = 3f; //10
|
|
public float turnSpeed = 0.05f; //0.15
|
|
bool TailSpawned = false;
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
DisplayName.SetDefault("Oarfish");
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
npc.damage = 60;
|
|
npc.width = 59;
|
|
npc.height = 38;
|
|
npc.defense = 10;
|
|
npc.lifeMax = 4000;
|
|
npc.aiStyle = -1;
|
|
aiType = -1;
|
|
npc.knockBackResist = 0f;
|
|
npc.value = Item.buyPrice(0, 0, 10, 0);
|
|
npc.behindTiles = true;
|
|
npc.noGravity = true;
|
|
npc.noTileCollide = true;
|
|
npc.HitSound = SoundID.NPCHit1;
|
|
npc.DeathSound = SoundID.NPCDeath1;
|
|
npc.netAlways = true;
|
|
banner = npc.type;
|
|
bannerItem = ModContent.ItemType<OarfishBanner>();
|
|
npc.Calamity().VulnerableToHeat = false;
|
|
npc.Calamity().VulnerableToSickness = true;
|
|
npc.Calamity().VulnerableToElectricity = true;
|
|
npc.Calamity().VulnerableToWater = false;
|
|
}
|
|
|
|
public override void SendExtraAI(BinaryWriter writer)
|
|
{
|
|
writer.WriteVector2(patrolSpot);
|
|
writer.Write(detectsPlayer);
|
|
writer.Write(npc.chaseable);
|
|
}
|
|
|
|
public override void ReceiveExtraAI(BinaryReader reader)
|
|
{
|
|
patrolSpot = reader.ReadVector2();
|
|
detectsPlayer = reader.ReadBoolean();
|
|
npc.chaseable = reader.ReadBoolean();
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
if ((Main.player[npc.target].Center - npc.Center).Length() < Main.player[npc.target].Calamity().GetAbyssAggro(250f, 150f) || npc.justHit)
|
|
detectsPlayer = true;
|
|
|
|
npc.chaseable = detectsPlayer;
|
|
|
|
if (npc.ai[2] > 0f)
|
|
npc.realLife = (int)npc.ai[2];
|
|
|
|
if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead)
|
|
npc.TargetClosest(true);
|
|
|
|
if (Main.netMode != NetmodeID.MultiplayerClient)
|
|
{
|
|
if (!TailSpawned && npc.ai[0] == 0f)
|
|
{
|
|
int Previous = npc.whoAmI;
|
|
for (int num36 = 0; num36 < maxLength; num36++)
|
|
{
|
|
int lol;
|
|
if (num36 >= 0 && num36 < minLength)
|
|
{
|
|
lol = NPC.NewNPC((int)npc.position.X + (npc.width / 2), (int)npc.position.Y + (npc.height / 2), ModContent.NPCType<OarfishBody>(), npc.whoAmI);
|
|
}
|
|
else
|
|
{
|
|
lol = NPC.NewNPC((int)npc.position.X + (npc.width / 2), (int)npc.position.Y + (npc.height / 2), ModContent.NPCType<OarfishTail>(), npc.whoAmI);
|
|
}
|
|
Main.npc[lol].realLife = npc.whoAmI;
|
|
Main.npc[lol].ai[2] = (float)npc.whoAmI;
|
|
Main.npc[lol].ai[1] = (float)Previous;
|
|
Main.npc[Previous].ai[0] = (float)lol;
|
|
NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, lol, 0f, 0f, 0f, 0);
|
|
Previous = lol;
|
|
}
|
|
TailSpawned = true;
|
|
}
|
|
}
|
|
|
|
if (npc.velocity.X < 0f)
|
|
npc.spriteDirection = -1;
|
|
else if (npc.velocity.X > 0f)
|
|
npc.spriteDirection = 1;
|
|
|
|
if (Main.player[npc.target].dead)
|
|
npc.TargetClosest(false);
|
|
|
|
npc.alpha -= 42;
|
|
if (npc.alpha < 0)
|
|
npc.alpha = 0;
|
|
|
|
if (Vector2.Distance(Main.player[npc.target].Center, npc.Center) > 5600f)
|
|
npc.active = false;
|
|
|
|
float num188 = speed;
|
|
float num189 = turnSpeed;
|
|
Vector2 vector18 = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f);
|
|
|
|
if (patrolSpot == Vector2.Zero)
|
|
patrolSpot = Main.player[npc.target].Center;
|
|
|
|
float num191 = detectsPlayer ? Main.player[npc.target].Center.X : patrolSpot.X;
|
|
float num192 = detectsPlayer ? Main.player[npc.target].Center.Y : patrolSpot.Y;
|
|
|
|
if (!detectsPlayer)
|
|
{
|
|
num192 += 300;
|
|
if (Math.Abs(npc.Center.X - num191) < 250f) //500
|
|
{
|
|
if (npc.velocity.X > 0f)
|
|
{
|
|
num191 += 300f;
|
|
}
|
|
else
|
|
{
|
|
num191 -= 300f;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
num188 *= 1.5f;
|
|
num189 *= 1.5f;
|
|
}
|
|
float num48 = num188 * 1.3f;
|
|
float num49 = num188 * 0.7f;
|
|
float num50 = npc.velocity.Length();
|
|
if (num50 > 0f)
|
|
{
|
|
if (num50 > num48)
|
|
{
|
|
npc.velocity.Normalize();
|
|
npc.velocity *= num48;
|
|
}
|
|
else if (num50 < num49)
|
|
{
|
|
npc.velocity.Normalize();
|
|
npc.velocity *= num49;
|
|
}
|
|
}
|
|
num191 = (float)((int)(num191 / 16f) * 16);
|
|
num192 = (float)((int)(num192 / 16f) * 16);
|
|
vector18.X = (float)((int)(vector18.X / 16f) * 16);
|
|
vector18.Y = (float)((int)(vector18.Y / 16f) * 16);
|
|
num191 -= vector18.X;
|
|
num192 -= vector18.Y;
|
|
float num193 = (float)System.Math.Sqrt((double)(num191 * num191 + num192 * num192));
|
|
float num196 = System.Math.Abs(num191);
|
|
float num197 = System.Math.Abs(num192);
|
|
float num198 = num188 / num193;
|
|
num191 *= num198;
|
|
num192 *= num198;
|
|
if ((npc.velocity.X > 0f && num191 > 0f) || (npc.velocity.X < 0f && num191 < 0f) || (npc.velocity.Y > 0f && num192 > 0f) || (npc.velocity.Y < 0f && num192 < 0f))
|
|
{
|
|
if (npc.velocity.X < num191)
|
|
{
|
|
npc.velocity.X = npc.velocity.X + num189;
|
|
}
|
|
else
|
|
{
|
|
if (npc.velocity.X > num191)
|
|
{
|
|
npc.velocity.X = npc.velocity.X - num189;
|
|
}
|
|
}
|
|
if (npc.velocity.Y < num192)
|
|
{
|
|
npc.velocity.Y = npc.velocity.Y + num189;
|
|
}
|
|
else
|
|
{
|
|
if (npc.velocity.Y > num192)
|
|
{
|
|
npc.velocity.Y = npc.velocity.Y - num189;
|
|
}
|
|
}
|
|
if ((double)System.Math.Abs(num192) < (double)num188 * 0.2 && ((npc.velocity.X > 0f && num191 < 0f) || (npc.velocity.X < 0f && num191 > 0f)))
|
|
{
|
|
if (npc.velocity.Y > 0f)
|
|
{
|
|
npc.velocity.Y = npc.velocity.Y + num189 * 2f;
|
|
}
|
|
else
|
|
{
|
|
npc.velocity.Y = npc.velocity.Y - num189 * 2f;
|
|
}
|
|
}
|
|
if ((double)System.Math.Abs(num191) < (double)num188 * 0.2 && ((npc.velocity.Y > 0f && num192 < 0f) || (npc.velocity.Y < 0f && num192 > 0f)))
|
|
{
|
|
if (npc.velocity.X > 0f)
|
|
{
|
|
npc.velocity.X = npc.velocity.X + num189 * 2f; //changed from 2
|
|
}
|
|
else
|
|
{
|
|
npc.velocity.X = npc.velocity.X - num189 * 2f; //changed from 2
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (num196 > num197)
|
|
{
|
|
if (npc.velocity.X < num191)
|
|
{
|
|
npc.velocity.X = npc.velocity.X + num189 * 1.1f; //changed from 1.1
|
|
}
|
|
else if (npc.velocity.X > num191)
|
|
{
|
|
npc.velocity.X = npc.velocity.X - num189 * 1.1f; //changed from 1.1
|
|
}
|
|
if ((double)(System.Math.Abs(npc.velocity.X) + System.Math.Abs(npc.velocity.Y)) < (double)num188 * 0.5)
|
|
{
|
|
if (npc.velocity.Y > 0f)
|
|
{
|
|
npc.velocity.Y = npc.velocity.Y + num189;
|
|
}
|
|
else
|
|
{
|
|
npc.velocity.Y = npc.velocity.Y - num189;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (npc.velocity.Y < num192)
|
|
{
|
|
npc.velocity.Y = npc.velocity.Y + num189 * 1.1f;
|
|
}
|
|
else if (npc.velocity.Y > num192)
|
|
{
|
|
npc.velocity.Y = npc.velocity.Y - num189 * 1.1f;
|
|
}
|
|
if ((double)(System.Math.Abs(npc.velocity.X) + System.Math.Abs(npc.velocity.Y)) < (double)num188 * 0.5)
|
|
{
|
|
if (npc.velocity.X > 0f)
|
|
{
|
|
npc.velocity.X = npc.velocity.X + num189;
|
|
}
|
|
else
|
|
{
|
|
npc.velocity.X = npc.velocity.X - num189;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
npc.rotation = (float)System.Math.Atan2((double)npc.velocity.Y, (double)npc.velocity.X) + 1.57f;
|
|
}
|
|
|
|
public override bool? CanBeHitByProjectile(Projectile projectile)
|
|
{
|
|
if (projectile.minion && !projectile.Calamity().overridesMinionDamagePrevention)
|
|
{
|
|
return detectsPlayer;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public override float SpawnChance(NPCSpawnInfo spawnInfo)
|
|
{
|
|
if (spawnInfo.player.Calamity().ZoneAbyssLayer2 && spawnInfo.water && !NPC.AnyNPCs(ModContent.NPCType<OarfishHead>()))
|
|
{
|
|
return SpawnCondition.CaveJellyfish.Chance * 0.3f;
|
|
}
|
|
if (spawnInfo.player.Calamity().ZoneAbyssLayer3 && spawnInfo.water && !NPC.AnyNPCs(ModContent.NPCType<OarfishHead>()))
|
|
{
|
|
return SpawnCondition.CaveJellyfish.Chance * 0.6f;
|
|
}
|
|
return 0f;
|
|
}
|
|
|
|
public override void NPCLoot()
|
|
{
|
|
int minCells = Main.expertMode ? 4 : 3;
|
|
int maxCells = Main.expertMode ? 7 : 5;
|
|
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 < 3; k++)
|
|
{
|
|
Dust.NewDust(npc.position, npc.width, npc.height, DustID.Blood, hitDirection, -1f, 0, default, 1f);
|
|
}
|
|
if (npc.life <= 0)
|
|
{
|
|
for (int k = 0; k < 10; k++)
|
|
{
|
|
Dust.NewDust(npc.position, npc.width, npc.height, DustID.Blood, hitDirection, -1f, 0, default, 1f);
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void OnHitPlayer(Player player, int damage, bool crit)
|
|
{
|
|
player.AddBuff(ModContent.BuffType<CrushDepth>(), 90);
|
|
}
|
|
}
|
|
}
|