Rethink damage data type, work on damage sensors
This commit is contained in:
+26
-23
@@ -183,35 +183,37 @@ defaultConsumable = Item
|
||||
, _itScope = NoScope
|
||||
, _itTargeting = NoTargeting
|
||||
}
|
||||
defaultApplyDamage :: [DamageType] -> Creature -> (World -> World, Creature)
|
||||
defaultApplyDamage :: [Damage] -> Creature -> (World -> World, Creature)
|
||||
defaultApplyDamage ds cr = (id, doPoisonDam $ foldl' (flip $ \d c -> snd $ applyIndividualDamage d c) cr ds')
|
||||
where
|
||||
(ps,ds') = partition isPoison ds
|
||||
isPoison PoisonDam{} = True
|
||||
isPoison Damage{_dmType=PoisonDam} = True
|
||||
isPoison _ = False
|
||||
poisonDam = quot (max 0 (sum (map _dmAmount ps))) 10
|
||||
doPoisonDam = over crHP (\hp -> hp - poisonDam)
|
||||
|
||||
applyIndividualDamage :: DamageType -> Creature -> (World -> World, Creature)
|
||||
applyIndividualDamage (Concussive amount fromDir push pushexp pushRad) cr
|
||||
= ( id
|
||||
, over crHP (\hp -> hp - amount)
|
||||
$ over crPos (+.+ (pushAmount *.* squashNormalizeV (_crPos cr -.- fromDir)))
|
||||
cr
|
||||
)
|
||||
where
|
||||
pushAmount
|
||||
| dist (_crPos cr) fromDir == 0 = 0
|
||||
| otherwise = min 5 $ (push*5*pushRad / (dist (_crPos cr) fromDir * _crMass cr))**pushexp
|
||||
applyIndividualDamage (TorqueDam amount rot) cr
|
||||
= ( id
|
||||
, over crHP (\hp -> hp - amount) $ over crDir (+ rot) cr)
|
||||
applyIndividualDamage (PushDam amount pback) cr
|
||||
= ( id
|
||||
, over crHP (\hp -> hp - amount) $ over crPos (+.+ ((1/_crMass cr) *.* pback )) cr
|
||||
)
|
||||
applyIndividualDamage dt cr
|
||||
= ( id , over crHP (\hp -> hp - _dmAmount dt) cr )
|
||||
applyDamageEffect :: Damage -> DamageEffect -> Creature -> Creature
|
||||
applyDamageEffect dm de cr = case de of
|
||||
NoDamageEffect -> cr
|
||||
PushDamage push pushexp pushRad -> cr
|
||||
& crPos %~ (+.+ (pushAmount *.* squashNormalizeV (_crPos cr -.- fromDir)))
|
||||
where
|
||||
pushAmount
|
||||
| dist (_crPos cr) fromDir == 0 = 0
|
||||
| otherwise = min 5 $ (push*5*pushRad / (dist (_crPos cr) fromDir * _crMass cr))**pushexp
|
||||
PushBackDamage pback -> cr
|
||||
& crPos %~ (+.+ ((1/_crMass cr) *.* pback ))
|
||||
TorqueDamage rot -> cr & crDir +~ rot
|
||||
where
|
||||
fromDir = _dmFrom dm
|
||||
|
||||
applyIndividualDamage :: Damage -> Creature -> (World -> World, Creature)
|
||||
applyIndividualDamage dm cr = ( id
|
||||
, cr
|
||||
& crHP -~ _dmAmount dm
|
||||
& applyDamageEffect dm (_dmEffect dm)
|
||||
)
|
||||
|
||||
defaultFlIt :: FloorItem
|
||||
defaultFlIt = FlIt {_flItRot=0,_flIt = defaultConsumable, _flItPos = V2 0 0, _flItID = 0}
|
||||
defaultMachine :: Machine
|
||||
@@ -223,7 +225,8 @@ defaultMachine = Machine
|
||||
, _mcPos = V2 0 0
|
||||
, _mcDir = 0
|
||||
, _mcHP = 1000
|
||||
, _mcSensor = 0
|
||||
, _mcSensorAmount = 0
|
||||
, _mcSensorToggle = False
|
||||
, _mcDamage = []
|
||||
, _mcLSs = []
|
||||
, _mcType = StaticMachine
|
||||
|
||||
Reference in New Issue
Block a user