diff options
author | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2016-08-12 16:35:55 +0200 |
---|---|---|
committer | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2016-08-12 16:35:55 +0200 |
commit | e65e3f11fe911a6ca1009cf35f4b3e7ca907c459 (patch) | |
tree | 1bba57124a382f4d4bc81272cbc61f82bdc8e0ce /src | |
parent | c0e64e4f383a1a64ff0cb7e40ac3256726fc82b6 (diff) | |
download | 2017-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.hs | 17 | ||||
-rw-r--r-- | src/Sequence/Contact/Tests.hs | 3 | ||||
-rw-r--r-- | src/Sequence/Contact/Types.hs | 54 | ||||
-rw-r--r-- | src/Sequence/Contact/Types/Internal.hs | 9 |
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 |
276 | rollTest :: Completable (FormulaM Stats Test) -> Sh GameState () | 276 | rollTest :: Completable (FormulaM Stats Test) -> Sh GameState () |
277 | rollTest = withArg $ maybe (return ()) outputResult <=< enactTest' | 277 | rollTest = 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 | |||
298 | enactTest' :: FormulaM Stats Test -> Sh GameState (Maybe (String, TestResult)) | 311 | enactTest' :: FormulaM Stats Test -> Sh GameState (Maybe (String, TestResult)) |
299 | enactTest' test = runMaybeT $ do | 312 | enactTest' 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 | ||
3 | module Sequence.Contact.Types | 3 | module Sequence.Contact.Types |
4 | ( module Sequence.Contact.Types | 4 | ( module Sequence.Contact.Types |
@@ -8,7 +8,7 @@ module Sequence.Contact.Types | |||
8 | import Sequence.Formula | 8 | import Sequence.Formula |
9 | 9 | ||
10 | import Control.Monad | 10 | import Control.Monad |
11 | import Control.Lens | 11 | import Control.Lens hiding (Context) |
12 | 12 | ||
13 | import Data.Default | 13 | import Data.Default |
14 | 14 | ||
@@ -25,8 +25,9 @@ import Data.Ratio | |||
25 | import Data.List | 25 | import Data.List |
26 | import Data.Ord | 26 | import Data.Ord |
27 | import Data.ExtendedReal | 27 | import Data.ExtendedReal |
28 | import Data.Monoid (Monoid(..), (<>)) | ||
28 | 29 | ||
29 | import Control.Monad.Reader (ask) | 30 | import Control.Monad.Reader (ask, local) |
30 | import Control.Monad.State | 31 | import Control.Monad.State |
31 | 32 | ||
32 | import Sequence.Contact.Types.Internal | 33 | import Sequence.Contact.Types.Internal |
@@ -44,18 +45,9 @@ makePrisms ''DamageType | |||
44 | instance {-# OVERLAPS #-} Default Armor where | 45 | instance {-# OVERLAPS #-} Default Armor where |
45 | def = const $ return 0 | 46 | def = const $ return 0 |
46 | 47 | ||
47 | makeLenses ''TestResult | 48 | makeLenses ''DiceResult |
48 | |||
49 | makeLenses ''Test | ||
50 | 49 | ||
51 | instance Default Test where | 50 | makeLenses ''TestResult |
52 | def = Test | ||
53 | { _tName = "" | ||
54 | , _tCritSuccessMod = 0 | ||
55 | , _tCritFailureMod = 0 | ||
56 | , _tBaseDifficulty = 50 | ||
57 | , _tMod = 0 | ||
58 | } | ||
59 | 51 | ||
60 | makePrisms ''Modifier | 52 | makePrisms ''Modifier |
61 | 53 | ||
@@ -79,12 +71,46 @@ instance Eq Effect where | |||
79 | instance Ord Effect where | 71 | instance Ord Effect where |
80 | compare = compare `on` (view effectName) | 72 | compare = compare `on` (view effectName) |
81 | 73 | ||
74 | instance Show Effect where | ||
75 | show = show . view effectName | ||
76 | |||
82 | instance Default Effect where | 77 | instance Default Effect where |
83 | def = Effect "" $ preview ctx | 78 | def = Effect "" $ preview ctx |
84 | 79 | ||
80 | instance 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 | |||
85 | effect :: String -> Effect | 95 | effect :: String -> Effect |
86 | effect str = def & set effectName str | 96 | effect str = def & set effectName str |
87 | 97 | ||
98 | makeLenses ''Test | ||
99 | |||
100 | instance 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 | |||
110 | deriving instance Eq TestResult | ||
111 | deriving instance Ord TestResult | ||
112 | deriving instance Show TestResult | ||
113 | |||
88 | makePrisms ''SeqVal | 114 | makePrisms ''SeqVal |
89 | makeLenses ''SeqVal | 115 | makeLenses ''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 | ||
53 | data TestResult = CritSuccess { _rWith, _rBy :: Int } | 53 | data 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 | ||
59 | data TestResult = TestResult | ||
60 | { _rRoll :: DiceResult | ||
61 | , _rResult :: Effect | ||
62 | } | ||
63 | |||
59 | data Test = Test | 64 | data 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 | ||
68 | data Modifier = Modifier (CI String) (Test -> FormulaM Stats Test) | 73 | data Modifier = Modifier (CI String) (Test -> FormulaM Stats Test) |
69 | 74 | ||