diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-06-13 18:44:54 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-06-13 18:44:54 +0200 |
commit | 12dce406808620989646a163ff77a0782eb5ef63 (patch) | |
tree | a12d4af28af55ba7b851ec8ca3e5f1bf27f572e6 /src | |
parent | ae1ea97cdcca8d230dbee9460ae5d28242404d20 (diff) | |
download | 2017-01-16_17:13:37-12dce406808620989646a163ff77a0782eb5ef63.tar 2017-01-16_17:13:37-12dce406808620989646a163ff77a0782eb5ef63.tar.gz 2017-01-16_17:13:37-12dce406808620989646a163ff77a0782eb5ef63.tar.bz2 2017-01-16_17:13:37-12dce406808620989646a163ff77a0782eb5ef63.tar.xz 2017-01-16_17:13:37-12dce406808620989646a163ff77a0782eb5ef63.zip |
combat rounds
Diffstat (limited to 'src')
-rw-r--r-- | src/Main.hs | 23 | ||||
-rw-r--r-- | src/Sequence/Types.hs | 2 | ||||
-rw-r--r-- | src/Sequence/Utils.hs | 2 |
3 files changed, 24 insertions, 3 deletions
diff --git a/src/Main.hs b/src/Main.hs index a38b514..e93d725 100644 --- a/src/Main.hs +++ b/src/Main.hs | |||
@@ -31,10 +31,12 @@ import Data.List | |||
31 | import Data.List | 31 | import Data.List |
32 | import Data.Maybe | 32 | import Data.Maybe |
33 | import Data.Bool | 33 | import Data.Bool |
34 | import Data.Monoid (All(..)) | ||
34 | 35 | ||
35 | import Data.Function | 36 | import Data.Function |
36 | 37 | ||
37 | import Control.Monad.State.Strict | 38 | import Control.Monad.State.Strict |
39 | import Control.Monad.Reader | ||
38 | import Control.Monad.Trans.Maybe | 40 | import Control.Monad.Trans.Maybe |
39 | import Control.Monad.List | 41 | import Control.Monad.List |
40 | 42 | ||
@@ -157,9 +159,28 @@ stateMaintenance = do | |||
157 | isUnconscious <- evalF =<< MaybeT (preuse $ lStats . sUnconscious) | 159 | isUnconscious <- evalF =<< MaybeT (preuse $ lStats . sUnconscious) |
158 | guard $ isDead || isUnconscious | 160 | guard $ isDead || isUnconscious |
159 | when isDead . lift . shellPutStrLn $ name ++ " died" | 161 | when isDead . lift . shellPutStrLn $ name ++ " died" |
160 | when isUnconscious . lift . shellPutStrLn $ name ++ " is unconscious" | 162 | when (isUnconscious && not isDead) . lift . shellPutStrLn $ name ++ " is unconscious" |
161 | gFocus' . eSeqVal .= Nothing | 163 | gFocus' . eSeqVal .= Nothing |
162 | gFocus .= Nothing | 164 | gFocus .= Nothing |
165 | void $ do | ||
166 | round <- use gRound | ||
167 | let | ||
168 | finished sVal = fromMaybe False (previews (seqVal . _Just) (<= 0) sVal) || view (seqRound . _Wrapped) sVal /= round | ||
169 | allFinished <- getAll . foldMapOf (gEntities . each . eStats . sSequence . _Just) (All . finished) <$> get | ||
170 | when allFinished $ do | ||
171 | let | ||
172 | advanceRound' :: EntityIdentifier -> Entity -> Sh GameState Entity | ||
173 | advanceRound' ident entity = fmap (fromMaybe entity . (\(m, s) -> s <$ m)) . (runStateT ?? entity) . runMaybeT $ do | ||
174 | cRound <- MaybeT . preuse $ eStats . sSequence . _Just . seqRound . _Wrapped | ||
175 | guard $ cRound < 0 | ||
176 | cVal <- MaybeT . preuse $ eStats . sSequence . _Just . seqVal . _Just | ||
177 | name <- lift . lift $ toName ident | ||
178 | nVal' <- MaybeT . preuse $ eStats . sSeqVal | ||
179 | nVal <- MaybeT . focusState eStats $ evalFormula' name nVal' | ||
180 | eStats . sSequence . _Just . seqVal . _Just += nVal | ||
181 | eStats . sSequence . _Just . seqRound . _Wrapped += 1 | ||
182 | gRounds -= 1 | ||
183 | gEntities <~ (imapM advanceRound' =<< use gEntities) | ||
163 | 184 | ||
164 | -- Query state | 185 | -- Query state |
165 | listFactions, listEntities :: Sh GameState () | 186 | listFactions, listEntities :: Sh GameState () |
diff --git a/src/Sequence/Types.hs b/src/Sequence/Types.hs index 59397d5..4aa55d3 100644 --- a/src/Sequence/Types.hs +++ b/src/Sequence/Types.hs | |||
@@ -159,4 +159,4 @@ gRounds' :: Getter GameState [Int] | |||
159 | gRounds' = to $ nub . sort . toListOf gRounds | 159 | gRounds' = to $ nub . sort . toListOf gRounds |
160 | 160 | ||
161 | gRound :: Getter GameState Int | 161 | gRound :: Getter GameState Int |
162 | gRound = to $ getMin . (<> Min 0) . view (gRounds . _Unwrapped) | 162 | gRound = to $ fromMaybe 0 . minimumOf gRounds |
diff --git a/src/Sequence/Utils.hs b/src/Sequence/Utils.hs index dc6657a..513cb0b 100644 --- a/src/Sequence/Utils.hs +++ b/src/Sequence/Utils.hs | |||
@@ -61,7 +61,7 @@ withFocus f = use gFocus >>= maybe (shellPutErrLn $ "Currently not focusing any | |||
61 | withFocus' :: (Entity -> Sh GameState a) -> Sh GameState (Maybe a) | 61 | withFocus' :: (Entity -> Sh GameState a) -> Sh GameState (Maybe a) |
62 | 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) |
63 | 63 | ||
64 | focusState :: MonadState GameState m => Traversal' GameState a -> StateT a (MaybeT m) b -> m (Maybe b) | 64 | focusState :: MonadState s m => Traversal' s a -> StateT a (MaybeT m) b -> m (Maybe b) |
65 | focusState lens action = runMaybeT $ uncurry (<$) . over _2 (lens .=) =<< runStateT action =<< MaybeT (preuse lens) | 65 | focusState lens action = runMaybeT $ uncurry (<$) . over _2 (lens .=) =<< runStateT action =<< MaybeT (preuse lens) |
66 | 66 | ||
67 | unaligned = view faction' def | 67 | unaligned = view faction' def |