271 lines
9.9 KiB
C#
271 lines
9.9 KiB
C#
using CalamityMod.Buffs.DamageOverTime;
|
|
using CalamityMod.Buffs.StatDebuffs;
|
|
using CalamityMod.CalPlayer;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using System;
|
|
using Terraria;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
|
|
namespace CalamityMod.Projectiles.Summon
|
|
{
|
|
public class MagicAxe : ModProjectile
|
|
{
|
|
private int counter = 0;
|
|
public override void SetStaticDefaults()
|
|
{
|
|
DisplayName.SetDefault("Axe");
|
|
ProjectileID.Sets.TrailCacheLength[projectile.type] = 4;
|
|
ProjectileID.Sets.TrailingMode[projectile.type] = 0;
|
|
ProjectileID.Sets.MinionShot[projectile.type] = true;
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
projectile.width = 52;
|
|
projectile.height = 52;
|
|
projectile.netImportant = true;
|
|
projectile.friendly = true;
|
|
projectile.ignoreWater = true;
|
|
projectile.minionSlots = 0;
|
|
projectile.timeLeft = 180;
|
|
projectile.penetrate = -1;
|
|
projectile.minion = true;
|
|
projectile.tileCollide = false;
|
|
projectile.extraUpdates = 1;
|
|
projectile.usesLocalNPCImmunity = true;
|
|
projectile.localNPCHitCooldown = 8;
|
|
projectile.alpha = 255;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
Player player = Main.player[projectile.owner];
|
|
CalamityPlayer modPlayer = player.Calamity();
|
|
|
|
projectile.rotation += 0.075f;
|
|
projectile.alpha -= 50;
|
|
float num634 = 1200f;
|
|
float num635 = 2500f;
|
|
float num637 = 0.05f;
|
|
for (int num638 = 0; num638 < Main.projectile.Length; num638++)
|
|
{
|
|
bool flag23 = Main.projectile[num638].type == ModContent.ProjectileType<MagicAxe>();
|
|
if (num638 != projectile.whoAmI && Main.projectile[num638].active && Main.projectile[num638].owner == projectile.owner && flag23 && Math.Abs(projectile.position.X - Main.projectile[num638].position.X) + Math.Abs(projectile.position.Y - Main.projectile[num638].position.Y) < (float)projectile.width)
|
|
{
|
|
if (projectile.position.X < Main.projectile[num638].position.X)
|
|
{
|
|
projectile.velocity.X = projectile.velocity.X - num637;
|
|
}
|
|
else
|
|
{
|
|
projectile.velocity.X = projectile.velocity.X + num637;
|
|
}
|
|
if (projectile.position.Y < Main.projectile[num638].position.Y)
|
|
{
|
|
projectile.velocity.Y = projectile.velocity.Y - num637;
|
|
}
|
|
else
|
|
{
|
|
projectile.velocity.Y = projectile.velocity.Y + num637;
|
|
}
|
|
}
|
|
}
|
|
if (projectile.ai[1] <= 30)
|
|
{
|
|
projectile.ai[1]++;
|
|
return;
|
|
}
|
|
bool flag24 = false;
|
|
if (projectile.ai[0] == 2f)
|
|
{
|
|
counter += 1;
|
|
projectile.extraUpdates = 4;
|
|
if (counter > 30)
|
|
{
|
|
counter = 1;
|
|
projectile.ai[0] = 0f;
|
|
projectile.extraUpdates = 1;
|
|
projectile.numUpdates = 0;
|
|
projectile.netUpdate = true;
|
|
}
|
|
else
|
|
{
|
|
flag24 = true;
|
|
}
|
|
}
|
|
if (flag24)
|
|
{
|
|
return;
|
|
}
|
|
Vector2 vector46 = projectile.position;
|
|
float homingRange = MagicHat.Range;
|
|
bool homeIn = false;
|
|
if (player.HasMinionAttackTargetNPC)
|
|
{
|
|
NPC npc = Main.npc[player.MinionAttackTargetNPC];
|
|
if (npc.CanBeChasedBy(projectile, false))
|
|
{
|
|
float num646 = Vector2.Distance(npc.Center, projectile.Center);
|
|
if (!homeIn && num646 < homingRange)
|
|
{
|
|
homingRange = num646;
|
|
vector46 = npc.Center;
|
|
homeIn = true;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int num645 = 0; num645 < Main.npc.Length; num645++)
|
|
{
|
|
NPC nPC2 = Main.npc[num645];
|
|
if (nPC2.CanBeChasedBy(projectile, false))
|
|
{
|
|
float num646 = Vector2.Distance(nPC2.Center, projectile.Center);
|
|
if (!homeIn && num646 < homingRange)
|
|
{
|
|
homingRange = num646;
|
|
vector46 = nPC2.Center;
|
|
homeIn = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
float num647 = num634;
|
|
if (homeIn)
|
|
{
|
|
num647 = num635;
|
|
}
|
|
if (Vector2.Distance(player.Center, projectile.Center) > num647)
|
|
{
|
|
projectile.ai[0] = 1f;
|
|
projectile.netUpdate = true;
|
|
}
|
|
if (homeIn && projectile.ai[0] == 0f)
|
|
{
|
|
Vector2 vector47 = vector46 - projectile.Center;
|
|
float num648 = vector47.Length();
|
|
vector47.Normalize();
|
|
if (num648 > 200f)
|
|
{
|
|
float scaleFactor2 = 24f; //8
|
|
vector47 *= scaleFactor2;
|
|
projectile.velocity = (projectile.velocity * 40f + vector47) / 41f;
|
|
}
|
|
else
|
|
{
|
|
float num649 = 12f; //4
|
|
vector47 *= -num649;
|
|
projectile.velocity = (projectile.velocity * 40f + vector47) / 41f; //41
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bool flag26 = false;
|
|
float num636 = 400f;
|
|
if (!flag26)
|
|
{
|
|
flag26 = projectile.ai[0] == 1f;
|
|
}
|
|
float num650 = 6f;
|
|
if (flag26)
|
|
{
|
|
num650 = 15f;
|
|
}
|
|
Vector2 center2 = projectile.Center;
|
|
Vector2 vector48 = player.Center - center2 + new Vector2(0f, -60f);
|
|
float playerDist = vector48.Length();
|
|
if (playerDist > 200f && num650 < 8f)
|
|
{
|
|
num650 = 8f;
|
|
}
|
|
if (playerDist < num636 && flag26 && !Collision.SolidCollision(projectile.position, projectile.width, projectile.height))
|
|
{
|
|
projectile.ai[0] = 0f;
|
|
projectile.netUpdate = true;
|
|
}
|
|
if (playerDist > 2000f)
|
|
{
|
|
projectile.position.X = player.Center.X - (float)(projectile.width / 2);
|
|
projectile.position.Y = player.Center.Y - (float)(projectile.height / 2);
|
|
projectile.netUpdate = true;
|
|
}
|
|
if (playerDist > 70f)
|
|
{
|
|
vector48.Normalize();
|
|
vector48 *= num650;
|
|
projectile.velocity = (projectile.velocity * 40f + vector48) / 41f;
|
|
}
|
|
else if (projectile.velocity.X == 0f && projectile.velocity.Y == 0f)
|
|
{
|
|
projectile.velocity.X = -0.15f;
|
|
projectile.velocity.Y = -0.05f;
|
|
}
|
|
}
|
|
if (counter > 0)
|
|
{
|
|
counter += Main.rand.Next(1, 4);
|
|
}
|
|
if (counter > 30)
|
|
{
|
|
counter = 0;
|
|
projectile.netUpdate = true;
|
|
}
|
|
if (projectile.ai[0] == 0f)
|
|
{
|
|
if (counter == 0 && homeIn && homingRange < 500f)
|
|
{
|
|
counter += 1;
|
|
if (Main.myPlayer == projectile.owner)
|
|
{
|
|
projectile.ai[0] = 2f;
|
|
Vector2 value20 = vector46 - projectile.Center;
|
|
value20.Normalize();
|
|
projectile.velocity = value20 * 16f; //8
|
|
projectile.netUpdate = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public override Color? GetAlpha(Color lightColor)
|
|
{
|
|
return new Color(0, 255, 111, projectile.alpha);
|
|
}
|
|
|
|
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
|
|
{
|
|
CalamityGlobalProjectile.DrawCenteredAndAfterimage(projectile, lightColor, ProjectileID.Sets.TrailingMode[projectile.type], 1);
|
|
return false;
|
|
}
|
|
|
|
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
|
|
{
|
|
target.AddBuff(ModContent.BuffType<BrimstoneFlames>(), 120);
|
|
target.AddBuff(ModContent.BuffType<GlacialState>(), 120);
|
|
target.AddBuff(ModContent.BuffType<Plague>(), 120);
|
|
target.AddBuff(ModContent.BuffType<HolyFlames>(), 120);
|
|
}
|
|
|
|
public override void OnHitPvp(Player target, int damage, bool crit)
|
|
{
|
|
target.AddBuff(ModContent.BuffType<BrimstoneFlames>(), 120);
|
|
target.AddBuff(ModContent.BuffType<GlacialState>(), 120);
|
|
target.AddBuff(ModContent.BuffType<Plague>(), 120);
|
|
target.AddBuff(ModContent.BuffType<HolyFlames>(), 120);
|
|
}
|
|
|
|
public override void Kill(int timeLeft)
|
|
{
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
Vector2 dspeed = new Vector2(Main.rand.NextFloat(-7f, 7f), Main.rand.NextFloat(-7f, 7f));
|
|
int dust = Dust.NewDust(projectile.Center, 1, 1, 66, dspeed.X, dspeed.Y, 160, new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB), 0.75f);
|
|
Main.dust[dust].noGravity = true;
|
|
}
|
|
}
|
|
}
|
|
}
|