Work towards adding external ammo sources

This commit is contained in:
2023-05-17 11:01:52 +01:00
parent 63c71c852d
commit 7df81559d9
30 changed files with 246 additions and 196 deletions
+11 -4
View File
@@ -37,7 +37,8 @@ useItemRightClick cr' w = fromMaybe (f w) $ do
itemEffect :: Creature -> Item -> World -> World
itemEffect cr it w = case it ^. itUse of
HeldUse{_heldUse = eff, _heldMods = usemods} ->
hammerTest $ tryReload cr it (_input w) $ foldl' (&) (useHeld eff) (useMod usemods) it cr
--hammerTest $ tryReload cr it (_input w) $ foldl' (&) (useHeld eff) (useMod usemods) it cr
hammerTest $ foldl' (&) (useHeld eff) (useMod usemods) it cr
LeftUse{} -> doequipmentchange
EquipUse{} -> doequipmentchange
-- ConsumeUse will cause problems if the item is not selected
@@ -66,9 +67,9 @@ tryReload cr it theinput f
cid = _crID cr
itNeedsLoading :: Item -> Bool
itNeedsLoading it = _laLoaded ic == 0 || not (_laPrimed ic)
where
ic = _heldConsumption (_itUse it)
itNeedsLoading it = fromMaybe False $ do
internalammo <- it ^? itUse . heldConsumption . laSource . _InternalSource
return $ _iaLoaded internalammo == 0 || not (_iaPrimed internalammo)
toggleEquipmentAt :: Int -> Creature -> World -> World
toggleEquipmentAt invid cr w = case getEquipmentAllocation w of
@@ -119,10 +120,16 @@ useItemLeftClick cr w = fromMaybe w $ do
invid <- cr ^? crManipulation . manObject . inInventory . ispItem
ituse <- cr ^? crInv . ix invid . itUse
case ituse of
HeldUse{} -> return $ hammerTest (cWorld . lWorld . creatures . ix (_crID cr) %~ crToggleReloading)
ConsumeUse{} -> return $ useItemRightClick cr w
EquipUse{} -> return $ useItemRightClick cr w
LeftUse{} -> return $ useItemRightClick cr w
_ -> Nothing
where
hammerTest f = case _crHammerPosition cr of
HammerUp -> f w
_ -> w & setuhamdown
setuhamdown = cWorld . lWorld . creatures . ix (_crID cr) . crHammerPosition .~ HammerDown
useItemHotkey :: Int -> Int -> World -> World
useItemHotkey crid invid w = fromMaybe w $ do
+1 -1
View File
@@ -174,7 +174,7 @@ reloadOverride :: Creature -> Creature
reloadOverride cr = fromMaybe cr $ do
guard $ cr ^. crStance . posture == Aiming
itRef <- cr ^? crManipulation . manObject . inInventory . ispItem
guard $ cr ^? crInv . ix itRef . itUse . heldConsumption . laLoaded == Just 0
guard $ cr ^? crInv . ix itRef . itUse . heldConsumption . laSource . _InternalSource . iaLoaded == Just 0
return $ cr & crActionPlan . apStrategy .~ StrategyActions Reload reloadActions
where
reloadActions =
+7 -2
View File
@@ -40,8 +40,13 @@ crIsReloading cr = case cr ^? crManipulation . manObject . inInventory . iselAct
crWeaponReady :: Creature -> Bool
crWeaponReady cr = fromMaybe False $ do
i <- cr ^? crManipulation . manObject . inInventory . ispItem
ic <- cr ^? crInv . ix i . itUse . heldConsumption
return (_laLoaded ic > 0 && _laPrimed ic)
asource <- cr ^? crInv . ix i . itUse . heldConsumption . laSource
case asource of
InternalSource ia -> return (_iaLoaded ia > 0 && _iaPrimed ia)
ExternalSource ea -> do
srcid <- ea ^? _Just
x <- cr ^? crInv . ix srcid . itUse . equipEffect . eeUse . euseAmmoAmount
return (x > 0)
crCanSeeCr :: Creature -> (World, Creature) -> Bool
crCanSeeCr tcr (w, cr) = hasLOS (_crPos cr) (_crPos tcr) w