Allow for partial reloading
This commit is contained in:
@@ -145,27 +145,28 @@ performAction cr w ac = case ac of
|
||||
NoAction -> ([],Nothing)
|
||||
|
||||
startReloadingWeapon :: Creature -> World -> Maybe World
|
||||
startReloadingWeapon cr w =
|
||||
let cid = _crID cr
|
||||
it = _crInv cr IM.! _crInvSel cr
|
||||
itRef = creatures . ix cid . crInv . ix (_crInvSel cr)
|
||||
in case it of
|
||||
Weapon {_itConsumption = LoadableAmmo {_wpMaxAmmo=maxA,_wpLoadedAmmo=lA ,_wpReloadState=rS,_wpReloadTime=rT}}
|
||||
| lA < maxA && rS == 0 -> Just $ set ( itRef . itConsumption . wpLoadedAmmo) maxA
|
||||
$ set ( itRef . itConsumption . wpReloadState) rT w
|
||||
_ -> Nothing
|
||||
startReloadingWeapon cr w = case it of
|
||||
Weapon {_itConsumption = LoadableAmmo {_ammoMax=maxA,_ammoLoaded=lA ,_reloadState=rS,_reloadTime=rT}}
|
||||
| lA < maxA && rS == Nothing' ->
|
||||
Just -- $ set ( itRef . itConsumption . ammoLoaded) maxA
|
||||
$ set ( itRef . itConsumption . reloadState) (Just' rT) w
|
||||
_ -> Nothing
|
||||
where
|
||||
cid = _crID cr
|
||||
it = _crInv cr IM.! _crInvSel cr
|
||||
itRef = creatures . ix cid . crInv . ix (_crInvSel cr)
|
||||
{- | Start reloading if clip is empty. -}
|
||||
crAutoReload :: Creature -> Creature
|
||||
crAutoReload cr = case cr ^? ptrItConsumption' . wpLoadedAmmo of
|
||||
crAutoReload cr = case cr ^? ptrItConsumption' . ammoLoaded of
|
||||
Just 0 | _posture (_crStance cr) /= Aiming
|
||||
-> cr & ptrItConsumption . wpReloadState %~ (`fromMaybe` reloadT)
|
||||
& ptrItConsumption . wpLoadedAmmo %~ (`fromMaybe` maxA)
|
||||
-> cr & ptrItConsumption . reloadState .~ (strictify reloadT)
|
||||
& ptrItConsumption . ammoLoaded %~ (`fromMaybe` maxA)
|
||||
_ -> cr
|
||||
where
|
||||
ptrItConsumption = crInv . ix (_crInvSel cr) . itConsumption
|
||||
ptrItConsumption' = crInv . ix (_crInvSel cr) . itConsumption
|
||||
reloadT = cr ^? ptrItConsumption' . wpReloadTime
|
||||
maxA = cr ^? ptrItConsumption' . wpMaxAmmo
|
||||
reloadT = cr ^? ptrItConsumption' . reloadTime
|
||||
maxA = cr ^? ptrItConsumption' . ammoMax
|
||||
{- | Teleport a creature to the mouse position -}
|
||||
blinkAction
|
||||
:: Creature
|
||||
|
||||
Reference in New Issue
Block a user