Cleanup
This commit is contained in:
@@ -15,7 +15,7 @@ putItemInInvID cid flid w = fromMaybe (Nothing,w) $ do
|
||||
return (Just i,w')
|
||||
|
||||
putItemInInvSlot :: Int -> Item -> IM.IntMap Item -> IM.IntMap Item
|
||||
putItemInInvSlot = IM.insertWith (const $ itConsumption . icAmount +~ 1)
|
||||
putItemInInvSlot = IM.insertWith (const $ itUse . useAmount +~ 1)
|
||||
|
||||
{- | Pick up a specific item. -}
|
||||
tryPutItemInInv :: Int -> FloorItem -> World -> Maybe (Int,World)
|
||||
|
||||
@@ -1,32 +1,33 @@
|
||||
module Dodge.Inventory.CheckSlots where
|
||||
import Dodge.Data
|
||||
|
||||
import Control.Lens
|
||||
import Data.Maybe
|
||||
import Dodge.Base.You
|
||||
import Dodge.Data
|
||||
import Dodge.Inventory.ItemSpace
|
||||
import qualified IntMapHelp as IM
|
||||
|
||||
import Data.Maybe
|
||||
--import Control.Lens
|
||||
|
||||
-- | checks whether or not an item will fit in your inventory
|
||||
-- if so return Just the next slot to be used
|
||||
{- | checks whether or not an item will fit in your inventory
|
||||
if so return Just the next slot to be used
|
||||
-}
|
||||
checkInvSlotsYou :: Item -> World -> Maybe Int
|
||||
checkInvSlotsYou it w
|
||||
| crNumFreeSlots ycr >= ceiling (_itInvSize it)
|
||||
= Just $ findItemSlot it inv
|
||||
| crNumFreeSlots ycr >= ceiling (_itInvSize it) =
|
||||
Just $ findItemSlot it inv
|
||||
| otherwise = Nothing
|
||||
where
|
||||
where
|
||||
ycr = you w
|
||||
inv = _crInv ycr
|
||||
|
||||
-- Assumes that the item is singular.
|
||||
-- Do not want to stack floor items for now
|
||||
findItemSlot :: Item -> IM.IntMap Item -> Int
|
||||
findItemSlot it inv = case _itConsumption it of
|
||||
ItemItselfConsumable _
|
||||
-> fromMaybe newslot $ IM.findIndex (\it' -> _itType it == _itType it') inv
|
||||
_ -> newslot
|
||||
findItemSlot it inv = case it ^? itUse . useAmount of
|
||||
Just _ ->
|
||||
fromMaybe newslot $ IM.findIndex (\it' -> _itType it == _itType it') inv
|
||||
_ -> newslot
|
||||
where
|
||||
newslot = maybe 0 ((+1) . fst) $ IM.lookupMax inv
|
||||
newslot = maybe 0 ((+ 1) . fst) $ IM.lookupMax inv
|
||||
|
||||
crNumFreeSlots :: Creature -> Int
|
||||
crNumFreeSlots cr = _crInvCapacity cr - invSize (_crInv cr)
|
||||
|
||||
@@ -8,6 +8,6 @@ import Control.Lens
|
||||
--import Data.Maybe
|
||||
|
||||
itSlotsTaken :: Item -> Int
|
||||
itSlotsTaken it = case it ^? itConsumption . icAmount of
|
||||
itSlotsTaken it = case it ^? itUse . useAmount of
|
||||
Nothing -> moduleSizes it + ceiling (_itInvSize it)
|
||||
Just i -> moduleSizes it + ceiling (_itInvSize it * fromIntegral i)
|
||||
|
||||
Reference in New Issue
Block a user