From a8b735183cc3a137b463d61305e2287e4ffa350f Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 9 Jul 2016 12:23:07 +0200 Subject: more transparent damage handling --- src/Main.hs | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/Main.hs b/src/Main.hs index 55c0d8b..46f1fa6 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -165,10 +165,10 @@ stateMaintenance = do isDead <- evalF =<< MaybeT (preuse $ lStats . sDead) isUnconscious <- evalF =<< MaybeT (preuse $ lStats . sUnconscious) guard $ isDead || isUnconscious - when isDead . lift . shellPutStrLn $ name ++ " died" + when isDead . lift . shellPutStrLn $ name ++ " is dead" when (isUnconscious && not isDead) . lift . shellPutStrLn $ name ++ " is unconscious" gFocus' . eSeqVal .= Nothing - gFocus .= Nothing + -- gFocus .= Nothing void $ do round <- use gRound let @@ -354,24 +354,27 @@ doShock dmg efLens = withFocus $ \focusId -> do lift . addNote $ "Effect: " ++ effectName 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 +takeHit dmg a1 a2 = flip withArg a1 $ \zones -> flip withArg a2 $ \dType -> withFocus $ \focusId -> do 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 . outputLogged focusId $ 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 + let zones' = map (review hitzone) $ toList zones + gLog <>= pure (focusId, "Hit for " ++ show dmg ++ " " ++ show dType ++ " to " ++ show zones') + forM_ zones $ \zone -> void . runMaybeT $ do + let + lStats :: Traversal' GameState Stats + lStats = gEntities . ix focusId . eStats + 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 . outputLogged focusId $ show dmg ++ " " ++ show dType ++ " to " ++ show (review hitzone zone) + 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