Files
loop/src/Dodge/Barreloid.hs
T
2026-05-08 10:45:05 +01:00

60 lines
1.9 KiB
Haskell

{-# LANGUAGE LambdaCase #-}
module Dodge.Barreloid (updateBarreloid) where
import Linear
import Data.List
import Data.Maybe
import Dodge.Creature.State
import Dodge.Data.World
import Dodge.SoundLogic
import Dodge.Spark
import Dodge.WorldEvent.Explosion
import Geometry
import LensHelp
updateBarreloid :: BarrelType -> Creature -> World -> World
updateBarreloid = \case
ExplosiveBarrel ps -> updateExpBarrel ps
PlainBarrel -> updateBarrel
updateExpBarrel :: [Point2] -> Creature -> World -> World
updateExpBarrel ps cr w = case cr ^. crHP of
HP x | x > 0 ->
w
& hiss
& cWorld . lWorld . creatures . ix (_crID cr) %~ damsToExpBarrel damages
& cWorld . lWorld . creatures . ix (_crID cr) . crHP . _HP
-~ length (_piercedPoints . _barrelType $ _crType cr)
& flip (foldl' f) ps
HP _ ->
w
& makeExplosionAt (CrIndirectO (cr ^. crID)) ((cr ^. crPos) & _z +~ 20) 0
& cWorld . lWorld . creatures . at (_crID cr) .~ Nothing
_ -> w
where
f w' p = makeSpark NormalSpark (p + normalizeV p + cr ^. crPos . _xy) (argV p) w'
damages = cr ^. crDamage
hiss
| null ps = id
| otherwise = soundContinue
(BarrelHiss (_crID cr)) (cr ^. crPos . _xy) foamSprayLoopS (Just 1)
updateBarrel :: Creature -> World -> World
updateBarrel cr = case cr ^. crHP of
HP x | x > 0 -> doDamage (cr ^. crID)
HP _ -> cWorld . lWorld . creatures . at (_crID cr) .~ Nothing
_ -> id
damsToExpBarrel :: [Damage] -> Creature -> Creature
damsToExpBarrel = flip $ foldl' damToExpBarrel
damToExpBarrel :: Creature -> Damage -> Creature
damToExpBarrel cr dm = case dm of
Piercing x p _ _ ->
cr & crHP . _HP -~ div x 200
& crType . barrelType . piercedPoints .:~ (p - cr ^. crPos . _xy)
Poison{} -> cr
Sparking{} -> cr
_ -> cr & crHP . _HP -~ fromMaybe 0 (dm ^? dmAmount)