Use Item as argument in lUse rather than Int

This commit is contained in:
2022-05-23 13:32:29 +01:00
parent 361dba88a0
commit a870457f2a
6 changed files with 25 additions and 22 deletions
+2 -1
View File
@@ -74,8 +74,9 @@ useLeftItem cid w
| itmShouldBeUsed = useItem cr w | itmShouldBeUsed = useItem cr w
| otherwise = fromMaybe w $ do | otherwise = fromMaybe w $ do
invid <- _crLeftInvSel cr invid <- _crLeftInvSel cr
itm <- cr ^? crInv . ix invid
f <- cr ^? crInv . ix invid . itUse . lUse f <- cr ^? crInv . ix invid . itUse . lUse
return $ f cr invid w return $ f itm cr w
where where
cr = _creatures w IM.! cid cr = _creatures w IM.! cid
itmShouldBeUsed = isJust (cr ^? crInv . ix (_crInvSel cr) . itUse . cUse) itmShouldBeUsed = isJust (cr ^? crInv . ix (_crInvSel cr) . itUse . cUse)
+1 -2
View File
@@ -316,7 +316,6 @@ data Intention = Intention
, _mvToPoint :: Maybe Point2 , _mvToPoint :: Maybe Point2
, _viewPoint :: Maybe Point2 , _viewPoint :: Maybe Point2
} }
data CrMvType data CrMvType
= NoMvType = NoMvType
| MvWalking { _mvSpeed :: Float } | MvWalking { _mvSpeed :: Float }
@@ -374,7 +373,7 @@ data ItemUse
, _useAim :: AimParams , _useAim :: AimParams
} }
| LeftUse | LeftUse
{ _lUse :: Creature -> Int -> World -> World { _lUse :: Item -> Creature -> World -> World
, _useDelay :: UseDelay , _useDelay :: UseDelay
, _useHammer :: HammerType , _useHammer :: HammerType
} }
+1 -1
View File
@@ -67,7 +67,7 @@ defaultlUse = LeftUse
, _useHammer = NoHammer , _useHammer = NoHammer
} }
luseInstantNoH :: (Creature -> Int -> World -> World) -> ItemUse luseInstantNoH :: (Item -> Creature -> World -> World) -> ItemUse
luseInstantNoH f = LeftUse luseInstantNoH f = LeftUse
{ _lUse = f { _lUse = f
, _useDelay = NoDelay , _useDelay = NoDelay
+3 -2
View File
@@ -30,14 +30,15 @@ boostPoint x cr w = case mayp2 of
boostSelfL boostSelfL
:: Float -- ^ boost amount :: Float -- ^ boost amount
-> Item
-> Creature -> Creature
-> Int -- ^ item inventory id
-> World -> World
-> World -> World
boostSelfL x cr invid w = case boostPoint x cr w of boostSelfL x itm cr w = case boostPoint x cr w of
Left p -> crEff p (itConsumption . ammoLoaded .~ 0) Left p -> crEff p (itConsumption . ammoLoaded .~ 0)
Right p -> crEff p (itConsumption . ammoLoaded -~ 1) Right p -> crEff p (itConsumption . ammoLoaded -~ 1)
where where
invid = fromJust $ _itInvPos itm
cid = _crID cr cid = _crID cr
cpos = _crPos cr cpos = _crPos cr
r = _crRad cr r = _crRad cr
+11 -10
View File
@@ -79,7 +79,7 @@ import System.Random
--import Control.Lens --import Control.Lens
import Control.Monad.State import Control.Monad.State
import Data.Maybe import Data.Maybe
import qualified Data.IntMap.Strict as IM --import qualified Data.IntMap.Strict as IM
import Data.Foldable import Data.Foldable
type ChainEffect type ChainEffect
@@ -331,33 +331,34 @@ ammoUseCheck f item cr w
{- | Applies a world effect after a hammer position check. {- | Applies a world effect after a hammer position check.
Arbitrary inventory position. -} Arbitrary inventory position. -}
hammerCheckL hammerCheckL
:: (Creature -> Int -> World -> World) -- ^ Underlying effect :: (Item -> Creature -> World -> World) -- ^ Underlying effect
-> Creature -> Int -> World -> World -> Item -> Creature -> World -> World
hammerCheckL f cr invid w = case (_crInv cr IM.! invid) ^? itUse . useHammer . hammerPosition of hammerCheckL f itm cr w = case itm ^? itUse . useHammer . hammerPosition of
Just HammerUp -> f cr invid $ setHammerDown w Just HammerUp -> f itm cr $ setHammerDown w
_ -> setHammerDown w _ -> setHammerDown w
where where
cid = _crID cr cid = _crID cr
invid = fromJust $ _itInvPos itm
setHammerDown = creatures . ix cid . crInv . ix invid setHammerDown = creatures . ix cid . crInv . ix invid
. itUse . useHammer . hammerPosition .~ HammerDown . itUse . useHammer . hammerPosition .~ HammerDown
{- | Applies a world effect after an ammo check. {- | Applies a world effect after an ammo check.
Arbitrary inventory position. -} Arbitrary inventory position. -}
shootL shootL
:: (Creature -> Int -> World -> World) :: (Item -> Creature -> World -> World)
-- ^ Underlying effect -- ^ Underlying effect
-> Item
-> Creature -> Creature
-> Int -- ^ Inventory position
-> World -> World
-> World -> World
shootL f cr invid w shootL f item cr w
| fireCondition = f cr invid w & pointerToItem %~ | fireCondition = f item cr w & pointerToItem %~
( itUseAmmo 1 ( itUseAmmo 1
. (itUse . useDelay . rateTime .~ _rateMax (_useDelay (_itUse item))) ) . (itUse . useDelay . rateTime .~ _rateMax (_useDelay (_itUse item))) )
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w | reloadCondition = fromMaybe w $ startReloadingWeapon cr w
| otherwise = w | otherwise = w
where where
cid = _crID cr cid = _crID cr
item = _crInv cr IM.! invid invid = fromJust $ _itInvPos item
pointerToItem = creatures . ix cid . crInv . ix invid pointerToItem = creatures . ix cid . crInv . ix invid
fireCondition = _reloadState (_itConsumption item) == Nothing' fireCondition = _reloadState (_itConsumption item) == Nothing'
&& _rateTime (_useDelay (_itUse item)) == 0 && _rateTime (_useDelay (_itUse item)) == 0
+7 -6
View File
@@ -27,7 +27,7 @@ rewindGun = defaultGun
, _wpCharge = 0 , _wpCharge = 0
} }
, _itEffect = ItRewindEffect rewindEffect [] , _itEffect = ItRewindEffect rewindEffect []
, _itUse = defaultlUse {_lUse = \cr invid -> useRewindGun (_crInv cr IM.! invid) cr} , _itUse = defaultlUse {_lUse = \itm cr -> useRewindGun itm cr}
} }
rewindEffect :: Item -> Creature -> World -> World rewindEffect :: Item -> Creature -> World -> World
rewindEffect itm cr w rewindEffect itm cr w
@@ -77,12 +77,13 @@ shrinkGunPic _ = noPic $ colorSH violet $ upperPrismPoly 5 $ square 5
-- be careful changing this around; potential problems include updating the -- be careful changing this around; potential problems include updating the
-- creature but using the old crInvSel value -- creature but using the old crInvSel value
useShrinkGun :: Creature -> Int -> World -> World -- 22.05.23 this has been changed from using invids to items
useShrinkGun cr invid w = if _itBool $ _itAttachment it useShrinkGun :: Item -> Creature -> World -> World
useShrinkGun it cr w = if _itBool $ _itAttachment it
then tryResize 0.5 $ stripNoItems cr . f False UndroppableIdentified . dropExcept cr invid then tryResize 0.5 $ stripNoItems cr . f False UndroppableIdentified . dropExcept cr invid
else tryResize 1 $ f True Uncursed . setMinInvSize defaultInvSize cr else tryResize 1 $ f True Uncursed . setMinInvSize defaultInvSize cr
where where
it = _crInv cr IM.! invid invid = fromJust $ _itInvPos it
tryResize x g = maybe w g $ sizeSelf x cr w tryResize x g = maybe w g $ sizeSelf x cr w
f isInUse cstatus = creatures . ix (_crID cr) . crInv . ix invid %~ f isInUse cstatus = creatures . ix (_crID cr) . crInv . ix invid %~
( (itAttachment . itBool .~ isInUse) . (itCurseStatus .~ cstatus) ) ( (itAttachment . itBool .~ isInUse) . (itCurseStatus .~ cstatus) )
@@ -107,8 +108,8 @@ blinkGun = defaultGun
aSelf :: Creature -> World -> World aSelf :: Creature -> World -> World
aSelf = blinkAction aSelf = blinkAction
aSelfL :: Creature -> Int -> World -> World aSelfL :: Item -> Creature -> World -> World
aSelfL cr _ = blinkAction cr aSelfL _ cr = blinkAction cr
effectGun :: String -> (Creature -> World -> World) -> Item effectGun :: String -> (Creature -> World -> World) -> Item
effectGun name eff = defaultGun effectGun name eff = defaultGun