Improve left use equipment interaction with general equipment
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user