44 lines
1.6 KiB
Haskell
44 lines
1.6 KiB
Haskell
module Dodge.Creature.Damage (applyCreatureDamage) where
|
|
|
|
import Dodge.Creature.Mass
|
|
import Linear
|
|
import Dodge.Material.Damage
|
|
import Data.List
|
|
--import Dodge.Creature.Mass
|
|
import Dodge.Creature.Material
|
|
--import Dodge.Creature.Test
|
|
import Dodge.Data.World
|
|
--import Dodge.Spark
|
|
--import Geometry
|
|
import LensHelp
|
|
|
|
applyCreatureDamage :: [Damage] -> Creature -> World -> World
|
|
applyCreatureDamage dms cr w = foldl' (applyIndividualDamage cr) w dms
|
|
|
|
applyIndividualDamage :: Creature -> World -> Damage -> World
|
|
applyIndividualDamage cr w (Inertial _ _ v) = w
|
|
& cWorld . lWorld . creatures . ix (_crID cr) . crPos . _xy +~ fmap (/ crMass (cr ^. crType)) v
|
|
applyIndividualDamage cr w dm =
|
|
let (i,w') = damMatSideEffect dm (crMaterial (_crType cr)) (Left cr) w
|
|
in w' & damageHP cr i
|
|
-- case dm of
|
|
-- Piercing{} -> applyPiercingDamage cr dm w
|
|
-- _ -> w & damageHP cr (_dmAmount dm)
|
|
|
|
--applyPiercingDamage :: Creature -> Damage -> World -> World
|
|
--applyPiercingDamage cr dm w
|
|
-- | crIsArmouredFrom (w ^. cWorld . lWorld . items) p cr
|
|
-- = f . makeSpark NormalSpark p1 (argV (p1 - p)) $ w
|
|
-- | otherwise = f . damageHP cr (_dmAmount dm) $ w
|
|
-- where
|
|
-- f = cWorld . lWorld . creatures . ix (_crID cr) . crPos . _xy +~ _dmVector dm
|
|
-- / V2 x x
|
|
-- x = crMass (_crType cr)
|
|
-- p = _dmPos dm
|
|
-- p1 = p + 2 *.* squashNormalizeV (p - cr ^. crPos . _xy)
|
|
|
|
damageHP :: Creature -> Int -> World -> World
|
|
damageHP cr x =
|
|
(cWorld . lWorld . creatures . ix (_crID cr) . crHP . _HP -~ x)
|
|
. (cWorld . lWorld . creatures . ix (_crID cr) . crPain +~ x)
|