Files
CalamityModPublic/Projectiles/Rogue/EclipsesFallMain.cs
T
2025-08-03 23:01:11 -04:00

79 lines
3.5 KiB
C#

using CalamityMod.Particles;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Rogue
{
public class EclipsesFallMain : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Rogue";
public override string Texture => "CalamityMod/Items/Weapons/Rogue/EclipsesFall";
// these also affect KB
public static float RainDamageMult = 0.4f;
public override void SetStaticDefaults()
{
ProjectileID.Sets.TrailCacheLength[Type] = 6;
ProjectileID.Sets.TrailingMode[Type] = 0;
}
public override void SetDefaults()
{
Projectile.width = Projectile.height = 40;
Projectile.friendly = true;
Projectile.ignoreWater = true;
Projectile.tileCollide = false;
Projectile.DamageType = RogueDamageClass.Instance;
Projectile.MaxUpdates = 2;
Projectile.penetrate = 3;
Projectile.usesLocalNPCImmunity = true;
Projectile.localNPCHitCooldown = 6 * Projectile.MaxUpdates;
Projectile.timeLeft = 150 * Projectile.MaxUpdates;
}
public override void AI()
{
Lighting.AddLight(Projectile.Center, 1f, 0.8f, 0.3f);
Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver4;
if (Main.rand.NextBool(5))
{
Vector2 trailPos = Projectile.Center + Vector2.UnitY.RotatedBy(Projectile.rotation) * Main.rand.NextFloat(-16f, 16f);
float trailScale = Main.rand.NextFloat(0.8f, 1.2f);
Color trailColor = Main.rand.NextBool() ? Color.Indigo : Color.DarkOrange;
Particle eclipseTrail = new SparkParticle(trailPos, Projectile.velocity * 0.2f, false, 60, trailScale, trailColor);
GeneralParticleHandler.SpawnParticle(eclipseTrail);
}
}
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => SpawnSpears(target);
public override void OnHitPlayer(Player target, Player.HurtInfo info) => SpawnSpears(target);
private void SpawnSpears(Entity target)
{
int spearAmt = Main.rand.Next(3, 4 + 1); // 3 or 4 spears
for (int n = 0; n < spearAmt; n++)
{
Vector2 spawnPos = target.Center - new Vector2(Main.rand.NextFloat(-100f, 100f), Main.rand.NextFloat(500f, 800f));
Vector2 spearVel = CalamityUtils.CalculatePredictiveAimToTargetMaxUpdates(spawnPos, target, 29f, 2) + Vector2.UnitX * Main.rand.NextFloat(-6f, 6f);
Projectile.NewProjectile(Projectile.GetSource_FromThis(), spawnPos, spearVel, ModContent.ProjectileType<EclipsesSmol>(), (int)(Projectile.damage * RainDamageMult), Projectile.knockBack * RainDamageMult, Projectile.owner);
}
}
public override bool PreDraw(ref Color lightColor)
{
CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Type], lightColor, 1);
return false;
}
public override void PostDraw(Color lightColor)
{
Texture2D glow = ModContent.Request<Texture2D>(Texture + "Glow").Value;
Main.EntitySpriteDraw(glow, Projectile.Center - Main.screenPosition, null, Color.White, Projectile.rotation, glow.Size() * 0.5f, Projectile.scale, SpriteEffects.None);
}
}
}