From 8639b2d42868a9602fa6fad87d29e8b38c69e0f6 Mon Sep 17 00:00:00 2001 From: justin Date: Sat, 27 Nov 2021 16:37:30 +0000 Subject: [PATCH] Push item use delay inside datatype, currently broken --- src/Dodge/Creature/Impulse/UseItem.hs | 6 +-- src/Dodge/Creature/State.hs | 2 +- src/Dodge/Data.hs | 26 +++++++------ src/Dodge/Default.hs | 6 +-- src/Dodge/Default/Weapon.hs | 54 ++++++++++++++++++++++++--- src/Dodge/Item.hs | 2 - src/Dodge/Item/Data.hs | 12 ++++-- src/Dodge/Item/Weapon/AmmoParams.hs | 19 ++++++++-- src/Dodge/Item/Weapon/BatteryGuns.hs | 15 ++------ src/Dodge/Item/Weapon/Bezier.hs | 6 +-- src/Dodge/Item/Weapon/Booster.hs | 4 +- src/Dodge/Item/Weapon/BulletGuns.hs | 41 ++++---------------- src/Dodge/Item/Weapon/Drone.hs | 7 +--- src/Dodge/Item/Weapon/ExtraEffect.hs | 5 +-- src/Dodge/Item/Weapon/Grenade.hs | 22 ++++------- src/Dodge/Item/Weapon/Launcher.hs | 20 ++++------ src/Dodge/Item/Weapon/Radar.hs | 12 +----- src/Dodge/Item/Weapon/Spawn.hs | 7 ++-- src/Dodge/Item/Weapon/SprayGuns.hs | 10 +---- src/Dodge/Item/Weapon/TriggerType.hs | 39 ++++++++++--------- src/Dodge/Item/Weapon/Utility.hs | 24 +++--------- 21 files changed, 162 insertions(+), 177 deletions(-) diff --git a/src/Dodge/Creature/Impulse/UseItem.hs b/src/Dodge/Creature/Impulse/UseItem.hs index d14a26fb4..fa830e4f7 100644 --- a/src/Dodge/Creature/Impulse/UseItem.hs +++ b/src/Dodge/Creature/Impulse/UseItem.hs @@ -32,8 +32,8 @@ itemEffect -> World itemEffect cr Consumable{_cnEffect=eff } w = maybe w (rmSelectedInvItem (_crID cr)) (eff (_crID cr) w) itemEffect cr it w = case it ^? itUse of - Just (RightUse eff) -> foldr ($) eff (_itUseModifiers it) it cr w - Just (LeftUse _ ) -> w & creatures . ix (_crID cr) . crLeftInvSel ?~ _crInvSel cr + Just (RightUse {_rUse = eff,_useMods = usemods}) -> foldr ($) eff usemods it cr w + Just (LeftUse {}) -> w & creatures . ix (_crID cr) . crLeftInvSel ?~ _crInvSel cr _ -> w --this is ugly @@ -42,7 +42,7 @@ useLeftItem cid w = case _crInv cr IM.! crinvsel ^? itUse . lUse of Just f -> f cr crinvsel w & creatures . ix cid . crLeftInvSel ?~ crinvsel Nothing -> case _crLeftInvSel cr of Just invid -> case _itUse $ _crInv cr IM.! invid of - LeftUse f -> f cr invid w + LeftUse {_lUse = f} -> f cr invid w _ -> w & creatures . ix cid . crLeftInvSel .~ Nothing Nothing -> case luse of Nothing -> w diff --git a/src/Dodge/Creature/State.hs b/src/Dodge/Creature/State.hs index d2257aea8..0e364b615 100644 --- a/src/Dodge/Creature/State.hs +++ b/src/Dodge/Creature/State.hs @@ -165,7 +165,7 @@ isFrictionless cr = case cr ^? crStance . carriage of stepItemUseCooldown :: Creature -> Creature stepItemUseCooldown cr = cr & crInv . ix iSel %~ - (itUseTime %~ decreaseToZero) . (wpCurWarmUp %~ decreaseToZero) + (itUse . useDelay . rateTime %~ decreaseToZero) . (wpCurWarmUp %~ decreaseToZero) where iSel = _crInvSel cr diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index 71b16d8f7..240d33d86 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -289,12 +289,23 @@ data FloorItem = FlIt { _flIt :: Item , _flItPos :: Point2 , _flItRot :: Float, data ItemPos = InInv { _itCrId :: Int , _itInvId :: Int } | OnFloor { _itFlID :: Int } +data UseDelay -- should just be Delay + = NoDelay + | DelayRate + {_rateMax :: Int + ,_rateTime :: Int + } data ItemUse = RightUse - { _rUse :: Item -> Creature -> World -> World + { _rUse :: Item -> Creature -> World -> World + , _useDelay :: UseDelay + , _useMods :: [(Item -> Creature -> World -> World) -> Item -> Creature -> World -> World] + , _useHammer :: HammerType } | LeftUse - { _lUse :: Creature -> Int -> World -> World + { _lUse :: Creature -> Int -> World -> World + , _itUseDelay :: UseDelay + , _itHammer :: HammerType } | NoUse data ItemAmmo @@ -318,13 +329,9 @@ data Item , _wpCurWarmUp :: Int , _wpMaxCoolDown :: Int , _wpCurCoolDown :: Int - , _itUseRate :: Int - , _itUseTime :: Int , _itUse :: ItemUse - , _itUseModifiers :: [(Item -> Creature -> World -> World) -> Item -> Creature -> World -> World] , _wpSpread :: Float , _wpRange :: Float - , _itHammer :: HammerPosition , _itFloorPict :: Item -> SPic , _itAimingSpeed :: Float , _itAimingRange :: Float @@ -357,7 +364,6 @@ data Item , _itInvDisplay :: Item -> String , _itInvColor :: Color , _itEffect :: ItEffect - , _itHammer :: HammerPosition , _itAimStance :: AimStance , _itCurseStatus :: CurseStatus , _itDimension :: ItemDimension @@ -389,7 +395,6 @@ data Item , _itAimZoom :: ItZoom , _itInvDisplay :: Item -> String , _itInvColor :: Color - , _itHammer :: HammerPosition , _itAimStance :: AimStance , _itCurseStatus :: CurseStatus , _itDimension :: ItemDimension @@ -402,9 +407,6 @@ data Item , _twMaxRange :: Float , _twAccuracy :: Float , _itUse :: ItemUse - , _itUseRate :: Int - , _itUseTime :: Int - , _itUseModifiers :: [(Item -> Creature -> World -> World) -> Item -> Creature -> World -> World] , _itAimingSpeed :: Float , _itAimingRange :: Float , _itZoom :: ItZoom @@ -416,7 +418,6 @@ data Item , _itInvDisplay :: Item -> String , _itInvColor :: Color , _itEffect :: ItEffect - , _itHammer :: HammerPosition , _itScroll :: Float -> Creature -> Item -> Item , _itAimStance :: AimStance , _itCurseStatus :: CurseStatus @@ -892,3 +893,4 @@ makeLenses ''MachineType makeLenses ''Zone makeLenses ''ItemDimension makeLenses ''Vocalization +makeLenses ''UseDelay diff --git a/src/Dodge/Default.hs b/src/Dodge/Default.hs index cfbbe7c1d..7579dd4ee 100644 --- a/src/Dodge/Default.hs +++ b/src/Dodge/Default.hs @@ -137,7 +137,6 @@ defaultEquipment = Equipment , _itFloorPict = \_ -> (,) emptySH $ setLayer 0 $ onLayer FlItLayer $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)] , _itEquipPict = \_ _ -> (,) emptySH blank , _itEffect = NoItEffect - , _itHammer = HammerUp , _itID = Nothing , _itAimingSpeed = 1 , _itAimingRange = 0 @@ -164,7 +163,6 @@ defaultConsumable = Consumable , _itInvColor = blue , _itInvDisplay = \it -> _itName it ++ " x" ++ show (_itAmount it) , _itEffect = wpRecock - , _itHammer = HammerUp , _itAimStance = LeaveHolstered , _itDimension = defaultItemDimension } @@ -214,7 +212,6 @@ defaultIt = Consumable , _itInvDisplay = _itName , _itInvColor = blue , _itEffect = NoItEffect - , _itHammer = HammerUp , _itAimStance = LeaveHolstered } defaultMachine :: Machine @@ -305,3 +302,6 @@ defaultTLS = TLS f _ t | _tlsTime t <= 0 = Nothing | otherwise = Just $ t & tlsTime -~ 1 + +upHammer :: HammerType +upHammer = HasHammer HammerUp diff --git a/src/Dodge/Default/Weapon.hs b/src/Dodge/Default/Weapon.hs index 301784a8b..abb0eb41f 100644 --- a/src/Dodge/Default/Weapon.hs +++ b/src/Dodge/Default/Weapon.hs @@ -20,6 +20,54 @@ defaultAmmo = LoadableAmmo , _wpReloadType = ActiveReload } +ruseRate :: Int + -> (Item -> Creature -> World -> World) + -> HammerType + -> [(Item -> Creature -> World -> World) -> Item -> Creature -> World -> World] + -> ItemUse +ruseRate i f ht usemods = RightUse + { _rUse = f + , _useDelay = DelayRate + { _rateMax = i + , _rateTime = 0 + } + , _useMods = usemods + , _useHammer = ht + } + +ruseInstant + :: (Item -> Creature -> World -> World) + -> HammerType + -> [(Item -> Creature -> World -> World) -> Item -> Creature -> World -> World] + -> ItemUse +ruseInstant f ht usemods = RightUse + { _rUse = f + , _useDelay = NoDelay + , _useMods = usemods + , _useHammer = ht + } + +defaultrUse :: ItemUse +defaultrUse = RightUse + { _rUse = \_ _ -> id + , _useDelay = DelayRate {_rateMax = 8, _rateTime = 0} + , _useMods = [] + , _useHammer = HasHammer HammerUp + } +defaultlUse :: ItemUse +defaultlUse = LeftUse + { _lUse = \_ _ -> id + , _itUseDelay = DelayRate {_rateMax = 8, _rateTime = 0} + , _itHammer = NoHammer + } + +luseInstantNoH :: (Creature -> Int -> World -> World) -> ItemUse +luseInstantNoH f = LeftUse + { _lUse = f + , _itUseDelay = NoDelay + , _itHammer = NoHammer + } + defaultGun :: Item defaultGun = Weapon { _itName = "default" @@ -30,13 +78,9 @@ defaultGun = Weapon , _wpCurWarmUp = 0 , _wpMaxCoolDown = 0 , _wpCurCoolDown = 0 - , _itUseRate = 8 - , _itUseTime = 0 - , _itUse = RightUse $ \_ _ -> id - , _itUseModifiers = [] + , _itUse = defaultrUse , _wpSpread = 0.02 , _wpRange = 20 - , _itHammer = HammerUp , _itFloorPict = const $ noPic $ colorSH green (prismPoly (map (addZ 3) $ rectNESW 3 3 (-3) (-3)) (map (addZ 0) $ rectNESW 5 3 (-5) (-7)) diff --git a/src/Dodge/Item.hs b/src/Dodge/Item.hs index ea2d502fa..1f4c0a725 100644 --- a/src/Dodge/Item.hs +++ b/src/Dodge/Item.hs @@ -17,7 +17,6 @@ keyToken n = defaultEquipment , _itFloorPict = \_ -> (,) emptySH $ setDepth 0.5 keyPic , _itEquipPict = \_ _ -> (,) emptySH $ setDepth 0 $ translate (-5) (-5) $ rotate (pi/2.5) keyPic , _itEffect = NoItEffect - , _itHammer = HammerUp , _itID = Nothing , _itAimingSpeed = 1 , _itAimingRange = 0 @@ -41,7 +40,6 @@ latchkey n = defaultEquipment , _itFloorPict = \_ -> (,) emptySH $ setDepth 0.5 latchkeyPic , _itEquipPict = \_ _ -> (,) emptySH $ setDepth 0 $ translate (-5) (-5) $ rotate (pi/2.5) latchkeyPic , _itEffect = NoItEffect - , _itHammer = HammerUp , _itID = Nothing , _itAimingSpeed = 1 , _itAimingRange = 0 diff --git a/src/Dodge/Item/Data.hs b/src/Dodge/Item/Data.hs index 2bea63c2d..b7ffe1851 100644 --- a/src/Dodge/Item/Data.hs +++ b/src/Dodge/Item/Data.hs @@ -1,11 +1,16 @@ {-# LANGUAGE StrictData #-} -module Dodge.Item.Data - where +{-# LANGUAGE TemplateHaskell #-} +module Dodge.Item.Data where +import Control.Lens +data HammerType + = NoHammer + | HasHammer {_hammerPosition :: HammerPosition} + deriving + (Eq, Ord, Show) data HammerPosition = HammerDown | HammerReleased | HammerUp - | NoHammer deriving (Eq, Ord, Show) data ItemIdentity @@ -49,3 +54,4 @@ data AimStance | LeaveHolstered deriving (Eq,Show,Ord,Enum) +makeLenses ''HammerType diff --git a/src/Dodge/Item/Weapon/AmmoParams.hs b/src/Dodge/Item/Weapon/AmmoParams.hs index 468a614bf..02c5aee51 100644 --- a/src/Dodge/Item/Weapon/AmmoParams.hs +++ b/src/Dodge/Item/Weapon/AmmoParams.hs @@ -1,5 +1,6 @@ module Dodge.Item.Weapon.AmmoParams ( useAmmoParams + , useAmmoParamsRate , loadedAmmo , useAmmoParamsVelMod , fractionLoadedAmmo @@ -11,9 +12,21 @@ import Geometry import Control.Lens -useAmmoParams :: ItemUse -useAmmoParams = RightUse $ \it -> let b = _aoType $ _wpAmmo it - in withVelWthHiteff (_amBulVel b) (_amBulWth b) (_amBulEff b) +useAmmoParamsRate :: Int + -> HammerType + -> [(Item -> Creature -> World -> World) -> Item -> Creature -> World -> World] + -> ItemUse +useAmmoParamsRate rate ht usemods = RightUse + { _rUse = useAmmoParams + , _useDelay = DelayRate {_rateMax = rate,_rateTime = 0} + , _useMods = usemods + , _useHammer = ht + } + +useAmmoParams :: Item -> Creature -> World -> World +useAmmoParams it = withVelWthHiteff (_amBulVel b) (_amBulWth b) (_amBulEff b) + where + b = _aoType $ _wpAmmo it useAmmoParamsVelMod :: Float -> Item -> Creature -> World -> World useAmmoParamsVelMod vfact it = withDelayedVelWthHiteff vfact (_amBulVel b) (_amBulWth b) (_amBulEff b) diff --git a/src/Dodge/Item/Weapon/BatteryGuns.hs b/src/Dodge/Item/Weapon/BatteryGuns.hs index ec98f96f6..ffc49c00b 100644 --- a/src/Dodge/Item/Weapon/BatteryGuns.hs +++ b/src/Dodge/Item/Weapon/BatteryGuns.hs @@ -42,11 +42,8 @@ teslaGun = defaultGun , _wpLoadedAmmo = 200 , _wpReloadTime = 80 } - , _itUseRate = 0 , _itAimStance = TwoHandFlat - , _itUseTime = 0 - , _itUse = RightUse $ const aTeslaArc - , _itUseModifiers = + , _itUse = ruseInstant (const aTeslaArc) NoHammer [ ammoCheckI , useTimeCheckI , withTempLight 1 100 (V3 0 0 1) @@ -77,10 +74,7 @@ lasGun = defaultAutoGun , _wpLoadedAmmo = 200 , _wpReloadTime = 80 } - , _itUseRate = 0 - , _itUseTime = 0 - , _itUse = RightUse $ const aLaser - , _itUseModifiers = + , _itUse = ruseInstant (const aLaser) NoHammer [ ammoCheckI , useTimeCheckI , withTempLight 1 100 (V3 1 1 0) @@ -118,10 +112,7 @@ tractorGun = defaultAutoGun , _wpLoadedAmmo = 10000 , _wpReloadTime = 40 } - , _itUseRate = 0 - , _itUseTime = 0 - , _itUse = RightUse aTractorBeam - , _itUseModifiers = + , _itUse = ruseInstant aTractorBeam NoHammer [ ammoUseCheckI ] , _wpSpread = 0.00001 diff --git a/src/Dodge/Item/Weapon/Bezier.hs b/src/Dodge/Item/Weapon/Bezier.hs index e6ad303a4..731702aa9 100644 --- a/src/Dodge/Item/Weapon/Bezier.hs +++ b/src/Dodge/Item/Weapon/Bezier.hs @@ -23,8 +23,8 @@ import Control.Monad.State bezierGun :: Item bezierGun = defaultGun { _itName = "B-GUN" - , _itUse = RightUse $ \_ -> useTargetPos $ \p -> shootBezier $ fromJust p -- <- the start point - , _itUseModifiers = + , _itUse = ruseRate 6 (\_ -> useTargetPos $ \p -> shootBezier $ fromJust p) -- <- the start point + NoHammer [ ammoCheckI , useTimeCheckI , withSoundStart tap2S @@ -36,14 +36,12 @@ bezierGun = defaultGun , _itFloorPict = bezierGunSPic , _itAttachment = NoItAttachment , _itScroll = \_ _ -> removeItTarget - , _itHammer = HammerUp , _itEffect = rbSetTarget , _itZoom = defaultItZoom , _itAimingRange = 0 , _wpAmmo = defaultAmmo { _wpMaxAmmo = 50 } - , _itUseRate = 6 , _itAimStance = TwoHandTwist } bezierGunSPic :: Item -> SPic diff --git a/src/Dodge/Item/Weapon/Booster.hs b/src/Dodge/Item/Weapon/Booster.hs index 634fa727c..0265ce2aa 100644 --- a/src/Dodge/Item/Weapon/Booster.hs +++ b/src/Dodge/Item/Weapon/Booster.hs @@ -118,9 +118,7 @@ boosterGun = defaultGun , _wpLoadedAmmo = 100 , _wpReloadTime = 20 } - , _itUseRate = 0 - , _itUseTime = 0 - , _itUse = LeftUse $ boostSelfL 10 + , _itUse = luseInstantNoH $ boostSelfL 10 , _wpSpread = 0.05 , _wpRange = 20 , _itFloorPict = \_ -> (,) emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-2,-2),(-2,2),(2,2),(2,0),(0,0),(0,-2)] diff --git a/src/Dodge/Item/Weapon/BulletGuns.hs b/src/Dodge/Item/Weapon/BulletGuns.hs index 2d4785b23..3587ee119 100644 --- a/src/Dodge/Item/Weapon/BulletGuns.hs +++ b/src/Dodge/Item/Weapon/BulletGuns.hs @@ -41,10 +41,7 @@ autoGun = defaultAutoGun , _wpLoadedAmmo = 30 , _wpReloadTime = 80 } - , _itUseRate = 5 - , _itUseTime = 0 - , _itUse = useAmmoParams - , _itUseModifiers = + , _itUse = useAmmoParamsRate 5 NoHammer [ ammoCheckI , charFiringStratI [('S', hammerCheckI) @@ -93,10 +90,7 @@ pistol = defaultGun , _wpLoadedAmmo = 15 , _wpReloadTime = 40 } - , _itUseRate = 8 - , _itUseTime = 0 - , _itUse = useAmmoParams - , _itUseModifiers = + , _itUse = useAmmoParamsRate 8 upHammer [ ammoCheckI , hammerCheckI , useTimeCheckI @@ -142,10 +136,7 @@ hvAutoGun = defaultAutoGun , _wpLoadedAmmo = 100 , _wpReloadTime = 200 } - , _itUseRate = 25 - , _itUseTime = 0 - , _itUse = useAmmoParams - , _itUseModifiers = + , _itUse = useAmmoParamsRate 25 NoHammer [ ammoCheckI , rateIncABI 24 7 (torqueBeforeAtLeast 0.1 0.1) (torqueAfterI 0.2) , withSoundStart bangEchoS @@ -178,10 +169,7 @@ ltAutoGun = defaultAutoGun , _wpLoadedAmmo = 25 , _wpReloadTime = 80 } - , _itUseRate = 3 - , _itUseTime = 0 - , _itUse = useAmmoParams - , _itUseModifiers = + , _itUse = useAmmoParamsRate 3 NoHammer [ ammoCheckI , useTimeCheckI , withSoundStart tap1S @@ -221,10 +209,7 @@ miniGun = defaultAutoGun , _wpReloadTime = 200 } , _wpMaxWarmUp = 100 - , _itUseRate = 0 - , _itUseTime = 0 - , _itUse = RightUse $ useAmmoParamsVelMod vm4 - , _itUseModifiers = + , _itUse = ruseInstant (useAmmoParamsVelMod vm4) NoHammer [ ammoCheckI , withWarmUpI crankSlowS , useTimeCheckI @@ -312,11 +297,7 @@ spreadGun = defaultGun , _wpLoadedAmmo = 5 , _wpReloadTime = 80 } - , _itUseRate = 20 - , _itUseTime = 0 - --, _itUse = \_ -> spreadNumVelWthHiteff spreadGunSpread 9 (V2 30 0) 2 basicBulletEffect - , _itUse = useAmmoParams - , _itUseModifiers = + , _itUse = useAmmoParamsRate 20 upHammer [ ammoCheckI , hammerCheckI , useTimeCheckI @@ -351,10 +332,7 @@ multGun = defaultGun , _wpLoadedAmmo = 2 , _wpReloadTime = 40 } - , _itUseRate = 20 - , _itUseTime = 0 - , _itUse = useAmmoParams - , _itUseModifiers = + , _itUse = useAmmoParamsRate 20 upHammer [ ammoCheckI , hammerCheckI , useTimeCheckI @@ -400,10 +378,7 @@ longGun = defaultGun , _wpReloadTime = 100 , _wpReloadType = PassiveReload skwareFadeTwoSecS } - , _itUseRate = 100 - , _itUseTime = 0 - , _itUse = useAmmoParams - , _itUseModifiers = + , _itUse = useAmmoParamsRate 100 upHammer [ ammoCheckI , hammerCheckI , useTimeCheckI diff --git a/src/Dodge/Item/Weapon/Drone.hs b/src/Dodge/Item/Weapon/Drone.hs index 778fa3c46..c3d760df7 100644 --- a/src/Dodge/Item/Weapon/Drone.hs +++ b/src/Dodge/Item/Weapon/Drone.hs @@ -1,6 +1,7 @@ module Dodge.Item.Weapon.Drone where import Dodge.Data import Dodge.Default.Weapon +import Dodge.Default import Dodge.SoundLogic.LoadSound import Dodge.Item.Weapon.TriggerType import Geometry @@ -28,10 +29,7 @@ lasDrones = defaultGun , _wpLoadedAmmo = 2 , _wpReloadTime = 80 } - , _itUseRate = 20 - , _itUseTime = 0 - , _itUse = RightUse aDroneWithItemParams - , _itUseModifiers = + , _itUse = ruseRate 20 aDroneWithItemParams upHammer [ ammoCheckI , useTimeCheckI , withSoundStart tap4S @@ -42,7 +40,6 @@ lasDrones = defaultGun , _itFloorPict = lasDronesPic , _itAimingSpeed = 0.2 , _itAimingRange = 0.5 - , _itHammer = NoHammer , _itEffect = NoItEffect , _itAimStance = TwoHandTwist } diff --git a/src/Dodge/Item/Weapon/ExtraEffect.hs b/src/Dodge/Item/Weapon/ExtraEffect.hs index d428a548a..4a7b29ad5 100644 --- a/src/Dodge/Item/Weapon/ExtraEffect.hs +++ b/src/Dodge/Item/Weapon/ExtraEffect.hs @@ -38,8 +38,7 @@ wpRecock = ItInvEffect moveHammerUp HammerDown = HammerReleased moveHammerUp HammerReleased = HammerUp moveHammerUp HammerUp = HammerUp - moveHammerUp NoHammer = NoHammer - fOnIt it = it & itHammer %~ moveHammerUp + fOnIt it = it & itUse . itHammer . hammerPosition %~ moveHammerUp --{- | --Special recock for the bezier gun. --Not sure of its purpose at this time... -} @@ -66,7 +65,7 @@ itemLaserScopeEffect f _ cr invid w | invid == _crInvSel cr && crIsAiming' cr = w & particles %~ (:) (makeLaserScope sp ep reloadFrac) - & creatures . ix (_crID cr) . crInv . ix invid . itHammer %~ moveHammerUp + & creatures . ix (_crID cr) . crInv . ix invid . itUse . itHammer . hammerPosition %~ moveHammerUp | otherwise = w where p = _crPos cr diff --git a/src/Dodge/Item/Weapon/Grenade.hs b/src/Dodge/Item/Weapon/Grenade.hs index 5b0f0cd65..d6eb69927 100644 --- a/src/Dodge/Item/Weapon/Grenade.hs +++ b/src/Dodge/Item/Weapon/Grenade.hs @@ -34,8 +34,7 @@ grenade = Throwable , _itFloorPict = \_ -> (,) emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)] , _twMaxRange = 150 , _twAccuracy = 30 - , _itUse = RightUse $ \_ -> throwGrenade makeExplosionAt - , _itUseModifiers = + , _itUse = ruseRate 25 (\_ -> throwGrenade makeExplosionAt) upHammer [ useTimeCheckI ] , _itAimingSpeed = 1 @@ -44,13 +43,10 @@ grenade = Throwable , _itAimZoom = defaultItZoom {_itZoomMax = f fuseTime, _itZoomMin = f fuseTime} , _itEquipPict = pictureWeaponOnAim' $ \_ -> grenadePic fuseTime , _itID = Nothing - , _itUseRate = 25 - , _itUseTime = 0 , _itAttachment = ItFuse fuseTime , _itInvColor = white , _itInvDisplay = basicWeaponDisplay , _itEffect = wpRecock - , _itHammer = HammerUp , _itScroll = changeFuse , _itAimStance = OneHand } @@ -133,7 +129,7 @@ throwArmReset x = ItInvEffect {_itInvEffect = f ,_itEffectCounter = x } f _ cr i = creatures . ix (_crID cr) . crInv %~ IM.adjust counterDown i counterDown it | _itEffectCounter (_itEffect it) == 0 = it - & itHammer .~ HammerUp + & itUse . itHammer . hammerPosition .~ HammerUp & itEquipPict .~ pictureWeaponOnAim' (\_ -> grenadePic 50) | otherwise = it & itEffect . itEffectCounter -~ 1 @@ -227,10 +223,8 @@ remoteBomb = defaultThrowable [(-3,-3),(-3,3),(3,3),(3,-3)] , _twMaxRange = 150 , _twAccuracy = 30 - , _itUse = RightUse $ const throwRemoteBomb - , _itUseModifiers = - [ hammerCheckI - ] + , _itUse = ruseRate 25 (const throwRemoteBomb) upHammer + [ hammerCheckI ] , _itAttachment = ItScope (V2 0 0) 0 1 True , _itEquipPict = pictureWeaponOnAim' $ \_ -> (,) emptySH remoteBombUnarmedPic } @@ -259,8 +253,8 @@ throwRemoteBomb cr w = setLocation j = _crInvSel cr resetName = set (creatures . ix cid . crInv . ix j . itName) "REMOTE" removePict = set (creatures . ix cid . crInv . ix j . itEquipPict) $ \ _ _ -> emptyBlank - resetFire = set (creatures . ix cid . crInv . ix j . itUse) - $ RightUse $ \_ -> explodeRemoteBomb itid i + resetFire = set (creatures . ix cid . crInv . ix j . itUse . rUse) + $ \_ -> explodeRemoteBomb itid i p' = _crPos cr +.+ rotateV (_crDir cr) (V2 (_crRad cr) 0) p | circOnSomeWall p' 4 w = _crPos cr +.+ rotateV (_crDir cr) (V2 (_crRad cr-4) 0) | otherwise = p' @@ -277,7 +271,7 @@ explodeRemoteBomb :: Int -> Int -> Creature -> World -> World explodeRemoteBomb itid pjid cr w = set (props . ix pjid . pjUpdate) (\_ -> retireRemoteBomb itid 30 pjid) -- $ set (props . ix pjid . pjDraw) (\_ -> blank) - $ set (creatures . ix cid . crInv . ix j . itUse) (RightUse $ \_ -> const id) + $ set (creatures . ix cid . crInv . ix j . itUse . rUse) (\_ -> const id) $ resetName $ resetPict -- $ resetScope @@ -305,7 +299,7 @@ retireRemoteBomb itid 0 pjid w = w & pointToItem (_itemPositions w IM.! itid) %~ ( (itAttachment . scopePos .~ V2 0 0) . (itZoom .~ defaultItZoom) - . (itUse .~ (RightUse $ const throwRemoteBomb)) + . (itUse . rUse .~ const throwRemoteBomb) ) & props %~ IM.delete pjid retireRemoteBomb itid t pjid w = setScope w diff --git a/src/Dodge/Item/Weapon/Launcher.hs b/src/Dodge/Item/Weapon/Launcher.hs index cbf67b3b5..01440289c 100644 --- a/src/Dodge/Item/Weapon/Launcher.hs +++ b/src/Dodge/Item/Weapon/Launcher.hs @@ -3,6 +3,7 @@ module Dodge.Item.Weapon.Launcher , remoteLauncher ) where import Dodge.Data +import Dodge.Default import Dodge.Default.Weapon import Dodge.Default.Shell import Dodge.SoundLogic.LoadSound @@ -48,10 +49,7 @@ launcher = defaultGun , _wpLoadedAmmo = 30 , _wpReloadTime = 80 } - , _itUseRate = 20 - , _itUseTime = 0 - , _itUse = RightUse aRocketWithItemParams - , _itUseModifiers = + , _itUse = ruseRate 20 aRocketWithItemParams upHammer [ ammoCheckI , useTimeCheckI , withSoundStart tap4S @@ -62,7 +60,6 @@ launcher = defaultGun , _itFloorPict = launcherPic , _itAimingSpeed = 0.2 , _itAimingRange = 0.5 - , _itHammer = NoHammer , _itEffect = NoItEffect , _itAimStance = TwoHandTwist } @@ -250,10 +247,7 @@ remoteLauncher = defaultGun , _wpLoadedAmmo = 30 , _wpReloadTime = 80 } - , _itUseRate = 10 - , _itUseTime = 0 - , _itUse = RightUse $ const fireRemoteLauncher - , _itUseModifiers = + , _itUse = ruseRate 10 (const fireRemoteLauncher) upHammer [ ammoCheckI , hammerCheckI ] @@ -294,8 +288,8 @@ fireRemoteLauncher cr w = setLocation j = _crInvSel cr newitid = IM.newKey $ _itemPositions w maybeitid = cr ^? crInv . ix j . itID . _Just - resetFire = set (creatures . ix cid . crInv . ix j . itUse) - $ RightUse $ \_ _ -> explodeRemoteRocket itid i + resetFire = set (creatures . ix cid . crInv . ix j . itUse . rUse) + $ \_ _ -> explodeRemoteRocket itid i resetName = set (creatures . ix cid . crInv . ix j . itName) "REMOTEROCKET" setLocation :: World -> World setLocation w' = case maybeitid of @@ -355,7 +349,7 @@ explodeRemoteRocket explodeRemoteRocket itid pjid w = set (props . ix pjid . pjUpdate) (\_ -> retireRemoteRocket itid 30 pjid) $ set (props . ix pjid . prDraw) (const mempty) - $ set (itPoint . itUse) (RightUse $ \_ _ -> id) + $ set (itPoint . itUse . rUse) (\_ _ -> id) $ resetName $ makeExplosionAt (_pjPos (_props w IM.! pjid)) w where @@ -387,7 +381,7 @@ remoteShellPic t retireRemoteRocket :: Int -> Int -> Int -> World -> World retireRemoteRocket itid 0 pjid w = set (pointToItem (_itemPositions w IM.! itid) . itAttachment . scopePos) (V2 0 0) - $ set (pointToItem (_itemPositions w IM.! itid) . itUse) (RightUse $ const fireRemoteLauncher) + $ set (pointToItem (_itemPositions w IM.! itid) . itUse . rUse) (const fireRemoteLauncher) (w & props %~ IM.delete pjid) retireRemoteRocket itid t pjid w = setScope w & props . ix pjid . pjUpdate .~ (\_ -> retireRemoteRocket itid (t-1) pjid) diff --git a/src/Dodge/Item/Weapon/Radar.hs b/src/Dodge/Item/Weapon/Radar.hs index abe99836b..ab4899e07 100644 --- a/src/Dodge/Item/Weapon/Radar.hs +++ b/src/Dodge/Item/Weapon/Radar.hs @@ -25,15 +25,11 @@ radar = defaultGun , _wpLoadedAmmo = 100 , _wpReloadTime = 200 } - , _itUseRate = 120 - , _itUseTime = 0 - , _itUse = RightUse $ const aRadarPulse - , _itUseModifiers = + , _itUse = ruseRate 120 (const aRadarPulse) upHammer [ ammoUseCheckI ] , _wpSpread = autogunSpread , _wpRange = 20 - , _itHammer = HammerUp , _itFloorPict = \_ -> (,) emptySH $ onLayer FlItLayer $ color blue $ polygon $ rectNESW 5 5 (-5) (-5) , _itAimingRange = 1 , _itZoom = defaultItZoom { _itZoomMax = 1} @@ -51,14 +47,10 @@ sonar = defaultGun , _wpLoadedAmmo = 100 , _wpReloadTime = 200 } - , _itUseRate = 120 - , _itUseTime = 0 - , _itUse = RightUse $ const aSonarPulse - , _itUseModifiers = + , _itUse = ruseRate 120 (const aSonarPulse) upHammer [ ammoUseCheckI ] , _wpRange = 20 - , _itHammer = HammerUp , _itFloorPict = \_ -> (,) emptySH $ onLayer FlItLayer $ color blue $ polygon $ rectNESW 5 5 (-5) (-5) , _itAimingRange = 1 , _itZoom = defaultItZoom {_itZoomMax = 1} diff --git a/src/Dodge/Item/Weapon/Spawn.hs b/src/Dodge/Item/Weapon/Spawn.hs index fb0548088..5a8bd51c4 100644 --- a/src/Dodge/Item/Weapon/Spawn.hs +++ b/src/Dodge/Item/Weapon/Spawn.hs @@ -3,6 +3,7 @@ import Dodge.Data import Dodge.Item.Weapon.TriggerType --import Dodge.Item.Weapon.Remote import Dodge.Default.Weapon +import Dodge.Default --import Dodge.Item.Weapon.Grenade import Geometry import qualified IntMapHelp as IM @@ -21,9 +22,9 @@ spawnGun cr = defaultGun , _wpLoadedAmmo = 1 , _wpReloadTime = 80 } - , _itUseRate = 100 - , _itUse = RightUse $ \_ -> spawnCrNextTo cr - , _itUseModifiers = + , _itUse = ruseRate 100 + (\_ -> spawnCrNextTo cr) + upHammer [ ammoCheckI , hammerCheckI ] diff --git a/src/Dodge/Item/Weapon/SprayGuns.hs b/src/Dodge/Item/Weapon/SprayGuns.hs index 9e11fbd78..3b15f9011 100644 --- a/src/Dodge/Item/Weapon/SprayGuns.hs +++ b/src/Dodge/Item/Weapon/SprayGuns.hs @@ -39,10 +39,7 @@ poisonSprayer = defaultAutoGun , _wpLoadedAmmo = 500 , _wpReloadTime = 100 } - , _itUseRate = 0 - , _itUseTime = 0 - , _itUse = RightUse $ const aGasCloud - , _itUseModifiers = + , _itUse = ruseInstant (const aGasCloud) NoHammer [ ammoCheckI , useTimeCheckI , withSoundForI foamSprayLoopS 5 @@ -66,10 +63,7 @@ flamer = defaultAutoGun , _wpLoadedAmmo = 250 , _wpReloadTime = 100 } - , _itUseRate = 0 - , _itUseTime = 0 - , _itUse = RightUse $ \_ -> randWalkAngle 0.2 0.01 aFlame - , _itUseModifiers = + , _itUse = ruseInstant (\_ -> randWalkAngle 0.2 0.01 aFlame) NoHammer [ ammoUseCheckI , withSidePushI 5 --, withTempLight 1 100 (V3 1 0 0) diff --git a/src/Dodge/Item/Weapon/TriggerType.hs b/src/Dodge/Item/Weapon/TriggerType.hs index f4eb0d230..866ab515e 100644 --- a/src/Dodge/Item/Weapon/TriggerType.hs +++ b/src/Dodge/Item/Weapon/TriggerType.hs @@ -110,23 +110,23 @@ rateIncABI -> ChainEffect rateIncABI startRate fastRate exeffFirst exeffCont eff item cr w | repeatFire = w - & pointItem %~ ( (itUseRate .~ max fastRate (currentRate - 1)) + & pointItem %~ ( (itUse . useDelay . rateMax .~ max fastRate (currentRate - 1)) . (wpAmmo . wpLoadedAmmo -~ 1) - . (itUseTime .~ currentRate) ) + . (itUse . useDelay . rateTime .~ currentRate) ) & exeffCont eff item cr | firstFire = w - & pointItem %~ ( (itUseRate .~ startRate - 1) + & pointItem %~ ( (itUse . useDelay . rateMax .~ startRate - 1) . (wpAmmo . wpLoadedAmmo -~ 1) - . (itUseTime .~ startRate) ) + . (itUse . useDelay . rateTime .~ startRate) ) & exeffFirst eff item cr | otherwise = w where cid = _crID cr itRef = _crInvSel cr pointItem = creatures . ix cid . crInv . ix itRef - currentRate = _itUseRate item - repeatFire = _wpReloadState (_wpAmmo item) == 0 && _itUseTime item == 1 - firstFire = _wpReloadState (_wpAmmo item) == 0 && _itUseTime item == 0 + currentRate = _rateMax (_useDelay (_itUse item)) + repeatFire = _wpReloadState (_wpAmmo item) == 0 && _rateTime (_useDelay (_itUse item)) == 1 + firstFire = _wpReloadState (_wpAmmo item) == 0 && _rateTime (_useDelay (_itUse item)) == 0 {- | Apply effect after a warm up. -} withWarmUpI :: SoundID -- ^ warm up sound id @@ -221,26 +221,28 @@ useAmmo amAmount eff item cr = eff item cr {- | Applies a world effect after an item use cooldown check. -} useTimeCheckI :: ChainEffect -useTimeCheckI f item cr w = case item ^? itUseTime of +useTimeCheckI f item cr w = case item ^? itUse . useDelay . rateTime of Just 0 -> f item cr $ setUseTime w _ -> w where cid = _crID cr - setUseTime = creatures . ix cid . crInv . ix (_crInvSel cr) . itUseTime +~ useRate - useRate = fromMaybe 0 $ item ^? itUseRate + setUseTime = creatures . ix cid . crInv . ix (_crInvSel cr) . itUse . useDelay . rateTime +~ userate + userate = fromMaybe 0 $ item ^? itUse . useDelay . rateMax {- | Applies a world effect after a hammer position check. -} hammerCheckI :: ChainEffect -hammerCheckI f it cr w = case it ^? itHammer of +hammerCheckI f it cr w = case it ^? itUse . itHammer . hammerPosition of Just HammerUp -> f it cr $ setHammerDown w _ -> setHammerDown w where cid = _crID cr - setHammerDown = creatures . ix cid . crInv . ix (_crInvSel cr) . itHammer .~ HammerDown + setHammerDown = creatures . ix cid . crInv . ix (_crInvSel cr) . itUse + . itHammer . hammerPosition .~ HammerDown {- | Applies a world effect after an ammo check. -} ammoUseCheckI :: ChainEffect ammoUseCheckI f item cr w | fireCondition = f item cr w & pointerToItem %~ - ( (wpAmmo . wpLoadedAmmo -~ 1) . (itUseTime .~ _itUseRate item) ) + ( (wpAmmo . wpLoadedAmmo -~ 1) + . (itUse . useDelay . rateTime .~ _rateMax ( _useDelay (_itUse item)) )) | reloadCondition = fromMaybe w $ startReloadingWeapon cr w | otherwise = w where @@ -248,7 +250,7 @@ ammoUseCheckI f item cr w itRef = _crInvSel cr pointerToItem = creatures . ix cid . crInv . ix itRef fireCondition = _wpReloadState (_wpAmmo item) == 0 - && _itUseTime item == 0 + && _rateTime (_useDelay (_itUse item)) == 0 && _wpLoadedAmmo (_wpAmmo item) > 0 reloadCondition = _wpLoadedAmmo (_wpAmmo item) == 0 {- | Applies a world effect after a hammer position check. @@ -259,12 +261,12 @@ hammerCheckL -> Int -> World -> World -hammerCheckL f cr invid w = case (_crInv cr IM.! invid) ^? itHammer of +hammerCheckL f cr invid w = case (_crInv cr IM.! invid) ^? itUse . itHammer . hammerPosition of Just HammerUp -> f cr invid $ setHammerDown w _ -> setHammerDown w where cid = _crID cr - setHammerDown = creatures . ix cid . crInv . ix invid . itHammer .~ HammerDown + setHammerDown = creatures . ix cid . crInv . ix invid . itUse . itHammer . hammerPosition .~ HammerDown {- | Applies a world effect after an ammo check. Arbitrary inventory position. -} shootL @@ -276,7 +278,8 @@ shootL -> World shootL f cr invid w | fireCondition = f cr invid w & pointerToItem %~ - ( (wpAmmo . wpLoadedAmmo -~ 1) . (itUseTime .~ _itUseRate item) ) + ( (wpAmmo . wpLoadedAmmo -~ 1) + . (itUse . useDelay . rateTime .~ _rateMax (_useDelay (_itUse item))) ) | reloadCondition = fromMaybe w $ startReloadingWeapon cr w | otherwise = w where @@ -284,7 +287,7 @@ shootL f cr invid w item = _crInv cr IM.! invid pointerToItem = creatures . ix cid . crInv . ix invid fireCondition = _wpReloadState (_wpAmmo item) == 0 - && _itUseTime item == 0 + && _rateTime (_useDelay (_itUse item)) == 0 && _wpLoadedAmmo (_wpAmmo item) > 0 reloadCondition = _wpLoadedAmmo (_wpAmmo item) == 0 withTempLight :: Int -> Float -> V3 Float -> ChainEffect diff --git a/src/Dodge/Item/Weapon/Utility.hs b/src/Dodge/Item/Weapon/Utility.hs index 5413c0c31..6a3415964 100644 --- a/src/Dodge/Item/Weapon/Utility.hs +++ b/src/Dodge/Item/Weapon/Utility.hs @@ -25,7 +25,7 @@ rewindGun = defaultGun , _wpCharge = 0 } , _itEffect = ItRewindEffect rewindEffect [] - , _itUse = LeftUse $ \cr invid -> useRewindGun (_crInv cr IM.! invid) cr + , _itUse = defaultlUse {_lUse = \cr invid -> useRewindGun (_crInv cr IM.! invid) cr} } rewindEffect :: ItEffect -> Creature -> Int -> World -> World rewindEffect _ cr invid w @@ -60,14 +60,8 @@ shrinkGun = defaultGun , _wpLoadedAmmo = 100 , _wpReloadTime = 20 } - , _itUseRate = 0 - , _itUseTime = 0 , _itAimStance = TwoHandFlat - , _itUse = LeftUse $ \cr invid -> useShrinkGun (_crInv cr IM.! invid) cr - , _itUseModifiers = - [ ammoCheckI - , hammerCheckI - ] + , _itUse = defaultlUse {_lUse = \cr invid -> useShrinkGun (_crInv cr IM.! invid) cr} , _wpSpread = 0.05 , _wpRange = 20 , _itFloorPict = shrinkGunPic @@ -99,13 +93,7 @@ blinkGun = defaultGun , _wpLoadedAmmo = 100 , _wpReloadTime = 20 } - , _itUseRate = 0 - , _itUseTime = 0 - , _itUse = LeftUse $ hammerCheckL $ shootL aSelfL - , _itUseModifiers = - [ ammoCheckI - , hammerCheckI - ] + , _itUse = defaultlUse {_lUse = 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)] @@ -123,12 +111,12 @@ aSelfL cr _ = blinkAction cr effectGun :: String -> (Creature -> World -> World) -> Item effectGun name eff = defaultGun { _itName = name ++ "Gun" - , _itUse = RightUse $ const eff + , _itUse = defaultrUse {_rUse = const eff} } autoEffectGun :: String -> (Creature -> World -> World) -> Item autoEffectGun name eff = defaultAutoGun { _itName = name ++ "Gun" - , _itUse = RightUse $ const eff + , _itUse = defaultrUse {_rUse = const eff} } forceFieldGun :: Item forceFieldGun = defaultGun @@ -140,8 +128,6 @@ forceFieldGun = defaultGun , _wpReloadTime = 40 , _wpReloadState = 0 } - , _itUseRate = 10 - , _itUseTime = 0 , _itUse = undefined , _wpSpread = 0.02 , _wpRange = 20