Improve rooms, make consumable use type

This commit is contained in:
2022-03-09 10:51:01 +00:00
parent 8ff18178b1
commit a4ec4e4889
16 changed files with 98 additions and 50 deletions
+16 -7
View File
@@ -3,31 +3,38 @@ module Dodge.Creature.Impulse.UseItem
, useLeftItem
) where
import Dodge.Data
--import Dodge.Inventory
import Dodge.Inventory
import qualified Data.IntMap.Strict as IM
import Control.Lens
import Data.Maybe
useItem :: Creature -> World -> World
useItem cr' w = fromMaybe w $ do
useItem cr' w = f $ fromMaybe w $ do
cr <- w ^? creatures . ix (_crID cr')
it <- cr ^? crInv . ix (_crInvSel cr)
return $ itemEffect cr it w
where
f = case _crID cr' of
0 -> youHammerPosition .~ HammerDown
_ -> id
itemEffect :: Creature -> Item -> World -> World
itemEffect cr it w = case it ^? itUse of
Just RightUse {_rUse = eff,_useMods = usemods} -> foldr ($) eff usemods it cr w
Just LeftUse {} -> lhammer setEquipLeftItem
Just EquipUse{} -> lhammer setEquipment
-- ConsumeUse will cause problems if the item is not selected
Just (ConsumeUse eff) -> hammerTest $ eff it cr . rmInvItem (_crID cr) (_crInvSel cr)
Just NoUse -> w
Nothing -> w
where
lhammer f' = w
& lSelHammerPosition .~ HammerDown
& case _lSelHammerPosition w of
HammerUp -> creatures . ix (_crID cr) %~ f'
_ -> id
hammerTest f = case _youHammerPosition w of
HammerUp -> f w
_ -> w
lhammer f' = w & case _youHammerPosition w of
HammerUp -> creatures . ix (_crID cr) %~ f'
_ -> id
setEquipLeftItem cr' = case _crLeftInvSel cr' of
Just i | i == _crInvSel cr' -> cr' & crLeftInvSel .~ Nothing
_ -> cr' & crLeftInvSel ?~ _crInvSel cr'
@@ -42,9 +49,11 @@ toggleEquipmentAt invid cr = cr & crInvEquipped . at invid %~ f
useLeftItem :: Int -> World -> World
useLeftItem cid w
| _crInvLock cr = w
| isJust (citem ^? itUse . cUse) = useItem cr w
| otherwise = fromMaybe w $ do
invid <- _crLeftInvSel cr
f <- cr ^? crInv . ix invid . itUse . lUse
return $ f cr invid w
where
cr = _creatures w IM.! cid
citem = _crInv cr IM.! _crInvSel cr