Allow to equip left click items

This commit is contained in:
2021-11-27 02:01:12 +00:00
parent 774808663a
commit e7ea7377e2
21 changed files with 93 additions and 116 deletions
+18 -12
View File
@@ -26,23 +26,29 @@ tryUseItem cr' w = case w ^? creatures . ix (_crID cr') of
Nothing -> w
itemEffect
:: Creature
:: Creature
-> Item
-> World
-> World
itemEffect cr Consumable{_cnEffect=eff } w = maybe w (rmSelectedInvItem (_crID cr)) (eff (_crID cr) w)
itemEffect cr it@Weapon{_itUse=eff} w = foldr ($) eff (_itUseModifiers it) it cr w
itemEffect cr it@Throwable{_itUse = eff} w = foldr ($) eff (_itUseModifiers it) it cr w
itemEffect _ _ w = w
useLeftItem
:: Int
-> World
-> World
useLeftItem cid w = case luse of
itemEffect cr it w = case it ^? itUse of
Just (Right eff) -> foldr ($) eff (_itUseModifiers it) it cr w
Just (Left _ ) -> w & creatures . ix (_crID cr) . crLeftInvSel ?~ _crInvSel cr
Nothing -> w
Just (invid, f) -> f cr invid w
--this is ugly
useLeftItem :: Int -> World -> World
useLeftItem cid w = case _crInv cr IM.! crinvsel ^? itUse . _Left of
Just f -> f cr crinvsel w & creatures . ix cid . crLeftInvSel ?~ crinvsel
Nothing -> case _crLeftInvSel cr of
Just invid -> case _itUse $ _crInv cr IM.! invid of
Left f -> f cr invid w
Right _ -> w & creatures . ix cid . crLeftInvSel .~ Nothing
Nothing -> case luse of
Nothing -> w
Just (invid, f) -> f cr invid w & creatures . ix cid . crLeftInvSel ?~ invid
where
crinvsel = _crInvSel cr
cr = _creatures w IM.! cid
luses = IM.mapMaybe (^? itLeftClickUse . _Just) (_crInv cr)
luses = IM.mapMaybe (^? itUse . _Left) (_crInv cr)
luse = listToMaybe $ IM.toList luses