Refactor damages

This commit is contained in:
2025-06-07 14:26:00 +01:00
parent 7a192e7631
commit 81a7dcd962
24 changed files with 271 additions and 277 deletions
+23 -10
View File
@@ -56,7 +56,7 @@ updateTurret rotSpeed mc w =
where
dodamage =
cWorld . lWorld . machines . ix mcid
%~ ( (mcDamage .~ [Damage ELECTRICAL (min 2500 $ max 0 (elecDam - 10)) 0 0 0])
%~ ( (mcDamage .~ [Electrical (min 2500 $ max 0 (elecDam - 10))])
. (mcHP -~ dam)
)
elecDamBranch
@@ -78,8 +78,8 @@ updateTurret rotSpeed mc w =
| otherwise = cWorld . lWorld . machines . ix mcid . mcType . _McTurret . tuFireTime %~ (max 0 . subtract 1)
isElectrical :: Damage -> Bool
isElectrical dm = case _dmType dm of
ELECTRICAL -> True
isElectrical dm = case dm of
Electrical{} -> True
_ -> False
mcUseItem :: Machine -> World -> World
@@ -168,19 +168,32 @@ senseDamage threshold dt mc =
| x > 0 = x
| otherwise = -5
where
f d = d `elem` sensorTypeDamages dt
x = sum . map _dmAmount $ filter (f . _dmType) (_mcDamage mc)
f = sensorTypeDamages dt
x = sum . map _dmAmount $ filter f (_mcDamage mc)
ni = fromIntegral (mc ^?! mcType . _McSensor . sensAmount) / fromIntegral threshold
updatels = fromMaybe id $ do
lsid <- mc ^? mcMounts . ix ObLightSource
return $ cWorld . lWorld . lightSources . ix lsid . lsParam . lsCol .~ V3 ni ni ni
sensorTypeDamages :: SensorType -> [DamageType]
sensorTypeDamages :: SensorType -> Damage -> Bool
sensorTypeDamages = \case
LaserSensor -> [LASERING]
ElectricSensor -> [ELECTRICAL]
ThermalSensor -> [FLAMING,SPARKING,EXPLOSIVE]
PhysicalSensor -> [PIERCING,BLUNT,CUTTING,CRUSHING,EXPLOSIVE,CONCUSSIVE]
LaserSensor -> \case
Lasering{} -> True
_ -> False
ElectricSensor -> \case
Electrical {} -> True
_ -> False
ThermalSensor -> \case
Flaming {} -> True
Sparking {} -> True
Explosive {} -> True
_ -> False
PhysicalSensor -> \case
Piercing {} -> True
Blunt {} -> True
Crushing {} -> True
Explosive {} -> True
_ -> False
--damageUsing :: DamageType -> Damage -> Either Int Int