module Dodge.Barreloid where import Data.List import Dodge.Creature.State import Dodge.Data.World import Dodge.SoundLogic import Dodge.Spark import Dodge.WorldEvent.Explosion import Geometry import LensHelp import System.Random updateBarreloid :: Creature -> World -> World updateBarreloid cr = case cr ^?! crType . barrelType of ExplosiveBarrel -> updateExpBarrel cr PlainBarrel -> updateBarrel cr -- should generate the sparks externally using new random generators updateExpBarrel :: Creature -> World -> World updateExpBarrel cr w | _crHP cr > 0 = foldl' (flip ($)) (hiss w & cWorld . lWorld . creatures . at (_crID cr) .~ newCr) pierceSparks | otherwise = makeExplosionAt (_crPos cr) $ stopSounds w & cWorld . lWorld . creatures . at (_crID cr) .~ Nothing where g = _randGen w damages = _csDamage $ _crState cr pierceSparks :: [World -> World] pierceSparks = zipWith3 (\p a -> createBarrelSpark (_crPos cr +.+ p) (a + argV p)) poss as colids as = randomRs (-0.7, 0.7) g colids = randomRs (0, 11) g poss = _piercedPoints $ _csSpState $ _crState cr newCr = Just $ applyFuseDamage $ set (crState . csDamage) [] $ damsToExpBarrel damages cr applyFuseDamage cr' = cr' & crHP %~ subtract (length . _piercedPoints . _csSpState $ _crState cr') hiss | null poss = id | otherwise = soundMultiFrom [BarrelHiss 0, BarrelHiss 1] (_crPos cr) foamSprayLoopS (Just 1) stopSounds = stopSoundFrom (BarrelHiss 0) . stopSoundFrom (BarrelHiss 1) updateBarrel :: Creature -> World -> World updateBarrel cr | _crHP cr > 0 = doDamage 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 Damage{_dmType = PIERCING{}} = True isPierce _ = False damToExpBarrel :: Creature -> Damage -> Creature damToExpBarrel cr dm = case _dmType dm of PIERCING -> over (crState . csSpState . piercedPoints) ((:) $ int -.- _crPos cr) $ cr & crHP -~ div amount 200 POISONDAM -> cr SPARKING -> cr -- PUSHDAM -> cr LensHelp.& crPos .+.+~ (1 / _crMass cr *.* _dePushBack (_dmEffect dm)) _ -> cr LensHelp.& crHP -~ amount where amount = _dmAmount dm int = _dmAt dm