Work on pickup and putdown of inventory items
This commit is contained in:
@@ -198,16 +198,12 @@ blinkShockwave
|
||||
blinkShockwave i p = makeShockwaveAt [i] p 60 1 2 cyan
|
||||
|
||||
setMinInvSize :: Int -> Creature -> World -> World
|
||||
setMinInvSize n cr = creatures . ix (_crID cr) . crInv %~ f
|
||||
where
|
||||
f inv = IM.unionWith const inv $ IM.fromList $ [0..n-1] <&> (, NoItem)
|
||||
setMinInvSize n cr = creatures . ix (_crID cr) . crInvCapacity .~ n
|
||||
|
||||
-- maybe this should be removed...
|
||||
stripNoItems :: Creature -> World -> World
|
||||
stripNoItems cr = organiseInvKeys (_crID cr) .
|
||||
( creatures . ix (_crID cr) . crInv %~ IM.mapMaybe f )
|
||||
where
|
||||
f NoItem = Nothing
|
||||
f x = Just x
|
||||
( creatures . ix (_crID cr) . crInv %~ IM.mapMaybe Just )
|
||||
|
||||
organiseInvKeys :: Int -> World -> World
|
||||
organiseInvKeys cid w = w & creatures . ix cid %~
|
||||
@@ -245,25 +241,17 @@ youDropItem w = case yourItem w ^? itCurseStatus of
|
||||
cr = you w
|
||||
{- | Copy an inventory item to the floor. -}
|
||||
copyInvItemToFloor :: Creature -> Int -> World -> World
|
||||
copyInvItemToFloor cr i w = case _crInv cr IM.! i of
|
||||
NoItem -> w
|
||||
it -> copyItemToFloor (_crPos cr) it w
|
||||
|
||||
|
||||
copyInvItemToFloor cr i w = copyItemToFloor (_crPos cr) (_crInv cr IM.! i) w
|
||||
|
||||
{- | Pick up a specific item. -}
|
||||
pickUpItem
|
||||
:: Int -- ^ Creature id
|
||||
-> FloorItem
|
||||
-> World
|
||||
-> World
|
||||
pickUpItem :: Int -> FloorItem -> World -> World
|
||||
pickUpItem cid flit w = case maybeInvSlot of
|
||||
Nothing -> w
|
||||
Just i -> w
|
||||
& soundStart (CrSound cid) (_flItPos flit) pickUpS Nothing
|
||||
& updateItLocation i
|
||||
& floorItems %~ IM.delete (_flItID flit)
|
||||
& creatures . ix cid . crInv . ix i %~ addItem it
|
||||
& creatures . ix cid . crInv %~ IM.insertWith (const $ itAmount +~ 1) i it
|
||||
where
|
||||
it = _flIt flit
|
||||
maybeInvSlot = checkInvSlotsYou it w
|
||||
|
||||
Reference in New Issue
Block a user