Implement dual laser tesla

This commit is contained in:
2022-04-07 10:06:39 +01:00
parent 6c1bf92082
commit 7ca9afeb5f
6 changed files with 62 additions and 58 deletions
+17 -4
View File
@@ -5,11 +5,11 @@ import qualified IntMapHelp as IM
import Control.Lens
import Data.Maybe
setHeldItemPos :: Creature -> World -> World
setHeldItemPos cr = fst . getHeldItemPos cr
setHeldItemLoc :: Creature -> World -> World
setHeldItemLoc cr = fst . getHeldItemLoc cr
getHeldItemPos :: Creature -> World -> (World,Int)
getHeldItemPos cr w = case maybeitid of
getHeldItemLoc :: Creature -> World -> (World,Int)
getHeldItemLoc cr w = case maybeitid of
Nothing ->
( w & creatures . ix cid . crInv . ix j . itID ?~ newitid
& itemPositions %~ IM.insert newitid (InInv cid j)
@@ -21,3 +21,16 @@ getHeldItemPos cr w = case maybeitid of
newitid = IM.newKey $ _itemPositions w
maybeitid = cr ^? crInv . ix j . itID . _Just
itid = fromMaybe newitid maybeitid
getItem :: Int -> World -> Maybe Item
getItem itid w = do
itpos <- w ^? itemPositions . ix itid
case itpos of
OnFloor flitid -> w ^? floorItems . ix flitid . flIt
InInv cid invid -> w ^? creatures . ix cid . crInv . ix invid
pointToItem :: Applicative f =>
ItemPos -> (Item -> f Item) -> World -> f World
pointToItem (InInv cid invid) = creatures . ix cid . crInv . ix invid
pointToItem (OnFloor flid) = floorItems . ix flid . flIt