summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGregor Kleen <pngwjpgh@users.noreply.github.com>2016-08-12 16:35:55 +0200
committerGregor Kleen <pngwjpgh@users.noreply.github.com>2016-08-12 16:35:55 +0200
commite65e3f11fe911a6ca1009cf35f4b3e7ca907c459 (patch)
tree1bba57124a382f4d4bc81272cbc61f82bdc8e0ce /src
parentc0e64e4f383a1a64ff0cb7e40ac3256726fc82b6 (diff)
download2017-01-16_17:13:37-e65e3f11fe911a6ca1009cf35f4b3e7ca907c459.tar
2017-01-16_17:13:37-e65e3f11fe911a6ca1009cf35f4b3e7ca907c459.tar.gz
2017-01-16_17:13:37-e65e3f11fe911a6ca1009cf35f4b3e7ca907c459.tar.bz2
2017-01-16_17:13:37-e65e3f11fe911a6ca1009cf35f4b3e7ca907c459.tar.xz
2017-01-16_17:13:37-e65e3f11fe911a6ca1009cf35f4b3e7ca907c459.zip
support for tests applying effects
Diffstat (limited to 'src')
-rw-r--r--src/Main.hs17
-rw-r--r--src/Sequence/Contact/Tests.hs3
-rw-r--r--src/Sequence/Contact/Types.hs54
-rw-r--r--src/Sequence/Contact/Types/Internal.hs9
4 files changed, 64 insertions, 19 deletions
diff --git a/src/Main.hs b/src/Main.hs
index 2d9f876..3b7b3f5 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -274,10 +274,10 @@ spawnFaction cFaction num cEntity nameTemplate
274 274
275-- Dice rolls 275-- Dice rolls
276rollTest :: Completable (FormulaM Stats Test) -> Sh GameState () 276rollTest :: Completable (FormulaM Stats Test) -> Sh GameState ()
277rollTest = withArg $ maybe (return ()) outputResult <=< enactTest' 277rollTest = withArg $ maybe (return ()) ((>>) <$> outputResult <*> applyEffect) <=< enactTest'
278 where 278 where
279 outputResult :: (String, TestResult) -> Sh GameState () 279 outputResult :: (String, TestResult) -> Sh GameState ()
280 outputResult (test, ppResult -> result) = do 280 outputResult (test, view (rRoll . to ppResult) -> result) = do
281 focusId <- use gFocus 281 focusId <- use gFocus
282 case focusId of 282 case focusId of
283 Nothing -> shellPutStrLn result 283 Nothing -> shellPutStrLn result
@@ -295,6 +295,19 @@ rollTest = withArg $ maybe (return ()) outputResult <=< enactTest'
295 | length str >= n = str 295 | length str >= n = str
296 | otherwise = ' ' : pad (n - 1) str 296 | otherwise = ' ' : pad (n - 1) str
297 297
298
299 applyEffect :: (String, TestResult) -> Sh GameState ()
300 applyEffect (test, view rResult -> (Effect (CI.original -> effectDesc) effect)) = void . runMaybeT $ do
301 focusId <- MaybeT $ use gFocus
302 name <- toName focusId
303 let
304 lStats :: Traversal' GameState Stats
305 lStats = gEntities . ix focusId . eStats
306 evalF = MaybeT . focusState lStats . evalFormula' [name]
307 guard =<< askBool ("Apply effects (" ++ effectDesc ++ ")?") True
308 lStats <~ (MaybeT . fmap join . runMaybeT $ evalF effect)
309 lift . outputLogged focusId $ test ++ " effects: " ++ effectDesc
310
298enactTest' :: FormulaM Stats Test -> Sh GameState (Maybe (String, TestResult)) 311enactTest' :: FormulaM Stats Test -> Sh GameState (Maybe (String, TestResult))
299enactTest' test = runMaybeT $ do 312enactTest' test = runMaybeT $ do
300 focusName <- MaybeT (use gFocus) >>= lift . toName 313 focusName <- MaybeT (use gFocus) >>= lift . toName
diff --git a/src/Sequence/Contact/Tests.hs b/src/Sequence/Contact/Tests.hs
index 2c21834..81b8d3c 100644
--- a/src/Sequence/Contact/Tests.hs
+++ b/src/Sequence/Contact/Tests.hs
@@ -117,7 +117,8 @@ enactTest rawTest = do
117 | pw <= bar = Success 117 | pw <= bar = Success
118 | pw >= critFailureBar = CritFailure 118 | pw >= critFailureBar = CritFailure
119 | otherwise = Failure 119 | otherwise = Failure
120 toResult <$> d 100 120 dResult <- toResult <$> d 100
121 TestResult <$> pure dResult <*> (test ^. tEffect) dResult
121 122
122-- hasTest :: Stats -> String -> Bool 123-- hasTest :: Stats -> String -> Bool
123-- hasTest stats str = has (getTest str) stats 124-- hasTest stats str = has (getTest str) stats
diff --git a/src/Sequence/Contact/Types.hs b/src/Sequence/Contact/Types.hs
index ca7da1f..12283b9 100644
--- a/src/Sequence/Contact/Types.hs
+++ b/src/Sequence/Contact/Types.hs
@@ -1,4 +1,4 @@
1{-# LANGUAGE TemplateHaskell, RecordWildCards, OverloadedStrings, OverloadedLists, ViewPatterns, RankNTypes, ImpredicativeTypes, FlexibleContexts, TypeSynonymInstances, FlexibleInstances #-} 1{-# LANGUAGE TemplateHaskell, RecordWildCards, OverloadedStrings, OverloadedLists, ViewPatterns, RankNTypes, ImpredicativeTypes, FlexibleContexts, TypeSynonymInstances, FlexibleInstances, StandaloneDeriving #-}
2 2
3module Sequence.Contact.Types 3module Sequence.Contact.Types
4 ( module Sequence.Contact.Types 4 ( module Sequence.Contact.Types
@@ -8,7 +8,7 @@ module Sequence.Contact.Types
8import Sequence.Formula 8import Sequence.Formula
9 9
10import Control.Monad 10import Control.Monad
11import Control.Lens 11import Control.Lens hiding (Context)
12 12
13import Data.Default 13import Data.Default
14 14
@@ -25,8 +25,9 @@ import Data.Ratio
25import Data.List 25import Data.List
26import Data.Ord 26import Data.Ord
27import Data.ExtendedReal 27import Data.ExtendedReal
28import Data.Monoid (Monoid(..), (<>))
28 29
29import Control.Monad.Reader (ask) 30import Control.Monad.Reader (ask, local)
30import Control.Monad.State 31import Control.Monad.State
31 32
32import Sequence.Contact.Types.Internal 33import Sequence.Contact.Types.Internal
@@ -44,18 +45,9 @@ makePrisms ''DamageType
44instance {-# OVERLAPS #-} Default Armor where 45instance {-# OVERLAPS #-} Default Armor where
45 def = const $ return 0 46 def = const $ return 0
46 47
47makeLenses ''TestResult 48makeLenses ''DiceResult
48
49makeLenses ''Test
50 49
51instance Default Test where 50makeLenses ''TestResult
52 def = Test
53 { _tName = ""
54 , _tCritSuccessMod = 0
55 , _tCritFailureMod = 0
56 , _tBaseDifficulty = 50
57 , _tMod = 0
58 }
59 51
60makePrisms ''Modifier 52makePrisms ''Modifier
61 53
@@ -79,12 +71,46 @@ instance Eq Effect where
79instance Ord Effect where 71instance Ord Effect where
80 compare = compare `on` (view effectName) 72 compare = compare `on` (view effectName)
81 73
74instance Show Effect where
75 show = show . view effectName
76
82instance Default Effect where 77instance Default Effect where
83 def = Effect "" $ preview ctx 78 def = Effect "" $ preview ctx
84 79
80instance Monoid Effect where
81 mempty = def
82 (Effect aName aEff) `mappend` (Effect bName bEff) = Effect name $ do
83 new <- aEff
84 maybe
85 (id :: FormulaM Stats (Maybe Stats) -> FormulaM Stats (Maybe Stats))
86 (local :: (Context Stats -> Context Stats) -> FormulaM Stats (Maybe Stats) -> FormulaM Stats (Maybe Stats))
87 (set ctx <$> new :: Maybe (Context Stats -> Context Stats))
88 $ bEff
89 where
90 name
91 | aName /= ""
92 , bName /= "" = aName <> ", " <> bName
93 | otherwise = aName <> bName
94
85effect :: String -> Effect 95effect :: String -> Effect
86effect str = def & set effectName str 96effect str = def & set effectName str
87 97
98makeLenses ''Test
99
100instance Default Test where
101 def = Test
102 { _tName = ""
103 , _tCritSuccessMod = 0
104 , _tCritFailureMod = 0
105 , _tBaseDifficulty = 50
106 , _tMod = 0
107 , _tEffect = const $ pure (def :: Effect)
108 }
109
110deriving instance Eq TestResult
111deriving instance Ord TestResult
112deriving instance Show TestResult
113
88makePrisms ''SeqVal 114makePrisms ''SeqVal
89makeLenses ''SeqVal 115makeLenses ''SeqVal
90 116
diff --git a/src/Sequence/Contact/Types/Internal.hs b/src/Sequence/Contact/Types/Internal.hs
index e9bb268..ca4d022 100644
--- a/src/Sequence/Contact/Types/Internal.hs
+++ b/src/Sequence/Contact/Types/Internal.hs
@@ -50,20 +50,25 @@ data DamageType = Ballistic
50 | Passthrough 50 | Passthrough
51 deriving (Eq, Ord, Enum, Bounded, Show) 51 deriving (Eq, Ord, Enum, Bounded, Show)
52 52
53data TestResult = CritSuccess { _rWith, _rBy :: Int } 53data DiceResult = CritSuccess { _rWith, _rBy :: Int }
54 | Success { _rWith, _rBy :: Int } 54 | Success { _rWith, _rBy :: Int }
55 | Failure { _rWith, _rBy :: Int } 55 | Failure { _rWith, _rBy :: Int }
56 | CritFailure { _rWith, _rBy :: Int } 56 | CritFailure { _rWith, _rBy :: Int }
57 deriving (Eq, Ord, Show) 57 deriving (Eq, Ord, Show)
58 58
59data TestResult = TestResult
60 { _rRoll :: DiceResult
61 , _rResult :: Effect
62 }
63
59data Test = Test 64data Test = Test
60 { _tName :: CI String 65 { _tName :: CI String
61 , _tCritSuccessMod 66 , _tCritSuccessMod
62 , _tCritFailureMod 67 , _tCritFailureMod
63 , _tBaseDifficulty 68 , _tBaseDifficulty
64 , _tMod :: Int 69 , _tMod :: Int
70 , _tEffect :: DiceResult -> FormulaM Stats Effect
65 } 71 }
66 deriving (Eq, Ord)
67 72
68data Modifier = Modifier (CI String) (Test -> FormulaM Stats Test) 73data Modifier = Modifier (CI String) (Test -> FormulaM Stats Test)
69 74