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; }