diff --git a/Projectiles/Ranged/ArcNovaDiffuserHoldout.cs b/Projectiles/Ranged/ArcNovaDiffuserHoldout.cs index d92fd9ce8d..a7950c1d60 100644 --- a/Projectiles/Ranged/ArcNovaDiffuserHoldout.cs +++ b/Projectiles/Ranged/ArcNovaDiffuserHoldout.cs @@ -1,27 +1,26 @@ -using System; -using CalamityMod.Items.Weapons.Ranged; +using CalamityMod.Items.Weapons.Ranged; using CalamityMod.Particles; +using CalamityMod.Projectiles.BaseProjectiles; using Microsoft.Xna.Framework; using ReLogic.Utilities; using Terraria; using Terraria.Audio; -using Terraria.Localization; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Ranged { - public class ArcNovaDiffuserHoldout : ModProjectile + public class ArcNovaDiffuserHoldout : BaseGunHoldoutProjectile { - // Take the name and texture from the weapon - public override LocalizedText DisplayName => CalamityUtils.GetItemName(); - public override string Texture => "CalamityMod/Items/Weapons/Ranged/ArcNovaDiffuser"; + public override int AssociatedItemID => ModContent.ItemType(); + public override Vector2 GunTipPosition => base.GunTipPosition - Vector2.UnitY.RotatedBy(Projectile.rotation) * 6f; + public override float MaxOffsetLengthFromArm => 10f; + public override float OffsetXUpwards => -5f; + public override float BaseOffsetY => -5f; + public override float OffsetYDownwards => 5f; public static int FramesPerLoad = 13; public static int MaxLoadableShots = 15; public static float BulletSpeed = 12f; - public int Time = 0; - - private Player Owner => Main.player[Projectile.owner]; public SlotId NovaChargeSlot; private ref float CurrentChargingFrames => ref Projectile.ai[0]; @@ -30,39 +29,25 @@ namespace CalamityMod.Projectiles.Ranged private bool ChargeLV1 => CurrentChargingFrames >= ArcNovaDiffuser.Charge1Frames; private bool ChargeLV2 => CurrentChargingFrames >= ArcNovaDiffuser.Charge2Frames; - public override void SetDefaults() + public override void KillHoldoutLogic() { - Projectile.width = 72; - Projectile.height = 38; - Projectile.friendly = true; - Projectile.tileCollide = false; - Projectile.DamageType = DamageClass.Ranged; - Projectile.ignoreWater = true; - } - - public override void AI() - { - Time++; - if (Time == 1) - Projectile.alpha = 255; - else - Projectile.alpha = 0; - - if (Owner.dead) // destroy the holdout if the player dies + if (HeldItem.type != Owner.ActiveItem().type || Owner is null || !Owner.active || Owner.CCed || Owner.dead || Owner.noItems) { Projectile.Kill(); - return; + Projectile.netUpdate = true; } + } - Vector2 armPosition = Owner.RotatedRelativePoint(Owner.MountedCenter, true); - Vector2 tipPosition = armPosition + Projectile.velocity * Projectile.width * 0.95f; - + public override void HoldoutAI() + { if (SoundEngine.TryGetActiveSound(NovaChargeSlot, out var ChargeSound) && ChargeSound.IsPlaying) ChargeSound.Position = Projectile.Center; // Fire if the owner stops channeling or otherwise cannot use the weapon. if (Owner.CantUseHoldout()) { + KeepRefreshingLifetime = false; + // Big Shot mode if (ChargeLV2) { @@ -77,16 +62,17 @@ namespace CalamityMod.Projectiles.Ranged Vector2 shootVelocity = Projectile.velocity.SafeNormalize(Vector2.UnitY) * BulletSpeed; int charge2Damage = Projectile.damage * 20; float charge2KB = Projectile.knockBack * 3f; - Projectile.NewProjectile(Projectile.GetSource_FromThis(), tipPosition, shootVelocity, ModContent.ProjectileType(), charge2Damage, charge2KB, Projectile.owner); + Projectile.NewProjectile(Projectile.GetSource_FromThis(), GunTipPosition, shootVelocity, ModContent.ProjectileType(), charge2Damage, charge2KB, Projectile.owner); Owner.Calamity().GeneralScreenShakePower = 6.5f; for (int i = 0; i <= 25; i++) { - Dust dust = Dust.NewDustPerfect(tipPosition - Projectile.velocity * 15, 107, shootVelocity.RotatedByRandom(MathHelper.ToRadians(15f)) * Main.rand.NextFloat(0.2f, 1.2f), 0, default, Main.rand.NextFloat(1f, 2.3f)); + Dust dust = Dust.NewDustPerfect(GunTipPosition - Projectile.velocity * 15, 107, shootVelocity.RotatedByRandom(MathHelper.ToRadians(15f)) * Main.rand.NextFloat(0.2f, 1.2f), 0, default, Main.rand.NextFloat(1f, 2.3f)); dust.noGravity = true; } ShotsLoaded = 0; ShootRecoilTimer = 24f; + OffsetLengthFromArm -= 25f; Projectile.netSpam = 0; Projectile.netUpdate = true; } @@ -110,15 +96,16 @@ namespace CalamityMod.Projectiles.Ranged Vector2 shootVelocity = Projectile.velocity.SafeNormalize(Vector2.UnitY) * BulletSpeed; Vector2 fireVec = shootVelocity.RotatedByRandom(MathHelper.ToRadians(2f)); - Projectile.NewProjectile(Projectile.GetSource_FromThis(), tipPosition, fireVec, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner); + Projectile.NewProjectile(Projectile.GetSource_FromThis(), GunTipPosition, fireVec, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner); for (int i = 0; i <= 4; i++) { - Dust dust = Dust.NewDustPerfect(tipPosition - Projectile.velocity * 15, 107, shootVelocity.RotatedByRandom(MathHelper.ToRadians(15f)) * Main.rand.NextFloat(0.9f, 1.2f), 0, default, Main.rand.NextFloat(0.8f, 1.8f)); + Dust dust = Dust.NewDustPerfect(GunTipPosition - Projectile.velocity * 15, 107, shootVelocity.RotatedByRandom(MathHelper.ToRadians(15f)) * Main.rand.NextFloat(0.9f, 1.2f), 0, default, Main.rand.NextFloat(0.8f, 1.8f)); dust.noGravity = true; } ShotsLoaded--; ShootRecoilTimer = 16f; + OffsetLengthFromArm -= 5f; Projectile.netSpam = 0; Projectile.netUpdate = true; } @@ -132,7 +119,7 @@ namespace CalamityMod.Projectiles.Ranged { for (int i = 0; i < 6; i++) { - SparkParticle spark2 = new SparkParticle((tipPosition - Projectile.velocity * 3) + Main.rand.NextVector2Circular(10, 10), -Projectile.velocity * Main.rand.NextFloat(9.1f, 17.8f), false, Main.rand.Next(9, 12), Main.rand.NextFloat(0.2f, 0.3f), Main.rand.NextBool(4) ? Color.Chartreuse : Color.Lime); + SparkParticle spark2 = new SparkParticle((GunTipPosition - Projectile.velocity * 3) + Main.rand.NextVector2Circular(10, 10), -Projectile.velocity * Main.rand.NextFloat(9.1f, 17.8f), false, Main.rand.Next(9, 12), Main.rand.NextFloat(0.2f, 0.3f), Main.rand.NextBool(4) ? Color.Chartreuse : Color.Lime); GeneralParticleHandler.SpawnParticle(spark2); } ShotsLoaded--; @@ -140,9 +127,6 @@ namespace CalamityMod.Projectiles.Ranged } else { - // While channeled, keep refreshing the projectile lifespan - Projectile.timeLeft = 2; - // Loads shots until maxed out if (ShotsLoaded < MaxLoadableShots && CurrentChargingFrames % FramesPerLoad == 0) ShotsLoaded++; @@ -176,17 +160,17 @@ namespace CalamityMod.Projectiles.Ranged float particleScale = MathHelper.Clamp(CurrentChargingFrames, 0f, ArcNovaDiffuser.Charge2Frames); for (int i = 0; i < (ChargeLV2 ? 4 : ChargeLV1 ? 3 : 2); i++) { - SparkParticle spark2 = new SparkParticle((tipPosition - Projectile.velocity * 4) + Main.rand.NextVector2Circular(12, 12), -Projectile.velocity * Main.rand.NextFloat(16.1f, 30.8f), false, Main.rand.Next(2, 7), Main.rand.NextFloat(particleScale / 350f, particleScale / 270f), Main.rand.NextBool(4) ? Color.Chartreuse : Color.Lime); + SparkParticle spark2 = new SparkParticle((GunTipPosition - Projectile.velocity * 4) + Main.rand.NextVector2Circular(12, 12), -Projectile.velocity * Main.rand.NextFloat(16.1f, 30.8f), false, Main.rand.Next(2, 7), Main.rand.NextFloat(particleScale / 350f, particleScale / 270f), Main.rand.NextBool(4) ? Color.Chartreuse : Color.Lime); GeneralParticleHandler.SpawnParticle(spark2); } - Particle orb = new GenericBloom(tipPosition, Projectile.velocity, Color.Lime, particleScale / 270f, 2, false); + Particle orb = new GenericBloom(GunTipPosition, Projectile.velocity, Color.Lime, particleScale / 270f, 2, false); GeneralParticleHandler.SpawnParticle(orb); - Particle orb2 = new GenericBloom(tipPosition, Projectile.velocity, Color.White, particleScale / 400f, 2, false); + Particle orb2 = new GenericBloom(GunTipPosition, Projectile.velocity, Color.White, particleScale / 400f, 2, false); GeneralParticleHandler.SpawnParticle(orb2); float strength = particleScale / 45f; Vector3 DustLight = new Vector3(0.000f, 0.255f, 0.000f); - Lighting.AddLight(tipPosition, DustLight * strength); + Lighting.AddLight(GunTipPosition, DustLight * strength); } // Full charge dusts @@ -194,7 +178,7 @@ namespace CalamityMod.Projectiles.Ranged { for (int i = 0; i < 36; i++) { - Dust chargefull = Dust.NewDustPerfect(tipPosition, 107); + Dust chargefull = Dust.NewDustPerfect(GunTipPosition, 107); chargefull.velocity = (MathHelper.TwoPi * i / 36f).ToRotationVector2() * 8f + Owner.velocity; chargefull.scale = Main.rand.NextFloat(1f, 1.3f); chargefull.noGravity = true; @@ -204,55 +188,19 @@ namespace CalamityMod.Projectiles.Ranged { for (int i = 0; i < 45; i++) { - Dust chargefull = Dust.NewDustPerfect(tipPosition, 107); + Dust chargefull = Dust.NewDustPerfect(GunTipPosition, 107); chargefull.velocity = (MathHelper.TwoPi * i / 36f).ToRotationVector2() * 12f + Owner.velocity; chargefull.scale = Main.rand.NextFloat(1.2f, 1.4f); chargefull.noGravity = true; } } } - UpdateProjectileHeldVariables(armPosition); - ManipulatePlayerVariables(); } - private void UpdateProjectileHeldVariables(Vector2 armPosition) - { - if (Main.myPlayer == Projectile.owner) - { - float interpolant = Utils.GetLerpValue(5f, 40f, Projectile.Distance(Main.MouseWorld), true); - Vector2 oldVelocity = Projectile.velocity; - Projectile.velocity = Vector2.Lerp(Projectile.velocity, Projectile.SafeDirectionTo(Main.MouseWorld), interpolant); - if (Projectile.velocity != oldVelocity) - { - Projectile.netSpam = 0; - Projectile.netUpdate = true; - } - } - Vector2 shootOffset = Projectile.velocity * MathHelper.Clamp(30f - ShootRecoilTimer, 0f, 30f) + new Vector2(0, 7); - Projectile.Center = armPosition + shootOffset; - Projectile.rotation = Projectile.velocity.ToRotation() + (Projectile.spriteDirection == -1 ? MathHelper.Pi : 0f); - Projectile.spriteDirection = Projectile.direction; - - // Rumble (only while channeling) - float rumble = MathHelper.Clamp(CurrentChargingFrames, 0f, ArcNovaDiffuser.Charge2Frames); - if (!Owner.CantUseHoldout()) - Projectile.position += Main.rand.NextVector2Circular(rumble / 70f, rumble / 70f); - } - - private void ManipulatePlayerVariables() - { - Owner.ChangeDir(Projectile.direction); - Owner.heldProj = Projectile.whoAmI; - Owner.itemTime = 2; - Owner.itemAnimation = 2; - Owner.itemRotation = (Projectile.velocity * Projectile.direction).ToRotation(); - } public override void OnKill(int timeLeft) { if (SoundEngine.TryGetActiveSound(NovaChargeSlot, out var ChargeSound)) ChargeSound?.Stop(); } - - public override bool? CanDamage() => false; } }