Fix bug concerning effects when dropping items

This commit is contained in:
2023-05-03 22:12:19 +01:00
parent d99d612e68
commit 487280a475
5 changed files with 72 additions and 114 deletions
+49 -84
View File
@@ -51,10 +51,10 @@ rmInvItem cid invid w = case w ^? getcid . crInv . ix invid . itUse . useAmount
_ ->
w
& pointcid %~ crCancelReloading
& pointcid . crInv %~ f
& removeAnySlotEquipment -- the ordering
& dounequipfunction -- of these is
& pointcid . crInv %~ f -- important
& pointcid . crLeftInvSel . lisMPos %~ g'
& removeAnySlotEquipment
& dounequipfunction
& doanyitemeffect
& pointcid . crInvEquipped %~ IM.delete invid
& pointcid . crInvEquipped %~ IM.mapKeys g
@@ -100,7 +100,6 @@ rmSelectedInvItem cid w = case w ^? cWorld . lWorld . creatures . ix cid . crMan
Just i -> rmInvItem cid i w
Nothing -> w
-- this looks ugly...
updateCloseObjects :: World -> World
updateCloseObjects w =
@@ -132,7 +131,7 @@ updateCloseObjects w =
updateRBList :: World -> World
updateRBList w
| w ^? rbOptions . opItemID == mcurrentitemid =
w & setEquipAllocation & setEquipActivation
w & setEquipAllocationActivation
| otherwise = fromMaybe (w & rbOptions .~ NoRightButtonOptions) $ do
i <- cr ^? crManipulation . manObject . inInventory . ispItem
esite <- cr ^? crInv . ix i . itUse . equipEffect . eeSite
@@ -147,8 +146,7 @@ updateRBList w
, _opAllocateEquipment = DoNotMoveEquipment
, _opActivateEquipment = NoChangeActivateEquipment
}
& setEquipAllocation
& setEquipActivation
& setEquipAllocationActivation
where
mcurrentitemid = do
i <- cr ^? crManipulation . manObject . inInventory . ispItem
@@ -166,45 +164,37 @@ chooseFreeSite cr = fromMaybe 0 . findIndex hasnoequipment
where
hasnoequipment ep = isNothing $ cr ^? crEquipment . ix ep
setEquipAllocationActivation :: World -> World
setEquipAllocationActivation = setEquipActivation . setEquipAllocation
setEquipAllocation :: World -> World
setEquipAllocation w = fromMaybe w $ do
curpos <- you w ^? crManipulation . manObject . inInventory . ispItem
return $ case _rbOptions w of
EquipOptions{_opEquip = es, _opSel = i} ->
case you w ^? crInvEquipped . ix curpos of
Just epos
| es !! i == epos ->
w & rbOptions . opAllocateEquipment
.~ RemoveEquipment
{ _allocOldPos = epos
}
Just epos
| isJust (you w ^? crEquipment . ix (es !! i)) ->
w & rbOptions . opAllocateEquipment
.~ SwapEquipment
{ _allocOldPos = epos
, _allocNewPos = es !! i
, _allocSwapID = _crEquipment (you w) M.! (es !! i)
}
Just epos ->
w & rbOptions . opAllocateEquipment
.~ MoveEquipment
{ _allocOldPos = epos
, _allocNewPos = es !! i
}
Nothing
| isJust (you w ^? crEquipment . ix (es !! i)) ->
w & rbOptions . opAllocateEquipment
.~ ReplaceEquipment
{ _allocNewPos = es !! i
, _allocRemoveID = _crEquipment (you w) M.! (es !! i)
}
Nothing ->
w & rbOptions . opAllocateEquipment
.~ PutOnEquipment
{ _allocNewPos = es !! i
}
_ -> w
i <- w ^? rbOptions . opSel
es <- w ^? rbOptions . opEquip . ix i
return $
w & rbOptions . opAllocateEquipment .~ case you w ^? crInvEquipped . ix curpos of
Just epos
| es == epos -> RemoveEquipment{_allocOldPos = epos}
Just epos
| isJust (you w ^? crEquipment . ix es) ->
SwapEquipment
{ _allocOldPos = epos
, _allocNewPos = es
, _allocSwapID = _crEquipment (you w) M.! es
}
Just epos ->
MoveEquipment
{ _allocOldPos = epos
, _allocNewPos = es
}
Nothing
| isJust (you w ^? crEquipment . ix es) ->
ReplaceEquipment
{ _allocNewPos = es
, _allocRemoveID = _crEquipment (you w) M.! es
}
Nothing -> PutOnEquipment{_allocNewPos = es}
setEquipActivation :: World -> World
setEquipActivation w = case w ^? rbOptions . opAllocateEquipment of
@@ -263,26 +253,33 @@ closeObjScrollDir x
changeSwapSel :: Int -> World -> World
changeSwapSel yi w
| yi == 0 = w
| yi > 0 = foldr ($) w $ replicate yi (changeSwapWith $ f IM.cycleLT)
| yi == 0 = w
| yi > 0 = foldr ($) w $ replicate yi (changeSwapWith $ f IM.cycleLT)
| otherwise = foldr ($) w $ replicate (negate yi) (changeSwapWith $ f IM.cycleGT)
where
f g i m = fst <$> g i m
changeSwapClose :: (Int -> IM.IntMap (SelectionItem ()) -> Maybe Int)
-> Int -> World -> World
changeSwapClose ::
(Int -> IM.IntMap (SelectionItem ()) -> Maybe Int) ->
Int ->
World ->
World
changeSwapClose f i w = fromMaybe w $ do
ss <- w ^? hud . hudElement . diSections . sssSections . ix 3 . ssItems
k <- f i ss
return $ w
return $
w
& cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . inNearby . ispCloseObject
.~ k
& hud . closeObjects %~ swapIndices i k
& hud . hudElement . diSections . sssExtra . sssSelPos . _Just . _2 .~ k
& worldEventFlags . at InventoryChange ?~ ()
changeSwapInv :: (Int -> IM.IntMap (SelectionItem ()) -> Maybe Int)
-> Int -> World -> World
changeSwapInv ::
(Int -> IM.IntMap (SelectionItem ()) -> Maybe Int) ->
Int ->
World ->
World
changeSwapInv f i w = fromMaybe w $ do
ss <- w ^? hud . hudElement . diSections . sssSections . ix 0 . ssItems
k <- f i ss
@@ -309,42 +306,10 @@ changeSwapInv f i w = fromMaybe w $ do
changeSwapWith :: (Int -> IM.IntMap (SelectionItem ()) -> Maybe Int) -> World -> World
changeSwapWith f w = case w ^? hud . hudElement . diSections . sssExtra . sssSelPos . _Just of
Just (0,i) -> w & changeSwapInv f i
Just (3,i) -> w & changeSwapClose f i
Just (0, i) -> w & changeSwapInv f i
Just (3, i) -> w & changeSwapClose f i
_ -> w
--changeSwapInvSel' :: Int -> World -> World
--changeSwapInvSel' k w = case you w ^? crManipulation . manObject of
-- Just (InInventory (SelItem i _)) ->
-- w & cWorld . lWorld . creatures . ix 0 %~ updatecreature i
-- & worldEventFlags . at InventoryChange ?~ ()
-- Just (InNearby (SelCloseObject i)) ->
-- w
-- & cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . inNearby . ispCloseObject
-- .~ ((i - k) `mod` numCO)
-- & hud . closeObjects %~ swapIndices i ((i - k) `mod` numCO)
-- & worldEventFlags . at InventoryChange ?~ ()
-- _ -> w
-- where
-- updatecreature i =
-- (crInv %~ IM.safeSwapKeys (i `mod` n) (swapi i))
-- . (crLeftInvSel . lisMPos . _Just %~ updateLeftInvSel i)
-- . (crManipulation . manObject . inInventory . ispItem %~ (`mod` n) . subtract k)
-- . (crInvEquipped %~ IM.safeSwapKeys i (swapi i))
-- . swapSite i (swapi i)
-- . swapSite (swapi i) i
-- swapSite a b = case cr ^? crInvEquipped . ix a of
-- Just epos -> crEquipment . ix epos .~ b
-- Nothing -> id
-- cr = you w
-- swapi i = (i - k) `mod` n
-- updateLeftInvSel i li
-- | i == li = swapi i
-- | swapi i == li = i
-- | otherwise = li
-- n = length $ _crInv cr
-- numCO = length $ w ^. hud . closeObjects
scrollAugInvSel :: Int -> World -> World
scrollAugInvSel yi w
| yi == 0 = w