Work on cleaning up item effects/attachments etc

This commit is contained in:
2022-07-27 16:39:58 +01:00
parent 8d17ce66e9
commit b52adddd5d
39 changed files with 696 additions and 844 deletions
+11 -7
View File
@@ -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