Fix more item bugs

This commit is contained in:
2025-08-24 23:50:16 +01:00
parent c2daa86463
commit d776c91cfd
9 changed files with 113 additions and 99 deletions
+1 -1
View File
@@ -111,7 +111,7 @@ tryPutItemInInvAt i cid itid w = do
-- return (Just i, w')
createItemYou :: Item -> World -> World
createItemYou itm w = w' -- fromMaybe w' $ fmap snd $ tryPutItemInInv 0 itid w'
createItemYou itm w = fromMaybe w' $ fmap snd $ tryPutItemInInv 0 itid w'
where
itid = IM.newKey $ w ^. cWorld . lWorld . items
pos = w ^?! cWorld . lWorld . creatures . ix 0 . crPos
+3 -4
View File
@@ -45,9 +45,9 @@ updateRootItemID m cr = fromMaybe cr $ do
crUpdateItemLocations :: Int -> LWorld -> LWorld
crUpdateItemLocations crid lw = fromMaybe lw $ do
mo <- lw ^? creatures . ix crid . crManipulation . manObject
itids <- lw ^? creatures . ix crid . crInv
cinv <- lw ^? creatures . ix crid . crInv
--let crinv = IM.restrictKeys (lw ^. items) (IS.fromList $ IM.elems itids)
let crinv = fmap (\k -> lw ^?! items . ix k) itids
let crinv = fmap (\k -> lw ^?! items . ix k) cinv
return $ crSetRoots crid $ IM.foldlWithKey' (crUpdateInvidLocations mo crid) lw crinv
crSetRoots :: Int -> LWorld -> LWorld
@@ -65,8 +65,7 @@ crUpdateInvidLocations :: ManipulatedObject -> Int -> LWorld -> Int -> Item -> L
crUpdateInvidLocations mo crid lw invid itm =
lw
& creatures . ix crid . crInv . ix invid .~ itid -- . itLocation .~ newloc
& items . ix invid .~ (itm & itLocation .~ newloc)
-- & itemLocations %~ IM.insert itid newloc
& items . ix itid .~ (itm & itLocation .~ newloc)
where
itid = itm ^. itID . unNInt
newloc =