This commit is contained in:
2022-07-27 12:49:23 +01:00
parent 6554d219dc
commit 8d17ce66e9
106 changed files with 2911 additions and 2678 deletions
+15 -14
View File
@@ -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)