Fix bug in weapon switching

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-14 01:22:54 +01:00
parent 6bf479dcf7
commit 9f5f29100b

View File

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