Allow for selection of equipment position

This commit is contained in:
2022-05-24 14:03:18 +01:00
parent fa82923a12
commit 7f55ba117f
14 changed files with 221 additions and 37 deletions
+37 -18
View File
@@ -22,8 +22,10 @@ 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 EquipUse{} -> setuhamdown $ lhammer $ toggleEquipmentAt (_crInvSel cr) it
Just LeftUse {} -> setuhamdown $ lhammer $ (toggleEquipmentAt (_rbOptions w) (_crInvSel cr)
. activateEquipmentAt (_rbOptions w))
Just EquipUse{} -> setuhamdown $ lhammer $ (toggleEquipmentAt (_rbOptions w) (_crInvSel cr)
. activateEquipmentAt (_rbOptions w))
-- ConsumeUse will cause problems if the item is not selected
Just (ConsumeUse eff) -> setuhamdown $ hammerTest $ eff it cr . rmInvItem (_crID cr) (_crInvSel cr)
Just NoUse -> setuhamdown w
@@ -35,24 +37,41 @@ itemEffect cr it w = case it ^? itUse of
lhammer f' = w & case _crHammerPosition cr of
HammerUp -> creatures . ix (_crID cr) %~ f'
_ -> 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
toggleEquipmentAt invid itm cr = case cr ^? crInvEquipped . ix invid of
Just epos -> cr & crInvEquipped . at invid .~ Nothing
& crEquipment . at epos .~ Nothing
Nothing -> equipUsingSite invid itm cr
activateEquipmentAt :: RightButtonOptions -> Creature -> Creature
activateEquipmentAt rbo = case (rbo ^? opActivateEquipment . activateEquipment, rbo ^? opActivateEquipment . deactivateEquipment) of
(Just i,_) -> crLeftInvSel ?~ i
(_,Just _) -> crLeftInvSel .~ Nothing
_ -> id
toggleEquipmentAt :: RightButtonOptions -> Int -> Creature -> Creature
toggleEquipmentAt rbops invid cr = case rbops ^? opAllocateEquipment of
Just DoNotMoveEquipment -> cr
Just PutOnEquipment {_allocNewPos = newp}
-> cr & crEquipment . at newp ?~ invid
& crInvEquipped . at invid ?~ newp
Just MoveEquipment {_allocNewPos=newp,_allocOldPos = oldp }
-> cr & crEquipment . at newp ?~ invid
& crEquipment . at oldp .~ Nothing
& crInvEquipped . at invid ?~ newp
Just SwapEquipment {_allocNewPos=newp, _allocOldPos = oldp, _allocSwapID = sid }
-> cr & crEquipment . at newp ?~ invid
& crEquipment . at oldp ?~ sid
& crInvEquipped . at invid ?~ newp
& crInvEquipped . at sid ?~ oldp
Just ReplaceEquipment {_allocNewPos = newp, _allocRemoveID = rid }
-> cr & crEquipment . at newp ?~ invid
& crInvEquipped . at invid ?~ newp
& crInvEquipped . at rid .~ Nothing
Just RemoveEquipment {_allocOldPos = oldp }
-> cr & crEquipment . at oldp .~ Nothing
& crInvEquipped . at invid .~ Nothing
Nothing -> error "tried to toggle equipment whilst not prepared"
-- case cr ^? crInvEquipped . ix invid of
-- Just epos -> cr & crInvEquipped . at invid .~ Nothing
-- & 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