Fold in more ammo parameters, distinguish loadable and charging weapons

This commit is contained in:
2021-11-27 14:29:44 +00:00
parent 92a8dd59b8
commit 224db733f6
19 changed files with 112 additions and 111 deletions
+4 -4
View File
@@ -152,19 +152,19 @@ startReloadingWeapon cr w =
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}
Weapon {_wpAmmo = LoadableAmmo {_wpMaxAmmo=maxA,_wpLoadedAmmo=lA ,_wpReloadState=rS,_wpReloadTime=rT}}
| lA < maxA && rS == 0 -> Just $ set ( itRef . wpAmmo . wpLoadedAmmo) maxA
$ set ( itRef . wpReloadState) rT w
$ set ( itRef . wpAmmo . wpReloadState) rT w
_ -> Nothing
{- | Start reloading if clip is empty. -}
crAutoReload :: Creature -> Creature
crAutoReload cr = case cr ^? crInv . ix (_crInvSel cr) . wpAmmo . wpLoadedAmmo of
Just 0 | _posture (_crStance cr) /= Aiming
-> cr & crInv . ix (_crInvSel cr) . wpReloadState %~ (`fromMaybe` reloadT)
-> cr & crInv . ix (_crInvSel cr) . wpAmmo . wpReloadState %~ (`fromMaybe` reloadT)
& crInv . ix (_crInvSel cr) . wpAmmo . wpLoadedAmmo %~ (`fromMaybe` maxA)
_ -> cr
where
reloadT = cr ^? crInv . ix (_crInvSel cr) . wpReloadTime
reloadT = cr ^? crInv . ix (_crInvSel cr) . wpAmmo . wpReloadTime
maxA = cr ^? crInv . ix (_crInvSel cr) . wpAmmo . wpMaxAmmo
{- | Teleport a creature to the mouse position -}
blinkAction
+22 -9
View File
@@ -123,17 +123,30 @@ invSideEff cr w = weaponReloadSounds cr $ IM.foldrWithKey f w (_crInv cr)
Just g -> g (_itEffect it) cr i w'
weaponReloadSounds :: Creature -> World -> World
weaponReloadSounds cr w = case _crInv cr IM.!? _crInvSel cr of
Just Weapon{_wpReloadType = PassiveReload stype,_wpReloadTime=rt,_wpReloadState=rs}
| rt == rs -> soundContinue (CrReloadSound 0) (_crPos cr) stype Nothing w
| otherwise -> w
Just Weapon{_wpReloadState = 0} -> w
Just Weapon{_wpReloadState = 1} -> stopSoundFrom (CrReloadSound cid) w
Just Weapon{} -> soundContinue (CrReloadSound cid) (_crPos cr) reloadS (Just 1) w
_ -> w
weaponReloadSounds cr w = case cr ^? crInv . ix (_crInvSel cr) . wpAmmo of
Just am@LoadableAmmo{} -> case _wpReloadType am of
PassiveReload stype |_wpReloadTime am ==_wpReloadState am
-> soundContinue (CrReloadSound 0) (_crPos cr) stype Nothing w
PassiveReload _ -> w
ActiveReload | _wpReloadState am == 1 -> stopSoundFrom (CrReloadSound cid) w
ActiveReload | _wpReloadState am == 0 -> w
ActiveReload -> soundContinue (CrReloadSound cid) (_crPos cr) reloadS (Just 1) w
Just ChargeableAmmo {} -> w
Nothing -> w
where
cid = _crID cr
--weaponReloadSounds cr w = case _crInv cr IM.!? _crInvSel cr of
-- Just Weapon{_wpAmmo=LoadableAmmo{_wpReloadType = PassiveReload stype,_wpReloadTime=rt,_wpReloadState=rs} }
-- | rt == rs -> soundContinue (CrReloadSound 0) (_crPos cr) stype Nothing w
-- | otherwise -> w
-- Just Weapon{_wpAmmo=LoadableAmmo{_wpReloadState = 0}} -> w
-- Just Weapon{_wpAmmo=LoadableAmmo{_wpReloadState = 1}} -> stopSoundFrom (CrReloadSound cid) w
-- Just Weapon{} -> soundContinue (CrReloadSound cid) (_crPos cr) reloadS (Just 1) w
-- _ -> w
-- where
-- cid = _crID cr
updateMovement :: Creature -> Creature
updateMovement cr
| isFrictionless cr = over crPos (+.+ momentum) $ setOldPos cr
@@ -157,7 +170,7 @@ stepItemUseCooldown cr = cr & crInv . ix iSel %~
iSel = _crInvSel cr
stepReloading :: Creature -> Creature
stepReloading cr = over (crInv . ix iSel . wpReloadState) decreaseToZero cr
stepReloading cr = over (crInv . ix iSel . wpAmmo . wpReloadState) decreaseToZero cr
where
iSel = _crInvSel cr
+2 -2
View File
@@ -35,12 +35,12 @@ onBoth :: (a -> b -> c) -> (d -> a) -> (d -> b) -> d -> c
onBoth f g h x = f (g x) (h x)
crIsReloading :: (World, Creature) -> Bool
crIsReloading (_,cr) = case cr ^? crInv . ix (_crInvSel cr) . wpReloadState of
crIsReloading (_,cr) = case cr ^? crInv . ix (_crInvSel cr) . wpAmmo . wpReloadState of
Just t -> t > 0
_ -> False
crIsReloadingR :: Creature -> Reader World Bool
crIsReloadingR cr = return $ case cr ^? crInv . ix (_crInvSel cr) . wpReloadState of
crIsReloadingR cr = return $ case cr ^? crInv . ix (_crInvSel cr) . wpAmmo . wpReloadState of
Just t -> t > 0
_ -> False