490 lines
20 KiB
C#
490 lines
20 KiB
C#
using CalamityMod.Buffs.DamageOverTime;
|
|
using Microsoft.Xna.Framework;
|
|
using System;
|
|
using System.IO;
|
|
using Terraria;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
namespace CalamityMod.NPCs.DevourerofGods
|
|
{
|
|
public class DevourerofGodsHead2 : ModNPC
|
|
{
|
|
private bool tail = false;
|
|
private bool flies = false;
|
|
private const int minLength = 15;
|
|
private const int maxLength = 16;
|
|
private int invinceTime = 180;
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
DisplayName.SetDefault("Cosmic Guardian");
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
npc.damage = 180;
|
|
npc.npcSlots = 5f;
|
|
npc.width = 64;
|
|
npc.height = 76;
|
|
npc.defense = 40;
|
|
npc.lifeMax = 100000;
|
|
npc.aiStyle = 6;
|
|
aiType = -1;
|
|
npc.knockBackResist = 0f;
|
|
npc.alpha = 255;
|
|
npc.behindTiles = true;
|
|
npc.noGravity = true;
|
|
npc.noTileCollide = true;
|
|
npc.canGhostHeal = false;
|
|
npc.HitSound = SoundID.NPCHit4;
|
|
npc.DeathSound = SoundID.NPCDeath14;
|
|
npc.netAlways = true;
|
|
for (int k = 0; k < npc.buffImmune.Length; k++)
|
|
{
|
|
npc.buffImmune[k] = true;
|
|
}
|
|
}
|
|
|
|
public override void SendExtraAI(BinaryWriter writer)
|
|
{
|
|
writer.Write(invinceTime);
|
|
writer.Write(npc.dontTakeDamage);
|
|
}
|
|
|
|
public override void ReceiveExtraAI(BinaryReader reader)
|
|
{
|
|
invinceTime = reader.ReadInt32();
|
|
npc.dontTakeDamage = reader.ReadBoolean();
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
bool expertMode = Main.expertMode;
|
|
float playerRunAcceleration = Main.player[npc.target].velocity.Y == 0f ? Math.Abs(Main.player[npc.target].moveSpeed * 0.3f) : (Main.player[npc.target].runAcceleration * 0.8f);
|
|
if (playerRunAcceleration <= 1f)
|
|
{
|
|
playerRunAcceleration = 1f;
|
|
}
|
|
if (invinceTime > 0)
|
|
{
|
|
invinceTime--;
|
|
npc.damage = 0;
|
|
npc.dontTakeDamage = true;
|
|
}
|
|
else
|
|
{
|
|
npc.damage = npc.defDamage;
|
|
npc.dontTakeDamage = false;
|
|
}
|
|
Vector2 vector = npc.Center;
|
|
Lighting.AddLight((int)((npc.position.X + (float)(npc.width / 2)) / 16f), (int)((npc.position.Y + (float)(npc.height / 2)) / 16f), 0.2f, 0.05f, 0.2f);
|
|
if (npc.ai[3] > 0f)
|
|
{
|
|
npc.realLife = (int)npc.ai[3];
|
|
}
|
|
if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead)
|
|
{
|
|
npc.TargetClosest(true);
|
|
}
|
|
npc.velocity.Length();
|
|
if (npc.alpha != 0)
|
|
{
|
|
int num935 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 182, 0f, 0f, 100, default, 2f);
|
|
Main.dust[num935].noGravity = true;
|
|
Main.dust[num935].noLight = true;
|
|
}
|
|
npc.alpha -= 12;
|
|
if (npc.alpha < 0)
|
|
{
|
|
npc.alpha = 0;
|
|
}
|
|
if (Main.netMode != NetmodeID.MultiplayerClient)
|
|
{
|
|
if (!tail && npc.ai[0] == 0f)
|
|
{
|
|
int Previous = npc.whoAmI;
|
|
for (int segmentSpawn = 0; segmentSpawn < maxLength; segmentSpawn++)
|
|
{
|
|
int segment;
|
|
if (segmentSpawn >= 0 && segmentSpawn < minLength)
|
|
{
|
|
segment = NPC.NewNPC((int)npc.position.X + (npc.width / 2), (int)npc.position.Y + (npc.height / 2), ModContent.NPCType<DevourerofGodsBody2>(), npc.whoAmI);
|
|
}
|
|
else
|
|
{
|
|
segment = NPC.NewNPC((int)npc.position.X + (npc.width / 2), (int)npc.position.Y + (npc.height / 2), ModContent.NPCType<DevourerofGodsTail2>(), npc.whoAmI);
|
|
}
|
|
Main.npc[segment].realLife = npc.whoAmI;
|
|
Main.npc[segment].ai[2] = (float)npc.whoAmI;
|
|
Main.npc[segment].ai[1] = (float)Previous;
|
|
Main.npc[Previous].ai[0] = (float)segment;
|
|
npc.netUpdate = true;
|
|
Previous = segment;
|
|
}
|
|
tail = true;
|
|
}
|
|
if (!npc.active && Main.netMode == NetmodeID.Server)
|
|
{
|
|
NetMessage.SendData(28, -1, -1, null, npc.whoAmI, -1f, 0f, 0f, 0, 0, 0);
|
|
}
|
|
}
|
|
if (CalamityGlobalNPC.DoGHead < 0 || !Main.npc[CalamityGlobalNPC.DoGHead].active)
|
|
{
|
|
for (int num569 = 0; num569 < 200; num569++)
|
|
{
|
|
if (Main.npc[num569].active && (Main.npc[num569].type == ModContent.NPCType<DevourerofGodsHead2>() || Main.npc[num569].type == ModContent.NPCType<DevourerofGodsBody2>() || Main.npc[num569].type == ModContent.NPCType<DevourerofGodsTail2>()))
|
|
{
|
|
Main.npc[num569].active = false;
|
|
}
|
|
}
|
|
}
|
|
if (Main.player[npc.target].dead)
|
|
{
|
|
npc.TargetClosest(false);
|
|
flies = true;
|
|
npc.velocity.Y = npc.velocity.Y - 3f;
|
|
if ((double)npc.position.Y < Main.topWorld + 16f)
|
|
{
|
|
npc.velocity.Y = npc.velocity.Y - 3f;
|
|
}
|
|
if ((double)npc.position.Y < Main.topWorld + 16f)
|
|
{
|
|
for (int a = 0; a < 200; a++)
|
|
{
|
|
if (Main.npc[a].aiStyle == npc.aiStyle)
|
|
{
|
|
Main.npc[a].active = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
int num180 = (int)(npc.position.X / 16f) - 1;
|
|
int num181 = (int)((npc.position.X + (float)npc.width) / 16f) + 2;
|
|
int num182 = (int)(npc.position.Y / 16f) - 1;
|
|
int num183 = (int)((npc.position.Y + (float)npc.height) / 16f) + 2;
|
|
if (num180 < 0)
|
|
{
|
|
num180 = 0;
|
|
}
|
|
if (num181 > Main.maxTilesX)
|
|
{
|
|
num181 = Main.maxTilesX;
|
|
}
|
|
if (num182 < 0)
|
|
{
|
|
num182 = 0;
|
|
}
|
|
if (num183 > Main.maxTilesY)
|
|
{
|
|
num183 = Main.maxTilesY;
|
|
}
|
|
float speed = playerRunAcceleration * 16f;
|
|
float turnSpeed = playerRunAcceleration * 0.23f;
|
|
if (Vector2.Distance(Main.player[npc.target].Center, vector) > 3000f) //RAGE
|
|
{
|
|
speed = playerRunAcceleration * 60f;
|
|
turnSpeed = playerRunAcceleration * 0.8f;
|
|
}
|
|
if (!flies)
|
|
{
|
|
for (int num952 = num180; num952 < num181; num952++)
|
|
{
|
|
for (int num953 = num182; num953 < num183; num953++)
|
|
{
|
|
if (Main.tile[num952, num953] != null && ((Main.tile[num952, num953].nactive() && (Main.tileSolid[(int)Main.tile[num952, num953].type] || (Main.tileSolidTop[(int)Main.tile[num952, num953].type] && Main.tile[num952, num953].frameY == 0))) || Main.tile[num952, num953].liquid > 64))
|
|
{
|
|
Vector2 vector105;
|
|
vector105.X = (float)(num952 * 16);
|
|
vector105.Y = (float)(num953 * 16);
|
|
if (npc.position.X + (float)npc.width > vector105.X && npc.position.X < vector105.X + 16f && npc.position.Y + (float)npc.height > vector105.Y && npc.position.Y < vector105.Y + 16f)
|
|
{
|
|
flies = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!flies)
|
|
{
|
|
npc.localAI[1] = 1f;
|
|
Rectangle rectangle12 = new Rectangle((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height);
|
|
int num954 = 1000;
|
|
bool flag95 = true;
|
|
if (npc.position.Y > Main.player[npc.target].position.Y)
|
|
{
|
|
for (int num955 = 0; num955 < 255; num955++)
|
|
{
|
|
if (Main.player[num955].active)
|
|
{
|
|
Rectangle rectangle13 = new Rectangle((int)Main.player[num955].position.X - num954, (int)Main.player[num955].position.Y - num954, num954 * 2, num954 * 2);
|
|
if (rectangle12.Intersects(rectangle13))
|
|
{
|
|
flag95 = false;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (flag95)
|
|
{
|
|
flies = true;
|
|
}
|
|
}
|
|
}
|
|
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);
|
|
float num191 = Main.player[npc.target].position.X + (float)(Main.player[npc.target].width / 2);
|
|
float num192 = Main.player[npc.target].position.Y + (float)(Main.player[npc.target].height / 2);
|
|
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));
|
|
if (!flies)
|
|
{
|
|
npc.TargetClosest(true);
|
|
npc.velocity.Y = npc.velocity.Y + (turnSpeed * 0.5f);
|
|
if (npc.velocity.Y > num188)
|
|
{
|
|
npc.velocity.Y = num188;
|
|
}
|
|
if ((double)(System.Math.Abs(npc.velocity.X) + System.Math.Abs(npc.velocity.Y)) < (double)num188 * 0.4)
|
|
{
|
|
if (npc.velocity.X < 0f)
|
|
{
|
|
npc.velocity.X = npc.velocity.X - num189 * 1.1f;
|
|
}
|
|
else
|
|
{
|
|
npc.velocity.X = npc.velocity.X + num189 * 1.1f;
|
|
}
|
|
}
|
|
else if (npc.velocity.Y == num188)
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
else if (npc.velocity.Y > 4f)
|
|
{
|
|
if (npc.velocity.X < 0f)
|
|
{
|
|
npc.velocity.X = npc.velocity.X + num189 * 0.9f;
|
|
}
|
|
else
|
|
{
|
|
npc.velocity.X = npc.velocity.X - num189 * 0.9f;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!flies && npc.behindTiles && npc.soundDelay == 0)
|
|
{
|
|
float num195 = num193 / 40f;
|
|
if (num195 < 10f)
|
|
{
|
|
num195 = 10f;
|
|
}
|
|
if (num195 > 20f)
|
|
{
|
|
num195 = 20f;
|
|
}
|
|
npc.soundDelay = (int)num195;
|
|
Main.PlaySound(15, (int)npc.position.X, (int)npc.position.Y, 1);
|
|
}
|
|
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;
|
|
}
|
|
else
|
|
{
|
|
npc.velocity.X = npc.velocity.X - num189 * 2f;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (num196 > num197)
|
|
{
|
|
if (npc.velocity.X < num191)
|
|
{
|
|
npc.velocity.X = npc.velocity.X + num189 * 1.1f;
|
|
}
|
|
else if (npc.velocity.X > num191)
|
|
{
|
|
npc.velocity.X = npc.velocity.X - num189 * 1.1f;
|
|
}
|
|
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;
|
|
if (flies)
|
|
{
|
|
if (npc.localAI[0] != 1f)
|
|
{
|
|
npc.netUpdate = true;
|
|
}
|
|
npc.localAI[0] = 1f;
|
|
}
|
|
else
|
|
{
|
|
if (npc.localAI[0] != 0f)
|
|
{
|
|
npc.netUpdate = true;
|
|
}
|
|
npc.localAI[0] = 0f;
|
|
}
|
|
if (((npc.velocity.X > 0f && npc.oldVelocity.X < 0f) || (npc.velocity.X < 0f && npc.oldVelocity.X > 0f) || (npc.velocity.Y > 0f && npc.oldVelocity.Y < 0f) || (npc.velocity.Y < 0f && npc.oldVelocity.Y > 0f)) && !npc.justHit)
|
|
{
|
|
npc.netUpdate = true;
|
|
}
|
|
}
|
|
|
|
public override void BossLoot(ref string name, ref int potionType)
|
|
{
|
|
potionType = ItemID.None;
|
|
}
|
|
|
|
public override bool CanHitPlayer(Player target, ref int cooldownSlot)
|
|
{
|
|
cooldownSlot = 1;
|
|
return true;
|
|
}
|
|
|
|
public override bool? DrawHealthBar(byte hbPosition, ref float scale, ref Vector2 position)
|
|
{
|
|
scale = 1.5f;
|
|
return null;
|
|
}
|
|
|
|
public override bool CheckActive()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public override void HitEffect(int hitDirection, double damage)
|
|
{
|
|
if (npc.life <= 0)
|
|
{
|
|
Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/DoT"), 1f);
|
|
npc.position.X = npc.position.X + (float)(npc.width / 2);
|
|
npc.position.Y = npc.position.Y + (float)(npc.height / 2);
|
|
npc.width = 50;
|
|
npc.height = 50;
|
|
npc.position.X = npc.position.X - (float)(npc.width / 2);
|
|
npc.position.Y = npc.position.Y - (float)(npc.height / 2);
|
|
for (int num621 = 0; num621 < 15; num621++)
|
|
{
|
|
int num622 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 173, 0f, 0f, 100, default, 2f);
|
|
Main.dust[num622].velocity *= 3f;
|
|
if (Main.rand.NextBool(2))
|
|
{
|
|
Main.dust[num622].scale = 0.5f;
|
|
Main.dust[num622].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f;
|
|
}
|
|
}
|
|
for (int num623 = 0; num623 < 30; num623++)
|
|
{
|
|
int num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 173, 0f, 0f, 100, default, 3f);
|
|
Main.dust[num624].noGravity = true;
|
|
Main.dust[num624].velocity *= 5f;
|
|
num624 = Dust.NewDust(new Vector2(npc.position.X, npc.position.Y), npc.width, npc.height, 173, 0f, 0f, 100, default, 2f);
|
|
Main.dust[num624].velocity *= 2f;
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void OnHitPlayer(Player player, int damage, bool crit)
|
|
{
|
|
player.AddBuff(ModContent.BuffType<GodSlayerInferno>(), 180, true);
|
|
player.AddBuff(BuffID.Frostburn, 180, true);
|
|
player.AddBuff(BuffID.Darkness, 180, true);
|
|
}
|
|
}
|
|
}
|