55 lines
1.9 KiB
Haskell
55 lines
1.9 KiB
Haskell
module Dodge.ItEffect where
|
|
import Dodge.Data
|
|
import Dodge.Item.Equipment
|
|
import Dodge.LightSource.Torch
|
|
import Control.Lens
|
|
|
|
doInvEffect :: ItInvEffect -> Item -> Creature -> World -> World
|
|
doInvEffect iie = case iie of
|
|
NoInvEffect -> const $ const id
|
|
RewindEffect -> rewindEffect
|
|
ResetAttachmentEffect -> resetAttachmentEffect
|
|
OnOffHeldEffect f g -> onOffEff f g
|
|
CreateHeldLight -> createHeldLight
|
|
CreateShieldWall -> createShieldWall
|
|
RemoveShieldWall -> removeShieldWall
|
|
|
|
doFloorEffect :: ItFloorEffect -> Int -> World -> World
|
|
doFloorEffect NoFloorEffect = const id
|
|
|
|
doDropEffect :: ItDropEffect -> Item -> Creature -> World -> World
|
|
doDropEffect iie = case iie of
|
|
NoDropEffect -> const $ const id
|
|
|
|
onOffEff :: ItInvEffect -> ItInvEffect -> Item -> Creature -> World -> World
|
|
onOffEff f g it
|
|
| _itIsHeld it = doInvEffect f it
|
|
| otherwise = doInvEffect g it
|
|
|
|
|
|
rewindEffect :: Item -> Creature -> World -> World
|
|
rewindEffect itm cr w
|
|
| Just invid == _crLeftInvSel cr = w & rewindWorlds %~ (take maxcharge . (w' : ))
|
|
& ptrWpCharge .~ length (_rewindWorlds w)
|
|
| otherwise = w & rewindWorlds .~ []
|
|
& ptrWpCharge .~ 0
|
|
where
|
|
invid = _ipInvID $ _itPos itm
|
|
ptrWpCharge = creatures . ix (_crID cr) . crInv . ix invid . itConsumption . wpCharge
|
|
maxcharge = _wpMaxCharge . _itConsumption $ itm
|
|
w' = w & rewindWorlds .~ []
|
|
& timeFlow .~ NormalTimeFlow
|
|
|
|
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 $ _itPos itm
|
|
pointToIt = creatures . ix (_crID cr) . crInv . ix invid
|
|
|
|
createHeldLight :: Item -> Creature -> World -> World
|
|
createHeldLight itm cr = createTorchLightOffset cr itm 0
|
|
|