diff options
Diffstat (limited to 'src/Sequence/Utils.hs')
-rw-r--r-- | src/Sequence/Utils.hs | 21 |
1 files changed, 19 insertions, 2 deletions
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 | ||
3 | module Sequence.Utils | 3 | module 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 | ||
45 | import Sequence.Utils.Ask | 46 | import Sequence.Utils.Ask |
46 | import Sequence.Contact.Types | 47 | import Sequence.Contact.Types |
48 | import Sequence.Formula | ||
47 | 49 | ||
48 | class Argument a st | a -> st where | 50 | class 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 | |||
59 | withFocus' :: (Entity -> Sh GameState a) -> Sh GameState (Maybe a) | 61 | withFocus' :: (Entity -> Sh GameState a) -> Sh GameState (Maybe a) |
60 | withFocus' f = preuse gFocus' >>= maybe (Nothing <$ shellPutErrLn "Currently not focusing any entity") (fmap Just . f) | 62 | withFocus' f = preuse gFocus' >>= maybe (Nothing <$ shellPutErrLn "Currently not focusing any entity") (fmap Just . f) |
61 | 63 | ||
64 | focusState :: MonadState GameState m => Traversal' GameState a -> StateT a (MaybeT m) b -> m (Maybe b) | ||
65 | focusState lens action = runMaybeT $ uncurry (<$) . over _2 (lens .=) =<< runStateT action =<< MaybeT (preuse lens) | ||
66 | |||
62 | unaligned = view faction' def | 67 | unaligned = view faction' def |
63 | 68 | ||
64 | toName :: MonadState GameState m => EntityIdentifier -> m String | 69 | toName :: 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 | ||
76 | toDesc :: (MonadState GameState m, MonadIO m) => EntityIdentifier -> m String | ||
77 | toDesc 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 | |||
71 | instance Completion EntityIdentifier GameState where | 88 | instance 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 |