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
This commit is contained in:
Nathanael Overton committed 2025-10-22 01:40:49 -04:00
1 parent 00cddfed05
commit c2e3ee89b9
3 files changed
+77 -26

No files matched your search

@@ -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'
@@ -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
+73 -22
View File
@@ -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<M1Garand>();
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<Texture2D>("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<M1GarandShot>(), 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;