133 lines
4.3 KiB
C#
133 lines
4.3 KiB
C#
using CalamityMod.Projectiles.Melee;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using Terraria;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
|
|
namespace CalamityMod.Projectiles.Rogue
|
|
{
|
|
public class EradicatorProjectile : ModProjectile
|
|
{
|
|
public override string Texture => "CalamityMod/Items/Weapons/Rogue/Eradicator";
|
|
internal float rotationDirection = 1f;
|
|
internal float rotationAmt = 0f;
|
|
internal float shootCounter = 0f;
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
DisplayName.SetDefault("Eradicator");
|
|
ProjectileID.Sets.TrailCacheLength[projectile.type] = 10;
|
|
ProjectileID.Sets.TrailingMode[projectile.type] = 1;
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
projectile.width = projectile.height = 58;
|
|
projectile.friendly = true;
|
|
projectile.tileCollide = false;
|
|
projectile.ignoreWater = true;
|
|
projectile.penetrate = -1;
|
|
projectile.aiStyle = 3;
|
|
projectile.timeLeft = 180;
|
|
aiType = ProjectileID.WoodenBoomerang;
|
|
projectile.usesLocalNPCImmunity = true;
|
|
projectile.localNPCHitCooldown = 18;
|
|
projectile.Calamity().rogue = true;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
Lighting.AddLight(projectile.Center, 0.35f, 0f, 0.25f);
|
|
if (projectile.aiStyle == 3)
|
|
CalamityGlobalProjectile.MagnetSphereHitscan(projectile, 300f, 6f, 8f, 6, ModContent.ProjectileType<NebulaShot>(), 1D, true);
|
|
else
|
|
StealthStrikeAI();
|
|
}
|
|
|
|
private void StealthStrikeAI()
|
|
{
|
|
if (rotationAmt < 0.75f)
|
|
rotationAmt += 0.005f;
|
|
projectile.rotation += rotationAmt * rotationDirection;
|
|
shootCounter += Main.rand.NextFloat(0f, 2f);
|
|
|
|
//Fire lasers at random
|
|
if (shootCounter >= 8f)
|
|
{
|
|
shootCounter = 0f;
|
|
Vector2 velocity = CalamityUtils.RandomVelocity(100f, 70f, 100f);
|
|
|
|
int laserDamage = (int)(projectile.damage * 0.5);
|
|
Projectile laser = Projectile.NewProjectileDirect(projectile.Center, velocity, ModContent.ProjectileType<NebulaShot>(), laserDamage, 0f, projectile.owner);
|
|
if (laser.whoAmI.WithinBounds(Main.maxProjectiles))
|
|
{
|
|
laser.Calamity().forceRogue = true;
|
|
laser.aiStyle = Main.rand.NextBool() ? 1 : -1;
|
|
laser.penetrate = -1;
|
|
laser.usesLocalNPCImmunity = true;
|
|
|
|
// This projectile has a hefty amount of extra updates, which will influence the hit cooldown.
|
|
laser.localNPCHitCooldown = 70;
|
|
}
|
|
}
|
|
|
|
projectile.StickyProjAI(6, true);
|
|
|
|
if (projectile.ai[0] != 0f)
|
|
return;
|
|
//Lazily homes in on the nearest NPC (boss preferential)
|
|
const float turnSpeed = 30f;
|
|
const float speedMult = 5f;
|
|
const float homingRange = 600f;
|
|
NPC uDie = projectile.Center.ClosestNPCAt(homingRange, true, true);
|
|
if (uDie != null)
|
|
{
|
|
Vector2 distNorm = (uDie.Center - projectile.Center).SafeNormalize(Vector2.UnitX);
|
|
projectile.velocity = (projectile.velocity * (turnSpeed - 1f) + distNorm * speedMult) / turnSpeed;
|
|
}
|
|
}
|
|
|
|
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
|
|
{
|
|
target.AddBuff(BuffID.OnFire, 600);
|
|
target.AddBuff(BuffID.Frostburn, 600);
|
|
}
|
|
|
|
public override void OnHitPvp(Player target, int damage, bool crit)
|
|
{
|
|
target.AddBuff(BuffID.OnFire, 600);
|
|
target.AddBuff(BuffID.Frostburn, 600);
|
|
}
|
|
|
|
public override void ModifyHitPvp(Player target, ref int damage, ref bool crit) => StealthStrikeSetup();
|
|
public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection)
|
|
{
|
|
StealthStrikeSetup();
|
|
projectile.ModifyHitNPCSticky(3, true);
|
|
}
|
|
|
|
private void StealthStrikeSetup()
|
|
{
|
|
if (!projectile.Calamity().stealthStrike || projectile.aiStyle == -1)
|
|
return;
|
|
rotationDirection = projectile.direction;
|
|
projectile.aiStyle = -1;
|
|
projectile.velocity *= 0.1f;
|
|
projectile.ai[0] = projectile.ai[1] = 0f;
|
|
}
|
|
|
|
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
|
|
{
|
|
CalamityUtils.DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], lightColor, 2);
|
|
return false;
|
|
}
|
|
|
|
public override void PostDraw(SpriteBatch spriteBatch, Color lightColor)
|
|
{
|
|
Vector2 origin = new Vector2(31f, 29f);
|
|
spriteBatch.Draw(ModContent.GetTexture("CalamityMod/Items/Weapons/Rogue/EradicatorGlow"), projectile.Center - Main.screenPosition, null, Color.White, projectile.rotation, origin, 1f, SpriteEffects.None, 0f);
|
|
}
|
|
}
|
|
}
|