Commit before attempting to move some data into a "local" world type
This commit is contained in:
@@ -6,6 +6,7 @@ module Dodge.Creature.Action
|
||||
, stripNoItems
|
||||
, setMinInvSize
|
||||
, dropUnselected
|
||||
, dropExcept
|
||||
, startReloadingWeapon
|
||||
, blinkAction
|
||||
, sizeSelf
|
||||
@@ -215,13 +216,17 @@ organiseInvKeys cid w = w & creatures . ix cid %~
|
||||
where
|
||||
cr = _creatures w IM.! cid
|
||||
pairs = IM.toList (_crInv cr)
|
||||
newSelKey = fromJust $ findIndex ( (== _crInvSel cr) . fst) pairs
|
||||
newSelKey = fromMaybe 0 $ findIndex ( (== _crInvSel cr) . fst) pairs
|
||||
newInv = IM.fromAscList $ zip [0..] $ map snd pairs
|
||||
|
||||
dropUnselected :: Creature -> World -> World
|
||||
dropUnselected cr w = foldr (dropItem cr) w . IM.keys
|
||||
$ _crInvSel cr `IM.delete` _crInv cr
|
||||
|
||||
dropExcept :: Creature -> Int -> World -> World
|
||||
dropExcept cr invid w = foldr (dropItem cr) w . IM.keys
|
||||
$ invid `IM.delete` _crInv cr
|
||||
|
||||
dropItem :: Creature -> Int -> World -> World
|
||||
dropItem cr invid = rmInvItem cid invid . copyInvItemToFloor cr invid . mayberemoveequip
|
||||
where
|
||||
|
||||
@@ -8,7 +8,7 @@ import Dodge.Inventory
|
||||
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import Control.Lens
|
||||
import Data.Maybe
|
||||
--import Data.Maybe
|
||||
|
||||
useItem :: Int -> World -> World
|
||||
useItem cid w = itemEffect cr it w
|
||||
@@ -25,22 +25,33 @@ itemEffect :: Creature -> Item -> World -> World
|
||||
itemEffect cr Consumable{_cnEffect=eff } w = maybe w (rmSelectedInvItem (_crID cr)) (eff (_crID cr) w)
|
||||
itemEffect cr it w = case it ^? itUse of
|
||||
Just RightUse {_rUse = eff,_useMods = usemods} -> foldr ($) eff usemods it cr w
|
||||
Just LeftUse {} -> w & creatures . ix (_crID cr) . crLeftInvSel ?~ _crInvSel cr
|
||||
Just LeftUse {} -> w
|
||||
& lSelHammerPosition .~ HammerDown
|
||||
& docycle
|
||||
_ -> w
|
||||
where
|
||||
docycle | _lSelHammerPosition w == HammerUp = creatures . ix (_crID cr) . crLeftInvSel %~ cyclelsel
|
||||
| otherwise = id
|
||||
cyclelsel mi = case mi of
|
||||
Just i | i == _crInvSel cr -> Nothing
|
||||
_ -> Just $ _crInvSel cr
|
||||
|
||||
--this is ugly
|
||||
useLeftItem :: Int -> World -> World
|
||||
useLeftItem cid w = case _crInv cr IM.! crinvsel ^? itUse . lUse of
|
||||
Just f -> f cr crinvsel w & creatures . ix cid . crLeftInvSel ?~ crinvsel
|
||||
Just f -> f cr crinvsel (w & creatures . ix cid . crLeftInvSel ?~ crinvsel)
|
||||
Nothing -> case _crLeftInvSel cr of
|
||||
Just invid -> case _itUse $ _crInv cr IM.! invid of
|
||||
LeftUse {_lUse = f} -> f cr invid w
|
||||
_ -> w & creatures . ix cid . crLeftInvSel .~ Nothing
|
||||
Nothing -> case luse of
|
||||
Nothing -> w
|
||||
Just (invid, f) -> f cr invid w & creatures . ix cid . crLeftInvSel ?~ invid
|
||||
Nothing -> w
|
||||
-- Nothing -> case luse of
|
||||
-- Nothing -> w
|
||||
-- Just (invid, f) -> f cr invid w & creatures . ix cid . crLeftInvSel ?~ invid
|
||||
where
|
||||
crinvsel = _crInvSel cr
|
||||
cr = _creatures w IM.! cid
|
||||
luses = IM.mapMaybe (^? itUse . lUse) (_crInv cr)
|
||||
luse = listToMaybe $ IM.toList luses
|
||||
-- luses = IM.mapMaybe (^? itUse . lUse) (_crInv cr)
|
||||
-- luse = listToMaybe $ IM.toList luses
|
||||
--the old code automatically selected the first unused item in the list: not
|
||||
--sure if I want this behaviour, can probably set it as an option later
|
||||
|
||||
@@ -3,6 +3,7 @@ module Dodge.Creature.State
|
||||
, doDamage
|
||||
) where
|
||||
import Dodge.Data
|
||||
import Dodge.Hammer
|
||||
import Dodge.Base
|
||||
import Dodge.Creature.State.WalkCycle
|
||||
--import Dodge.Creature.Test
|
||||
@@ -129,9 +130,6 @@ invItemUpdate = itUse %~ useupdate
|
||||
useupdate = (useHammer . hammerPosition %~ moveHammerUp)
|
||||
. (useDelay . warmTime %~ decreaseToZero)
|
||||
. (useDelay . rateTime %~ decreaseToZero)
|
||||
moveHammerUp HammerDown = HammerReleased
|
||||
moveHammerUp HammerReleased = HammerUp
|
||||
moveHammerUp HammerUp = HammerUp
|
||||
|
||||
invSideEff :: Creature -> World -> World
|
||||
invSideEff cr w = weaponReloadSounds cr $ IM.foldrWithKey f w (_crInv cr)
|
||||
|
||||
Reference in New Issue
Block a user