Improve left use equipment interaction with general equipment

This commit is contained in:
2022-05-23 16:59:24 +01:00
parent c2770e6b5c
commit fa82923a12
4 changed files with 33 additions and 8 deletions
+22 -3
View File
@@ -22,7 +22,7 @@ itemEffect :: Creature -> Item -> World -> World
itemEffect cr it w = case it ^? itUse of
Just RightUse {_rUse = eff,_useMods = usemods}
-> hammerTest $ foldr ($) eff usemods it cr
Just LeftUse {} -> setuhamdown $ lhammer setEquipLeftItem
Just LeftUse {} -> setuhamdown $ lhammer (setEquipLeftItem)
Just EquipUse{} -> setuhamdown $ lhammer $ toggleEquipmentAt (_crInvSel cr) it
-- ConsumeUse will cause problems if the item is not selected
Just (ConsumeUse eff) -> setuhamdown $ hammerTest $ eff it cr . rmInvItem (_crID cr) (_crInvSel cr)
@@ -37,7 +37,15 @@ itemEffect cr it w = case it ^? itUse of
_ -> id
setEquipLeftItem cr' = case _crLeftInvSel cr' of
Just i | i == _crInvSel cr' -> cr' & crLeftInvSel .~ Nothing
& crInvEquipped . at i .~ Nothing
-- if the following causes an exception we have reached a state that
-- should not be possible
& crEquipment . at (_crInvEquipped cr' IM.! i) .~ Nothing
-- Just i -> cr' & crLeftInvSel ?~ _crInvSel cr'
-- should left use equipment be removed if replaced by left use
-- equipment that uses a different site?
_ -> cr' & crLeftInvSel ?~ _crInvSel cr'
& equipUsingSiteCheck (_crInvSel cr') it
setuhamdown = creatures . ix (_crID cr) . crHammerPosition .~ HammerDown
toggleEquipmentAt :: Int -> Item -> Creature -> Creature
@@ -46,6 +54,12 @@ toggleEquipmentAt invid itm cr = case cr ^? crInvEquipped . ix invid of
& crEquipment . at epos .~ Nothing
Nothing -> equipUsingSite invid itm cr
-- | First check if the item is already equiped, then do nothing
equipUsingSiteCheck :: Int -> Item -> Creature -> Creature
equipUsingSiteCheck invid itm cr
| isJust (cr ^? crInvEquipped . ix invid) = cr
| otherwise = equipUsingSite invid itm cr
equipUsingSite :: Int -> Item -> Creature -> Creature
equipUsingSite invid itm cr = cr
& crInvEquipped . at invid ?~ epos
@@ -55,7 +69,10 @@ equipUsingSite invid itm cr = cr
epos = eqSiteToPos cr (_eqSite $ _itUse itm)
removeOtherEquipment = case cr ^? crEquipment . ix epos of
Nothing -> id
Just oid -> crInvEquipped . at oid .~ Nothing
Just oid -> (crInvEquipped . at oid .~ Nothing) . removeIfLUse oid
removeIfLUse oid
| _crLeftInvSel cr == Just oid = crLeftInvSel .~ Nothing
| otherwise = id
eqSiteToPos :: Creature -> EquipSite -> EquipPosition
eqSiteToPos cr es = case es of
@@ -80,5 +97,7 @@ useLeftItem cid w
where
cr = _creatures w IM.! cid
itmShouldBeUsed = isJust (cr ^? crInv . ix (_crInvSel cr) . itUse . cUse)
|| isJust (cr ^? crInv . ix (_crInvSel cr) . itUse . eqUse)
|| ( isJust (cr ^? crInv . ix (_crInvSel cr) . itUse . eqUse)
&& _crLeftInvSel cr /= Just (_crInvSel cr)
)
-- TODO determine itmShouldBeUsed with reference to config options
+1
View File
@@ -378,6 +378,7 @@ data ItemUse
, _useDelay :: UseDelay
, _useHammer :: HammerType
, _eqSite :: EquipSite
, _eqUse :: Creature -> Int -> World -> World
}
| ConsumeUse
{ _cUse :: Item -> Creature -> World -> World
+2
View File
@@ -66,6 +66,7 @@ defaultlUse = LeftUse
, _useDelay = FixedRate {_rateMax = 8, _rateTime = 0}
, _useHammer = NoHammer
, _eqSite = GoesOnSpecial
, _eqUse = \_ _ -> id
}
luseInstantNoH :: (Item -> Creature -> World -> World) -> ItemUse
@@ -74,6 +75,7 @@ luseInstantNoH f = LeftUse
, _useDelay = NoDelay
, _useHammer = NoHammer
, _eqSite = GoesOnSpecial
, _eqUse = \_ _ -> id
}
defaultAimParams :: AimParams
defaultAimParams = AimParams
+8 -5
View File
@@ -9,7 +9,7 @@ import Dodge.Default.Weapon
--import Sound.Data
import Geometry
import Picture
import qualified IntMapHelp as IM
--import qualified IntMapHelp as IM
import Shape
import ShapePicture
@@ -27,7 +27,9 @@ rewindGun = defaultGun
, _wpCharge = 0
}
, _itEffect = ItRewindEffect rewindEffect []
, _itUse = defaultlUse {_lUse = useRewindGun}
, _itUse = defaultlUse
& lUse .~ useRewindGun
& eqSite .~ GoesOnChest
}
rewindEffect :: Item -> Creature -> World -> World
rewindEffect itm cr w
@@ -38,7 +40,7 @@ rewindEffect itm cr w
where
invid = fromJust $ _itInvPos itm
ptrWpCharge = creatures . ix (_crID cr) . crInv . ix invid . itConsumption . wpCharge
maxcharge = _wpMaxCharge . _itConsumption $ _crInv cr IM.! invid
maxcharge = _wpMaxCharge . _itConsumption $ itm
w' = w & rewindWorlds .~ []
& timeFlow .~ NormalTimeFlow
@@ -99,8 +101,9 @@ blinkGun = defaultGun
, _reloadTime = 20
}
, _itUse = defaultlUse
{_lUse = hammerCheckL $ shootL aSelfL
} & useHammer .~ upHammer
& lUse .~ hammerCheckL (shootL aSelfL)
& useHammer .~ upHammer
& eqSite .~ GoesOnWrist
-- , _itFloorPict = const . noPic . colorSH chartreuse $ upperPrismPoly 2 $ square 2
}