diff options
Diffstat (limited to 'src/Sequence/Contact')
-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 |
3 files changed, 49 insertions, 17 deletions
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 | ||