63 lines
2.3 KiB
Haskell
63 lines
2.3 KiB
Haskell
module Dodge.ItEffect
|
|
( doInvEffect
|
|
) where
|
|
|
|
import qualified IntMapHelp as IM
|
|
import Control.Lens
|
|
import Dodge.Data.World
|
|
import Dodge.Euse
|
|
|
|
doInvEffect :: ItInvEffect -> Item -> Creature -> World -> World
|
|
doInvEffect iie = case iie of
|
|
NoInvEffect -> const $ const id
|
|
ChargeIfEquipped -> chargeIfEquipped
|
|
ChargeIfInInventory -> chargeIfInInventory
|
|
SetCharge i -> setItemCharge i
|
|
EffectRootNotroot f g -> rootNotrootEff f g
|
|
CreateShieldWall -> createShieldWall
|
|
RemoveShieldWall -> removeShieldWall
|
|
EffectWhileRoot f -> rootNotrootEff f NoInvEffect
|
|
EffectWhileAttached f -> effectWhileAttached f
|
|
|
|
rootNotrootEff :: ItInvEffect -> ItInvEffect -> Item -> Creature -> World -> World
|
|
rootNotrootEff f g it
|
|
| it ^? itLocation . ilIsRoot == Just True = doInvEffect f it
|
|
| otherwise = doInvEffect g it
|
|
|
|
effectWhileAttached :: ItInvEffect -> Item -> Creature -> World -> World
|
|
effectWhileAttached f it
|
|
| it ^? itLocation . ilIsAttached == Just True = doInvEffect f it
|
|
| otherwise = const id
|
|
|
|
--timeScrollEffect :: Item -> Creature -> World -> World
|
|
--timeScrollEffect itm _ w = w & timeFlow .~ ScrollTimeFlow
|
|
-- { _scrollSmoothing = 0
|
|
-- , _reverseAmount = itm ^?! itUse . leftConsumption . wpCharge
|
|
-- , _futureWorlds = []
|
|
-- }
|
|
|
|
setItemCharge :: Int -> Item -> Creature -> World -> World
|
|
setItemCharge i itm cr w =
|
|
w & ptrWpCharge %~ const i
|
|
where
|
|
invid = _ilInvID $ _itLocation itm
|
|
ptrWpCharge = cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix invid . itUse . leftConsumption . wpCharge
|
|
|
|
chargeIfInInventory :: Item -> Creature -> World -> World
|
|
chargeIfInInventory itm cr w =
|
|
w & ptrWpCharge %~ (min maxcharge . (+ 1))
|
|
where
|
|
invid = _ilInvID $ _itLocation itm
|
|
ptrWpCharge = cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix invid . itUse . leftConsumption . wpCharge
|
|
maxcharge = itm ^?! itUse . leftConsumption . wpMaxCharge
|
|
|
|
chargeIfEquipped :: Item -> Creature -> World -> World
|
|
chargeIfEquipped itm cr
|
|
| invid `IM.member` (cr ^. crInvHotkeys) =
|
|
ptrWpCharge %~ (min maxcharge . (+ 1))
|
|
| otherwise = ptrWpCharge .~ 0
|
|
where
|
|
invid = _ilInvID $ _itLocation itm
|
|
ptrWpCharge = cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix invid . itUse . leftConsumption . wpCharge
|
|
maxcharge = itm ^?! itUse . leftConsumption . wpMaxCharge
|