Add file
This commit is contained in:
@@ -0,0 +1,44 @@
|
|||||||
|
module Dodge.Inventory.Add where
|
||||||
|
import Dodge.Data
|
||||||
|
import Dodge.Inventory.CheckSlots
|
||||||
|
|
||||||
|
import Data.Maybe
|
||||||
|
import Control.Lens
|
||||||
|
import qualified Data.IntMap.Strict as IM
|
||||||
|
|
||||||
|
putItemInInvID :: Int -> Int -> World -> World
|
||||||
|
putItemInInvID cid flid w = fromMaybe w
|
||||||
|
$ tryPutItemInInv cid (_floorItems w IM.! flid) w
|
||||||
|
|
||||||
|
putItemInInvSlot :: Int -> Item -> IM.IntMap Item -> IM.IntMap Item
|
||||||
|
putItemInInvSlot invsel it = IM.insertWith (const $ itConsumption . itAmount' +~ 1) invsel it
|
||||||
|
|
||||||
|
{- | Pick up a specific item. -}
|
||||||
|
tryPutItemInInv :: Int -> FloorItem -> World -> Maybe World
|
||||||
|
tryPutItemInInv cid flit w = case maybeInvSlot of
|
||||||
|
Nothing -> Nothing
|
||||||
|
Just i -> Just $ w
|
||||||
|
& updateItLocation i
|
||||||
|
& floorItems %~ IM.delete (_flItID flit)
|
||||||
|
& creatures . ix cid . crInv %~ putItemInInvSlot i it
|
||||||
|
where
|
||||||
|
it = _flIt flit
|
||||||
|
maybeInvSlot = checkInvSlotsYou it w
|
||||||
|
updateItLocation invid w' = case _itID it of
|
||||||
|
Nothing -> w'
|
||||||
|
Just j -> w' & itemPositions . ix j .~ InInv cid invid
|
||||||
|
|
||||||
|
--{- | Pick up a specific item. -}
|
||||||
|
--putItemInInv :: Int -> FloorItem -> World -> World
|
||||||
|
--putItemInInv cid flit w = case maybeInvSlot of
|
||||||
|
-- Nothing -> w
|
||||||
|
-- Just i -> w
|
||||||
|
-- & updateItLocation i
|
||||||
|
-- & floorItems %~ IM.delete (_flItID flit)
|
||||||
|
-- & creatures . ix cid . crInv %~ IM.insertWith (const $ itAmount +~ 1) i it
|
||||||
|
-- where
|
||||||
|
-- it = _flIt flit
|
||||||
|
-- maybeInvSlot = checkInvSlotsYou it w
|
||||||
|
-- updateItLocation invid w' = case _itID it of
|
||||||
|
-- Nothing -> w'
|
||||||
|
-- Just j -> w' & itemPositions . ix j .~ InInv cid invid
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
module Dodge.Inventory.ItemSpace where
|
||||||
|
import Dodge.Data
|
||||||
|
|
||||||
|
import Control.Lens
|
||||||
|
|
||||||
|
itSlotsTaken :: Item -> Int
|
||||||
|
itSlotsTaken it = case it ^? itConsumption . itAmount' of
|
||||||
|
Nothing -> ceiling (_itInvSize it)
|
||||||
|
Just i -> ceiling (_itInvSize it * fromIntegral i)
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{-# LANGUAGE TupleSections #-}
|
||||||
|
module Multiset where
|
||||||
|
import qualified Data.Map.Strict as M
|
||||||
|
import Control.Monad
|
||||||
|
|
||||||
|
powlistN :: Int -> [a] ->[[a]]
|
||||||
|
powlistN _ [] = [[]]
|
||||||
|
powlistN n (x:xs)
|
||||||
|
| n <=0 = [[]]
|
||||||
|
| otherwise = ((x:) <$> powlistN (n-1) xs) ++ powlistN n xs
|
||||||
|
|
||||||
|
-- exponential, so don't use it on long lists
|
||||||
|
powlist :: [a] -> [[a]]
|
||||||
|
powlist = filterM (const [True,False])
|
||||||
|
|
||||||
|
toMultiset :: Ord a => [a] -> M.Map a Int
|
||||||
|
toMultiset = foldr (uncurry $ M.insertWith (+)) M.empty . map (,1)
|
||||||
Reference in New Issue
Block a user