diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-06-13 20:03:24 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-06-13 20:03:24 +0200 |
commit | 0c5fe56414a323f49d7b086c0a64a216443a22bb (patch) | |
tree | eb0fee8a463e09bc2dada338de5f42c5bbb3f552 /src/Main.hs | |
parent | 1ca2b48b49d559158cda4feffa145bdfded2c1c2 (diff) | |
download | 2017-01-16_17:13:37-0c5fe56414a323f49d7b086c0a64a216443a22bb.tar 2017-01-16_17:13:37-0c5fe56414a323f49d7b086c0a64a216443a22bb.tar.gz 2017-01-16_17:13:37-0c5fe56414a323f49d7b086c0a64a216443a22bb.tar.bz2 2017-01-16_17:13:37-0c5fe56414a323f49d7b086c0a64a216443a22bb.tar.xz 2017-01-16_17:13:37-0c5fe56414a323f49d7b086c0a64a216443a22bb.zip |
action log
Diffstat (limited to 'src/Main.hs')
-rw-r--r-- | src/Main.hs | 28 |
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 | |||
23 | import Data.Set (Set) | 23 | import Data.Set (Set) |
24 | import qualified Data.Set as Set | 24 | import qualified Data.Set as Set |
25 | 25 | ||
26 | import Data.Sequence (Seq) | ||
27 | import qualified Data.Sequence as Seq | ||
28 | |||
26 | import Data.Bimap (Bimap) | 29 | import Data.Bimap (Bimap) |
27 | import qualified Data.Bimap as Bimap | 30 | import qualified Data.Bimap as Bimap |
28 | 31 | ||
@@ -33,6 +36,8 @@ import Data.Maybe | |||
33 | import Data.Bool | 36 | import Data.Bool |
34 | import Data.Monoid (All(..)) | 37 | import Data.Monoid (All(..)) |
35 | 38 | ||
39 | import Data.Foldable (toList) | ||
40 | |||
36 | import Data.Function | 41 | import Data.Function |
37 | 42 | ||
38 | import Control.Monad.State.Strict | 43 | import 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 | ||
294 | spendSeq :: Int -> Sh GameState () | 300 | spendSeq :: Int -> String -> Sh GameState () |
295 | spendSeq n = withFocus $ \focusId -> do | 301 | spendSeq 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 | ||
298 | delay :: Sh GameState () | 305 | delay :: Sh GameState () |
299 | delay = withFocus $ \focusId -> () <$ runMaybeT (delay' focusId) | 306 | delay = 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 | ||
308 | addNote :: String -> Sh GameState () | 316 | addNote :: String -> Sh GameState () |
309 | addNote note = withFocus $ \focusId -> gEntities . ix focusId . eNotes %= (note :) | 317 | addNote note = withFocus $ \focusId -> gEntities . ix focusId . eNotes %= (note :) |
@@ -359,3 +367,9 @@ takeFatigue :: Int -> Sh GameState () | |||
359 | takeFatigue dmg = withFocus $ \focusId -> do | 367 | takeFatigue 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 | |||
371 | dumpLog :: Sh GameState () | ||
372 | dumpLog = 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 | ||