Cleanup
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user