Allow for door destruction
This commit is contained in:
@@ -9,21 +9,23 @@ import Data.Maybe
|
||||
import Control.Lens
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
|
||||
putItemInInvID :: Int -> Int -> World -> World
|
||||
putItemInInvID cid flid w = fromMaybe w
|
||||
$ tryPutItemInInv cid (_floorItems w IM.! flid) w
|
||||
putItemInInvID :: Int -> Int -> World -> (Maybe Int,World)
|
||||
putItemInInvID cid flid w = fromMaybe (Nothing,w) $ do
|
||||
(i,w') <- tryPutItemInInv cid (_floorItems w IM.! flid) w
|
||||
return (Just i,w')
|
||||
|
||||
putItemInInvSlot :: Int -> Item -> IM.IntMap Item -> IM.IntMap Item
|
||||
putItemInInvSlot = IM.insertWith (const $ itConsumption . icAmount +~ 1)
|
||||
|
||||
{- | Pick up a specific item. -}
|
||||
tryPutItemInInv :: Int -> FloorItem -> World -> Maybe World
|
||||
tryPutItemInInv :: Int -> FloorItem -> World -> Maybe (Int,World)
|
||||
tryPutItemInInv cid flit w = case maybeInvSlot of
|
||||
Nothing -> Nothing
|
||||
Just i -> Just $ w
|
||||
Just i -> Just (i, w
|
||||
& updateItLocation i
|
||||
& floorItems %~ IM.delete (_flItID flit)
|
||||
& creatures . ix cid . crInv %~ putItemInInvSlot i it
|
||||
)
|
||||
where
|
||||
it = _flIt flit
|
||||
maybeInvSlot = checkInvSlotsYou it w
|
||||
@@ -45,6 +47,6 @@ tryPutItemInInv cid flit w = case maybeInvSlot of
|
||||
-- updateItLocation invid w' = case _itID it of
|
||||
-- Nothing -> w'
|
||||
-- Just j -> w' & itemPositions . ix j .~ InInv cid invid
|
||||
createPutItem :: Item -> World -> World
|
||||
createPutItem :: Item -> World -> (Maybe Int, World)
|
||||
createPutItem it w = uncurry (putItemInInvID (_yourID w))
|
||||
$ copyItemToFloorID (_crPos $ you w) (applyModules it) w
|
||||
|
||||
Reference in New Issue
Block a user