This commit is contained in:
2021-12-03 01:56:55 +00:00
parent bebc73882a
commit b2a9192fe4
3 changed files with 57 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
module Dodge.Inventory.CheckSlots where
import Dodge.Data
import Dodge.Base.You
--import Control.Lens
import qualified Data.IntMap.Strict as IM
-- | 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 >= _itInvSize it
= Just $ maybe 0 ((+1) . fst) $ IM.lookupMax inv
| otherwise = Nothing
where
ycr = you w
inv = _crInv ycr
crNumFreeSlots :: Creature -> Int
crNumFreeSlots cr = _crInvCapacity cr - invSize (_crInv cr)
crInvSize :: Creature -> Int
crInvSize = invSize . _crInv
invSize :: IM.IntMap Item -> Int
invSize = sum . fmap _itInvSize