Generalise weapon character modes

This commit is contained in:
2021-04-29 23:13:41 +02:00
parent 6a38950501
commit 619756dd73
8 changed files with 129 additions and 127 deletions
+40
View File
@@ -1,2 +1,42 @@
module Dodge.Item.Attachment
where
import Dodge.Data
import Dodge.Item.Attachment.Data
import Control.Lens hiding ((|>),(<|))
import Data.Sequence
import Data.Maybe (fromJust)
import qualified Data.IntMap.Strict as IM
incCharMode' :: ItAttachment -> ItAttachment
incCharMode' = itCharMode %~ cycleL
where
cycleL (x :<| xs) = xs |> x
cycleL xs = xs
decCharMode' :: ItAttachment -> ItAttachment
decCharMode' = itCharMode %~ cycleR
where
cycleR (xs :|> x) = x <| xs
cycleR xs = xs
incCharMode
:: Int -- ^ Inventory selection
-> World
-> World
incCharMode i = creatures . ix 0 . crInv . ix i . itAttachment . _Just %~ incCharMode'
decCharMode
:: Int -- ^ Inventory selection
-> World
-> World
decCharMode i = creatures . ix 0 . crInv . ix i . itAttachment . _Just %~ decCharMode'
charFiringStrat
:: [(Char, Int -> World -> World)] -- ^ Different firing effects for different characters
-> Int -- ^ Creature id
-> World
-> World
charFiringStrat strats cid w =
let Just (c :<| _) = w ^? creatures . ix cid . crInv
. ix (_crInvSel $ _creatures w IM.! cid) . itAttachment
. _Just . itCharMode
in fromJust (Prelude.lookup c strats) cid w