Tweak weapons

This commit is contained in:
2021-09-06 21:58:36 +01:00
parent 60dc2d9342
commit 6ecd739d6f
6 changed files with 65 additions and 58 deletions
+24 -30
View File
@@ -1,4 +1,9 @@
module Dodge.Item.Attachment
( charFiringStratI
, scrollCharMode
, decreaseFuse
, increaseFuse
)
where
import Dodge.Data
import Dodge.Item.Attachment.Data
@@ -6,19 +11,9 @@ import Dodge.Default
import Control.Lens hiding ((|>),(<|))
import Data.Sequence
import Data.Maybe (fromJust)
import Data.Maybe
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
scrollCharMode
:: Float -- ^ Amount scrolled
@@ -34,34 +29,32 @@ incCharMode
:: Int -- ^ Inventory selection
-> World
-> World
incCharMode i = creatures . ix 0 . crInv . ix i . itAttachment %~ incCharMode'
incCharMode i = creatures . ix 0 . crInv . ix i . itAttachment . itCharMode %~ cycleL
where
cycleL (x :<| xs) = xs |> x
cycleL xs = xs
decCharMode
:: Int -- ^ Inventory selection
-> World
-> World
decCharMode i = creatures . ix 0 . crInv . ix i . itAttachment %~ decCharMode'
charFiringStrat
:: [(Char, Creature -> World -> World)] -- ^ Different firing effects for different characters
-> Creature -- ^ Creature id
-> World
-> World
charFiringStrat strats cr w = case w ^? creatures . ix cid . crInv
. ix (_crInvSel $ _creatures w IM.! cid) . itAttachment . itCharMode of
Just (c :<| _) -> fromJust (Prelude.lookup c strats) cr w
_ -> w
decCharMode i = creatures . ix 0 . crInv . ix i . itAttachment . itCharMode %~ cycleR
where
cid = _crID cr
charFiringStratI
:: [(Char, (Item -> Creature -> World -> World) -> Item -> Creature -> World -> World)] -- ^ Different firing effects for different characters
-> (Item -> Creature -> World -> World)
cycleR (xs :|> x) = x <| xs
cycleR xs = xs
type ChainEffect =
(Item -> Creature -> World -> World)
-> Item
-> Creature
-> Creature
-> World
-> World
charFiringStratI
:: [(Char, ChainEffect)] -- ^ Different firing effects for different characters
-> ChainEffect
charFiringStratI strats eff item cr w = case w ^? creatures . ix cid . crInv
. ix (_crInvSel $ _creatures w IM.! cid) . itAttachment . itCharMode of
Just (c :<| _) -> fromJust (Prelude.lookup c strats) eff item cr w
Just (c :<| _) -> fromMaybe id (Prelude.lookup c strats) eff item cr w
_ -> w
where
cid = _crID cr
@@ -84,7 +77,8 @@ increaseFuse fuse itid w = w
decreaseFuse
:: Int -- ^ Old fuse time
-> Int -- ^ Inventory item reference (I believe)
-> World -> World
-> World
-> World
decreaseFuse fuse itid w = w
& creatures . ix 0 . crInv . ix itid %~
( itScrollUp .~ decreaseFuse newTime )