module Dodge.WorldEvent.DamageBlock ( damageBlocksBy , damageWall ) where import Dodge.Data import Dodge.Data.DamageType import Control.Lens damageWall :: DamageType -> Wall -> World -> World damageWall dt wl = case _wlStructure wl of MachinePart mcid -> machines . ix mcid . mcDamage %~ (dt :) BlockPart blid -> blocks . ix blid %~ damageBlockWith dt _ -> id damageBlockWith :: DamageType -> Block -> Block damageBlockWith _ = id damageBlocksBy :: Int -> Wall -> World -> World damageBlocksBy x wl = case wl ^? wlStructure . wlStBlock of Just blid -> blocks . ix blid . blHPs %~ reduceHeadBy x Nothing -> id where reduceHeadBy y (z:zs) = z - y : zs reduceHeadBy _ [] = []