From 845c1f282ea4e49618ff40ca3d57f4907f466d03 Mon Sep 17 00:00:00 2001 From: justin Date: Wed, 20 Jul 2022 20:40:13 +0100 Subject: [PATCH] Move function fields outside equipment --- src/Dodge/Creature/Impulse/UseItem.hs | 8 +++++--- src/Dodge/Creature/State.hs | 3 ++- src/Dodge/Cuse.hs | 9 +++++++++ src/Dodge/Data.hs | 8 ++++---- src/Dodge/Data/CamouflageStatus.hs | 5 +++++ src/Dodge/Data/Creature.hs | 10 +++++----- src/Dodge/Data/Item/.HeldUse.hs.swo | Bin 0 -> 12288 bytes src/Dodge/Data/Item/HeldUse.hs | 15 +++++++++++++++ src/Dodge/Default/Weapon.hs | 6 +++--- src/Dodge/Euse.hs | 20 ++++++++++++++++++++ src/Dodge/Inventory.hs | 3 ++- src/Dodge/Item/Consumable.hs | 2 +- src/Dodge/Item/Equipment.hs | 23 +++++++++++++++-------- src/Dodge/Item/Weapon/Radar.hs | 4 +--- 14 files changed, 87 insertions(+), 29 deletions(-) create mode 100644 src/Dodge/Cuse.hs create mode 100644 src/Dodge/Data/CamouflageStatus.hs create mode 100644 src/Dodge/Data/Item/.HeldUse.hs.swo create mode 100644 src/Dodge/Euse.hs diff --git a/src/Dodge/Creature/Impulse/UseItem.hs b/src/Dodge/Creature/Impulse/UseItem.hs index 47a3e18e0..a6842b59f 100644 --- a/src/Dodge/Creature/Impulse/UseItem.hs +++ b/src/Dodge/Creature/Impulse/UseItem.hs @@ -4,6 +4,8 @@ module Dodge.Creature.Impulse.UseItem ) where import Dodge.Data import Dodge.Luse +import Dodge.Cuse +import Dodge.Euse import Dodge.Inventory import Dodge.Reloading import Dodge.Item.Location @@ -31,7 +33,7 @@ itemEffect cr it w = case it ^? itUse of Just LeftUse {} -> doequipmentchange Just EquipUse{} -> doequipmentchange -- ConsumeUse will cause problems if the item is not selected - Just (ConsumeUse eff) -> setuhamdown $ hammerTest $ eff it cr . rmInvItem (_crID cr) (crSel cr) + Just (ConsumeUse eff) -> setuhamdown $ hammerTest $ (useC eff) it cr . rmInvItem (_crID cr) (crSel cr) Just NoUse -> setuhamdown w Nothing -> setuhamdown w where @@ -92,8 +94,8 @@ toggleEquipmentAt rbops invid cr w = case rbops ^? opAllocateEquipment of crpoint = creatures . ix (_crID cr) itmat i = _crInv cr IM.! i itm = itmat (crSel cr) - onequip itm' = (_eqOnEquip . _eqEq . _itUse) itm' itm' - onremove itm' = (_eqOnRemove . _eqEq . _itUse) itm' itm' + onequip itm' = useE ((_eqOnEquip . _eqEq . _itUse) itm') itm' + onremove itm' = useE ((_eqOnRemove . _eqEq . _itUse) itm') itm' useLeftItem :: Int -> World -> World useLeftItem cid w diff --git a/src/Dodge/Creature/State.hs b/src/Dodge/Creature/State.hs index 25f7bddfd..3cf9d3cb4 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.Euse import Dodge.EnergyBall import Dodge.Damage import Dodge.Hammer @@ -181,7 +182,7 @@ useUpdate = (useHammer %~ moveHammerUp) . (useDelay . rateTime %~ decreaseToZero) useEquipment :: Creature -> Int -> World -> World -useEquipment cr i = _eqUse (_eqEq $ _itUse itm) itm cr +useEquipment cr i = useE (_eqUse (_eqEq $ _itUse itm)) itm cr where itm = _crInv cr IM.! i -- a map updating all inventory items diff --git a/src/Dodge/Cuse.hs b/src/Dodge/Cuse.hs new file mode 100644 index 000000000..5910499ec --- /dev/null +++ b/src/Dodge/Cuse.hs @@ -0,0 +1,9 @@ +module Dodge.Cuse where +import Dodge.Data + +import Control.Lens + +useC :: Cuse -> Item -> Creature -> World -> World +useC cu = case cu of + CDoNothing -> const $ const id + CHeal x -> const $ \cr -> creatures . ix (_crID cr) . crHP +~ x diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index e047d1193..6ae52a1d3 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -416,16 +416,16 @@ data ItemUse , _eqEq :: Equipment } | ConsumeUse - { _cUse :: Item -> Creature -> World -> World + { _cUse :: Cuse --Item -> Creature -> World -> World } | EquipUse { _eqEq :: Equipment } | NoUse data Equipment = Equipment - { _eqUse :: Item -> Creature -> World -> World - , _eqOnEquip :: Item -> Creature -> World -> World - , _eqOnRemove :: Item -> Creature -> World -> World + { _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 diff --git a/src/Dodge/Data/CamouflageStatus.hs b/src/Dodge/Data/CamouflageStatus.hs new file mode 100644 index 000000000..1d3c906f5 --- /dev/null +++ b/src/Dodge/Data/CamouflageStatus.hs @@ -0,0 +1,5 @@ +module Dodge.Data.CamouflageStatus where +data CamouflageStatus + = FullyVisible + | Invisible + deriving (Eq,Ord,Enum) diff --git a/src/Dodge/Data/Creature.hs b/src/Dodge/Data/Creature.hs index 56f0978a5..de79b406e 100644 --- a/src/Dodge/Data/Creature.hs +++ b/src/Dodge/Data/Creature.hs @@ -1,14 +1,14 @@ {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE StrictData #-} -module Dodge.Data.Creature where +module Dodge.Data.Creature + ( module Dodge.Data.Creature + , module Dodge.Data.CamouflageStatus + ) where +import Dodge.Data.CamouflageStatus import Sound.Data import Geometry.Data import Color import Control.Lens -data CamouflageStatus - = FullyVisible - | Invisible - deriving (Eq,Ord,Enum) data CreatureStatistics = CreatureStatistics { _strength :: Int , _dexterity :: Int diff --git a/src/Dodge/Data/Item/.HeldUse.hs.swo b/src/Dodge/Data/Item/.HeldUse.hs.swo new file mode 100644 index 0000000000000000000000000000000000000000..d5718c11b1da42044e374581e97e7556c482f138 GIT binary patch literal 12288 zcmeI2y>A>v7{(_k0wLn?m7Yx^(xAJu6N;n=ito!dIwz;Qa~z-=@4n|9Zg%IiJ8R=8 zf(C(r|9~bE5;PP@AZkDedPEaJMS&=3A)?^fkGq>(5k=_|y(|5^yU+W+^YP5=HJ-iI z>s#C2#rm4S^_&p@y>e&otLION_kTGq-p*31;yiHwtIVry_G=xjEH#ap)VfA1Q(Ieo zb+xupw2da-EfX7?GM$jt4Q^xX4XR!n906V}AumkJ>JHQUG1MI+K;eeeU6YpUr zPgJwHQr(X&-K$r=u>;OB!4zL64z$55@421aSX(3KMgTdqf z|5vIx{Qj&EKY;JSXW(NHf+4sBUIKSd3ULSg1il5g!6)Dd5a@%~z-4d_ybM;rQ{YMP z_lgjIfM3DS;2ZD-_#Au)rr=G`2Is+9a1#7`LWsY>Z{SDpHMk8v0u%5C=z)6^u^%g@m+ny-4TMp%{ReXd7|(^v<^ zp^WXldAS<{6*A6MP^e*5hWuP5l;DDTaH3&g;Y#%Hb~Sg zNyAWDOZm8~oSw{LKP(r=vA-wNMNT`Dx=AuxC|H>Mqy$O-LgU*PSw4G?HiSvcsNbuQJEaz?DK57yvwtvtHxrV?2FkHak4s{?W^8S zoXRmZwTdV6xcf2;6DKsFLlp<2=%<&Zgid;GGw-0#%V@{M2;%Q@xK)<59Noips~Byy z9@R+ljn_4aPhEv4M;w}1`MdIf9Bq_H-GQ1tx!M}@74U>mQSqr4N9gM<6Yb%LrQXJN5|Ifq XOq3yJ>$TTj_Q literal 0 HcmV?d00001 diff --git a/src/Dodge/Data/Item/HeldUse.hs b/src/Dodge/Data/Item/HeldUse.hs index 266424fbc..5caefe015 100644 --- a/src/Dodge/Data/Item/HeldUse.hs +++ b/src/Dodge/Data/Item/HeldUse.hs @@ -1,5 +1,6 @@ module Dodge.Data.Item.HeldUse where import Dodge.Combine.Data +import Dodge.Data.CamouflageStatus data HeldUse = HeldDoNothing | HeldUseAmmoParams @@ -18,6 +19,20 @@ data HeldUse = HeldDoNothing | HeldForceField | HeldShatter +data Cuse = CDoNothing + | CHeal Int + +data Euse = EDoNothing + | EDetector Detector + | EMagShield + | EWristShield + | EHeadLamp + | ECamouflage CamouflageStatus + + | EonWristShield + + | EoffWristShield + data Luse = LDoNothing | LRewind | LShrink diff --git a/src/Dodge/Default/Weapon.hs b/src/Dodge/Default/Weapon.hs index a47417896..478993bb0 100644 --- a/src/Dodge/Default/Weapon.hs +++ b/src/Dodge/Default/Weapon.hs @@ -47,9 +47,9 @@ defaultlUse = LeftUse defaultEquip :: Equipment defaultEquip = Equipment { _eqSite = GoesOnSpecial - , _eqUse = \_ _ -> id - , _eqOnEquip = \_ _ -> id - , _eqOnRemove = \_ _ -> id + , _eqUse = EDoNothing + , _eqOnEquip = EDoNothing + , _eqOnRemove = EDoNothing , _eqParams = NoEquipParams , _eqViewDist = Nothing } diff --git a/src/Dodge/Euse.hs b/src/Dodge/Euse.hs new file mode 100644 index 000000000..f76f1b8e5 --- /dev/null +++ b/src/Dodge/Euse.hs @@ -0,0 +1,20 @@ +module Dodge.Euse where +import Dodge.Data +import Dodge.Item.Weapon.ExtraEffect +import Dodge.Item.Weapon.Radar +import Dodge.SoundLogic.ExternallyGeneratedSounds +import Dodge.Item.Equipment +import LensHelp + +useE :: Euse -> Item -> Creature -> World -> World +useE eo = case eo of + EDoNothing -> const $ const id + EDetector dt -> autoEffect (detectorEffect dt) 100 click1S + EMagShield -> useMagShield + EWristShield -> setWristShieldPos + EHeadLamp -> createHeadLamp + ECamouflage vis -> overCID (crCamouflage .~ vis) + + EonWristShield -> onEquipWristShield + + EoffWristShield -> onRemoveWristShield diff --git a/src/Dodge/Inventory.hs b/src/Dodge/Inventory.hs index cdae51968..33a433373 100644 --- a/src/Dodge/Inventory.hs +++ b/src/Dodge/Inventory.hs @@ -25,6 +25,7 @@ module Dodge.Inventory ) where import Dodge.Data +import Dodge.Euse import Dodge.Inventory.CloseObject import Dodge.Inventory.CheckSlots import Dodge.Inventory.ItemSpace @@ -71,7 +72,7 @@ rmInvItem cid invid w = case w ^? creatures . ix cid . crInv . ix invid . itCons itm = _crInv cr IM.! invid dounequipfunction = fromMaybe id $ do rmf <- itm ^? itUse . eqEq . eqOnRemove - return $ rmf itm cr + return $ useE rmf itm cr doanyitemeffect = fromMaybe id $ do rmf <- itm ^? itEffect . ieDrop return $ rmf itm cr diff --git a/src/Dodge/Item/Consumable.hs b/src/Dodge/Item/Consumable.hs index 9f4f2c992..9d88a78cf 100644 --- a/src/Dodge/Item/Consumable.hs +++ b/src/Dodge/Item/Consumable.hs @@ -15,7 +15,7 @@ import qualified Data.IntMap.Strict as IM medkit :: Int -> Item medkit i = defaultConsumable { _itUse = ConsumeUse - {_cUse = \_ cr w -> w & creatures . ix (_crID cr) . crHP +~ i + {_cUse = CHeal i } , _itID = Nothing } diff --git a/src/Dodge/Item/Equipment.hs b/src/Dodge/Item/Equipment.hs index ff166371f..9b389d79a 100644 --- a/src/Dodge/Item/Equipment.hs +++ b/src/Dodge/Item/Equipment.hs @@ -15,6 +15,13 @@ module Dodge.Item.Equipment , speedLegs , jumpLegs , flameShield + + , useMagShield + , setWristShieldPos + , createHeadLamp + , overCID + , onEquipWristShield + , onRemoveWristShield ) where import Dodge.Data import Dodge.LightSource.Torch @@ -38,7 +45,7 @@ magShield = defaultEquipment { _itID = Nothing , _itAttachment = AttachMInt Nothing } - & itUse . eqEq . eqUse .~ useMagShield + & itUse . eqEq . eqUse .~ EMagShield --useMagShield & itUse . eqEq . eqSite .~ GoesOnWrist & itType . iyBase .~ EQUIP MAGSHIELD useMagShield :: Item -> Creature -> World -> World @@ -73,9 +80,9 @@ wristArmour = defaultEquipment {_itID = Nothing } & itUse . eqEq . eqSite .~ GoesOnWrist - & itUse . eqEq . eqOnEquip .~ onEquipWristShield - & itUse . eqEq . eqUse .~ setWristShieldPos - & itUse . eqEq . eqOnRemove .~ onRemoveWristShield + & itUse . eqEq . eqOnEquip .~ EonWristShield --onEquipWristShield + & itUse . eqEq . eqUse .~ EWristShield --setWristShieldPos + & itUse . eqEq . eqOnRemove .~ EoffWristShield --onRemoveWristShield & itType . iyBase .~ EQUIP WRISTARMOUR onEquipWristShield :: Item -> Creature -> World -> World @@ -232,7 +239,7 @@ headLamp1 = defaultEquipment { _itEffect = NoItEffect , _itID = Nothing } - & itUse . eqEq . eqUse .~ createHeadLamp + & itUse . eqEq . eqUse .~ EHeadLamp --createHeadLamp & itUse . eqEq . eqSite .~ GoesOnHead & itType . iyBase .~ EQUIP HEADLAMP1 headLamp :: Item @@ -240,7 +247,7 @@ headLamp = defaultEquipment { _itEffect = NoItEffect , _itID = Nothing } - & itUse . eqEq . eqUse .~ createHeadLamp + & itUse . eqEq . eqUse .~ EHeadLamp --createHeadLamp & itUse . eqEq . eqSite .~ GoesOnHead & itType . iyBase .~ EQUIP HEADLAMP @@ -268,8 +275,8 @@ wristInvisibility = defaultEquipment { _itID = Nothing } & itUse . eqEq . eqSite .~ GoesOnWrist - & itUse . eqEq . eqOnEquip .~ overCID (crCamouflage .~ Invisible) - & itUse . eqEq . eqOnRemove .~ overCID (crCamouflage .~ FullyVisible) + & itUse . eqEq . eqOnEquip .~ ECamouflage Invisible --overCID (crCamouflage .~ Invisible) + & itUse . eqEq . eqOnRemove .~ ECamouflage FullyVisible --overCID (crCamouflage .~ FullyVisible) & itType . iyBase .~ EQUIP (INVISIBILITYEQUIPMENT GoesOnWrist) overCID :: (Creature -> Creature) -> Item -> Creature -> World -> World diff --git a/src/Dodge/Item/Weapon/Radar.hs b/src/Dodge/Item/Weapon/Radar.hs index f51b7515c..0586645f8 100644 --- a/src/Dodge/Item/Weapon/Radar.hs +++ b/src/Dodge/Item/Weapon/Radar.hs @@ -2,8 +2,6 @@ module Dodge.Item.Weapon.Radar where import Dodge.Data import Dodge.RadarSweep import Dodge.Default -import Dodge.Item.Weapon.ExtraEffect -import Dodge.SoundLogic import Control.Lens @@ -21,7 +19,7 @@ clickDetector dt = defaultWeapon autoDetector :: Detector -> Item autoDetector dt = defaultEquipment & itUse . eqEq . eqSite .~ GoesOnWrist - & itUse . eqEq . eqUse .~ autoEffect (detectorEffect dt) 100 click1S + & itUse . eqEq . eqUse .~ EDetector dt --autoEffect (detectorEffect dt) 100 click1S & itUse . eqEq . eqParams .~ EquipCounter 0 & itUse . eqEq . eqViewDist ?~ 350 & itType . iyBase .~ EQUIP (AUTODETECTOR dt)