summaryrefslogtreecommitdiff
path: root/src/Sequence/Contact
diff options
context:
space:
mode:
Diffstat (limited to 'src/Sequence/Contact')
-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
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
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