Pass ammo magazine items to held item use chain

This commit is contained in:
2024-06-25 15:50:22 +01:00
parent c723d1b1e1
commit 009a6cd30f
7 changed files with 289 additions and 238 deletions
+35 -34
View File
@@ -25,7 +25,7 @@ import LensHelp
import RandomHelp
import Sound.Data
useMod :: HeldMod -> [(Item -> Creature -> World -> World) -> Item -> Creature -> World -> World]
useMod :: HeldMod -> [([Item] -> Item -> Creature -> World -> World) -> [Item] -> Item -> Creature -> World -> World]
useMod hm = case hm of
HeldModNothing -> []
PoisonSprayerMod ->
@@ -382,35 +382,32 @@ mcUseHeld hit = case hit of
LASGUN -> mcShootLaser
_ -> \_ _ -> id
useHeld :: Huse -> Item -> Creature -> World -> World
useHeld :: Huse -> [Item] -> Item -> Creature -> World -> World
useHeld hu = case hu of
HeldDoNothing -> const $ const id
HeldDoNothing -> const . const $ const id
HeldUseAmmoParams -> shootBullet
HeldOverNozzlesUseGasParams -> overNozzles useGasParams
HeldPJCreation -> usePjCreation
HeldPJCreationX i -> usePjCreationX i
HeldFireRemoteShell -> fireRemoteShell
HeldDetectorEffect dt -> detectorEffect dt
HeldDetectorEffect dt -> const $ detectorEffect dt
HeldTeslaArc -> shootTeslaArc
HeldLaser -> shootLaser
HeldCircleLaser -> circleLaser
HeldDualLaser -> shootDualLaser
HeldTractor -> aTractorBeam
HeldCircleLaser -> const circleLaser
HeldDualLaser -> const shootDualLaser
HeldTractor -> const aTractorBeam
-- HeldSonicWave -> aSonicWave
HeldForceField -> useForceFieldGun
HeldShatter -> shootShatter
HeldExplodeRemoteShell itid pjid -> const $ const $ explodeRemoteRocket itid pjid
HeldForceField -> const useForceFieldGun
HeldShatter -> const shootShatter
HeldExplodeRemoteShell itid pjid -> const $ const $ const $ explodeRemoteRocket itid pjid
usePjCreation :: Item -> Creature -> World -> World
usePjCreation itm cr = createProjectile apm itm cr
where
apm = fromMaybe (error "cannot find shell ammo projectile") $ do
invid <- itm ^? itLocation . ipInvID
cr ^? crInv . ix (invid + 1) . itUse . amagParams
usePjCreation :: [Item] -> Item -> Creature -> World -> World
usePjCreation ams itm cr = fromMaybe id $ do
apm <- ams ^? ix 0 . itUse . amagParams
return $ createProjectile apm itm cr
usePjCreationX :: Int -> Item -> Creature -> World -> World
usePjCreationX i itm cr =
usePjCreationX :: Int -> [Item] -> Item -> Creature -> World -> World
usePjCreationX i ams itm cr =
foldr
f
(createProjectile apm itm cr)
@@ -422,7 +419,8 @@ usePjCreationX i itm cr =
f n = (. createProjectile apm itm (cr & crDir +~ (2 * pi * fromIntegral n / fromIntegral i)))
overNozzles ::
(Nozzle -> Item -> Creature -> World -> World) ->
(Nozzle -> [Item] -> Item -> Creature -> World -> World) ->
[Item] ->
Item ->
Creature ->
World ->
@@ -430,26 +428,28 @@ overNozzles ::
overNozzles = overNozzles' . overNozzle
overNozzles' ::
(Item -> Creature -> World -> Nozzle -> (World, Nozzle)) ->
([Item] -> Item -> Creature -> World -> Nozzle -> (World, Nozzle)) ->
[Item] ->
Item ->
Creature ->
World ->
World
overNozzles' eff it cr w = neww & cWorld . lWorld . creatures . ix cid . crInv . ix i . itParams . sprayNozzles .~ newNozzles
overNozzles' eff ams it cr w = neww & cWorld . lWorld . creatures . ix cid . crInv . ix i . itParams . sprayNozzles .~ newNozzles
where
cid = _crID cr
i = w ^?! cWorld . lWorld . creatures . ix cid . crManipulation . manObject . inInventory . ispItem
(neww, newNozzles) = mapAccumR (eff it cr) w $ _sprayNozzles (_itParams it)
(neww, newNozzles) = mapAccumR (eff ams it cr) w $ _sprayNozzles (_itParams it)
overNozzle ::
(Nozzle -> Item -> Creature -> World -> World) ->
(Nozzle -> [Item] -> Item -> Creature -> World -> World) ->
[Item] ->
Item ->
Creature ->
World ->
Nozzle ->
(World, Nozzle)
overNozzle eff it cr w nz =
( eff nz it (cr & crDir +~ wa + na) w & randGen .~ g
overNozzle eff ams it cr w nz =
( eff nz ams it (cr & crDir +~ wa + na) w & randGen .~ g
, nz & nzCurrentWalkAngle .~ wa
)
where
@@ -468,21 +468,22 @@ getAmmoMagazine itm cr = do
guard $ amtype == magtype
return mag
useGasParams :: Nozzle -> Item -> Creature -> World -> World
useGasParams nz it cr =
useGasParams :: Nozzle -> [Item] -> Item -> Creature -> World -> World
useGasParams nz ams it cr =
createGas
(_ampCreateGas (_amagParams amag))
gastype
(_nzPressure nz)
pos
dir
cr
where
amag = fromMaybe (error "cannot find gas ammo") $ getAmmoMagazine it cr
gastype = fromMaybe (error "cannot find gas ammo") $ ams ^? ix 0 . itUse . amagParams . ampCreateGas
-- amag = fromMaybe (error "cannot find gas ammo") $ getAmmoMagazine it cr
dir = _crDir cr
pos = _crPos cr +.+ (_nzLength nz *.* unitVectorAtAngle (_crDir cr))
fireRemoteShell :: Item -> Creature -> World -> World
fireRemoteShell it cr w =
fireRemoteShell :: [Item] -> Item -> Creature -> World -> World
fireRemoteShell ams it cr w =
set
(cWorld . lWorld . creatures . ix cid . crInv . ix j . itUse . heldUse)
(HeldExplodeRemoteShell itid i)
@@ -537,8 +538,8 @@ mcShootLaser it mc = cWorld . lWorld . lasers .:~ lasRayAt (_lasColor $ _itParam
dam = _lasDamage $ _itParams it
-- | assumes that the item is held
shootTeslaArc :: Item -> Creature -> World -> World
shootTeslaArc it cr w =
shootTeslaArc :: [Item] -> Item -> Creature -> World -> World
shootTeslaArc ams it cr w =
w'
& cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itRef . itParams .~ ip
where