Cleanup menu code, fix reloading crash for nonweapons

This commit is contained in:
2022-03-20 20:09:29 +00:00
parent 988a0de578
commit 2a5b6d3597
3 changed files with 39 additions and 37 deletions
+8 -6
View File
@@ -15,13 +15,15 @@ startReloadingWeapon cr = (creatures . ix (_crID cr) . crInv . ix (_crInvSel cr)
icTryStartReloading
icTryStartReloading :: Item -> Maybe Item
icTryStartReloading it
| _ammoLoaded am < _ammoBaseMax (_itConsumption it) && _reloadState am == Nothing'
= Just $ it & itConsumption . reloadState .~ Just' (_reloadTime am)
icTryStartReloading it = do
am <- it ^? itConsumption
amloaded <- am ^? ammoLoaded
ammax <- am ^? ammoBaseMax
rstate <- am ^? reloadState
if amloaded < ammax && rstate == Nothing'
then Just $ it & itConsumption . reloadState .~ Just' (_reloadTime am)
& if _reloadType am == ActiveClear then itConsumption . ammoLoaded .~ 0 else id
| otherwise = Nothing
where
am = _itConsumption it
else Nothing
crStopReloading :: Creature -> Creature
crStopReloading cr = cr & crInv . ix (_crInvSel cr) . itConsumption . reloadState .~ Nothing'