diff options
Diffstat (limited to 'src/Sequence/Contact/Types.hs')
-rw-r--r-- | src/Sequence/Contact/Types.hs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/Sequence/Contact/Types.hs b/src/Sequence/Contact/Types.hs index c69a698..80d35d2 100644 --- a/src/Sequence/Contact/Types.hs +++ b/src/Sequence/Contact/Types.hs | |||
@@ -31,6 +31,7 @@ import Data.Dynamic.Lens | |||
31 | 31 | ||
32 | import Control.Monad.Reader (ask, local) | 32 | import Control.Monad.Reader (ask, local) |
33 | import Control.Monad.State | 33 | import Control.Monad.State |
34 | import Control.Monad.Trans.Maybe | ||
34 | 35 | ||
35 | import Sequence.Contact.Types.Internal | 36 | import Sequence.Contact.Types.Internal |
36 | 37 | ||
@@ -77,17 +78,17 @@ instance Show Effect where | |||
77 | show = show . view effectName | 78 | show = show . view effectName |
78 | 79 | ||
79 | instance Default Effect where | 80 | instance Default Effect where |
80 | def = Effect "" $ preview ctx | 81 | def = Effect "" mzero |
81 | 82 | ||
82 | instance Monoid Effect where | 83 | instance Monoid Effect where |
83 | mempty = def | 84 | mempty = def |
84 | (Effect aName aEff) `mappend` (Effect bName bEff) = Effect name $ do | 85 | (Effect aName aEff) `mappend` (Effect bName bEff) = Effect name . MaybeT $ do |
85 | new <- aEff | 86 | new <- runMaybeT aEff |
86 | maybe | 87 | maybe |
87 | (id :: FormulaM Stats (Maybe Stats) -> FormulaM Stats (Maybe Stats)) | 88 | (id :: FormulaM Stats (Maybe Stats) -> FormulaM Stats (Maybe Stats)) |
88 | (local :: (Context Stats -> Context Stats) -> FormulaM Stats (Maybe Stats) -> FormulaM Stats (Maybe Stats)) | 89 | (local :: (Context Stats -> Context Stats) -> FormulaM Stats (Maybe Stats) -> FormulaM Stats (Maybe Stats)) |
89 | (set ctx <$> new :: Maybe (Context Stats -> Context Stats)) | 90 | (set ctx <$> new :: Maybe (Context Stats -> Context Stats)) |
90 | $ bEff | 91 | $ runMaybeT bEff |
91 | where | 92 | where |
92 | name | 93 | name |
93 | | aName /= "" | 94 | | aName /= "" |
@@ -97,6 +98,9 @@ instance Monoid Effect where | |||
97 | effect :: String -> Effect | 98 | effect :: String -> Effect |
98 | effect str = def & set effectName str | 99 | effect str = def & set effectName str |
99 | 100 | ||
101 | instance IsString Effect where | ||
102 | fromString = effect | ||
103 | |||
100 | makeLenses ''Test | 104 | makeLenses ''Test |
101 | 105 | ||
102 | instance Default Test where | 106 | instance Default Test where |
@@ -106,7 +110,7 @@ instance Default Test where | |||
106 | , _tCritFailureMod = 0 | 110 | , _tCritFailureMod = 0 |
107 | , _tBaseDifficulty = 50 | 111 | , _tBaseDifficulty = 50 |
108 | , _tMod = 0 | 112 | , _tMod = 0 |
109 | , _tEffect = const $ pure (def :: Effect) | 113 | , _tEffect = const mzero |
110 | } | 114 | } |
111 | 115 | ||
112 | deriving instance Eq TestResult | 116 | deriving instance Eq TestResult |
@@ -174,7 +178,7 @@ instance Default Stats where | |||
174 | } | 178 | } |
175 | 179 | ||
176 | applyModifier :: String -> (Test -> FormulaM Stats Test) -> Effect | 180 | applyModifier :: String -> (Test -> FormulaM Stats Test) -> Effect |
177 | applyModifier effectName modifier = Effect (CI.mk effectName) $ previews ctx apply | 181 | applyModifier effectName modifier = Effect (CI.mk effectName) . MaybeT $ previews ctx apply |
178 | where | 182 | where |
179 | apply = sModifiers <>~ [Modifier (CI.mk $ effectName ++ " (modifier)") modifier] | 183 | apply = sModifiers <>~ [Modifier (CI.mk $ effectName ++ " (modifier)") modifier] |
180 | 184 | ||