Apply different damage amounts to different materials

This commit is contained in:
2025-10-24 10:08:36 +01:00
parent b2265297b5
commit 9a3c642684
4 changed files with 72 additions and 65 deletions
+22 -20
View File
@@ -1,36 +1,38 @@
module Dodge.Creature.Damage (applyCreatureDamage) where
import Linear
--import Linear
import Dodge.Material.Damage
import Data.List
import Dodge.Creature.Mass
--import Dodge.Creature.Mass
import Dodge.Creature.Material
import Dodge.Creature.Test
--import Dodge.Creature.Test
import Dodge.Data.World
import Dodge.Spark
import Geometry
--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 dm = damMatSideEffect dm (crMaterial (_crType cr)) (Left cr) $
case dm of
Piercing{} -> applyPiercingDamage cr dm w
_ -> w & damageHP cr (_dmAmount dm)
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)
--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 =