Rethink item ammo to item consumables, start item type datatype

This commit is contained in:
2021-11-29 16:22:31 +00:00
parent 3a605b8156
commit f40d486d68
31 changed files with 238 additions and 193 deletions
+11 -12
View File
@@ -144,29 +144,28 @@ performAction cr w ac = case ac of
(imps , _) -> (imps, Just $ DoReplicatePartial sac (t-1) sac)
NoAction -> ([],Nothing)
startReloadingWeapon
:: Creature
-> World
-> Maybe World
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 {_wpAmmo = LoadableAmmo {_wpMaxAmmo=maxA,_wpLoadedAmmo=lA ,_wpReloadState=rS,_wpReloadTime=rT}}
| lA < maxA && rS == 0 -> Just $ set ( itRef . wpAmmo . wpLoadedAmmo) maxA
$ set ( itRef . wpAmmo . wpReloadState) rT w
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
{- | Start reloading if clip is empty. -}
crAutoReload :: Creature -> Creature
crAutoReload cr = case cr ^? crInv . ix (_crInvSel cr) . wpAmmo . wpLoadedAmmo of
crAutoReload cr = case cr ^? ptrItConsumption' . wpLoadedAmmo of
Just 0 | _posture (_crStance cr) /= Aiming
-> cr & crInv . ix (_crInvSel cr) . wpAmmo . wpReloadState %~ (`fromMaybe` reloadT)
& crInv . ix (_crInvSel cr) . wpAmmo . wpLoadedAmmo %~ (`fromMaybe` maxA)
-> cr & ptrItConsumption . wpReloadState %~ (`fromMaybe` reloadT)
& ptrItConsumption . wpLoadedAmmo %~ (`fromMaybe` maxA)
_ -> cr
where
reloadT = cr ^? crInv . ix (_crInvSel cr) . wpAmmo . wpReloadTime
maxA = cr ^? crInv . ix (_crInvSel cr) . wpAmmo . wpMaxAmmo
ptrItConsumption = crInv . ix (_crInvSel cr) . itConsumption
ptrItConsumption' = crInv . ix (_crInvSel cr) . itConsumption
reloadT = cr ^? ptrItConsumption' . wpReloadTime
maxA = cr ^? ptrItConsumption' . wpMaxAmmo
{- | Teleport a creature to the mouse position -}
blinkAction
:: Creature