35 lines
939 B
Haskell
35 lines
939 B
Haskell
module Dodge.Inventory.CheckSlots (
|
|
checkInvSlotsYou,
|
|
crNumFreeSlots,
|
|
maxInvSlots,
|
|
) where
|
|
|
|
import NewInt
|
|
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 (NewInt InvInt)
|
|
checkInvSlotsYou it w = do
|
|
ycr <- w ^? cWorld . lWorld . creatures . ix 0
|
|
guard $ crNumFreeSlots (w ^. cWorld . lWorld . items) ycr >= itInvHeight it
|
|
Just . NInt . IM.newKey . _unNIntMap $ _crInv ycr
|
|
|
|
-- the intmap should be _items
|
|
crNumFreeSlots :: IM.IntMap Item -> Creature -> Int
|
|
crNumFreeSlots m cr = maxInvSlots - invSize (fmap f (_crInv cr))
|
|
where
|
|
f i = m ^?! ix i
|
|
|
|
maxInvSlots :: Int
|
|
maxInvSlots = 250
|
|
|
|
invSize :: NewIntMap InvInt Item -> Int
|
|
invSize = alaf Sum foldMap itInvHeight
|