From 0802edda630246a0ff9f82196e55f09780ffa965 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 12 Jun 2016 03:44:53 +0200 Subject: Armour --- src/Main.hs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src/Main.hs') diff --git a/src/Main.hs b/src/Main.hs index f409a04..a38b514 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -308,16 +308,31 @@ doShock dmg efLens = withFocus $ \focusId -> do if cripple ^. seApplied then guard $ dmg >= reBar else guard $ val >= bar + lStats . efLens . seApplied .= True (CI.original -> effectName, effect) <- view _Effect <$> (evalF . table $ cripple ^. seEffect) lStats <~ (MaybeT . fmap join . runMaybeT $ evalF effect) lift $ shellPutStrLn effectName lift . addNote $ "Effect: " ++ effectName -takeHit :: Int -> Completable (Set Hitzone) -> Sh GameState () -takeHit dmg = withArg $ \zones -> withFocus $ \focusId -> forM_ zones $ \zone -> do - gEntities . ix focusId . eStats . sDamage . ix zone += dmg - doShock dmg (sCripple . ix zone) - doShock dmg sPainShock +takeHit :: Int -> Completable (Set Hitzone) -> Completable DamageType -> Sh GameState () +takeHit dmg a1 a2 = flip withArg a1 $ \zones -> flip withArg a2 $ \dType -> withFocus $ \focusId -> forM_ zones $ \zone -> void . runMaybeT $ do + let + lStats :: Traversal' GameState Stats + lStats = gEntities . ix focusId . eStats + name <- toName focusId + armor <- MaybeT . preuse $ lStats . sArmor . ix zone + dmg' <- MaybeT . focusState lStats . evalFormula' name $ absorb armor dType dmg + forM_ (Map.toList dmg') $ \(dType, dmg) -> lift . runMaybeT $ do + guard $ dmg > 0 + lift $ shellPutStrLn $ name ++ " took " ++ show dmg ++ " " ++ show dType + case dType of + Fatigue -> lStats . sFatigue += dmg + _ -> lStats . sDamage . ix zone += dmg + case dType of + Fatigue -> lift $ doShock dmg sFatigueShock + _ -> lift $ do + doShock dmg (sCripple . ix zone) + doShock dmg sPainShock takeFatigue :: Int -> Sh GameState () takeFatigue dmg = withFocus $ \focusId -> do -- cgit v1.2.3