From c2e3ee89b9338d9be89c8d780df95097bb240442 Mon Sep 17 00:00:00 2001 From: Nathanael Overton Date: Wed, 22 Oct 2025 01:40:49 -0400 Subject: [PATCH] Garand bugfixes and tweaks - Reload sound now converted to an active sound so its source always updates to the player's position as it plays - Fixed a bug where the last frame drawn before the projectile gets killed displays incorrectly - Made PreDraw and PostDraw return false immediately on the first 2 frames of the holdout being spawned because this baseclass just simply doesn't draw correctly at the start - Made the last shot hold frame 3 after it increments to it to match the start of the reload animation - Slightly increased holdout offset recoil after firing (doesnt affect gameplay) - Tooltip more clearly states how it converts bullets - Properly organized the projectile named in localization --- ...ods.CalamityMod.Items.Weapons.Ranged.hjson | 2 +- .../Mods.CalamityMod.Projectiles.Ranged.hjson | 6 +- Projectiles/Ranged/M1GarandHoldout.cs | 95 ++++++++++++++----- 3 files changed, 77 insertions(+), 26 deletions(-) diff --git a/Localization/en-US/Mods.CalamityMod.Items.Weapons.Ranged.hjson b/Localization/en-US/Mods.CalamityMod.Items.Weapons.Ranged.hjson index 3543f0a636..4c6070bd2f 100644 --- a/Localization/en-US/Mods.CalamityMod.Items.Weapons.Ranged.hjson +++ b/Localization/en-US/Mods.CalamityMod.Items.Weapons.Ranged.hjson @@ -677,7 +677,7 @@ M1Garand: { DisplayName: M1 Garand Tooltip: ''' - Shots fired only inherit the damage of the bullet used + Converts bullets into .30-06 rounds which inherit the damage of the converted bullet Fires 8 bullets before ejecting the rifle's cartridge Bullets which ricochet off coins can ricochet off cartridges too 'Mind your thumb' diff --git a/Localization/en-US/Mods.CalamityMod.Projectiles.Ranged.hjson b/Localization/en-US/Mods.CalamityMod.Projectiles.Ranged.hjson index 0efa140c93..0d8698e719 100644 --- a/Localization/en-US/Mods.CalamityMod.Projectiles.Ranged.hjson +++ b/Localization/en-US/Mods.CalamityMod.Projectiles.Ranged.hjson @@ -114,6 +114,9 @@ KarasawaShot.DisplayName: Karasawa Shot LeafArrow.DisplayName: Leaf Arrow LunarBolt.DisplayName: Bolt LuxorsGiftRanged.DisplayName: Luxor's Ranged +M1GarandBulletCasing.DisplayName: M1 Garand Bullet Casing +M1GarandEmptyClip.DisplayName: M1 Garand Empty Clip +M1GarandShot.DisplayName: .30-06 Round MagnaShot.DisplayName: Magna Bolt MagnomalyAura.DisplayName: Magnomaly Aura MagnomalyBeam.DisplayName: Beam @@ -262,6 +265,3 @@ LeviatitanMeteor.DisplayName: Leviatitan Meteor LeviatitanExplosion.DisplayName: Leviatitan Explosion SulphuricDrop.DisplayName: Sulphuric Drop AcidRocket.DisplayName: Acid Rocket -M1GarandBulletCasing.DisplayName: M1 Garand Bullet Casing -M1GarandEmptyClip.DisplayName: M1 Garand Empty Clip -M1GarandShot.DisplayName: .30-06 Round diff --git a/Projectiles/Ranged/M1GarandHoldout.cs b/Projectiles/Ranged/M1GarandHoldout.cs index 94301063f8..9a26341432 100644 --- a/Projectiles/Ranged/M1GarandHoldout.cs +++ b/Projectiles/Ranged/M1GarandHoldout.cs @@ -9,6 +9,7 @@ using Terraria.Audio; using Terraria.GameContent; using Terraria.ModLoader; using System; +using ReLogic.Utilities; namespace CalamityMod.Projectiles.Ranged { @@ -17,7 +18,8 @@ namespace CalamityMod.Projectiles.Ranged public override int AssociatedItemID => ModContent.ItemType(); public ref float CurrentState => ref Projectile.ai[0]; - public ref float Timer => ref Projectile.ai[1]; + public ref float reloadTimeLeft => ref Projectile.ai[1]; + public ref float globalTimer => ref Projectile.ai[2]; private float muzzleFlashTimer; private float flashVariant; @@ -44,6 +46,7 @@ namespace CalamityMod.Projectiles.Ranged public static readonly SoundStyle FireSound = new("CalamityMod/Sounds/Item/WulfrumBlunderbussFire") { PitchVariance = 0.1f }; public static readonly SoundStyle PingSound = new("CalamityMod/Sounds/Item/M1GarandPing"); public static readonly SoundStyle ReloadSound = new("CalamityMod/Sounds/Item/M1GarandReload"); + private SlotId reloadSoundSlot; public override void Load() { @@ -51,8 +54,12 @@ namespace CalamityMod.Projectiles.Ranged HoldoutGlow = ModContent.Request("CalamityMod/Projectiles/Ranged/M1GarandHoldoutGlow", AssetRequestMode.ImmediateLoad); } - public override void SetStaticDefaults() => Main.projFrames[Type] = 6; + public override void SetStaticDefaults() + { + Main.projFrames[Type] = 6; + Projectile.frame = Main.projFrames[Type] - 1; + } public override void KillHoldoutLogic() { // Only allow the projectile to kill if we're not reloading @@ -65,6 +72,8 @@ namespace CalamityMod.Projectiles.Ranged public override void HoldoutAI() { + globalTimer++; + // Decrements the timer which controls the duration of the flash if (muzzleFlashTimer > 0f) muzzleFlashTimer -= 1f; @@ -72,6 +81,7 @@ namespace CalamityMod.Projectiles.Ranged if (shouldPing) pingAnimationTimer += 3; + hereInstead: // Code reads from back here after getting the 'goto' set down below switch (CurrentState) { // Normal Firing State @@ -83,15 +93,33 @@ namespace CalamityMod.Projectiles.Ranged if (Projectile.frameCounter >= MathHelper.Clamp(Owner.ActiveItem().useAnimation - 18, 0f, Owner.ActiveItem().useAnimation)) { if (Owner.CantUseHoldout()) + { Projectile.Kill(); + return; + } + + if (Owner.Calamity().garandShots != 0) + Projectile.frame = 0; + else + { + CurrentState = 1; // Begin reloading + reloadTimeLeft = 120; + goto hereInstead; + } - Projectile.frame = 0; Projectile.frameCounter = 0; } } // Begin firing else if (Projectile.frame == 0) { + if (Owner.Calamity().garandShots == 0 && globalTimer < 3) + { + CurrentState = 1; // Begin reloading + reloadTimeLeft = 120; + goto hereInstead; + } + if (Projectile.frameCounter != 1) { Projectile.frameCounter++; @@ -119,7 +147,7 @@ namespace CalamityMod.Projectiles.Ranged shouldPing = true; } - OffsetLengthFromArm -= 3f; + OffsetLengthFromArm -= 3.5f; // Consume a shot Owner.Calamity().garandShots--; @@ -152,12 +180,6 @@ namespace CalamityMod.Projectiles.Ranged Vector2 offsetPos = GunTipPosition - Projectile.velocity.SafeNormalize(Vector2.UnitY) * 18f; Projectile.NewProjectile(Projectile.GetSource_FromThis(), offsetPos, velocity, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner); } - else - { - OffsetLengthFromArm -= 1f; - CurrentState = 1; // Change state to reloading - Timer = 120; - } } // The firing animation else if (Projectile.frame > 0) @@ -174,31 +196,30 @@ namespace CalamityMod.Projectiles.Ranged // Reloading case 1: - - Timer--; + reloadTimeLeft--; // Keep the player from switching weapons Owner.channel = true; // The gun points slightly downwards during the first part - if (Timer <= 120 && Timer > 75) + if (reloadTimeLeft <= 120 && reloadTimeLeft > 75) { Projectile.rotation += 0.15f * Projectile.spriteDirection; } // Lerp back to the normal pos - else if (Timer < 75 && Timer >= 64) + else if (reloadTimeLeft < 75 && reloadTimeLeft >= 64) { - float progress = (75f - Timer) / (75f - 64f); + float progress = (75f - reloadTimeLeft) / (75f - 64f); float lerpedOffset = MathHelper.Lerp(0.15f, 0f, progress); Projectile.rotation += lerpedOffset * Projectile.spriteDirection; } - else if (Timer == 39) + else if (reloadTimeLeft == 39) { OffsetLengthFromArm -= 2f; } // Hold frame 3 until this point - if (Timer > 40) + if (reloadTimeLeft > 40) { Projectile.frame = 3; Projectile.frameCounter = 0; @@ -220,15 +241,28 @@ namespace CalamityMod.Projectiles.Ranged Projectile.frame = Main.projFrames[Type] - 1; } - if (Timer == 110) + if (reloadTimeLeft == 110) { - SoundEngine.PlaySound(ReloadSound, Projectile.Center); + reloadSoundSlot = SoundEngine.PlaySound(ReloadSound, Projectile.Center); + } + + if (SoundEngine.TryGetActiveSound(reloadSoundSlot, out var sound) && sound.IsPlaying) + { + // Update the sound's position to the current projectile center + sound.Position = Projectile.Center; } // Reload and cull the projectile - if (Timer <= 0) + if (reloadTimeLeft <= 0) { + // Stop when sound is complete + if (SoundEngine.TryGetActiveSound(reloadSoundSlot, out var soundToStop) && soundToStop.IsPlaying) + { + soundToStop.Stop(); + } + Owner.Calamity().garandShots += 8; + globalTimer = 0; Projectile.Kill(); Projectile.netUpdate = true; } @@ -243,13 +277,21 @@ namespace CalamityMod.Projectiles.Ranged public override bool PreDraw(ref Color lightColor) { + // This class doesn't draw correctly on the first 2 frames. + if (globalTimer < 3) + return false; + + int chosenFrame = Math.Clamp(Projectile.frame, 0, Main.projFrames[Type] - 1); Texture2D texture = TextureAssets.Projectile[Type].Value; Vector2 drawPosition = Projectile.Center - Main.screenPosition; - Rectangle frame = texture.Frame(verticalFrames: Main.projFrames[Type], frameY: Math.Clamp(Projectile.frame, 0, Main.projFrames[Type] - 1)); + Rectangle frame = texture.Frame(verticalFrames: Main.projFrames[Type], frameY: chosenFrame); float drawRotation = Projectile.rotation + (Projectile.spriteDirection == -1 ? MathHelper.Pi : 0f); float scale = Projectile.scale * Owner.gravDir; SpriteEffects flipSprite = (Projectile.spriteDirection * Owner.gravDir == -1) ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + if ((CurrentState != 1 && Owner.Calamity().garandShots == 0 && Projectile.frame >= 3)) // After firing the last shot, hold frame 3 after it increments to it to match the start of the reload animation + frame = texture.Frame(verticalFrames: Main.projFrames[Type], frameY: 3); + Main.EntitySpriteDraw(texture, drawPosition, frame, Projectile.GetAlpha(lightColor), drawRotation, frame.Size() * 0.5f, scale, flipSprite); // Flash @@ -342,8 +384,17 @@ namespace CalamityMod.Projectiles.Ranged // Glowmask. public override void PostDraw(Color lightColor) { + // This class doesn't draw correctly on the first 2 frames. + if (CurrentState == 1 || globalTimer < 3) + return; + + int chosenFrame = Math.Clamp(Projectile.frame, 0, Main.projFrames[Type] - 1); + + if (globalTimer > 2 && globalTimer < 6) // If the holdout just spawned in and isn't in the reload state, play a belated flash animation. + chosenFrame = 0; + Texture2D texture = TextureAssets.Projectile[Type].Value; - Rectangle frame = texture.Frame(verticalFrames: Main.projFrames[Type], frameY: Math.Clamp(Projectile.frame, 0, Main.projFrames[Type] - 1)); + Rectangle frame = texture.Frame(verticalFrames: Main.projFrames[Type], frameY: chosenFrame); Texture2D glowTexture = HoldoutGlow.Value; Vector2 drawPosition = Projectile.Center - Main.screenPosition;