From 9f5f29100bf11e42efab2eccd1b269d16d3a4f5e Mon Sep 17 00:00:00 2001 From: Hans Kokx Date: Sat, 14 Mar 2026 01:22:54 +0100 Subject: [PATCH] Fix bug in weapon switching Signed-off-by: Hans Kokx --- lib/features/player/player.dart | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/features/player/player.dart b/lib/features/player/player.dart index a38b7d3..7a4fdee 100644 --- a/lib/features/player/player.dart +++ b/lib/features/player/player.dart @@ -61,12 +61,19 @@ class Player { void updateWeaponSwitch() { if (switchState == WeaponSwitchState.lowering) { + // If the map doesn't contain the pending weapon, stop immediately + if (weapons[pendingWeaponType] == null) { + switchState = WeaponSwitchState.idle; + return; + } + weaponAnimOffset += switchSpeed; if (weaponAnimOffset >= 500.0) { weaponAnimOffset = 500.0; - // Grab the pending weapon from inventory, default to pistol if something goes wrong - currentWeapon = weapons[pendingWeaponType ?? WeaponType.pistol]!; + // We already know it's not null now, but we can keep the + // fallback to pistol just to be extra safe. + currentWeapon = weapons[pendingWeaponType]!; switchState = WeaponSwitchState.raising; }