From 0c5fe56414a323f49d7b086c0a64a216443a22bb Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Mon, 13 Jun 2016 20:03:24 +0200 Subject: action log --- src/Main.hs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'src/Main.hs') diff --git a/src/Main.hs b/src/Main.hs index e93d725..3e6b750 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -23,6 +23,9 @@ import qualified Data.Map.Strict as Map import Data.Set (Set) import qualified Data.Set as Set +import Data.Sequence (Seq) +import qualified Data.Sequence as Seq + import Data.Bimap (Bimap) import qualified Data.Bimap as Bimap @@ -33,6 +36,8 @@ import Data.Maybe import Data.Bool import Data.Monoid (All(..)) +import Data.Foldable (toList) + import Data.Function import Control.Monad.State.Strict @@ -91,10 +96,11 @@ main = do , cmd "combat" entitySeqVal "Roll sequence value for the current focus and enter combat" , cmd "combat'" factionSeqVal "Roll sequence values for all members of a faction and have them enter combat" , cmd "spend" spendSeq "Spend some of the current focus´ AP" - , cmd "delay" delay "Spend AP until the current focus´ sequence is no higher than the next highest" + , cmd "delay" delay "Spend AP until the current focus´ sequence is no higher than the next highest and focus that one" , cmd "note" addNote "Add a note to the current focus" , cmd "hit" takeHit "Damage the focused entity" , cmd "fatigue" takeFatigue "Inflict fatigue damage upon the focused entity" + , cmd "log" dumpLog "Print the combat log" ] , wordBreakChars = wordBreakChars initialShellDescription \\ [',', '*'] } @@ -291,19 +297,21 @@ entitySeqVal' ident = void . runMaybeT $ do & set seqEpsilon (entity ^. eStats . sSeqEpsilon) gEntities . at ident .= Just (newEntity & set eSeqVal val) -spendSeq :: Int -> Sh GameState () -spendSeq n = withFocus $ \focusId -> do +spendSeq :: Int -> String -> Sh GameState () +spendSeq n logStr = withFocus $ \focusId -> do gEntities . ix focusId . eStats . sSequence . _Just . seqVal . _Just -= n + gLog <>= pure (focusId, logStr) delay :: Sh GameState () -delay = withFocus $ \focusId -> () <$ runMaybeT (delay' focusId) +delay = withFocus $ fmap (\_ -> ()) . runMaybeT . delay' where delay' focusId = do - tipId <- MaybeT $ preuse tip + tipId <- MaybeT . preuse $ priorityQueue . folding (fmap snd . listToMaybe . filter (\(_, i) -> i /= focusId)) tipSeq <- MaybeT . preuse $ gEntities . ix tipId . eStats . sSequence . _Just . seqVal . _Just focusSeq <- MaybeT . preuse $ gEntities . ix focusId . eStats . sSequence . _Just . seqVal . _Just - guard $ focusSeq > tipSeq - lift . spendSeq $ focusSeq - tipSeq + guard $ focusSeq >= tipSeq + tipName <- toName tipId + lift $ spendSeq (focusSeq - tipSeq) ("Wait for " ++ tipName) addNote :: String -> Sh GameState () addNote note = withFocus $ \focusId -> gEntities . ix focusId . eNotes %= (note :) @@ -359,3 +367,9 @@ takeFatigue :: Int -> Sh GameState () takeFatigue dmg = withFocus $ \focusId -> do gEntities . ix focusId . eStats . sFatigue += dmg doShock dmg sFatigueShock + +dumpLog :: Sh GameState () +dumpLog = use gLog >>= mapMOf (each . _1) toName >>= shellPutStrLn . toTable + where + toTable :: Seq (String, String) -> String + toTable (map (rowG . toListOf both) . toList -> table) = layoutTableToString table (Just (["Entity", "String"], [def, def])) [def, def] unicodeBoldHeaderS -- cgit v1.2.3