72 lines
2.6 KiB
Haskell
72 lines
2.6 KiB
Haskell
module Dodge.ItEffect where
|
|
|
|
import qualified IntMapHelp as IM
|
|
import Control.Lens
|
|
import Dodge.Data.World
|
|
import Dodge.Euse
|
|
import Dodge.LightSource.Torch
|
|
|
|
doInvEffect :: ItInvEffect -> Item -> Creature -> World -> World
|
|
doInvEffect iie = case iie of
|
|
NoInvEffect -> const $ const id
|
|
ChargeIfEquipped -> chargeIfEquipped
|
|
ChargeIfInInventory -> chargeIfInInventory
|
|
SetCharge i -> setItemCharge i
|
|
EffectIfHeld f g -> onOffEff f g
|
|
CreateHeldLight -> createHeldLight
|
|
CreateShieldWall -> createShieldWall
|
|
RemoveShieldWall -> removeShieldWall
|
|
EffectWhileHeld f -> onOffEff f NoInvEffect
|
|
|
|
doFloorEffect :: ItFloorEffect -> Int -> World -> World
|
|
doFloorEffect NoFloorEffect = const id
|
|
|
|
onOffEff :: ItInvEffect -> ItInvEffect -> Item -> Creature -> World -> World
|
|
onOffEff f g it
|
|
| _itIsHeld it = doInvEffect f it
|
|
| otherwise = doInvEffect g it
|
|
|
|
--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 = _ipInvID $ _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 = _ipInvID $ _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 = _ipInvID $ _itLocation itm
|
|
ptrWpCharge = cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix invid . itUse . leftConsumption . wpCharge
|
|
maxcharge = itm ^?! itUse . leftConsumption . wpMaxCharge
|
|
|
|
--resetAttachmentEffect :: Item -> Creature -> World -> World
|
|
--resetAttachmentEffect itm cr w
|
|
-- | _ieCounter iteff < 0 = w & pointToIt . itAttachment .~ NoItAttachment
|
|
-- | otherwise = w & pointToIt . itEffect . ieCounter -~ 1
|
|
-- where
|
|
-- iteff = _itEffect itm
|
|
-- invid = _ipInvID $ _itLocation itm
|
|
-- pointToIt = cWorld . creatures . ix (_crID cr) . crInv . ix invid
|
|
|
|
createHeldLight :: Item -> Creature -> World -> World
|
|
createHeldLight itm cr = createTorchLightOffset cr itm 0
|