Improve click detectors
Introduce "gadgets" as a structural function, for items that can be used when held and when not held. Click detectors are such an item. Make click detectors correctly attach and use up batteries when used.
This commit is contained in:
+13
-4
@@ -44,7 +44,7 @@ hammerCheck f it cr w = case it ^? ldtValue . itUse . heldTriggerType of
|
||||
heldEffectMuzzles :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
|
||||
heldEffectMuzzles t cr w =
|
||||
uncurry (applyCME (_ldtValue t) cr) cmew
|
||||
& cWorld . lWorld . lTestString .~ map (show . _mzAmmoSlot) muzzles
|
||||
-- & cWorld . lWorld . lTestString .~ map (show . _mzAmmoSlot) muzzles
|
||||
& doWeaponRepetitions upitm cr
|
||||
where
|
||||
muzzles = t ^. ldtValue . itUse . heldAim . aimMuzzles
|
||||
@@ -63,7 +63,12 @@ doWeaponRepetitions itm cr = case itm ^? ldtValue . itUse . heldParams . weaponR
|
||||
|
||||
applyCME :: Item -> Creature -> CumulativeMuzzleEffect -> World -> World
|
||||
applyCME itm cr cme
|
||||
| _cmeSound cme = applyInvLock itm cr . applySoundCME itm cr . applySidePush spush cr . applyTorqueCME itm cr . applyRecoil itm cr
|
||||
| _cmeSound cme =
|
||||
applyInvLock itm cr
|
||||
. applySoundCME itm cr
|
||||
. applySidePush spush cr
|
||||
. applyTorqueCME itm cr
|
||||
. applyRecoil itm cr
|
||||
| otherwise = failsound
|
||||
where
|
||||
spush = fromMaybe 0 $ itm ^? itUse . heldParams . sidePush
|
||||
@@ -131,10 +136,14 @@ loadMuzzle ::
|
||||
(LabelDoubleTree ComposeLinkType Item, Maybe (Muzzle, Int, LabelDoubleTree ComposeLinkType Item))
|
||||
loadMuzzle t@(LDT _ l _) mz = fromMaybe (t, Nothing) $ do
|
||||
let as = _mzAmmoSlot mz
|
||||
amamount = 1
|
||||
amamount = _mzAmmoPerShot mz
|
||||
(i, (_, mag)) <- findWithIx (isAmmoIntLink as . fst) l
|
||||
availableammo <- mag ^? ldtValue . itUse . amagLoadStatus . iaLoaded
|
||||
let usedammo = min amamount availableammo
|
||||
let usedammo = case amamount of
|
||||
UseUpTo x -> min x availableammo
|
||||
UseExactly x
|
||||
| x <= availableammo -> x
|
||||
| otherwise -> 0
|
||||
guard $ usedammo > 0
|
||||
return
|
||||
( t & ldtLeft . ix i . _2 . ldtValue . itUse . amagLoadStatus . iaLoaded -~ usedammo
|
||||
|
||||
Reference in New Issue
Block a user