module Dodge.Item.Attachment ( charFiringStratI , scrollCharMode , changeFuse ) where import Dodge.Data import Dodge.ChainEffect import Dodge.Default import Control.Lens hiding ((|>),(<|)) import Data.Sequence import Data.Maybe import qualified Data.IntMap.Strict as IM scrollCharMode :: Float -- ^ Amount scrolled -> Creature -> Item -> Item scrollCharMode x _ | x > 0 = incCharMode | x < 0 = decCharMode | otherwise = id incCharMode :: Item -> Item incCharMode = itAttachment . atCharMode %~ cycleL where cycleL (x :<| xs) = xs |> x cycleL xs = xs decCharMode :: Item -> Item decCharMode = itAttachment . atCharMode %~ cycleR where cycleR (xs :|> x) = x <| xs cycleR xs = xs charFiringStratI :: [(Char, ChainEffect)] -- ^ Different firing effects for different characters -> ChainEffect charFiringStratI strats eff item cr w = case w ^? creatures . ix cid . crInv . ix (crSel $ _creatures w IM.! cid) . itAttachment . atCharMode of Just (c :<| _) -> fromMaybe id (Prelude.lookup c strats) eff item cr w _ -> w where cid = _crID cr changeFuse :: Float -- ^ Old fuse time -> Creature -- ^ Inventory item reference (I believe) -> Item -> Item changeFuse scrollAmount _ it = it & ( itAttachment .~ AttachFuse newTime ) & ( itUse . useAim . aimZoom .~ defaultItZoom{_itZoomMax = zm, _itZoomMin = zm} ) where oldTime = _atFuseTime $ _itAttachment it newTime = min 90 $ max 20 $ oldTime - round (5 * scrollAmount) zm = 50 / fromIntegral newTime --removeItAttachment :: Int -> Int -> World -> World --removeItAttachment i _ w = w & creatures . ix i . crInv . ix itRef . itAttachment .~ NoItAttachment -- where -- cr = _creatures w IM.! i -- itRef = _crInvSel cr