Fix bug in weapon switching
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -61,12 +61,19 @@ class Player {
|
|||||||
|
|
||||||
void updateWeaponSwitch() {
|
void updateWeaponSwitch() {
|
||||||
if (switchState == WeaponSwitchState.lowering) {
|
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;
|
weaponAnimOffset += switchSpeed;
|
||||||
if (weaponAnimOffset >= 500.0) {
|
if (weaponAnimOffset >= 500.0) {
|
||||||
weaponAnimOffset = 500.0;
|
weaponAnimOffset = 500.0;
|
||||||
|
|
||||||
// Grab the pending weapon from inventory, default to pistol if something goes wrong
|
// We already know it's not null now, but we can keep the
|
||||||
currentWeapon = weapons[pendingWeaponType ?? WeaponType.pistol]!;
|
// fallback to pistol just to be extra safe.
|
||||||
|
currentWeapon = weapons[pendingWeaponType]!;
|
||||||
|
|
||||||
switchState = WeaponSwitchState.raising;
|
switchState = WeaponSwitchState.raising;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user