Major item refactor, still broken

This commit is contained in:
2025-08-24 19:34:09 +01:00
parent 22b4be440a
commit 94f6d5c630
62 changed files with 820 additions and 805 deletions
+10 -8
View File
@@ -45,10 +45,10 @@ destroyInvItem cid invid w =
& removeithotkey
where
removeitloc = fromMaybe id $ do
itid <- w ^? cWorld . lWorld . creatures . ix cid . crInv . ix invid . itID . unNInt
return $ cWorld . lWorld . itemLocations . at itid .~ Nothing
itid <- w ^? cWorld . lWorld . creatures . ix cid . crInv . ix invid
return $ cWorld . lWorld . items . at itid .~ Nothing
removeithotkey = fromMaybe id $ do
itid <- w ^? cWorld . lWorld . creatures . ix cid . crInv . ix invid . itID . unNInt
itid <- w ^? cWorld . lWorld . creatures . ix cid . crInv . ix invid
hk <- w ^? cWorld . lWorld . imHotkeys . unNIntMap . ix itid
return $
(cWorld . lWorld . imHotkeys . unNIntMap . at itid .~ Nothing)
@@ -62,14 +62,14 @@ destroyAllInvItems cr w =
$ cr ^. crInv
destroyItem :: Int -> World -> World
destroyItem itid w = case w ^? cWorld . lWorld . itemLocations . ix itid of
destroyItem itid w = case w ^? cWorld . lWorld . items . ix itid . itLocation of
Nothing -> error $ "Tried to destroy item that does not exist; item id: " ++ show itid
Just InInv{_ilCrID = cid, _ilInvID = invid} -> destroyInvItem cid invid w
Just OnTurret{} -> error "need to write code for destroying items on turrets"
Just OnFloor ->
w & cWorld . lWorld . itemLocations . at itid .~ Nothing
w & cWorld . lWorld . items . at itid .~ Nothing
& cWorld . lWorld . floorItems . at itid .~ Nothing
Just InVoid -> w & cWorld . lWorld . itemLocations . at itid .~ Nothing
Just InVoid -> w & cWorld . lWorld . items . at itid .~ Nothing
-- note rmInvItem does not fully destroy the item, other updates to the item
-- location are required
@@ -82,7 +82,7 @@ rmInvItem cid invid w =
& pointcid . crEquipment . each %~ g
& updateselection
& updateselectionextra
& pointcid %~ updateRootItemID
& pointcid %~ updateRootItemID (w ^. cWorld . lWorld . items)
& worldEventFlags . at InventoryChange ?~ ()
where
pointcid = cWorld . lWorld . creatures . ix cid
@@ -95,7 +95,8 @@ rmInvItem cid invid w =
| otherwise =
pointcid . crManipulation . manObject . imSelectedItem %~ g
cr = w ^?! cWorld . lWorld . creatures . ix cid
itm = _crInv cr IM.! invid
itid = _crInv cr IM.! invid
itm = w ^?! cWorld . lWorld . items . ix itid
dounequipfunction = effectOnRemove itm cr
-- fromMaybe id $ do
-- rmf <- itm ^? itUse . uequipEffect . eeOnRemove
@@ -104,6 +105,7 @@ rmInvItem cid invid w =
epos <-
w
^? cWorld . lWorld . creatures . ix cid . crInv . ix invid
>>= \k -> w ^? cWorld . lWorld . items . ix k
. itLocation
. ilEquipSite
. _Just