Cleanup
This commit is contained in:
+19
-17
@@ -14,41 +14,43 @@ startReloadingWeapon :: Creature -> World -> Maybe World
|
||||
startReloadingWeapon cr = (creatures . ix (_crID cr) . crInv . ix (_crInvSel cr))
|
||||
icTryStartReloading
|
||||
|
||||
-- TODO clean this up, rethink datatypes
|
||||
icTryStartReloading :: Item -> Maybe Item
|
||||
icTryStartReloading it = do
|
||||
am <- it ^? itConsumption
|
||||
amloaded <- am ^? ammoLoaded
|
||||
ammax <- am ^? ammoBaseMax
|
||||
rstate <- am ^? reloadState
|
||||
amloaded <- am ^? laLoaded
|
||||
ammax <- am ^? laMax
|
||||
rstate <- am ^? laReloadState
|
||||
if amloaded < ammax && rstate == Nothing'
|
||||
then Just $ it
|
||||
& itConsumption . reloadState .~ Just' (_reloadTime am)
|
||||
& if _reloadType am == ActiveClear
|
||||
then itConsumption . ammoLoaded .~ 0
|
||||
& itConsumption . laReloadState .~ Just' (_laReloadTime am)
|
||||
& if _laReloadType am == ActiveClear
|
||||
then itConsumption . laLoaded .~ 0
|
||||
else id
|
||||
else Nothing
|
||||
|
||||
crStopReloading :: Creature -> Creature
|
||||
crStopReloading cr = cr & crInv . ix (_crInvSel cr) . itConsumption . reloadState .~ Nothing'
|
||||
crStopReloading cr = cr & crInv . ix (_crInvSel cr) . itConsumption . laReloadState .~ Nothing'
|
||||
|
||||
-- ugly TODO cleanup
|
||||
stepReloading :: Creature -> Creature
|
||||
stepReloading cr = case cr ^? crInv . ix isel . itConsumption . reloadState . _Just' of
|
||||
stepReloading cr = case cr ^? crInv . ix isel . itConsumption . laReloadState . _Just' of
|
||||
Just 0 -> cr & crInv . ix isel %~ doload
|
||||
Just _ -> cr & crInv . ix isel . itConsumption . reloadState . _Just' %~ decreaseToZero
|
||||
Just _ -> cr & crInv . ix isel . itConsumption . laReloadState . _Just' %~ decreaseToZero
|
||||
Nothing -> cr
|
||||
where
|
||||
isel = _crInvSel cr
|
||||
doload it = case _reloadType itcon of
|
||||
doload it = case _laReloadType itcon of
|
||||
ActivePartial x
|
||||
| x + _ammoLoaded itcon < itMaxAmmo -> it & itConsumption . ammoLoaded %~ (+ x)
|
||||
& itConsumption . reloadState .~ Just' (_reloadTime itcon)
|
||||
| otherwise -> it & itConsumption . ammoLoaded .~ itMaxAmmo
|
||||
& itConsumption . reloadState .~ Nothing'
|
||||
_ -> it & itConsumption . ammoLoaded .~ itMaxAmmo
|
||||
& itConsumption . reloadState .~ Nothing'
|
||||
| x + _laLoaded itcon < itMaxAmmo -> it & itConsumption . laLoaded %~ (+ x)
|
||||
& itConsumption . laReloadState .~ Just' (_laReloadTime itcon)
|
||||
| otherwise -> it & itConsumption . laLoaded .~ itMaxAmmo
|
||||
& itConsumption . laReloadState .~ Nothing'
|
||||
_ -> it & itConsumption . laLoaded .~ itMaxAmmo
|
||||
& itConsumption . laReloadState .~ Nothing'
|
||||
where
|
||||
itcon = _itConsumption it
|
||||
itMaxAmmo = _ammoBaseMax itcon
|
||||
itMaxAmmo = _laMax itcon
|
||||
|
||||
--{- | Start reloading if clip is empty. -}
|
||||
--crAutoReload :: Creature -> Creature
|
||||
|
||||
Reference in New Issue
Block a user