From 297b4e0b3ccca34196e7f5e4acc415a2cd580545 Mon Sep 17 00:00:00 2001 From: justin Date: Fri, 19 May 2023 20:00:11 +0100 Subject: [PATCH] Simplify and correct hammer check for held weapons --- src/Dodge/HeldUse.hs | 36 ++++++++++++++++++---------- src/Dodge/Item/Weapon/TriggerType.hs | 24 +++++-------------- src/Dodge/Render/List.hs | 1 - 3 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/Dodge/HeldUse.hs b/src/Dodge/HeldUse.hs index b184beaa1..f7280b43c 100644 --- a/src/Dodge/HeldUse.hs +++ b/src/Dodge/HeldUse.hs @@ -62,7 +62,7 @@ useMod hm = case hm of , withSoundStart tap4S , useTimeCheck , ammoCheckI - , hammerCheckI + , blCheck ] TeslaMod -> [ useAmmoAmount 1 @@ -109,20 +109,22 @@ useMod hm = case hm of , withSoundStart tap4S , useTimeCheck , ammoCheckI - , hammerCheckI + , blCheck ] ShatterMod -> [ useAmmoAmount 1 -- , withSoundStart tap3S , useTimeCheck - , ammoHammerCheck + , ammoCheckI + , blCheck ] AmmoCheckMod -> [ammoCheckI] AmmoUseCheckMod -> [useAmmoAmount 1,useTimeCheck, ammoCheckI] AmmoHammerTimeUseOneMod -> [ useAmmoAmount 1 , useTimeCheck - , ammoHammerCheck + , ammoCheckI + , blCheck ] BangCaneMod -> [ withMuzFlareI @@ -133,7 +135,8 @@ useMod hm = case hm of , useAmmoAmount 1 , withSoundStart tap3S , useTimeCheck - , ammoHammerCheck + , ammoCheckI + , blCheck ] VolleyGunMod -> [ withRecoil @@ -144,7 +147,8 @@ useMod hm = case hm of , useAllAmmo , withSoundItemChoiceStart caneStickSoundChoice , useTimeCheck - , ammoHammerCheck + , ammoCheckI + , blCheck ] AutoRifleMod -> -- note this is the same as BangCanemMod with the first changed @@ -167,7 +171,8 @@ useMod hm = case hm of , useAmmoAmount 1 , withSoundStart bangEchoS , useTimeCheck - , ammoHammerCheck + , ammoCheckI + , blCheck ] ElephantGunMod -> [ withRecoil @@ -178,7 +183,8 @@ useMod hm = case hm of , useAmmoAmount 1 , withSoundStart bangEchoS , useTimeCheck - , ammoHammerCheck + , ammoCheckI + , blCheck ] AutoAmrMod -> [ withRecoil @@ -209,7 +215,8 @@ useMod hm = case hm of , useAllAmmo , withSoundItemChoiceStart bangStickSoundChoice , useTimeCheck - , ammoHammerCheck + , ammoCheckI + , blCheck ] PistolMod -> [ withMuzFlareI @@ -220,7 +227,8 @@ useMod hm = case hm of , withSoundStart tap3S , useAmmoAmount 1 , useTimeCheck - , ammoHammerCheck + , ammoCheckI + , blCheck ] AutoPistolMod -> [ withMuzFlareI @@ -254,7 +262,8 @@ useMod hm = case hm of , lockInvFor 7 , sideEffectOnFrame 7 (\_ cr -> TorqueCr 0.2 (_crID cr)) --(torqueSideEffect 0.2) , useTimeCheck - , ammoHammerCheck + , ammoCheckI + , blCheck ] BurstRifleRepeatMod -> [ withRecoil @@ -305,7 +314,8 @@ useMod hm = case hm of -- rather than locking the inventory, a better solution may be to check -- that the weapon is still in your hands in the repeated frames , useTimeCheck - , ammoHammerCheck + , ammoCheckI + , blCheck ] RevolverXRepeatMod -> [ withRecoil @@ -328,8 +338,8 @@ useMod hm = case hm of , useAllAmmo , withSoundStart bangEchoS , useTimeCheck - , hammerCheckI , ammoCheckI + , blCheck ] where f = do diff --git a/src/Dodge/Item/Weapon/TriggerType.hs b/src/Dodge/Item/Weapon/TriggerType.hs index 09f0b9c42..dc5eb5c39 100644 --- a/src/Dodge/Item/Weapon/TriggerType.hs +++ b/src/Dodge/Item/Weapon/TriggerType.hs @@ -54,16 +54,16 @@ module Dodge.Item.Weapon.TriggerType ( duplicateOffsets, duplicateOffsetsV2, duplicateOffsetsFocus, - hammerCheckI, hammerCheckL, shootL, useTimeCheck, ammoCheckI, applyInaccuracy, modClock, - ammoHammerCheck, + blCheck, ) where +import qualified SDL import Data.Foldable import Data.Maybe import Dodge.Base @@ -146,17 +146,6 @@ ammoCheckI eff itm cr w = case itm ^? itUse . heldConsumption . laSource of -> w _ -> eff itm cr $ w & cWorld . lWorld . creatures . ix (_crID cr) %~ crCancelReloading --- combined ammo and hammer check: want to be able to auto-reload even if the --- hammer is down? -ammoHammerCheck :: ChainEffect -ammoHammerCheck eff itm cr w - | _iaLoaded ic <= 0 || not (_iaPrimed ic) = w - -- fromMaybe w (startReloadingWeapon cr w) - | otherwise = case itm ^? itUse . heldHammer of - Just HammerUp -> eff itm cr $ w & cWorld . lWorld . creatures . ix (_crID cr) %~ crCancelReloading - _ -> w - where - ic = itm ^?! itUse . heldConsumption . laSource . _InternalSource itUseCharge :: Int -> Item -> Item itUseCharge x = itUse . leftConsumption . arLoaded %~ (max 0 . subtract x) @@ -388,12 +377,11 @@ useTimeCheck f item cr w = case item ^? itUse . heldDelay . rateTime of itRef = cr ^?! crManipulation . manObject . inInventory . ispItem -- unsafe!! TODO change userate = fromMaybe 0 $ item ^? itUse . heldDelay . rateMax + -- | Applies a world effect after a hammer position check. -hammerCheckI :: ChainEffect -hammerCheckI f it cr w = case it ^? itUse . heldHammer of - Just HammerUp - | it ^?! itUse . heldConsumption . laSource . _InternalSource . iaPrimed -> - f it cr w +blCheck :: ChainEffect +blCheck f it cr w = case w ^? input . mouseButtons . ix SDL.ButtonLeft of + Just 0 -> f it cr w _ -> w {- | Applies a world effect after a hammer position check. diff --git a/src/Dodge/Render/List.hs b/src/Dodge/Render/List.hs index 915759063..a5735fdba 100644 --- a/src/Dodge/Render/List.hs +++ b/src/Dodge/Render/List.hs @@ -86,7 +86,6 @@ stackPicturesAtOff i = mconcat . zipWith (drawListElement 10 1 0) [i, i -1 ..] selSecDrawCursor :: Int -> ListDisplayParams -> SelectionSections a -> Picture selSecDrawCursor xsize ldp sss = fromMaybe mempty $ do (i, j) <- sss ^? sssExtra . sssSelPos . _Just - --yint <- sss ^? sssSections . ix i . ssCursor . _Just . scurPos yint <- selSecYint i j sss xint <- sss ^? sssSections . ix i . ssIndent si <- sss ^? sssSections . ix i . ssItems . ix j