summaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs28
1 files changed, 21 insertions, 7 deletions
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
23import Data.Set (Set) 23import Data.Set (Set)
24import qualified Data.Set as Set 24import qualified Data.Set as Set
25 25
26import Data.Sequence (Seq)
27import qualified Data.Sequence as Seq
28
26import Data.Bimap (Bimap) 29import Data.Bimap (Bimap)
27import qualified Data.Bimap as Bimap 30import qualified Data.Bimap as Bimap
28 31
@@ -33,6 +36,8 @@ import Data.Maybe
33import Data.Bool 36import Data.Bool
34import Data.Monoid (All(..)) 37import Data.Monoid (All(..))
35 38
39import Data.Foldable (toList)
40
36import Data.Function 41import Data.Function
37 42
38import Control.Monad.State.Strict 43import Control.Monad.State.Strict
@@ -91,10 +96,11 @@ main = do
91 , cmd "combat" entitySeqVal "Roll sequence value for the current focus and enter combat" 96 , cmd "combat" entitySeqVal "Roll sequence value for the current focus and enter combat"
92 , cmd "combat'" factionSeqVal "Roll sequence values for all members of a faction and have them enter combat" 97 , cmd "combat'" factionSeqVal "Roll sequence values for all members of a faction and have them enter combat"
93 , cmd "spend" spendSeq "Spend some of the current focus´ AP" 98 , cmd "spend" spendSeq "Spend some of the current focus´ AP"
94 , cmd "delay" delay "Spend AP until the current focus´ sequence is no higher than the next highest" 99 , cmd "delay" delay "Spend AP until the current focus´ sequence is no higher than the next highest and focus that one"
95 , cmd "note" addNote "Add a note to the current focus" 100 , cmd "note" addNote "Add a note to the current focus"
96 , cmd "hit" takeHit "Damage the focused entity" 101 , cmd "hit" takeHit "Damage the focused entity"
97 , cmd "fatigue" takeFatigue "Inflict fatigue damage upon the focused entity" 102 , cmd "fatigue" takeFatigue "Inflict fatigue damage upon the focused entity"
103 , cmd "log" dumpLog "Print the combat log"
98 ] 104 ]
99 , wordBreakChars = wordBreakChars initialShellDescription \\ [',', '*'] 105 , wordBreakChars = wordBreakChars initialShellDescription \\ [',', '*']
100 } 106 }
@@ -291,19 +297,21 @@ entitySeqVal' ident = void . runMaybeT $ do
291 & set seqEpsilon (entity ^. eStats . sSeqEpsilon) 297 & set seqEpsilon (entity ^. eStats . sSeqEpsilon)
292 gEntities . at ident .= Just (newEntity & set eSeqVal val) 298 gEntities . at ident .= Just (newEntity & set eSeqVal val)
293 299
294spendSeq :: Int -> Sh GameState () 300spendSeq :: Int -> String -> Sh GameState ()
295spendSeq n = withFocus $ \focusId -> do 301spendSeq n logStr = withFocus $ \focusId -> do
296 gEntities . ix focusId . eStats . sSequence . _Just . seqVal . _Just -= n 302 gEntities . ix focusId . eStats . sSequence . _Just . seqVal . _Just -= n
303 gLog <>= pure (focusId, logStr)
297 304
298delay :: Sh GameState () 305delay :: Sh GameState ()
299delay = withFocus $ \focusId -> () <$ runMaybeT (delay' focusId) 306delay = withFocus $ fmap (\_ -> ()) . runMaybeT . delay'
300 where 307 where
301 delay' focusId = do 308 delay' focusId = do
302 tipId <- MaybeT $ preuse tip 309 tipId <- MaybeT . preuse $ priorityQueue . folding (fmap snd . listToMaybe . filter (\(_, i) -> i /= focusId))
303 tipSeq <- MaybeT . preuse $ gEntities . ix tipId . eStats . sSequence . _Just . seqVal . _Just 310 tipSeq <- MaybeT . preuse $ gEntities . ix tipId . eStats . sSequence . _Just . seqVal . _Just
304 focusSeq <- MaybeT . preuse $ gEntities . ix focusId . eStats . sSequence . _Just . seqVal . _Just 311 focusSeq <- MaybeT . preuse $ gEntities . ix focusId . eStats . sSequence . _Just . seqVal . _Just
305 guard $ focusSeq > tipSeq 312 guard $ focusSeq >= tipSeq
306 lift . spendSeq $ focusSeq - tipSeq 313 tipName <- toName tipId
314 lift $ spendSeq (focusSeq - tipSeq) ("Wait for " ++ tipName)
307 315
308addNote :: String -> Sh GameState () 316addNote :: String -> Sh GameState ()
309addNote note = withFocus $ \focusId -> gEntities . ix focusId . eNotes %= (note :) 317addNote note = withFocus $ \focusId -> gEntities . ix focusId . eNotes %= (note :)
@@ -359,3 +367,9 @@ takeFatigue :: Int -> Sh GameState ()
359takeFatigue dmg = withFocus $ \focusId -> do 367takeFatigue dmg = withFocus $ \focusId -> do
360 gEntities . ix focusId . eStats . sFatigue += dmg 368 gEntities . ix focusId . eStats . sFatigue += dmg
361 doShock dmg sFatigueShock 369 doShock dmg sFatigueShock
370
371dumpLog :: Sh GameState ()
372dumpLog = use gLog >>= mapMOf (each . _1) toName >>= shellPutStrLn . toTable
373 where
374 toTable :: Seq (String, String) -> String
375 toTable (map (rowG . toListOf both) . toList -> table) = layoutTableToString table (Just (["Entity", "String"], [def, def])) [def, def] unicodeBoldHeaderS