Refactor floor items, removing ids (not fully checked)
This commit is contained in:
@@ -23,9 +23,9 @@ import Dodge.FloorItem
|
||||
import Dodge.Inventory.CheckSlots
|
||||
import qualified IntMapHelp as IM
|
||||
|
||||
tryPutFloorItemIDInInv :: Int -> NewInt FloorInt -> World -> Maybe (Int, World)
|
||||
tryPutFloorItemIDInInv cid flitid w = do
|
||||
flit <- w ^? cWorld . lWorld . floorItems . unNIntMap . ix (_unNInt flitid)
|
||||
tryPutFloorItemIDInInv :: Int -> Int -> World -> Maybe (Int, World)
|
||||
tryPutFloorItemIDInInv cid i w = do
|
||||
flit <- w ^? cWorld . lWorld . floorItems . ix i
|
||||
tryPutItemInInv cid flit w
|
||||
|
||||
-- not sure why we have the cid here, this will probably only work for cid == 0
|
||||
@@ -46,7 +46,7 @@ tryPutItemInInv cid flit w = case maybeInvSlot of
|
||||
Just
|
||||
( i
|
||||
, w
|
||||
& cWorld . lWorld . floorItems . unNIntMap %~ IM.delete (_unNInt $ _flItID flit)
|
||||
& cWorld . lWorld . floorItems %~ IM.delete (flit ^. flIt . itID . unNInt)
|
||||
& cWorld . lWorld . creatures . ix cid . crInv %~ IM.insert i it
|
||||
& updateItLocation i
|
||||
-- I forget whether using "at" rather than "IM.insert" here caused problems
|
||||
@@ -93,14 +93,14 @@ tryPutItemInInv cid flit w = case maybeInvSlot of
|
||||
-- return (Just i, w')
|
||||
|
||||
createItemYou :: Item -> World -> (ItemLocation, World)
|
||||
createItemYou itm w = fromMaybe (OnFloor flid, w') $ do
|
||||
(invid, w'') <- tryPutFloorItemIDInInv 0 flid w'
|
||||
createItemYou itm w = fromMaybe (OnFloor, w') $ do
|
||||
(invid, w'') <- tryPutFloorItemIDInInv 0 itid w'
|
||||
itloc <- w'' ^? cWorld . lWorld . creatures . ix 0 . crInv . ix invid . itLocation
|
||||
return (itloc, w'')
|
||||
where
|
||||
itid = IM.newKey $ w ^. cWorld . lWorld . itemLocations
|
||||
pos = w ^?! cWorld . lWorld . creatures . ix 0 . crPos
|
||||
(flid,w') = copyItemToFloorID pos (itm & itID .~ NInt itid) w
|
||||
w' = copyItemToFloorID pos (itm & itID .~ NInt itid) w
|
||||
|
||||
|
||||
-- | Pick up a specific item.
|
||||
|
||||
Reference in New Issue
Block a user