Magnets
This commit is contained in:
@@ -22,45 +22,45 @@ tryUseItem cr' w = case w ^? creatures . ix (_crID cr') of
|
||||
Nothing -> w
|
||||
|
||||
itemEffect :: Creature -> Item -> World -> World
|
||||
--itemEffect cr Consumable{_cnEffect=eff } w = maybe w (rmSelectedInvItem (_crID cr)) (eff (_crID cr) w)
|
||||
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 LeftUse {} -> w
|
||||
-- & lSelHammerPosition .~ HammerDown
|
||||
-- & docycle
|
||||
--Just EquipUse -> w & creatures . ix (_crID cr) . crInvEquipped . at (_crInvSel cr) %~ f
|
||||
Just EquipUse -> lhammer setEquipment
|
||||
Just EquipUse{} -> lhammer setEquipment
|
||||
Just NoUse -> w
|
||||
Nothing -> w
|
||||
where
|
||||
f Nothing = Just ()
|
||||
f (Just ()) = Nothing
|
||||
-- toggleEquip invid =
|
||||
lhammer f = w
|
||||
lhammer f' = w
|
||||
& lSelHammerPosition .~ HammerDown
|
||||
& case _lSelHammerPosition w of
|
||||
HammerUp -> creatures . ix (_crID cr) %~ f
|
||||
HammerUp -> creatures . ix (_crID cr) %~ f'
|
||||
_ -> id
|
||||
setEquipLeftItem cr = case _crLeftInvSel cr of
|
||||
Just i | i == _crInvSel cr -> cr & crLeftInvSel .~ Nothing
|
||||
_ -> cr & crLeftInvSel .~ (Just $ _crInvSel cr)
|
||||
setEquipment = crInvEquipped . at (_crInvSel cr) %~ f
|
||||
docycle | _lSelHammerPosition w == HammerUp = creatures . ix (_crID cr) . crLeftInvSel %~ cyclelsel
|
||||
| otherwise = id
|
||||
cyclelsel mi = case mi of
|
||||
Just i | i == _crInvSel cr -> Nothing
|
||||
_ -> Just $ _crInvSel cr
|
||||
setEquipLeftItem cr' = case _crLeftInvSel cr' of
|
||||
Just i | i == _crInvSel cr' -> cr' & crLeftInvSel .~ Nothing
|
||||
_ -> cr' & crLeftInvSel ?~ _crInvSel cr'
|
||||
setEquipment = toggleEquipmentAt (_crInvSel cr)
|
||||
|
||||
toggleEquipmentAt :: Int -> Creature -> Creature
|
||||
toggleEquipmentAt invid cr = cr & crInvEquipped . at invid %~ f
|
||||
where
|
||||
f Nothing = Just ()
|
||||
f (Just ()) = Nothing
|
||||
|
||||
--this is ugly
|
||||
useLeftItem :: Int -> World -> World
|
||||
useLeftItem cid w | _crInvLock $ _creatures w IM.! cid = w
|
||||
useLeftItem cid w
|
||||
| _crInvLock $ _creatures w IM.! cid = w
|
||||
| otherwise = useLeftItem' cid w
|
||||
|
||||
|
||||
useLeftItem' :: Int -> World -> World
|
||||
useLeftItem' cid w = case cr ^? crInv . ix crinvsel . itUse . lUse of
|
||||
Just f -> f cr crinvsel (w & creatures . ix cid . crLeftInvSel ?~ crinvsel)
|
||||
Nothing -> case _crLeftInvSel cr of
|
||||
useLeftItem' cid w = case cr ^? crInv . ix crinvsel . itUse of
|
||||
Just EquipUse{} -> w
|
||||
& lSelHammerPosition .~ HammerDown
|
||||
& case _lSelHammerPosition w of
|
||||
HammerUp -> creatures . ix cid %~ toggleEquipmentAt crinvsel
|
||||
_ -> id
|
||||
Just LeftUse {_lUse = f} -> f cr crinvsel (w & creatures . ix cid . crLeftInvSel ?~ crinvsel)
|
||||
_ -> case _crLeftInvSel cr of
|
||||
Just invid -> case _itUse $ _crInv cr IM.! invid of
|
||||
LeftUse {_lUse = f} -> f cr invid w
|
||||
_ -> w & creatures . ix cid . crLeftInvSel .~ Nothing
|
||||
|
||||
@@ -19,6 +19,7 @@ import Picture
|
||||
import qualified IntMapHelp as IM
|
||||
--import StrictHelp
|
||||
|
||||
import qualified Data.IntSet as IS
|
||||
import Data.Maybe
|
||||
import Data.Function
|
||||
import Control.Lens
|
||||
@@ -134,8 +135,11 @@ invItemUpdate = itUse %~ useupdate
|
||||
. (useDelay . rateTime %~ decreaseToZero)
|
||||
|
||||
invSideEff :: Creature -> World -> World
|
||||
invSideEff cr w = weaponReloadSounds cr $ IM.foldrWithKey f w (_crInv cr)
|
||||
invSideEff cr w = weaponReloadSounds cr
|
||||
. flip (IS.foldr useeq) (_crInvEquipped cr)
|
||||
$ IM.foldrWithKey f w (_crInv cr)
|
||||
where
|
||||
useeq i = _eqUse (_itUse $ _crInv cr IM.! i) cr i
|
||||
f i it w' = case it ^? itEffect . itInvEffect of
|
||||
Nothing -> w' & doitemupdate
|
||||
Just g -> g (_itEffect it) cr i w' & doitemupdate
|
||||
|
||||
Reference in New Issue
Block a user