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
| otherwise = fromMaybe w $ do
invid <- _crLeftInvSel cr
itm <- cr ^? crInv . ix invid
f <- cr ^? crInv . ix invid . itUse . lUse
return $ f cr invid w
return $ f itm cr w
where
cr = _creatures w IM.! cid
itmShouldBeUsed = isJust (cr ^? crInv . ix (_crInvSel cr) . itUse . cUse)
+1 -2
View File
@@ -316,7 +316,6 @@ data Intention = Intention
, _mvToPoint :: Maybe Point2
, _viewPoint :: Maybe Point2
}
data CrMvType
= NoMvType
| MvWalking { _mvSpeed :: Float }
@@ -374,7 +373,7 @@ data ItemUse
, _useAim :: AimParams
}
| LeftUse
{ _lUse :: Creature -> Int -> World -> World
{ _lUse :: Item -> Creature -> World -> World
, _useDelay :: UseDelay
, _useHammer :: HammerType
}
+1 -1
View File
@@ -67,7 +67,7 @@ defaultlUse = LeftUse
, _useHammer = NoHammer
}
luseInstantNoH :: (Creature -> Int -> World -> World) -> ItemUse
luseInstantNoH :: (Item -> Creature -> World -> World) -> ItemUse
luseInstantNoH f = LeftUse
{ _lUse = f
, _useDelay = NoDelay
+3 -2
View File
@@ -30,14 +30,15 @@ boostPoint x cr w = case mayp2 of
boostSelfL
:: Float -- ^ boost amount
-> Item
-> Creature
-> Int -- ^ item inventory id
-> 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)
Right p -> crEff p (itConsumption . ammoLoaded -~ 1)
where
invid = fromJust $ _itInvPos itm
cid = _crID cr
cpos = _crPos cr
r = _crRad cr
+11 -10
View File
@@ -79,7 +79,7 @@ import System.Random
--import Control.Lens
import Control.Monad.State
import Data.Maybe
import qualified Data.IntMap.Strict as IM
--import qualified Data.IntMap.Strict as IM
import Data.Foldable
type ChainEffect
@@ -331,33 +331,34 @@ ammoUseCheck f item cr w
{- | Applies a world effect after a hammer position check.
Arbitrary inventory position. -}
hammerCheckL
:: (Creature -> Int -> World -> World) -- ^ Underlying effect
-> Creature -> Int -> World -> World
hammerCheckL f cr invid w = case (_crInv cr IM.! invid) ^? itUse . useHammer . hammerPosition of
Just HammerUp -> f cr invid $ setHammerDown w
:: (Item -> Creature -> World -> World) -- ^ Underlying effect
-> Item -> Creature -> World -> World
hammerCheckL f itm cr w = case itm ^? itUse . useHammer . hammerPosition of
Just HammerUp -> f itm cr $ setHammerDown w
_ -> setHammerDown w
where
cid = _crID cr
invid = fromJust $ _itInvPos itm
setHammerDown = creatures . ix cid . crInv . ix invid
. itUse . useHammer . hammerPosition .~ HammerDown
{- | Applies a world effect after an ammo check.
Arbitrary inventory position. -}
shootL
:: (Creature -> Int -> World -> World)
:: (Item -> Creature -> World -> World)
-- ^ Underlying effect
-> Item
-> Creature
-> Int -- ^ Inventory position
-> World
-> World
shootL f cr invid w
| fireCondition = f cr invid w & pointerToItem %~
shootL f item cr w
| fireCondition = f item cr w & pointerToItem %~
( itUseAmmo 1
. (itUse . useDelay . rateTime .~ _rateMax (_useDelay (_itUse item))) )
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
| otherwise = w
where
cid = _crID cr
item = _crInv cr IM.! invid
invid = fromJust $ _itInvPos item
pointerToItem = creatures . ix cid . crInv . ix invid
fireCondition = _reloadState (_itConsumption item) == Nothing'
&& _rateTime (_useDelay (_itUse item)) == 0
+7 -6
View File
@@ -27,7 +27,7 @@ rewindGun = defaultGun
, _wpCharge = 0
}
, _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 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
-- creature but using the old crInvSel value
useShrinkGun :: Creature -> Int -> World -> World
useShrinkGun cr invid w = if _itBool $ _itAttachment it
-- 22.05.23 this has been changed from using invids to items
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
else tryResize 1 $ f True Uncursed . setMinInvSize defaultInvSize cr
where
it = _crInv cr IM.! invid
invid = fromJust $ _itInvPos it
tryResize x g = maybe w g $ sizeSelf x cr w
f isInUse cstatus = creatures . ix (_crID cr) . crInv . ix invid %~
( (itAttachment . itBool .~ isInUse) . (itCurseStatus .~ cstatus) )
@@ -107,8 +108,8 @@ blinkGun = defaultGun
aSelf :: Creature -> World -> World
aSelf = blinkAction
aSelfL :: Creature -> Int -> World -> World
aSelfL cr _ = blinkAction cr
aSelfL :: Item -> Creature -> World -> World
aSelfL _ cr = blinkAction cr
effectGun :: String -> (Creature -> World -> World) -> Item
effectGun name eff = defaultGun