module Dodge.Inventory.CheckSlots ( checkInvSlotsYou, crNumFreeSlots, maxInvSlots, ) where import Control.Monad import Dodge.Item.InvSize import Control.Lens import Data.Monoid import Dodge.Data.World import qualified IntMapHelp 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 = do ycr <- w ^? cWorld . lWorld . creatures . ix 0 guard $ crNumFreeSlots (w ^. cWorld . lWorld . items) ycr >= itInvHeight it Just . IM.newKey $ _crInv ycr crNumFreeSlots :: IM.IntMap Item -> Creature -> Int --crNumFreeSlots cr = _crInvCapacity cr - invSize (_crInv cr) crNumFreeSlots m cr = maxInvSlots - invSize (fmap f (_crInv cr)) where f i = m ^?! ix i maxInvSlots :: Int maxInvSlots = 25 invSize :: IM.IntMap Item -> Int invSize = alaf Sum foldMap itInvHeight