Refactor damages to materials
This commit is contained in:
@@ -9,22 +9,25 @@ import Dodge.Spark
|
||||
import Geometry
|
||||
import LensHelp
|
||||
|
||||
applyCreatureDamage :: [Damage] -> Creature -> World -> World
|
||||
applyCreatureDamage dms cr = case crMaterial (cr ^. crType) of
|
||||
Flesh -> defaultApplyDamage dms cr
|
||||
Crystal -> id
|
||||
_ -> defaultApplyDamage dms cr
|
||||
--applyCreatureDamage :: [Damage] -> Creature -> World -> World
|
||||
--applyCreatureDamage dms cr =
|
||||
-- case crMaterial (cr ^. crType) of
|
||||
-- Flesh -> defaultApplyDamage dms cr
|
||||
-- Crystal -> id
|
||||
-- _ -> defaultApplyDamage dms cr
|
||||
|
||||
defaultApplyDamage :: [Damage] -> Creature -> World -> World
|
||||
defaultApplyDamage ds cr w =
|
||||
foldl' (applyIndividualDamage cr) w ds'
|
||||
& cWorld . lWorld . creatures . ix (_crID cr) %~ doPoisonDam
|
||||
where
|
||||
(ps, ds') = partition isPoison ds
|
||||
isPoison Poison{} = True
|
||||
isPoison _ = False
|
||||
poisonDam = quot (max 0 (sum (map _dmAmount ps))) 10
|
||||
doPoisonDam = crHP -~ poisonDam
|
||||
--defaultApplyDamage :: [Damage] -> Creature -> World -> World
|
||||
--defaultApplyDamage ds cr w =
|
||||
applyCreatureDamage :: [Damage] -> Creature -> World -> World
|
||||
applyCreatureDamage dms cr w = foldl' (applyIndividualDamage cr) w dms
|
||||
-- foldl' (applyIndividualDamage cr) w ds'
|
||||
-- & cWorld . lWorld . creatures . ix (_crID cr) %~ doPoisonDam
|
||||
-- where
|
||||
-- (ps, ds') = partition isPoison ds
|
||||
-- isPoison Poison{} = True
|
||||
-- isPoison _ = False
|
||||
-- poisonDam = quot (max 0 (sum (map _dmAmount ps))) 10
|
||||
-- doPoisonDam = crHP -~ poisonDam
|
||||
|
||||
--applyDamageEffect :: Damage -> DamageEffect -> Creature -> World -> World
|
||||
--applyDamageEffect dm de cr = case de of
|
||||
@@ -64,5 +67,5 @@ damageHP :: Creature -> Int -> World -> World
|
||||
damageHP cr x =
|
||||
cWorld . lWorld . creatures . ix (_crID cr)
|
||||
%~ ( (crHP -~ x)
|
||||
. (crPastDamage +~ x)
|
||||
. (crPain +~ x)
|
||||
)
|
||||
|
||||
@@ -204,7 +204,7 @@ targetYouWhenCognizant w cr = case cr ^? crPerception . cpAwareness . ix 0 of
|
||||
|
||||
searchIfDamaged :: Creature -> Creature
|
||||
searchIfDamaged cr
|
||||
| _crPastDamage cr > 0
|
||||
| _crPain cr > 0
|
||||
&& _apStrategy (_crActionPlan cr) == WatchAndWait =
|
||||
cr & crPerception . cpVigilance .~ Vigilant
|
||||
& crActionPlan . apStrategy
|
||||
|
||||
@@ -106,7 +106,7 @@ corpseOrGib :: Creature -> World -> World
|
||||
corpseOrGib cr = case cr ^? crDamage . to maxDamageType . _Just . _1 of
|
||||
Just CookingDamage -> addcorpse (thecorpse & cpSPic %~ scorchSPic)
|
||||
Just PoisonDamage -> addcorpse (thecorpse & cpSPic %~ poisonSPic)
|
||||
Just PhysicalDamage | _crPastDamage cr > 200 -> addCrGibs cr
|
||||
Just PhysicalDamage | _crPain cr > 200 -> addCrGibs cr
|
||||
_ -> addcorpse thecorpse
|
||||
where
|
||||
addcorpse ctype = plNew (cWorld . lWorld . corpses) cpID ctype
|
||||
@@ -130,15 +130,15 @@ doDamage cr = applyPastDamages cr . applyCreatureDamage (cr ^. crDamage) cr
|
||||
-- TODO generalise shake to arbitrary damage amounts
|
||||
applyPastDamages :: Creature -> World -> World
|
||||
applyPastDamages cr w
|
||||
| _crPastDamage cr > 200 = dojitter 3 100
|
||||
| _crPastDamage cr > 20 = dojitter 2 10
|
||||
| _crPastDamage cr > 0 = dojitter 1 1
|
||||
| _crPain cr > 200 = dojitter 3 100
|
||||
| _crPain cr > 20 = dojitter 2 10
|
||||
| _crPain cr > 0 = dojitter 1 1
|
||||
| otherwise = w
|
||||
where
|
||||
dojitter x y =
|
||||
let (p, g) = runState (randInCirc x) (_randGen w)
|
||||
in w & cWorld . lWorld . creatures . ix (_crID cr) %~ crMvBy p
|
||||
& cWorld . lWorld . creatures . ix (_crID cr) . crPastDamage -~ y
|
||||
& cWorld . lWorld . creatures . ix (_crID cr) . crPain -~ y
|
||||
& randGen .~ g
|
||||
|
||||
-- a loop going over all root inventory items
|
||||
|
||||
Reference in New Issue
Block a user