summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-06-14 03:26:18 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2016-06-14 03:26:18 +0200
commitd196ace4100ec5f8cfb0fad265d3baa44873fc9d (patch)
tree6f6714769e2d539b70aef2f06ea0d7e16e46855e /src
parent0c5fe56414a323f49d7b086c0a64a216443a22bb (diff)
download2017-01-16_17:13:37-d196ace4100ec5f8cfb0fad265d3baa44873fc9d.tar
2017-01-16_17:13:37-d196ace4100ec5f8cfb0fad265d3baa44873fc9d.tar.gz
2017-01-16_17:13:37-d196ace4100ec5f8cfb0fad265d3baa44873fc9d.tar.bz2
2017-01-16_17:13:37-d196ace4100ec5f8cfb0fad265d3baa44873fc9d.tar.xz
2017-01-16_17:13:37-d196ace4100ec5f8cfb0fad265d3baa44873fc9d.zip
fixed questions
Diffstat (limited to 'src')
-rw-r--r--src/Main.hs14
-rw-r--r--src/Sequence/Contact/Tests.hs5
-rw-r--r--src/Sequence/Contact/Types.hs20
-rw-r--r--src/Sequence/Formula.hs55
-rw-r--r--src/Sequence/Utils.hs2
5 files changed, 51 insertions, 45 deletions
diff --git a/src/Main.hs b/src/Main.hs
index 3e6b750..636e5ea 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -62,8 +62,6 @@ import qualified Data.Text.Lazy as Lazy (Text)
62import qualified Data.Text.Lazy as Lazy.Text 62import qualified Data.Text.Lazy as Lazy.Text
63import Data.Text.Template 63import Data.Text.Template
64 64
65import Debug.Trace
66
67main :: IO () 65main :: IO ()
68main = do 66main = do
69 historyFile <- getUserCacheFile "sequence" "history" 67 historyFile <- getUserCacheFile "sequence" "history"
@@ -158,7 +156,7 @@ stateMaintenance = do
158 lStats = gEntities . ix focusId . eStats 156 lStats = gEntities . ix focusId . eStats
159 evalF formula = do 157 evalF formula = do
160 stats <- MaybeT $ preuse lStats 158 stats <- MaybeT $ preuse lStats
161 (nStats, x) <- (evalFormula name :: Stats -> FormulaM Stats a -> MaybeT (Sh GameState) (Stats, a)) stats formula 159 (nStats, x) <- (evalFormula [name] :: Stats -> FormulaM Stats a -> MaybeT (Sh GameState) (Stats, a)) stats formula
162 lStats .= nStats 160 lStats .= nStats
163 return x 161 return x
164 isDead <- evalF =<< MaybeT (preuse $ lStats . sDead) 162 isDead <- evalF =<< MaybeT (preuse $ lStats . sDead)
@@ -182,7 +180,7 @@ stateMaintenance = do
182 cVal <- MaybeT . preuse $ eStats . sSequence . _Just . seqVal . _Just 180 cVal <- MaybeT . preuse $ eStats . sSequence . _Just . seqVal . _Just
183 name <- lift . lift $ toName ident 181 name <- lift . lift $ toName ident
184 nVal' <- MaybeT . preuse $ eStats . sSeqVal 182 nVal' <- MaybeT . preuse $ eStats . sSeqVal
185 nVal <- MaybeT . focusState eStats $ evalFormula' name nVal' 183 nVal <- MaybeT . focusState eStats $ evalFormula' [name] nVal'
186 eStats . sSequence . _Just . seqVal . _Just += nVal 184 eStats . sSequence . _Just . seqVal . _Just += nVal
187 eStats . sSequence . _Just . seqRound . _Wrapped += 1 185 eStats . sSequence . _Just . seqRound . _Wrapped += 1
188 gRounds -= 1 186 gRounds -= 1
@@ -274,7 +272,7 @@ rollTest = withArg $ enactTest' >=> maybe (return ()) (shellPutStrLn . ppResult)
274enactTest' :: (FormulaM Stats Test) -> Sh GameState (Maybe TestResult) 272enactTest' :: (FormulaM Stats Test) -> Sh GameState (Maybe TestResult)
275enactTest' test = withFocus' $ \focus -> do 273enactTest' test = withFocus' $ \focus -> do
276 focusName <- use gFocus >>= toName . fromJust 274 focusName <- use gFocus >>= toName . fromJust
277 (newFocus, result) <- evalFormula focusName focus (enactTest =<< test) 275 (newFocus, result) <- evalFormula [focusName] focus (enactTest =<< test)
278 gFocus' .= newFocus 276 gFocus' .= newFocus
279 return result 277 return result
280 278
@@ -290,7 +288,7 @@ entitySeqVal' ident = void . runMaybeT $ do
290 sVal <- MaybeT . return $ preview (eStats . sSeqVal) entity 288 sVal <- MaybeT . return $ preview (eStats . sSeqVal) entity
291 name <- toName ident 289 name <- toName ident
292 round <- use gRound 290 round <- use gRound
293 (newEntity, sNum) <- evalFormula name entity sVal 291 (newEntity, sNum) <- evalFormula [name] entity sVal
294 let val = Just $ def 292 let val = Just $ def
295 & set (seqRound . _Wrapped) round 293 & set (seqRound . _Wrapped) round
296 & set seqVal (Just sNum) 294 & set seqVal (Just sNum)
@@ -329,7 +327,7 @@ doShock dmg efLens = withFocus $ \focusId -> do
329 -- (nStats, x) <- (evalFormula name :: Stats -> FormulaM Stats a -> MaybeT (Sh GameState) (Stats, a)) stats formula 327 -- (nStats, x) <- (evalFormula name :: Stats -> FormulaM Stats a -> MaybeT (Sh GameState) (Stats, a)) stats formula
330 -- lStats .= nStats 328 -- lStats .= nStats
331 -- return x 329 -- return x
332 evalF = MaybeT . focusState lStats . evalFormula' name 330 evalF = MaybeT . focusState lStats . evalFormula' [name]
333 cVar cLens = evalF =<< MaybeT (preuse $ lStats . (cripple ^. cLens)) 331 cVar cLens = evalF =<< MaybeT (preuse $ lStats . (cripple ^. cLens))
334 bar <- cVar seBar 332 bar <- cVar seBar
335 val <- cVar seVal 333 val <- cVar seVal
@@ -350,7 +348,7 @@ takeHit dmg a1 a2 = flip withArg a1 $ \zones -> flip withArg a2 $ \dType -> with
350 lStats = gEntities . ix focusId . eStats 348 lStats = gEntities . ix focusId . eStats
351 name <- toName focusId 349 name <- toName focusId
352 armor <- MaybeT . preuse $ lStats . sArmor . ix zone 350 armor <- MaybeT . preuse $ lStats . sArmor . ix zone
353 dmg' <- MaybeT . focusState lStats . evalFormula' name $ absorb armor dType dmg 351 dmg' <- MaybeT . focusState lStats . evalFormula' [name] $ absorb armor dType dmg
354 forM_ (Map.toList dmg') $ \(dType, dmg) -> lift . runMaybeT $ do 352 forM_ (Map.toList dmg') $ \(dType, dmg) -> lift . runMaybeT $ do
355 guard $ dmg > 0 353 guard $ dmg > 0
356 lift $ shellPutStrLn $ name ++ " took " ++ show dmg ++ " " ++ show dType 354 lift $ shellPutStrLn $ name ++ " took " ++ show dmg ++ " " ++ show dType
diff --git a/src/Sequence/Contact/Tests.hs b/src/Sequence/Contact/Tests.hs
index 8665186..c100ce9 100644
--- a/src/Sequence/Contact/Tests.hs
+++ b/src/Sequence/Contact/Tests.hs
@@ -40,7 +40,7 @@ tests = do
40 40
41 views sExtraSkills (baseTests <>) 41 views sExtraSkills (baseTests <>)
42 where 42 where
43 test k v = maybe mempty (Map.singleton k) <$> preview v 43 test k v = maybe mempty (Map.singleton k) <$> previews v (set (mapped . tName) k)
44 44
45 skillTest = to (\x -> flip (set tBaseDifficulty) def <$> x) 45 skillTest = to (\x -> flip (set tBaseDifficulty) def <$> x)
46 attributeTest = to (\x -> flip (set tBaseDifficulty) def . (* 10) <$> x) 46 attributeTest = to (\x -> flip (set tBaseDifficulty) def . (* 10) <$> x)
@@ -61,10 +61,11 @@ instance Argument (FormulaM Stats Test) GameState where
61enactTest :: Test -> FormulaM Stats TestResult 61enactTest :: Test -> FormulaM Stats TestResult
62enactTest rawTest = do 62enactTest rawTest = do
63 test <- foldM (&) rawTest =<< toListOf (ctx . sModifiers . folded . _Modifier . _2) <$> ask 63 test <- foldM (&) rawTest =<< toListOf (ctx . sModifiers . folded . _Modifier . _2) <$> ask
64 manualMod <- val ignored [CI.original (rawTest ^. tName), "Modifier"] False
64 let 65 let
65 critFailureBar = 95 - test^.tCritFailureMod 66 critFailureBar = 95 - test^.tCritFailureMod
66 critSuccessBar = 5 + test^.tCritSuccessMod 67 critSuccessBar = 5 + test^.tCritSuccessMod
67 bar = test^.tBaseDifficulty + test^.tMod 68 bar = test^.tBaseDifficulty + test^.tMod + manualMod
68 toResult pw = (toResult' pw) pw (abs $ bar - pw) 69 toResult pw = (toResult' pw) pw (abs $ bar - pw)
69 toResult' pw 70 toResult' pw
70 | bar > critSuccessBar 71 | bar > critSuccessBar
diff --git a/src/Sequence/Contact/Types.hs b/src/Sequence/Contact/Types.hs
index 9bb9903..4bd9790 100644
--- a/src/Sequence/Contact/Types.hs
+++ b/src/Sequence/Contact/Types.hs
@@ -130,16 +130,16 @@ applyModifier effectName modifier = Effect (CI.mk effectName) $ previews ctx app
130 where 130 where
131 apply = sModifiers <>~ [Modifier (CI.mk $ effectName ++ " (modifier)") modifier] 131 apply = sModifiers <>~ [Modifier (CI.mk $ effectName ++ " (modifier)") modifier]
132 132
133vStrength = val sAStrength "Stärke?" True 133vStrength = val sAStrength ["Stärke"] True
134vEndurance = val sAEndurance "Ausdauer?" True 134vEndurance = val sAEndurance ["Ausdauer"] True
135vMass = val sAMass "Masse?" True 135vMass = val sAMass ["Masse"] True
136vReflexes = val sAReflexes "Reflexe?" True 136vReflexes = val sAReflexes ["Reflexe"] True
137vMobility = val sAMobility "Beweglichkeit?" True 137vMobility = val sAMobility ["Beweglichkeit"] True
138vDexterity = val sADexterity "Geschicklichkeit?" True 138vDexterity = val sADexterity ["Geschicklichkeit"] True
139vIntelligence = val sAIntelligence "Intelligenz?" True 139vIntelligence = val sAIntelligence ["Intelligenz"] True
140vCharisma = val sACharisma "Charisma?" True 140vCharisma = val sACharisma ["Charisma"] True
141vPerception = val sAPerception "Wahrnehmung?" True 141vPerception = val sAPerception ["Wahrnehmung"] True
142vWillpower = val sAWillpower "Entschlossenheit?" True 142vWillpower = val sAWillpower ["Entschlossenheit"] True
143 143
144scaled :: Ratio Int -> Iso' Int Int 144scaled :: Ratio Int -> Iso' Int Int
145scaled r = iso (\x -> floor $ x % 1 * r) (\x -> round $ x % 1 / r) 145scaled r = iso (\x -> floor $ x % 1 * r) (\x -> round $ x % 1 / r)
diff --git a/src/Sequence/Formula.hs b/src/Sequence/Formula.hs
index 4830788..be5032a 100644
--- a/src/Sequence/Formula.hs
+++ b/src/Sequence/Formula.hs
@@ -1,4 +1,4 @@
1{-# LANGUAGE RecordWildCards, RankNTypes, TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses, ViewPatterns, TypeFamilies, GADTs, TypeOperators, ExistentialQuantification, FlexibleContexts #-} 1{-# LANGUAGE RecordWildCards, RankNTypes, TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses, ViewPatterns, TypeFamilies, GADTs, TypeOperators, ExistentialQuantification, FlexibleContexts, IncoherentInstances #-}
2 2
3module Sequence.Formula 3module Sequence.Formula
4 ( FormulaM, Formula, quot' 4 ( FormulaM, Formula, quot'
@@ -30,12 +30,12 @@ import Data.Maybe
30import Data.Either 30import Data.Either
31import Data.Tuple 31import Data.Tuple
32 32
33import Data.Set (Set)
34import qualified Data.Set as Set
35
36import Data.Map (Map) 33import Data.Map (Map)
37import qualified Data.Map as Map 34import qualified Data.Map as Map
38 35
36import Data.Set (Set)
37import qualified Data.Set as Set
38
39class (:<:) small large where 39class (:<:) small large where
40 ctx' :: Traversal' large small 40 ctx' :: Traversal' large small
41 41
@@ -45,21 +45,27 @@ instance a :<: a where
45instance a :<: (a, a) where 45instance a :<: (a, a) where
46 ctx' = both 46 ctx' = both
47 47
48instance a :<: (a, b) where 48instance a :<: b => a :<: (b, c) where
49 ctx' = _1 49 ctx' = _1 . ctx'
50 50
51instance a :<: (b, a) where 51instance a :<: (c, a) where
52 ctx' = _2 52 ctx' = _2
53 53
54instance () :<: a where 54instance () :<: a where
55 ctx' = united 55 ctx' = united
56 56
57data Context small = forall large. (small :<: large) => Context large 57instance a :<: b => a :<: Maybe b where
58 ctx' = _Just . ctx'
59
60data Context small = forall large. (small :<: large) => Context large (Maybe (Formula small))
58 61
59ctx :: Traversal' (Context input) input 62ctx :: Traversal' (Context input) input
60ctx modifySmall (Context large) = Context <$> ctx' modifySmall large 63ctx modifySmall (Context large fSt) = flip Context fSt <$> ctx' modifySmall large
64
65ctxStore :: Traversal' (Context input) (Formula input)
66ctxStore modifyF (Context large fSt) = Context large <$> _Just modifyF fSt
61 67
62type FormulaM input a = StateT (Set String) (ReaderT (Context input) (ExceptT (Question input) EventM)) a 68type FormulaM input a = StateT (Set [String]) (ReaderT (Context input) (ExceptT (Question input) EventM)) a
63 69
64type Formula input = FormulaM input Int 70type Formula input = FormulaM input Int
65 71
@@ -68,7 +74,7 @@ instance MonadBase EventM EventM where
68 74
69data Question input = Question 75data Question input = Question
70 { answer :: Traversal' input (Formula input) 76 { answer :: Traversal' input (Formula input)
71 , prompt :: String 77 , prompt :: [String]
72 , keepResult :: Bool 78 , keepResult :: Bool
73 } 79 }
74 80
@@ -94,29 +100,30 @@ instance Integral a => Num (FormulaM input a) where
94quot' :: Integral a => FormulaM input a -> FormulaM input a -> FormulaM input a 100quot' :: Integral a => FormulaM input a -> FormulaM input a -> FormulaM input a
95quot' = liftM2 quot 101quot' = liftM2 quot
96 102
97askQuestion :: (MonadIO m, sInput :<: lInput) => String -> lInput -> Question sInput -> m lInput 103askQuestion :: (MonadIO m, sInput :<: lInput) => [String] -> (lInput, Maybe (Formula sInput)) -> Question sInput -> m (lInput, Maybe (Formula sInput))
98askQuestion promptPref input q@(Question{..}) = flip (set $ ctx' . answer) input . maybe (throwError q) return <$> askQ (promptPref' ++ prompt) (join . fmap readMaybe) 104askQuestion promptPref input q@(Question{..}) = flip (if keepResult then set $ _1 . ctx' . answer else set _2 . Just) input . maybe (throwError q) return <$> askQ (wPromptPref $ promptPref ++ prompt) (join . fmap readMaybe)
99 where 105 where
100 promptPref' 106 wPromptPref [] = " »"
101 | null promptPref = "" 107 wPromptPref [x] = x ++ " »"
102 | otherwise = promptPref ++ " » " 108 wPromptPref (x:xs) = x ++ " » " ++ wPromptPref xs
103 109
104evalFormula :: (MonadIO m, sInput :<: lInput) => String -> lInput -> FormulaM sInput a -> m (lInput, a) 110evalFormula :: (MonadIO m, sInput :<: lInput) => [String] -> lInput -> FormulaM sInput a -> m (lInput, a)
105evalFormula = evalFormula' [] 111evalFormula promptPref input = evalFormula' [] promptPref (input, Nothing)
106 where 112 where
107 evalFormula' finalChanges promptPref input formula = do 113 evalFormula' :: (MonadIO m, sInput :<: lInput) => [lInput -> lInput] -> [String] -> (lInput, Maybe (Formula sInput)) -> FormulaM sInput a -> m (lInput, a)
108 result <- liftIO . enact . runExceptT . (runReaderT ?? (Context input)) . (evalStateT ?? Set.empty) $ formula 114 evalFormula' finalChanges promptPref (input, fSt) formula = do
115 result <- liftIO . enact . runExceptT . (runReaderT ?? (Context input fSt)) . (evalStateT ?? Set.empty) $ formula
109 case result of 116 case result of
110 Left q@(Question{..}) -> askQuestion promptPref input q >>= flip (flip evalFormula' promptPref $ bool (pure . set (ctx' . answer) $ throwError q) mempty keepResult ++ finalChanges) formula 117 Left q@(Question{..}) -> askQuestion promptPref (input, fSt) q >>= flip (flip evalFormula' promptPref $ set (ctx' . answer) (throwError q) : finalChanges) formula
111 Right result -> return (foldr ($) input finalChanges, result) 118 Right result -> return (foldr ($) input finalChanges, result)
112 119
113evalFormula' :: (MonadIO m, sInput :<: lInput, MonadState lInput m) => String -> FormulaM sInput a -> m a 120evalFormula' :: (MonadIO m, sInput :<: lInput, MonadState lInput m) => [String] -> FormulaM sInput a -> m a
114evalFormula' promptPref formula = uncurry (<$) . over _2 put . swap =<< flip (evalFormula promptPref) formula =<< get 121evalFormula' promptPref formula = uncurry (<$) . over _2 put . swap =<< flip (evalFormula promptPref) formula =<< get
115 122
116val :: Integral a => Traversal' input (Formula input) -> String -> Bool -> Formula input 123val :: Traversal' input (Formula input) -> [String] -> Bool -> Formula input
117val answer prompt keepResult = do 124val answer prompt keepResult = do
118 gets (Set.member prompt) >>= bool (modify $ Set.insert prompt) (modify (Set.delete prompt) >> throwError Question{..}) 125 gets (Set.member prompt) >>= bool (modify $ Set.insert prompt) (modify (Set.delete prompt) >> throwError Question{..})
119 preview (ctx . answer) >>= maybe (throwError Question{..}) id 126 preview (if keepResult then ctx . answer else ctxStore) >>= (modify (Set.delete prompt) >>) . fromMaybe (throwError Question{..})
120 127
121d, z :: Integral a => Int -> FormulaM input a 128d, z :: Integral a => Int -> FormulaM input a
122d n = liftBase . fmap fromIntegral $ D.d n 129d n = liftBase . fmap fromIntegral $ D.d n
diff --git a/src/Sequence/Utils.hs b/src/Sequence/Utils.hs
index 513cb0b..929189e 100644
--- a/src/Sequence/Utils.hs
+++ b/src/Sequence/Utils.hs
@@ -77,7 +77,7 @@ toDesc :: (MonadState GameState m, MonadIO m) => EntityIdentifier -> m String
77toDesc ident = do 77toDesc ident = do
78 name <- toName ident 78 name <- toName ident
79 health <- runMaybeT $ do 79 health <- runMaybeT $ do
80 maxVit <- MaybeT . focusState (gEntities . ix ident) . evalFormula' name =<< (MaybeT . preuse $ gEntities . ix ident . eStats . sMaxVitality) 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 81 hDamage <- MaybeT . preuse $ gEntities . ix ident . eStats . sTotalDamage
82 fDamage <- MaybeT . preuse $ gEntities . ix ident . eStats . sFatigue 82 fDamage <- MaybeT . preuse $ gEntities . ix ident . eStats . sFatigue
83 return $ (maxVit - hDamage, maxVit - fDamage) 83 return $ (maxVit - hDamage, maxVit - fDamage)