57 lines
1.8 KiB
Haskell
57 lines
1.8 KiB
Haskell
{-# LANGUAGE LambdaCase #-}
|
|
|
|
module Dodge.Barreloid (updateBarreloid) where
|
|
|
|
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
|
|
| cr ^. crHP > 0 =
|
|
w
|
|
& hiss
|
|
& cWorld . lWorld . creatures . ix (_crID cr) %~ damsToExpBarrel damages
|
|
& cWorld . lWorld . creatures . ix (_crID cr) . crHP
|
|
-~ length (_piercedPoints . _barrelType $ _crType cr)
|
|
& cWorld . lWorld . creatures . ix (_crID cr) . crDamage .~ mempty
|
|
& flip (foldl' f) ps
|
|
| otherwise =
|
|
w
|
|
& makeExplosionAt ((cr ^. crPos) `v2z` 20) 0
|
|
& cWorld . lWorld . creatures . at (_crID cr) .~ Nothing
|
|
where
|
|
f w' p = makeSpark NormalSpark (p + normalizeV p + cr ^. crPos) (argV p) w'
|
|
damages = cr ^. crDamage
|
|
hiss
|
|
| null ps = id
|
|
| otherwise = soundContinue (BarrelHiss (_crID cr)) (_crPos cr) foamSprayLoopS (Just 1)
|
|
|
|
updateBarrel :: Creature -> World -> World
|
|
updateBarrel cr
|
|
| _crHP cr > 0 = doDamage (cr ^. crID)
|
|
| otherwise = cWorld . lWorld . creatures . at (_crID cr) .~ Nothing
|
|
|
|
damsToExpBarrel :: [Damage] -> Creature -> Creature
|
|
damsToExpBarrel = flip $ foldl' damToExpBarrel
|
|
|
|
damToExpBarrel :: Creature -> Damage -> Creature
|
|
damToExpBarrel cr dm = case dm of
|
|
Piercing x p _ ->
|
|
cr & crHP -~ div x 200
|
|
& crType . barrelType . piercedPoints .:~ (p - _crPos cr)
|
|
Poison{} -> cr
|
|
Sparking{} -> cr
|
|
_ -> cr & crHP -~ fromMaybe 0 (dm ^? dmAmount)
|