Fix bug in item loc when combining items, rethink centralizing item locs

This commit is contained in:
2024-09-24 18:07:25 +01:00
parent a6eb5cf982
commit 34c244a332
4 changed files with 8 additions and 3 deletions
+3 -1
View File
@@ -15,6 +15,8 @@ import Dodge.Item.Grammar
import Data.Maybe
import Control.Applicative
-- this assumes the creature inventory is well formed, specifically the
-- location ids
tryGetRootItemInvID :: Int -> Creature -> Maybe Int
tryGetRootItemInvID i cr = do
let adj = case invAdj' (_crInv cr) of
@@ -39,7 +41,7 @@ crUpdateItemLocations crid lw = fromMaybe lw $ do
crUpdateInvidLocations :: ManipulatedObject -> Int -> LWorld -> Int -> Item -> LWorld
crUpdateInvidLocations mo crid lw invid itm = lw
& creatures . ix crid . crInv . ix invid . itLocation .~ newloc
& itemLocations . ix itid .~ newloc
& itemLocations %~ IM.insert itid newloc
where
itid = itm ^. itID
newloc = InInv crid invid (Just invid == mo ^? inInventory . imSelectedItem)