From 10945609fe1e5f32ff8f5ca606ad098df7b2c794 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 10 Jul 2016 19:14:50 +0200 Subject: Fix handling of death, unconsciousness, etc. --- src/Main.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Main.hs b/src/Main.hs index 3d098e2..279a65d 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -163,11 +163,12 @@ stateMaintenance = do (nStats, x) <- (evalFormula [name] :: Stats -> FormulaM Stats a -> MaybeT (Sh GameState) (Stats, a)) stats formula lStats .= nStats return x - isDead <- evalF =<< MaybeT (preuse $ lStats . sDead) - isUnconscious <- evalF =<< MaybeT (preuse $ lStats . sUnconscious) - isDestroyed <- evalF =<< MaybeT (preuse $ lStats . sDestroyed) + safe a = lift $ fromMaybe False <$> runMaybeT a + isDead <- safe $ evalF =<< MaybeT (preuse $ lStats . sDead) + isUnconscious <- safe $ evalF =<< MaybeT (preuse $ lStats . sUnconscious) + isDestroyed <- safe $ evalF =<< MaybeT (preuse $ lStats . sDestroyed) guard $ isDead || isUnconscious || isDestroyed - case (isDead, isDestroyed, isUnconscious) of + case (isDead, isUnconscious, isDestroyed) of (True, _, _) -> lift . shellPutStrLn $ name ++ " is dead" (_, True, _) -> lift . shellPutStrLn $ name ++ " is unconscious" (_, _, True) -> lift . shellPutStrLn $ name ++ " is destroyed" -- cgit v1.2.3