Work on pickup and putdown of inventory items

This commit is contained in:
2021-11-30 16:44:33 +00:00
parent 27b1a6da9e
commit 3754627e0d
10 changed files with 42 additions and 60 deletions
+6 -18
View File
@@ -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
-1
View File
@@ -107,7 +107,6 @@ equipSpeed :: Item -> Float
equipSpeed _ = 1
{- | Speed modifier of an item when aiming. -}
equipAimSpeed :: Item -> Float
equipAimSpeed NoItem = 1
equipAimSpeed it
| _itIdentity it == FrontArmour = 0.5
| _itIdentity it == FlameShield = 0.5