Files
CalamityModPublic/Projectiles/Magic/DivineRetributionSpear.cs
T
tomat 67bceff6e7 Initial dotnet format pass.
This commit formats the entire codebase according to `dotnet format` and its limited understanding of our provided `.editorconfig`.
2024-02-28 21:49:50 -08:00

109 lines
4.4 KiB
C#

using System;
using CalamityMod.Buffs.DamageOverTime;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Audio;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Magic
{
public class DivineRetributionSpear : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Magic";
public override void SetStaticDefaults()
{
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 7;
ProjectileID.Sets.TrailingMode[Projectile.type] = 0;
}
public override void SetDefaults()
{
Projectile.width = 30;
Projectile.height = 30;
Projectile.friendly = true;
Projectile.ignoreWater = true;
Projectile.tileCollide = false;
Projectile.DamageType = DamageClass.Magic;
Projectile.extraUpdates = 1;
Projectile.penetrate = 1;
Projectile.timeLeft = 420;
}
public override void AI()
{
float aiVelocityMult = 25f * Projectile.ai[1]; //100
float scaleFactor = 5f * Projectile.ai[1]; //5
float homingRange = 1000f;
if (Projectile.velocity.X < 0f)
{
Projectile.spriteDirection = -1;
Projectile.rotation = (float)Math.Atan2((double)-(double)Projectile.velocity.Y, (double)-(double)Projectile.velocity.X);
}
else
{
Projectile.spriteDirection = 1;
Projectile.rotation = (float)Math.Atan2((double)Projectile.velocity.Y, (double)Projectile.velocity.X);
}
Lighting.AddLight(Projectile.Center, 0.7f, 0.3f, 0f);
if (Main.player[Projectile.owner].active && !Main.player[Projectile.owner].dead)
{
if (Projectile.Distance(Main.player[Projectile.owner].Center) > homingRange)
{
Vector2 moveDirection = Projectile.SafeDirectionTo(Main.player[Projectile.owner].Center, Vector2.UnitY);
Projectile.velocity = (Projectile.velocity * (aiVelocityMult - 1f) + moveDirection * scaleFactor) / aiVelocityMult;
return;
}
CalamityUtils.HomeInOnNPC(Projectile, true, 200f, 9f, 20f);
}
else
{
if (Projectile.timeLeft > 30)
{
Projectile.timeLeft = 30;
}
}
}
public override bool PreDraw(ref Color lightColor)
{
CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor, 1);
return false;
}
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => target.AddBuff(ModContent.BuffType<HolyFlames>(), 180);
public override void OnHitPlayer(Player target, Player.HurtInfo info) => target.AddBuff(ModContent.BuffType<HolyFlames>(), 180);
public override void OnKill(int timeLeft)
{
Projectile.position = Projectile.Center;
Projectile.width = Projectile.height = 96;
Projectile.position.X = Projectile.position.X - (float)(Projectile.width / 2);
Projectile.position.Y = Projectile.position.Y - (float)(Projectile.height / 2);
Projectile.maxPenetrate = -1;
Projectile.penetrate = -1;
Projectile.usesLocalNPCImmunity = true;
Projectile.localNPCHitCooldown = 10;
Projectile.Damage();
SoundEngine.PlaySound(SoundID.Item74, Projectile.Center);
for (int i = 0; i < 6; i++)
{
Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width, Projectile.height, DustID.CopperCoin, 0, 0);
}
for (int j = 0; j < 10; j++)
{
int divinity = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width, Projectile.height, DustID.CopperCoin, 0, 0);
Main.dust[divinity].noGravity = true;
Main.dust[divinity].velocity *= 3f;
divinity = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width, Projectile.height, DustID.CopperCoin, 0, 0);
Main.dust[divinity].velocity *= 2f;
Main.dust[divinity].noGravity = true;
}
}
}
}