module Dodge.Item.Weapon.Utility where import Dodge.Data import Dodge.Base import Dodge.Default import Dodge.Picture.Layer import Dodge.Creature.Action import Dodge.Item.Weapon.TriggerType import Dodge.Default.Weapon import Sound.Data import Geometry import Picture import qualified IntMapHelp as IM import Shape import ShapePicture import qualified Data.Map.Strict as M import Control.Lens rewindGun :: Item rewindGun = defaultGun { _itName = "REWINDER" , _itIdentity = Rewinder , _wpMaxAmmo = 0 , _wpLoadedAmmo = 0 , _itUse = useRewindGun , _itEffect = ItRewindEffect rewindEffect [] , _itLeftClickUse = Just $ \cr invid -> useRewindGun (_crInv cr IM.! invid) cr } rewindEffect :: ItEffect -> Creature -> Int -> World -> World rewindEffect iteff cr invid w = w & rewindWorlds %~ (take 100 . (w' : )) & creatures . ix (_crID cr) . crInv . ix invid . wpLoadedAmmo .~ length (_rewindWorlds w) where w' = w & rewindWorlds .~ [] & rewinding .~ True useRewindGun :: Item -> Creature -> World -> World useRewindGun it cr w = case _rewindWorlds w of (w':[]) -> rewindusing w' [] (_:w':ws) -> rewindusing w' ws _ -> w where rewindusing w' ws = w' -- & creatures . ix (_crID cr) .~ cr & upbuts & rewindWorlds .~ ws & lClickHammer .~ HammerUp & worldEvents %~ (. (worldEvents %~ (.(rewinding .~ False)))) -- fucking nesting upbuts = (keys .~ _keys w) . (mouseButtons .~ _mouseButtons w) shrinkGun :: Item shrinkGun = defaultGun { _itName = "SHRINKER" , _itIdentity = Generic , _wpMaxAmmo = 100 , _wpLoadedAmmo = 100 , _wpReloadTime = 20 , _wpReloadState = 0 , _itUseRate = 0 , _itUseTime = 0 , _itAimStance = TwoHandFlat , _itUse = useShrinkGun , _itUseModifiers = [ ammoCheckI , hammerCheckI ] , _itLeftClickUse = Nothing , _wpSpread = 0.05 , _wpRange = 20 , _itFloorPict = shrinkGunPic , _itAimingSpeed = 1 , _itAimingRange = 0 , _itAttachment = ItBool True } shrinkGunPic :: Item -> SPic shrinkGunPic _ = noPic $ colorSH violet $ upperPrismPoly 5 $ square 5 -- be careful changing this around; potential problems include updating the -- creature but using the old crInvSel value useShrinkGun :: Item -> Creature -> World -> World useShrinkGun it cr w = if _itBool $ _itAttachment it then tryResize 0.5 $ stripNoItems cr . f False UndroppableIdentified . dropUnselected cr else tryResize 1 $ f True Uncursed . setMinInvSize defaultInvSize cr where tryResize x g = maybe w g $ sizeSelf x cr w f isInUse cstatus = creatures . ix (_crID cr) . crInv . ix (_crInvSel cr) %~ ( (itAttachment . itBool .~ isInUse) . (itCurseStatus .~ cstatus) ) blinkGun :: Item blinkGun = defaultGun { _itName = "BLINKER" , _itIdentity = Blinker , _wpMaxAmmo = 100 , _wpLoadedAmmo = 100 , _wpReloadTime = 20 , _wpReloadState = 0 , _itUseRate = 0 , _itUseTime = 0 , _itUse = const blinkAction , _itUseModifiers = [ ammoCheckI , hammerCheckI ] , _itLeftClickUse = Just $ hammerCheckL $ shootL aSelfL , _wpSpread = 0.05 , _wpRange = 20 , _itFloorPict = \_ -> (,) emptySH $ onLayer FlItLayer $ polygon $ map toV2[(-2,-2),(-2,2),(2,2),(2,0),(0,0),(0,-2)] , _itAimingSpeed = 1 , _itAimingRange = 0 } aSelf :: Creature -> World -> World aSelf = blinkAction aSelfL :: Creature -> Int -> World -> World aSelfL cr _ = blinkAction cr effectGun :: String -> (Creature -> World -> World) -> Item effectGun name eff = defaultGun { _itName = name ++ "Gun" , _itUse = const eff } autoEffectGun :: String -> (Creature -> World -> World) -> Item autoEffectGun name eff = defaultAutoGun { _itName = name ++ "Gun" , _itUse = const eff } forceFieldGun :: Item forceFieldGun = defaultGun { _itName = "FORCEFIELD" , _itIdentity = ForceFieldGun , _wpMaxAmmo = 100 , _wpLoadedAmmo = 100 , _wpReloadTime = 40 , _wpReloadState = 0 , _itUseRate = 10 , _itUseTime = 0 , _itUse = undefined , _wpSpread = 0.02 , _wpRange = 20 , _itFloorPict = \_ -> (,) emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-4,-4),(-4,4),(4,4),(4,0),(0,0),(0,-4)] , _itAimingSpeed = 0.4 , _itAimingRange = 0.5 } -- grapGun = defaultGun -- { _itName = "grapGun" -- , _itIdentity = GrapGun -- , _wpMaxAmmo = 1 -- , _wpLoadedAmmo = 1 -- , _wpReloadTime = 40 -- , _wpReloadState = 0 -- , _itUseRate = 10 -- , _itUseTime = 0 -- , _itUse = grapFire -- , _wpSpread = 0.002 -- , _wpRange = 20 -- , _wpIsAuto = False -- , _itFloorPict = onLayer FlItLayer $ polygon [(-4,-4),(-4,4),(4,4),(4,0),(0,0),(0,-4)] -- , _itAmount = 1 -- , _itMaxStack = 1 -- , _itAimingSpeed = 1 -- , _itAimingRange = 0.5 -- }