From 866196ab3e8fb538dc8edddc982f5e780c040bcb Mon Sep 17 00:00:00 2001 From: justin Date: Wed, 20 Jul 2022 22:43:30 +0100 Subject: [PATCH] Move item effect functions --- src/Dodge/Creature/State.hs | 3 +- src/Dodge/Data.hs | 63 ++++++--------------- src/Dodge/Data/Hammer.hs | 16 ++++++ src/Dodge/Data/ItEffect.hs | 11 ++++ src/Dodge/Data/Item/Use.hs | 69 +++++++++++++++++++++++ src/Dodge/Data/Item/UseDelay.hs | 21 +++++++ src/Dodge/Data/LoadAction.hs | 2 +- src/Dodge/Default/AimParams.hs | 2 +- src/Dodge/Hammer.hs | 2 +- src/Dodge/Inventory.hs | 3 +- src/Dodge/ItEffect.hs | 54 ++++++++++++++++++ src/Dodge/Item/Data.hs | 86 ----------------------------- src/Dodge/Item/Equipment.hs | 43 ++++++--------- src/Dodge/Item/Equipment/Booster.hs | 11 +--- src/Dodge/Item/Weapon/Grenade.hs | 86 ++++++++++++++--------------- src/Dodge/Item/Weapon/Utility.hs | 14 +---- 16 files changed, 257 insertions(+), 229 deletions(-) create mode 100644 src/Dodge/Data/Hammer.hs create mode 100644 src/Dodge/Data/ItEffect.hs create mode 100644 src/Dodge/Data/Item/Use.hs create mode 100644 src/Dodge/Data/Item/UseDelay.hs create mode 100644 src/Dodge/ItEffect.hs diff --git a/src/Dodge/Creature/State.hs b/src/Dodge/Creature/State.hs index 3cf9d3cb4..782e2d23a 100644 --- a/src/Dodge/Creature/State.hs +++ b/src/Dodge/Creature/State.hs @@ -3,6 +3,7 @@ module Dodge.Creature.State , doDamage ) where import Dodge.Data +import Dodge.ItEffect import Dodge.Euse import Dodge.EnergyBall import Dodge.Damage @@ -196,7 +197,7 @@ invSideEff :: Creature -> World -> World invSideEff cr w = weaponReloadSounds cr $ IM.foldrWithKey f w (_crInv cr) where f i it w' = itemInvSideEffect cr it - $ doItemTargeting i cr w' & maybe id (\g -> g it cr) (it ^? itEffect . ieInv) + $ doItemTargeting i cr w' & maybe id (\g -> doInvEffect g it cr) (it ^? itEffect . ieInv) itemInvSideEffect :: Creature -> Item -> World -> World itemInvSideEffect cr it diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index 7df86be86..31adc16fd 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -10,6 +10,10 @@ circular imports are probably not a good idea. {-# LANGUAGE DerivingStrategies #-} module Dodge.Data ( module Dodge.Data + , module Dodge.Data.ItEffect + , module Dodge.Data.Hammer + , module Dodge.Data.Item.Use + , module Dodge.Data.Item.UseDelay , module Dodge.Data.ArcStep , module Dodge.Data.CrWlID , module Dodge.Data.Item.HeldUse @@ -61,6 +65,10 @@ module Dodge.Data , module Dodge.Data.RadarBlip , module Dodge.Data.PathGraph ) where +import Dodge.Data.ItEffect +import Dodge.Data.Hammer +import Dodge.Data.Item.Use +import Dodge.Data.Item.UseDelay import Dodge.Data.CrWlID import Dodge.Data.ArcStep import Dodge.Data.Item.HeldUse @@ -404,39 +412,6 @@ data PressPlate = PressPlate , _ppText :: String } data FloorItem = FlIt { _flIt :: Item , _flItPos :: Point2 , _flItRot :: Float, _flItID :: Int} -data ItemUse - = RightUse - { _rUse :: HeldUse -- Item -> Creature -> World -> World - , _useDelay :: UseDelay - , _useMods :: HeldMod --[(Item -> Creature -> World -> World) -> Item -> Creature -> World -> World] - , _useHammer :: HammerPosition - , _useAim :: AimParams - , _heldScroll :: HeldScroll --Float -> Creature -> Item -> Item - } - | LeftUse - { _lUse :: Luse --Item -> Creature -> World -> World - , _useDelay :: UseDelay - , _useHammer :: HammerPosition - , _eqEq :: Equipment - } - | ConsumeUse - { _cUse :: Cuse --Item -> Creature -> World -> World - } - | EquipUse - { _eqEq :: Equipment - } - | NoUse -data Equipment = Equipment - { _eqUse :: Euse --Item -> Creature -> World -> World - , _eqOnEquip :: Euse --Item -> Creature -> World -> World - , _eqOnRemove :: Euse --Item -> Creature -> World -> World - , _eqSite :: EquipSite - , _eqParams :: EquipParams - , _eqViewDist :: Maybe Float - } - -_itUseAimStance :: Item -> AimStance -_itUseAimStance = _aimStance . _useAim . _itUse data Item = Item { _itConsumption :: ItemConsumption @@ -471,25 +446,25 @@ data Targeting data ItEffect = NoItEffect | ItInvEffect - {_ieInv :: Item -> Creature -> World -> World + {_ieInv :: ItInvEffect --Item -> Creature -> World -> World ,_ieCounter :: Int } | ItRewindEffect - {_ieInv :: Item -> Creature -> World -> World + {_ieInv :: ItInvEffect --Item -> Creature -> World -> World ,_ieStoredWorlds :: [World] } | ItEffect - {_ieInv :: Item -> Creature -> World -> World - ,_ieFloor :: Int -> World -> World + {_ieInv :: ItInvEffect --Item -> Creature -> World -> World + ,_ieFloor :: ItFloorEffect --Int -> World -> World ,_ieCounter :: Int } | ItInvEffectID - {_ieInv :: Item -> Creature -> World -> World + {_ieInv :: ItInvEffect --Item -> Creature -> World -> World ,_ieMID :: Maybe Int } -- the duplication of ieMID may cause errors... | ItInvEffectDrop - { _ieInv :: Item -> Creature -> World -> World - , _ieDrop :: Item -> Creature -> World -> World + { _ieInv :: ItInvEffect --Item -> Creature -> World -> World + , _ieDrop :: ItDropEffect --Item -> Creature -> World -> World , _ieMID :: Maybe Int } data IntID a = IntID Int a @@ -612,10 +587,6 @@ data GunBarrels , _brlInaccuracy :: Float } | SingleBarrel {_brlInaccuracy :: Float} -data EquipParams - = NoEquipParams - | EquipID {_eparamID :: Int} - | EquipCounter {_eparamInt :: Int} data ItemParams = NoParams | ShellLauncher @@ -1256,7 +1227,6 @@ makeLenses ''CreatureState makeLenses ''World makeLenses ''Creature makeLenses ''Item -makeLenses ''ItemUse makeLenses ''ItEffect makeLenses ''FloorItem makeLenses ''TweakParam @@ -1288,7 +1258,6 @@ makeLenses ''ScreenLayer makeLenses ''Beam makeLenses ''BeamType makeLenses ''WorldBeams -makeLenses ''EquipParams makeLenses ''TerminalCommand makeLenses ''TerminalInput makeLenses ''GenParams @@ -1301,6 +1270,8 @@ makeLenses ''PSType makeLenses ''PlacementSpot makeLenses ''Placement +_itUseAimStance :: Item -> AimStance +_itUseAimStance = _aimStance . _useAim . _itUse crSel :: Creature -> Int crSel = _iselPos . _crInvSel diff --git a/src/Dodge/Data/Hammer.hs b/src/Dodge/Data/Hammer.hs new file mode 100644 index 000000000..b51f31eac --- /dev/null +++ b/src/Dodge/Data/Hammer.hs @@ -0,0 +1,16 @@ +{-# LANGUAGE StrictData #-} +{-# LANGUAGE TemplateHaskell #-} +module Dodge.Data.Hammer where +import Control.Lens +data HammerType + = NoHammer + | HasHammer {_hammerPosition :: HammerPosition} + deriving + (Eq, Ord, Show) +data HammerPosition + = HammerDown + | HammerReleased + | HammerUp + deriving + (Eq, Ord, Show) +makeLenses ''HammerType diff --git a/src/Dodge/Data/ItEffect.hs b/src/Dodge/Data/ItEffect.hs new file mode 100644 index 000000000..2a8004cdb --- /dev/null +++ b/src/Dodge/Data/ItEffect.hs @@ -0,0 +1,11 @@ +module Dodge.Data.ItEffect where + +data ItInvEffect = NoInvEffect + | RewindEffect + | ResetAttachmentEffect + | OnOffHeldEffect ItInvEffect ItInvEffect + | CreateHeldLight + | CreateShieldWall + | RemoveShieldWall +data ItFloorEffect = NoFloorEffect +data ItDropEffect = NoDropEffect diff --git a/src/Dodge/Data/Item/Use.hs b/src/Dodge/Data/Item/Use.hs new file mode 100644 index 000000000..a01885f9d --- /dev/null +++ b/src/Dodge/Data/Item/Use.hs @@ -0,0 +1,69 @@ +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE StrictData #-} +module Dodge.Data.Item.Use where +import Dodge.Data.Item.HeldUse +import Dodge.Data.Item.HeldScroll +import Dodge.Data.Item.UseDelay +import Dodge.Data.Hammer +import Dodge.Equipment.Data +import Control.Lens + +data ItemUse + = RightUse + { _rUse :: HeldUse -- Item -> Creature -> World -> World + , _useDelay :: UseDelay + , _useMods :: HeldMod --[(Item -> Creature -> World -> World) -> Item -> Creature -> World -> World] + , _useHammer :: HammerPosition + , _useAim :: AimParams + , _heldScroll :: HeldScroll --Float -> Creature -> Item -> Item + } + | LeftUse + { _lUse :: Luse --Item -> Creature -> World -> World + , _useDelay :: UseDelay + , _useHammer :: HammerPosition + , _eqEq :: Equipment + } + | ConsumeUse + { _cUse :: Cuse --Item -> Creature -> World -> World + } + | EquipUse + { _eqEq :: Equipment + } + | NoUse +data Equipment = Equipment + { _eqUse :: Euse --Item -> Creature -> World -> World + , _eqOnEquip :: Euse --Item -> Creature -> World -> World + , _eqOnRemove :: Euse --Item -> Creature -> World -> World + , _eqSite :: EquipSite + , _eqParams :: EquipParams + , _eqViewDist :: Maybe Float + } +data AimParams = AimParams + { _aimWeight :: Int + , _aimRange :: Float + , _aimZoom :: ItZoom + , _aimStance :: AimStance + , _aimHandlePos :: Float + , _aimMuzPos :: Float + } +data AimStance + = TwoHandTwist + | TwoHandFlat + | OneHand + | LeaveHolstered + deriving + (Eq,Show,Ord,Enum) + +data EquipParams + = NoEquipParams + | EquipID {_eparamID :: Int} + | EquipCounter {_eparamInt :: Int} +data ItZoom = ItZoom + { _itZoomMax :: Float + , _itZoomMin :: Float + , _itZoomFac :: Float + } +makeLenses ''ItemUse +makeLenses ''AimParams +makeLenses ''EquipParams +makeLenses ''ItZoom diff --git a/src/Dodge/Data/Item/UseDelay.hs b/src/Dodge/Data/Item/UseDelay.hs new file mode 100644 index 000000000..f1737790a --- /dev/null +++ b/src/Dodge/Data/Item/UseDelay.hs @@ -0,0 +1,21 @@ +{-# LANGUAGE StrictData #-} +{-# LANGUAGE TemplateHaskell #-} +module Dodge.Data.Item.UseDelay where +import Control.Lens +data UseDelay -- should just be Delay + = NoDelay + | FixedRate + {_rateMax :: Int + ,_rateTime :: Int + } + | VariableRate + {_rateMax :: Int + ,_rateTime :: Int + ,_rateMaxMax :: Int + ,_rateMinMax :: Int + } + | WarmUpNoDelay + {_warmTime :: Int + ,_warmMax :: Int + } +makeLenses ''UseDelay diff --git a/src/Dodge/Data/LoadAction.hs b/src/Dodge/Data/LoadAction.hs index e9734ddab..347ebc05a 100644 --- a/src/Dodge/Data/LoadAction.hs +++ b/src/Dodge/Data/LoadAction.hs @@ -2,7 +2,7 @@ {-# LANGUAGE StrictData #-} module Dodge.Data.LoadAction where import Sound.Data -import Dodge.Item.Data +import Dodge.Data.Hammer import Control.Lens data LoadAction = LoadEject {_actionTime :: Int, _actionSound :: SoundID} diff --git a/src/Dodge/Default/AimParams.hs b/src/Dodge/Default/AimParams.hs index 212832cfe..f0cf3c3ee 100644 --- a/src/Dodge/Default/AimParams.hs +++ b/src/Dodge/Default/AimParams.hs @@ -1,5 +1,5 @@ module Dodge.Default.AimParams where -import Dodge.Item.Data +import Dodge.Data.Item.Use defaultAimParams :: AimParams defaultAimParams = AimParams diff --git a/src/Dodge/Hammer.hs b/src/Dodge/Hammer.hs index a5d8ceb8b..21ead8931 100644 --- a/src/Dodge/Hammer.hs +++ b/src/Dodge/Hammer.hs @@ -1,5 +1,5 @@ module Dodge.Hammer where -import Dodge.Item.Data +import Dodge.Data.Hammer moveHammerUp :: HammerPosition -> HammerPosition moveHammerUp HammerDown = HammerReleased diff --git a/src/Dodge/Inventory.hs b/src/Dodge/Inventory.hs index 33a433373..75d5b380b 100644 --- a/src/Dodge/Inventory.hs +++ b/src/Dodge/Inventory.hs @@ -25,6 +25,7 @@ module Dodge.Inventory ) where import Dodge.Data +import Dodge.ItEffect import Dodge.Euse import Dodge.Inventory.CloseObject import Dodge.Inventory.CheckSlots @@ -75,7 +76,7 @@ rmInvItem cid invid w = case w ^? creatures . ix cid . crInv . ix invid . itCons return $ useE rmf itm cr doanyitemeffect = fromMaybe id $ do rmf <- itm ^? itEffect . ieDrop - return $ rmf itm cr + return $ doDropEffect rmf itm cr removeAnySlotEquipment = case w ^? creatures . ix cid . crInvEquipped . ix invid of Just epos -> creatures . ix cid . crEquipment . at epos .~ Nothing Nothing -> id diff --git a/src/Dodge/ItEffect.hs b/src/Dodge/ItEffect.hs new file mode 100644 index 000000000..6e9dce832 --- /dev/null +++ b/src/Dodge/ItEffect.hs @@ -0,0 +1,54 @@ +module Dodge.ItEffect where +import Dodge.Data +import Dodge.Item.Equipment +import Dodge.LightSource.Torch +import Control.Lens + +doInvEffect :: ItInvEffect -> Item -> Creature -> World -> World +doInvEffect iie = case iie of + NoInvEffect -> const $ const id + RewindEffect -> rewindEffect + ResetAttachmentEffect -> resetAttachmentEffect + OnOffHeldEffect f g -> onOffEff f g + CreateHeldLight -> createHeldLight + CreateShieldWall -> createShieldWall + RemoveShieldWall -> removeShieldWall + +doFloorEffect :: ItFloorEffect -> Int -> World -> World +doFloorEffect NoFloorEffect = const id + +doDropEffect :: ItDropEffect -> Item -> Creature -> World -> World +doDropEffect iie = case iie of + NoDropEffect -> const $ const id + +onOffEff :: ItInvEffect -> ItInvEffect -> Item -> Creature -> World -> World +onOffEff f g it + | _itIsHeld it = doInvEffect f it + | otherwise = doInvEffect g it + + +rewindEffect :: Item -> Creature -> World -> World +rewindEffect itm cr w + | Just invid == _crLeftInvSel cr = w & rewindWorlds %~ (take maxcharge . (w' : )) + & ptrWpCharge .~ length (_rewindWorlds w) + | otherwise = w & rewindWorlds .~ [] + & ptrWpCharge .~ 0 + where + invid = _ipInvID $ _itPos itm + ptrWpCharge = creatures . ix (_crID cr) . crInv . ix invid . itConsumption . wpCharge + maxcharge = _wpMaxCharge . _itConsumption $ itm + w' = w & rewindWorlds .~ [] + & timeFlow .~ NormalTimeFlow + +resetAttachmentEffect :: Item -> Creature -> World -> World +resetAttachmentEffect itm cr w + | _ieCounter iteff < 0 = w & pointToIt . itAttachment .~ NoItAttachment + | otherwise = w & pointToIt . itEffect . ieCounter -~ 1 + where + iteff = _itEffect itm + invid = _ipInvID $ _itPos itm + pointToIt = creatures . ix (_crID cr) . crInv . ix invid + +createHeldLight :: Item -> Creature -> World -> World +createHeldLight itm cr = createTorchLightOffset cr itm 0 + diff --git a/src/Dodge/Item/Data.hs b/src/Dodge/Item/Data.hs index 36ac47c48..66f5dc988 100644 --- a/src/Dodge/Item/Data.hs +++ b/src/Dodge/Item/Data.hs @@ -2,98 +2,12 @@ {-# 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 - deriving - (Eq, Ord, Show) ---data ItemIdentity --- = Pistol --- | SpreadGun --- | MultGun --- | HvAutoGun --- | AutoGun --- | LtAutoGun --- | MiniGun --- | Medkit25 --- | MagShield --- | FrontArmour --- | JetPack --- | FlameShield --- | Generic --- | SparkGun --- | ShatterGun --- | LongGun --- | Flamethrower --- | Blinker --- | Rewinder --- | Grenade --- | RemoteBomb --- | TeslaGun --- | LasGun --- | ForceFieldGun --- | GrapGun --- | TractorGun --- | Launcher --- | RemoteLauncher --- | LightningGun --- | PoisonSprayer --- | FlatShield --- deriving --- (Eq,Show,Ord,Enum) -data AimStance - = TwoHandTwist - | TwoHandFlat - | OneHand - | LeaveHolstered - deriving - (Eq,Show,Ord,Enum) --- TODO check how much of this is necessary -data ItZoom = ItZoom - { _itZoomMax :: Float - , _itZoomMin :: Float - , _itZoomFac :: Float - } data CurseStatus = Uncursed | UndroppableIdentified | UndroppableUnidentified -data AimParams = AimParams - { _aimWeight :: Int - , _aimRange :: Float - , _aimZoom :: ItZoom - , _aimStance :: AimStance - , _aimHandlePos :: Float - , _aimMuzPos :: Float - } -data UseDelay -- should just be Delay - = NoDelay - | FixedRate - {_rateMax :: Int - ,_rateTime :: Int - } - | VariableRate - {_rateMax :: Int - ,_rateTime :: Int - ,_rateMaxMax :: Int - ,_rateMinMax :: Int - } - | WarmUpNoDelay - {_warmTime :: Int - ,_warmMax :: Int - } data BarrelSpread = AlignedBarrels | SpreadBarrels {_spreadAngle :: Float} | RotatingBarrels {_rotatingBarrelInaccuracy :: Float} makeLenses ''BarrelSpread -makeLenses ''HammerType -makeLenses ''ItZoom -makeLenses ''AimParams -makeLenses ''UseDelay diff --git a/src/Dodge/Item/Equipment.hs b/src/Dodge/Item/Equipment.hs index 9b389d79a..8b7ef7d3c 100644 --- a/src/Dodge/Item/Equipment.hs +++ b/src/Dodge/Item/Equipment.hs @@ -22,9 +22,11 @@ module Dodge.Item.Equipment , overCID , onEquipWristShield , onRemoveWristShield + + , createShieldWall + , removeShieldWall ) where import Dodge.Data -import Dodge.LightSource.Torch import Dodge.Item.Draw import Dodge.Item.Equipment.Booster import Dodge.LightSource @@ -38,7 +40,8 @@ import Picture import Geometry import qualified IntMapHelp as IM import LensHelp ---import ShortShow + +import Data.Maybe magShield :: Item magShield = defaultEquipment @@ -116,22 +119,14 @@ setWristShieldPos itm cr w = w torch :: Item torch = defaultWeapon - & itEffect .~ effectOnOffHeld createHeldLight (const $ const id) + & itEffect .~ effectOnOffHeld CreateHeldLight NoInvEffect-- createHeldLight (const $ const id) & itType . iyBase .~ HELD TORCH & itUse . useAim . aimHandlePos .~ 5 & itUse . useAim . aimMuzPos .~ 10 -createHeldLight :: Creature -> Int -> World -> World -createHeldLight cr i = createTorchLightOffset cr itm 0 --- tempLightSources .:~ tlsTimeRadColPos 1 250 0.7 --- (p +.+.+ rotate3 (_crDir cr) (heldItemOffset itm cr (V3 8 0 1.5))) - where --- p = addZ 0 $ _crPos cr - itm = cr ^?! crInv . ix i - flatShield :: Item flatShield = defaultWeapon - & itEffect .~ effectOnOffHeld createShieldWall removeShieldWall + & itEffect .~ effectOnOffHeld CreateShieldWall RemoveShieldWall --createShieldWall removeShieldWall -- the above seems to work, but I am not sure why: it may break on edge -- cases & itUse .~ defaultrUse @@ -171,14 +166,14 @@ shieldWall crid = defaultWall -- _ | isMovementDam dm -> w & creatures . ix crid . crState . crDamage .:~ dm -- _ -> w -createShieldWall :: Creature -> Int -> World -> World -createShieldWall cr invid w = case _ieMID $ _itEffect it of +createShieldWall :: Item -> Creature -> World -> World +createShieldWall it cr w = case _ieMID $ _itEffect it of Nothing -> let (wlid,w') = createWall ((shieldWall crid) {_wlLine = wlline,_wlID = wlid}) w in w' & creatures . ix crid . crInv . ix invid . itEffect . ieMID ?~ wlid Just wid -> moveWallID wid wlline w where + invid = fromJust $ _itID it crid = _crID cr - it = _crInv (_creatures w IM.! crid) IM.! invid wlline = (a,b) crdirv = unitVectorAtAngle $ _crDir cr crpos = _crPos cr @@ -187,29 +182,23 @@ createShieldWall cr invid w = case _ieMID $ _itEffect it of b = crpos +.+ rad *.* crdirv +.+ 10 *.* therot crdirv therot | crIsAiming cr = vNormal | otherwise = rotateV (twoFlatHRot cr) . vNormal -removeShieldWall :: Creature -> Int -> World -> World -removeShieldWall cr invid w = case _ieMID $ _itEffect it of +removeShieldWall :: Item -> Creature -> World -> World +removeShieldWall it cr w = case _ieMID $ _itEffect it of Nothing -> w Just wid -> w & deleteWallID wid & creatures . ix crid . crInv . ix invid . itEffect . ieMID .~ Nothing where crid = _crID cr - it = _crInv (_creatures w IM.! crid) IM.! invid + invid = fromJust (_itID it) effectOnOffHeld - :: (Creature -> Int -> World -> World) -- ^ effect when held - -> (Creature -> Int -> World -> World) -- ^ effect when not held + :: ItInvEffect -- ^ effect when held + -> ItInvEffect -- ^ effect when not held -> ItEffect effectOnOffHeld f f' = ItInvEffectID - { _ieInv = g + { _ieInv = OnOffHeldEffect f f' , _ieMID = Nothing } - where - g itm cr w - | crSel cr == invid = f cr invid w - | otherwise = f' cr invid w - where - invid = _ipInvID $ _itPos itm {- | Increases speed, reduces friction, cannot only move forwards. -} jetPack :: Item diff --git a/src/Dodge/Item/Equipment/Booster.hs b/src/Dodge/Item/Equipment/Booster.hs index 9f5ce91fc..a576c3f9c 100644 --- a/src/Dodge/Item/Equipment/Booster.hs +++ b/src/Dodge/Item/Equipment/Booster.hs @@ -118,12 +118,5 @@ boosterGun = defaultLeftItem } & itType . iyBase .~ LEFT BOOSTER resetAttachmentID :: ItEffect -resetAttachmentID = ItInvEffect f 0 - where - f itm cr w - | _ieCounter iteff < 0 = w & pointToIt . itAttachment .~ NoItAttachment - | otherwise = w & pointToIt . itEffect . ieCounter -~ 1 - where - iteff = _itEffect itm - invid = _ipInvID $ _itPos itm - pointToIt = creatures . ix (_crID cr) . crInv . ix invid +resetAttachmentID = ItInvEffect ResetAttachmentEffect 0 + diff --git a/src/Dodge/Item/Weapon/Grenade.hs b/src/Dodge/Item/Weapon/Grenade.hs index a50613c87..ea1ca9051 100644 --- a/src/Dodge/Item/Weapon/Grenade.hs +++ b/src/Dodge/Item/Weapon/Grenade.hs @@ -76,50 +76,50 @@ grenadeDraw :: Float -> Prop -> SPic grenadeDraw dir prop = translateSPz (_pjZ prop) $ uncurryV translateSPf (_prPos prop) $ rotateSP dir $ grenadePic $ _pjTimer prop -throwGrenade - :: (Point2 -> World -> World) -- ^ Payload - -> Creature - -> World - -> World -throwGrenade thePayload cr w = setWp $ removePict $ over props addG w - where - n = _crID cr - addG = IM.insert i $ Bomb - { _prPos = p - , _pjZ = 10 - , _pjVelZ = 2 - , _pjVel = v - , _prDraw = grenadeDraw dir - , _pjID = i - , _pjUpdate = moveGrenade - , _pjPayload = thePayload - , _pjTimer = fuseTime - } - j = crSel cr - removePict = id -- set (creatures . ix n . crInv . ix j . itEquipPict) $ \ _ _ -> (,) emptySH blank - i = IM.newKey $ _props w - v' = 1 / (fromIntegral fuseTime * _cameraZoom w) *.* rotateV (_cameraRot w) ( _mousePos w) - v | magV v' > 6 = 6 *.* normalizeV v' - | otherwise = v' - 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' - dir = argV v - setWp :: World -> World - setWp w' = w' & creatures . ix n . crInv . ix j . itEffect .~ throwArmReset 20 - fuseTime = _atFuseTime $ _itAttachment $ _crInv cr IM.! j +--throwGrenade +-- :: (Point2 -> World -> World) -- ^ Payload +-- -> Creature +-- -> World +-- -> World +--throwGrenade thePayload cr w = setWp $ removePict $ over props addG w +-- where +-- n = _crID cr +-- addG = IM.insert i $ Bomb +-- { _prPos = p +-- , _pjZ = 10 +-- , _pjVelZ = 2 +-- , _pjVel = v +-- , _prDraw = grenadeDraw dir +-- , _pjID = i +-- , _pjUpdate = moveGrenade +-- , _pjPayload = thePayload +-- , _pjTimer = fuseTime +-- } +-- j = crSel cr +-- removePict = id -- set (creatures . ix n . crInv . ix j . itEquipPict) $ \ _ _ -> (,) emptySH blank +-- i = IM.newKey $ _props w +-- v' = 1 / (fromIntegral fuseTime * _cameraZoom w) *.* rotateV (_cameraRot w) ( _mousePos w) +-- v | magV v' > 6 = 6 *.* normalizeV v' +-- | otherwise = v' +-- 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' +-- dir = argV v +-- setWp :: World -> World +-- setWp w' = w' & creatures . ix n . crInv . ix j . itEffect .~ throwArmReset 20 +-- fuseTime = _atFuseTime $ _itAttachment $ _crInv cr IM.! j -throwArmReset :: Int -> ItEffect -throwArmReset x = ItInvEffect {_ieInv = f ,_ieCounter = x } - where - f itm cr = creatures . ix (_crID cr) . crInv %~ IM.adjust counterDown i - where - i = _ipInvID $ _itPos itm - counterDown it - | _ieCounter (_itEffect it) == 0 = it - & itUse . useHammer .~ HammerUp --- & itEquipPict .~ pictureWeaponAim (\_ -> grenadePic 50) - | otherwise = it & itEffect . ieCounter -~ 1 +--throwArmReset :: Int -> ItEffect +--throwArmReset x = ItInvEffect {_ieInv = f ,_ieCounter = x } +-- where +-- f itm cr = creatures . ix (_crID cr) . crInv %~ IM.adjust counterDown i +-- where +-- i = _ipInvID $ _itPos itm +-- counterDown it +-- | _ieCounter (_itEffect it) == 0 = it +-- & itUse . useHammer .~ HammerUp +---- & itEquipPict .~ pictureWeaponAim (\_ -> grenadePic 50) +-- | otherwise = it & itEffect . ieCounter -~ 1 --flameGrenade :: Item --flameGrenade = grenade { diff --git a/src/Dodge/Item/Weapon/Utility.hs b/src/Dodge/Item/Weapon/Utility.hs index 6839158ca..015c22b21 100644 --- a/src/Dodge/Item/Weapon/Utility.hs +++ b/src/Dodge/Item/Weapon/Utility.hs @@ -20,24 +20,12 @@ rewindGun = defaultLeftItem { _wpMaxCharge = 250 , _wpCharge = 0 } - , _itEffect = ItRewindEffect rewindEffect [] + , _itEffect = ItRewindEffect RewindEffect [] , _itUse = defaultlUse & lUse .~ LRewind --useRewindGun & eqEq . eqSite .~ GoesOnChest } & itType . iyBase .~ LEFT REWINDER -rewindEffect :: Item -> Creature -> World -> World -rewindEffect itm cr w - | Just invid == _crLeftInvSel cr = w & rewindWorlds %~ (take maxcharge . (w' : )) - & ptrWpCharge .~ length (_rewindWorlds w) - | otherwise = w & rewindWorlds .~ [] - & ptrWpCharge .~ 0 - where - invid = _ipInvID $ _itPos itm - ptrWpCharge = creatures . ix (_crID cr) . crInv . ix invid . itConsumption . wpCharge - maxcharge = _wpMaxCharge . _itConsumption $ itm - w' = w & rewindWorlds .~ [] - & timeFlow .~ NormalTimeFlow -- needs to shift this item to the current inventory slot shrinkGun :: Item