summaryrefslogtreecommitdiff
path: root/src/Sequence
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-06-11 23:00:13 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2016-06-11 23:00:13 +0200
commitbf24ff9ffd25841da5e20386548fb63ff191ed9a (patch)
treebcdfee20698fa0accdbb5dc5457770f45cd19fd0 /src/Sequence
parent1bdb2f64c92f79918ea5e1a3f98af45e06d4aae7 (diff)
download2017-01-16_17:13:37-bf24ff9ffd25841da5e20386548fb63ff191ed9a.tar
2017-01-16_17:13:37-bf24ff9ffd25841da5e20386548fb63ff191ed9a.tar.gz
2017-01-16_17:13:37-bf24ff9ffd25841da5e20386548fb63ff191ed9a.tar.bz2
2017-01-16_17:13:37-bf24ff9ffd25841da5e20386548fb63ff191ed9a.tar.xz
2017-01-16_17:13:37-bf24ff9ffd25841da5e20386548fb63ff191ed9a.zip
Death & Unconsciousness
Diffstat (limited to 'src/Sequence')
-rw-r--r--src/Sequence/Contact/Types.hs8
-rw-r--r--src/Sequence/Formula.hs2
-rw-r--r--src/Sequence/Utils.hs21
3 files changed, 27 insertions, 4 deletions
diff --git a/src/Sequence/Contact/Types.hs b/src/Sequence/Contact/Types.hs
index 9854d92..80d4360 100644
--- a/src/Sequence/Contact/Types.hs
+++ b/src/Sequence/Contact/Types.hs
@@ -181,4 +181,10 @@ sDead :: Fold Stats (FormulaM Stats Bool)
181sDead = folding $ do 181sDead = folding $ do
182 maxVitality <- preview sMaxVitality 182 maxVitality <- preview sMaxVitality
183 damage <- view sTotalDamage 183 damage <- view sTotalDamage
184 return $ liftM2 (>) <$> Just (return damage) <*> maxVitality 184 return $ liftM2 (>=) <$> Just (return damage) <*> maxVitality
185
186sUnconscious :: Fold Stats (FormulaM Stats Bool)
187sUnconscious = folding $ do
188 maxVitality <- preview sMaxVitality
189 damage <- view sFatigue
190 return $ liftM2 (>=) <$> Just (return damage) <*> maxVitality
diff --git a/src/Sequence/Formula.hs b/src/Sequence/Formula.hs
index 4f2e61b..4830788 100644
--- a/src/Sequence/Formula.hs
+++ b/src/Sequence/Formula.hs
@@ -3,7 +3,7 @@
3module Sequence.Formula 3module Sequence.Formula
4 ( FormulaM, Formula, quot' 4 ( FormulaM, Formula, quot'
5 , (:<:)(..), Context(..), ctx 5 , (:<:)(..), Context(..), ctx
6 , evalFormula 6 , evalFormula, evalFormula'
7 , val 7 , val
8 , d, z 8 , d, z
9 , Table, table 9 , Table, table
diff --git a/src/Sequence/Utils.hs b/src/Sequence/Utils.hs
index 8b205ea..1b52630 100644
--- a/src/Sequence/Utils.hs
+++ b/src/Sequence/Utils.hs
@@ -1,8 +1,9 @@
1{-# LANGUAGE ViewPatterns, FlexibleContexts, MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, UndecidableInstances, OverloadedStrings #-} 1{-# LANGUAGE ViewPatterns, FlexibleContexts, MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, UndecidableInstances, OverloadedStrings, RankNTypes #-}
2 2
3module Sequence.Utils 3module Sequence.Utils
4 ( withArg, withFocus, withFocus' 4 ( withArg, withFocus, withFocus'
5 , toName 5 , focusState
6 , toName, toDesc
6 , Argument(..) 7 , Argument(..)
7 , Completion(..) 8 , Completion(..)
8 , module Sequence.Utils.Ask 9 , module Sequence.Utils.Ask
@@ -44,6 +45,7 @@ import System.Console.Shell.Backend.Haskeline
44 45
45import Sequence.Utils.Ask 46import Sequence.Utils.Ask
46import Sequence.Contact.Types 47import Sequence.Contact.Types
48import Sequence.Formula
47 49
48class Argument a st | a -> st where 50class Argument a st | a -> st where
49 arg :: String -> Sh st (Maybe a) 51 arg :: String -> Sh st (Maybe a)
@@ -59,6 +61,9 @@ withFocus f = use gFocus >>= maybe (shellPutErrLn $ "Currently not focusing any
59withFocus' :: (Entity -> Sh GameState a) -> Sh GameState (Maybe a) 61withFocus' :: (Entity -> Sh GameState a) -> Sh GameState (Maybe a)
60withFocus' f = preuse gFocus' >>= maybe (Nothing <$ shellPutErrLn "Currently not focusing any entity") (fmap Just . f) 62withFocus' f = preuse gFocus' >>= maybe (Nothing <$ shellPutErrLn "Currently not focusing any entity") (fmap Just . f)
61 63
64focusState :: MonadState GameState m => Traversal' GameState a -> StateT a (MaybeT m) b -> m (Maybe b)
65focusState lens action = runMaybeT $ uncurry (<$) . over _2 (lens .=) =<< runStateT action =<< MaybeT (preuse lens)
66
62unaligned = view faction' def 67unaligned = view faction' def
63 68
64toName :: MonadState GameState m => EntityIdentifier -> m String 69toName :: MonadState GameState m => EntityIdentifier -> m String
@@ -68,6 +73,18 @@ toName ident = do
68 let number' = bool id ('#':) isShadowed $ number 73 let number' = bool id ('#':) isShadowed $ number
69 fromMaybe number' . fmap (review entityName) . Bimap.lookup ident <$> use gEntityNames 74 fromMaybe number' . fmap (review entityName) . Bimap.lookup ident <$> use gEntityNames
70 75
76toDesc :: (MonadState GameState m, MonadIO m) => EntityIdentifier -> m String
77toDesc ident = do
78 name <- toName ident
79 health <- runMaybeT $ do
80 maxVit <- MaybeT . focusState (gEntities . ix ident) . evalFormula' name =<< (MaybeT . preuse $ gEntities . ix ident . eStats . sMaxVitality)
81 hDamage <- MaybeT . preuse $ gEntities . ix ident . eStats . sTotalDamage
82 fDamage <- MaybeT . preuse $ gEntities . ix ident . eStats . sFatigue
83 return $ (maxVit - hDamage, maxVit - fDamage)
84 case health of
85 Just dmg -> return $ name ++ " " ++ show dmg
86 Nothing -> return name
87
71instance Completion EntityIdentifier GameState where 88instance Completion EntityIdentifier GameState where
72 completableLabel _ = "<entity>" 89 completableLabel _ = "<entity>"
73 complete _ st prefix = return . filter ((isPrefixOf `on` CI.foldCase) prefix) . map ((evalState ?? st) . toName) . Map.keys $ st ^. gEntities 90 complete _ st prefix = return . filter ((isPrefixOf `on` CI.foldCase) prefix) . map ((evalState ?? st) . toName) . Map.keys $ st ^. gEntities