Cleanup barrels

This commit is contained in:
2025-06-14 23:08:11 +01:00
parent 5286485d62
commit 02498e5abb
14 changed files with 352 additions and 353 deletions
+9 -13
View File
@@ -1,7 +1,7 @@
module Dodge.Barreloid where
module Dodge.Barreloid (updateBarreloid) where
import Data.Maybe
import Data.List
import Data.Maybe
import Dodge.Creature.State
import Dodge.Data.World
import Dodge.SoundLogic
@@ -13,7 +13,7 @@ import System.Random
updateBarreloid :: Creature -> World -> World
updateBarreloid cr = case cr ^?! crType . barrelType of
ExplosiveBarrel -> updateExpBarrel cr
ExplosiveBarrel{} -> updateExpBarrel cr
PlainBarrel -> updateBarrel cr
-- should generate the sparks externally using new random generators
@@ -31,11 +31,11 @@ updateExpBarrel cr w
poss
as
as = randomRs (-0.7, 0.7) g
poss = _piercedPoints $ _csSpState $ _crState cr
poss = _piercedPoints $ _barrelType $ _crType cr
newCr = Just $ applyFuseDamage $ set (crState . csDamage) [] $ damsToExpBarrel damages cr
applyFuseDamage cr' =
cr' & crHP
%~ subtract (length . _piercedPoints . _csSpState $ _crState cr')
%~ subtract (length . _piercedPoints . _barrelType $ _crType cr')
hiss
| null poss = id
| otherwise = soundMultiFrom [BarrelHiss 0, BarrelHiss 1] (_crPos cr) foamSprayLoopS (Just 1)
@@ -47,17 +47,13 @@ updateBarrel cr
| otherwise = cWorld . lWorld . creatures . at (_crID cr) .~ Nothing
damsToExpBarrel :: [Damage] -> Creature -> Creature
damsToExpBarrel ds cr = foldl' damToExpBarrel (foldl' damToExpBarrel cr pierceDam) otherDam
where
(pierceDam, otherDam) = partition isPierce ds
isPierce Piercing{} = True
isPierce _ = False
damsToExpBarrel = flip $ foldl' damToExpBarrel
damToExpBarrel :: Creature -> Damage -> Creature
damToExpBarrel cr dm = case dm of
Piercing x p _ ->
over (crState . csSpState . piercedPoints) ((:) $ p -.- _crPos cr) $
cr & crHP -~ div x 200
cr & crHP -~ div x 200
& crType . barrelType . piercedPoints .:~ (p - _crPos cr)
Poison{} -> cr
Sparking{} -> cr
_ -> cr LensHelp.& crHP -~ fromMaybe 0 (dm ^? dmAmount)
_ -> cr & crHP -~ fromMaybe 0 (dm ^? dmAmount)