Work on cleaning up item effects/attachments etc
This commit is contained in:
@@ -12,26 +12,30 @@ getHeldItemLoc :: Creature -> World -> (World,Int)
|
||||
getHeldItemLoc cr w = case maybeitid of
|
||||
Nothing ->
|
||||
( w & cWorld . creatures . ix cid . crInv . ix j . itID ?~ newitid
|
||||
& cWorld . itemPositions %~ IM.insert newitid (InInv cid j)
|
||||
& cWorld . itemLocations %~ IM.insert newitid (InInv cid j)
|
||||
, itid)
|
||||
_ -> (w, itid)
|
||||
where
|
||||
cid = _crID cr
|
||||
j = crSel cr
|
||||
newitid = IM.newKey $ _itemPositions (_cWorld w)
|
||||
newitid = IM.newKey $ _itemLocations (_cWorld w)
|
||||
maybeitid = cr ^? crInv . ix j . itID . _Just
|
||||
itid = fromMaybe newitid maybeitid
|
||||
|
||||
getItem :: Int -> World -> Maybe Item
|
||||
getItem itid w = do
|
||||
itpos <- w ^? cWorld . itemPositions . ix itid
|
||||
itpos <- w ^? cWorld . itemLocations . ix itid
|
||||
case itpos of
|
||||
OnFloor flitid -> w ^? cWorld . floorItems . ix flitid . flIt
|
||||
InInv cid invid -> w ^? cWorld . creatures . ix cid . crInv . ix invid
|
||||
VoidItm -> Nothing
|
||||
|
||||
pointerToItemLocation :: Applicative f =>
|
||||
ItemLocation -> (Item -> f Item) -> World -> f World
|
||||
pointerToItemLocation (InInv cid invid) = cWorld . creatures . ix cid . crInv . ix invid
|
||||
pointerToItemLocation (OnFloor flid) = cWorld . floorItems . ix flid . flIt
|
||||
pointerToItemLocation _ = const pure
|
||||
|
||||
pointerToItem :: Applicative f =>
|
||||
ItemPos -> (Item -> f Item) -> World -> f World
|
||||
pointerToItem (InInv cid invid) = cWorld . creatures . ix cid . crInv . ix invid
|
||||
pointerToItem (OnFloor flid) = cWorld . floorItems . ix flid . flIt
|
||||
pointerToItem _ = const pure
|
||||
Item -> (Item -> f Item) -> World -> f World
|
||||
pointerToItem = pointerToItemLocation . _itLocation
|
||||
|
||||
Reference in New Issue
Block a user