summaryrefslogtreecommitdiff
path: root/src/Sequence/Contact
diff options
context:
space:
mode:
authorGregor Kleen <pngwjpgh@users.noreply.github.com>2017-01-16 18:10:17 +0100
committerGregor Kleen <pngwjpgh@users.noreply.github.com>2017-01-16 18:10:17 +0100
commitce890f4b6fd478bf5a254390f5bc49e4afd97c8c (patch)
treefb5a239a32b610470cbefbd279f465df89c5f5f1 /src/Sequence/Contact
parent7ff2052235140669bc9e9c5c1e94b194626dee67 (diff)
download2017-01-16_17:13:37-ce890f4b6fd478bf5a254390f5bc49e4afd97c8c.tar
2017-01-16_17:13:37-ce890f4b6fd478bf5a254390f5bc49e4afd97c8c.tar.gz
2017-01-16_17:13:37-ce890f4b6fd478bf5a254390f5bc49e4afd97c8c.tar.bz2
2017-01-16_17:13:37-ce890f4b6fd478bf5a254390f5bc49e4afd97c8c.tar.xz
2017-01-16_17:13:37-ce890f4b6fd478bf5a254390f5bc49e4afd97c8c.zip
Burstfirerewrite
Diffstat (limited to 'src/Sequence/Contact')
-rw-r--r--src/Sequence/Contact/Archetypes.hs61
-rw-r--r--src/Sequence/Contact/Tests.hs56
-rw-r--r--src/Sequence/Contact/Types.hs16
-rw-r--r--src/Sequence/Contact/Types/Internal.hs10
4 files changed, 96 insertions, 47 deletions
diff --git a/src/Sequence/Contact/Archetypes.hs b/src/Sequence/Contact/Archetypes.hs
index b8bc1b0..566d72d 100644
--- a/src/Sequence/Contact/Archetypes.hs
+++ b/src/Sequence/Contact/Archetypes.hs
@@ -75,11 +75,8 @@ archetypes = [ ("Requisite", prop)
75 , ("AUV", auv) 75 , ("AUV", auv)
76 ] 76 ]
77 77
78cTable :: Ord v => [(Integer, Integer, v)] -> Table v
79cTable = Map.fromList . map (\(from, to, value) -> (value, (abs (to - from) + 1) % 100))
80
81death :: Hitzone -> Effect 78death :: Hitzone -> Effect
82death zone = Effect "Tod" . runMaybeT $ do 79death zone = Effect "Tod" $ do
83 maxVitality <- (MaybeT . preview $ ctx . sMaxVitality) >>= lift 80 maxVitality <- (MaybeT . preview $ ctx . sMaxVitality) >>= lift
84 currentDmg <- MaybeT . preview $ ctx . sDamage' zone 81 currentDmg <- MaybeT . preview $ ctx . sDamage' zone
85 allDmg <- MaybeT . preview $ ctx . sTotalDamage 82 allDmg <- MaybeT . preview $ ctx . sTotalDamage
@@ -87,16 +84,16 @@ death zone = Effect "Tod" . runMaybeT $ do
87 dmg' = if dmg >= 0 then dmg else 0 84 dmg' = if dmg >= 0 then dmg else 0
88 MaybeT . previews ctx $ set (sDamage' zone) dmg' 85 MaybeT . previews ctx $ set (sDamage' zone) dmg'
89 86
90unconsciousR :: Formula Stats -> FormulaM Stats (Maybe Stats) 87unconsciousR :: Formula Stats -> FormulaMT MaybeT Stats Stats
91unconsciousR roundsF = do 88unconsciousR roundsF = do
92 rounds <- roundsF 89 rounds <- lift roundsF
93 previews ctx $ over (sSequence . _Just . seqRound . _Wrapped) (+ rounds) 90 MaybeT . previews ctx $ over (sSequence . _Just . seqRound . _Wrapped) (+ rounds)
94 91
95unconscious :: FormulaM Stats (Maybe Stats) 92unconscious :: FormulaMT MaybeT Stats Stats
96unconscious = previews ctx $ set sSequence Nothing 93unconscious = MaybeT . previews ctx $ set sSequence Nothing
97 94
98amputate :: Hitzone -> Effect 95amputate :: Hitzone -> Effect
99amputate zone = Effect (CI.mk $ review hitzone zone ++ " ist verloren") . runMaybeT $ do 96amputate zone = Effect (CI.mk $ review hitzone zone ++ " ist verloren") $ do
100 hitzones <- MaybeT . preview $ ctx . sHitzones 97 hitzones <- MaybeT . preview $ ctx . sHitzones
101 (fromRational -> zoneProp) <- MaybeT . return $ Map.lookup zone hitzones 98 (fromRational -> zoneProp) <- MaybeT . return $ Map.lookup zone hitzones
102 MaybeT . previews ctx . execState $ do 99 MaybeT . previews ctx . execState $ do
@@ -221,7 +218,7 @@ human = Humanoid
221 & set seBar (vitBar 0.75) 218 & set seBar (vitBar 0.75)
222 & set seReBar (vitBar 0.2) 219 & set seReBar (vitBar 0.2)
223 & set seEffect (cTable [ (1, 5, death "Torso") 220 & set seEffect (cTable [ (1, 5, death "Torso")
224 , (6, 25, Effect "Organschäden" . previews ctx $ over sFatigue (+ 25) . over (sDamage' "Torso") (+ 10)) 221 , (6, 25, Effect "Organschäden" . MaybeT . previews ctx $ over sFatigue (+ 25) . over (sDamage' "Torso") (+ 10))
225 , (26, 45, effect "Innere Blutung (3 Schaden (Au) Minuten)") 222 , (26, 45, effect "Innere Blutung (3 Schaden (Au) Minuten)")
226 , (46, 75, Effect "Bewusstlos" unconscious) 223 , (46, 75, Effect "Bewusstlos" unconscious)
227 , (76, 100, Effect "Bewusstlos" . unconsciousR $ d 10) 224 , (76, 100, Effect "Bewusstlos" . unconsciousR $ d 10)
@@ -234,7 +231,7 @@ human = Humanoid
234 & set seBar (vitBar 0.2) 231 & set seBar (vitBar 0.2)
235 & set seReBar (vitBar 0.2) 232 & set seReBar (vitBar 0.2)
236 & set seEffect ( cTable [ (1, 5, effect "Querschnittsgelähmt") 233 & set seEffect ( cTable [ (1, 5, effect "Querschnittsgelähmt")
237 , (6, 25, Effect "Kastration" . previews ctx $ over sFatigue (+ 15)) 234 , (6, 25, Effect "Kastration" . MaybeT . previews ctx $ over sFatigue (+ 15))
238 , (26, 50, effect "Innere Blutung (2 Schaden (Au) Minuten)") 235 , (26, 50, effect "Innere Blutung (2 Schaden (Au) Minuten)")
239 , (51, 100, Effect "Bewusstlos" unconscious) 236 , (51, 100, Effect "Bewusstlos" unconscious)
240 ]) 237 ])
@@ -255,14 +252,14 @@ human = Humanoid
255 , (6, 25, Effect "Koma" unconscious) 252 , (6, 25, Effect "Koma" unconscious)
256 , (26, 45, Effect "Bewusstlos" . unconsciousR $ d 10) 253 , (26, 45, Effect "Bewusstlos" . unconsciousR $ d 10)
257 , (46, 75, Effect "Bewusstlos" unconscious) 254 , (46, 75, Effect "Bewusstlos" unconscious)
258 , (76, 100, Effect "Verlangsamt" $ d 10 >>= (\loss -> previews ctx $ over (sSequence . _Just . seqVal . _Just) (+ (-loss)))) 255 , (76, 100, Effect "Verlangsamt" $ lift (d 10) >>= (\loss -> MaybeT . previews ctx $ over (sSequence . _Just . seqVal . _Just) (+ (-loss))))
259 ]) 256 ])
260 , _sFatigueShock = def 257 , _sFatigueShock = def
261 & set seReBar (vitBar 0.75) 258 & set seReBar (vitBar 0.75)
262 & set seEffect ( cTable [ (1, 25, Effect "Bewusstlos" . unconsciousR $ 2 * d 10) 259 & set seEffect ( cTable [ (1, 25, Effect "Bewusstlos" . unconsciousR $ 2 * d 10)
263 , (26, 50, Effect "Bewusstlos" . unconsciousR $ d 10) 260 , (26, 50, Effect "Bewusstlos" . unconsciousR $ d 10)
264 , (51, 75, Effect "Bewusstlos" unconscious) 261 , (51, 75, Effect "Bewusstlos" unconscious)
265 , (76, 100, Effect "Verlangsamt" $ 2 * d 10 >>= (\loss -> previews ctx $ over (sSequence . _Just . seqVal . _Just) (+ (-loss)))) 262 , (76, 100, Effect "Verlangsamt" $ lift (2 * d 10) >>= (\loss -> MaybeT . previews ctx $ over (sSequence . _Just . seqVal . _Just) (+ (-loss))))
266 ]) 263 ])
267 264
268 , _sExtraSkills = [] 265 , _sExtraSkills = []
@@ -278,7 +275,7 @@ human = Humanoid
278 & set seEffect (cTable [ (1, 10, amputate zone) 275 & set seEffect (cTable [ (1, 10, amputate zone)
279 , (11, 25, effect $ review hitzone zone ++ " ist gelähmt und unbrauchbar") 276 , (11, 25, effect $ review hitzone zone ++ " ist gelähmt und unbrauchbar")
280 , (26, 45, effect $ review hitzone zone ++ " hat eingeschränkte Funktion (-50%)") 277 , (26, 45, effect $ review hitzone zone ++ " hat eingeschränkte Funktion (-50%)")
281 , (46, 75, Effect "Schwerste Schmerzen" . previews ctx $ over sFatigue (+ 10)) 278 , (46, 75, Effect "Schwerste Schmerzen" . MaybeT . previews ctx $ over sFatigue (+ 10))
282 , (76, 100, effect "Fleischwunde") 279 , (76, 100, effect "Fleischwunde")
283 ]) 280 ])
284 bein zone = def 281 bein zone = def
@@ -287,7 +284,7 @@ human = Humanoid
287 & set seReBar (vitBar 0.2) 284 & set seReBar (vitBar 0.2)
288 & set seEffect (cTable [ (1, 10, amputate zone) 285 & set seEffect (cTable [ (1, 10, amputate zone)
289 , (11, 45, effect $ review hitzone zone ++ " ist gelähmt und unbrauchbar (halbierte Bewegung)") 286 , (11, 45, effect $ review hitzone zone ++ " ist gelähmt und unbrauchbar (halbierte Bewegung)")
290 , (46, 75, Effect "Schwerste Schmerzen" . previews ctx $ over sFatigue (+ 10)) 287 , (46, 75, Effect "Schwerste Schmerzen" . MaybeT . previews ctx $ over sFatigue (+ 10))
291 , (76, 100, effect "Fleischwunde") 288 , (76, 100, effect "Fleischwunde")
292 ]) 289 ])
293 290
@@ -343,7 +340,7 @@ dog = Quadruped
343 & set seBar (vitBar 0.75) 340 & set seBar (vitBar 0.75)
344 & set seReBar (vitBar 0.2) 341 & set seReBar (vitBar 0.2)
345 & set seEffect ( cTable [ (1, 5, death "Torso") 342 & set seEffect ( cTable [ (1, 5, death "Torso")
346 , (6, 25, Effect "Organschäden" . previews ctx $ over sFatigue (+ 25) . over (sDamage' "Torso") (+ 10)) 343 , (6, 25, Effect "Organschäden" . MaybeT . previews ctx $ over sFatigue (+ 25) . over (sDamage' "Torso") (+ 10))
347 , (26, 45, effect "Innere Blutung (3 Schaden (Au) Minuten)") 344 , (26, 45, effect "Innere Blutung (3 Schaden (Au) Minuten)")
348 , (46, 75, Effect "Bewusstlos" unconscious) 345 , (46, 75, Effect "Bewusstlos" unconscious)
349 , (76, 100, Effect "Bewusstlos" . unconsciousR $ d 10) 346 , (76, 100, Effect "Bewusstlos" . unconsciousR $ d 10)
@@ -354,7 +351,7 @@ dog = Quadruped
354 & set seBar (vitBar 0.2) 351 & set seBar (vitBar 0.2)
355 & set seReBar (vitBar 0.2) 352 & set seReBar (vitBar 0.2)
356 & set seEffect ( cTable [ (1, 5, effect "Querschnittsgelähmt") 353 & set seEffect ( cTable [ (1, 5, effect "Querschnittsgelähmt")
357 , (6, 25, Effect "Kastration" . previews ctx $ over sFatigue (+ 10)) 354 , (6, 25, Effect "Kastration" . MaybeT . previews ctx $ over sFatigue (+ 10))
358 , (26, 50, effect "Innere Blutung (2 Schaden (Au) Minuten)") 355 , (26, 50, effect "Innere Blutung (2 Schaden (Au) Minuten)")
359 , (51, 100, Effect "Bewusstlos" . unconsciousR $ 2 * d 10) 356 , (51, 100, Effect "Bewusstlos" . unconsciousR $ 2 * d 10)
360 ]) 357 ])
@@ -386,8 +383,8 @@ dog = Quadruped
386 & set seReBar (vitBar 0.2) 383 & set seReBar (vitBar 0.2)
387 & set seEffect ( cTable [ (1, 10, amputate zone) 384 & set seEffect ( cTable [ (1, 10, amputate zone)
388 , (11, 25, effect $ review hitzone zone ++ " ist gelähmt und unbrauchbar (halbierte Bewegung)") 385 , (11, 25, effect $ review hitzone zone ++ " ist gelähmt und unbrauchbar (halbierte Bewegung)")
389 , (26, 45, Effect "Schmerzen" . previews ctx $ over sFatigue (+ 15)) 386 , (26, 45, Effect "Schmerzen" . MaybeT . previews ctx $ over sFatigue (+ 15))
390 , (46, 100, Effect "Fleischwunde" . previews ctx $ over sFatigue (+ 5)) 387 , (46, 100, Effect "Fleischwunde" . MaybeT . previews ctx $ over sFatigue (+ 5))
391 ]) 388 ])
392 389
393dolphin = Dolphin 390dolphin = Dolphin
@@ -437,7 +434,7 @@ dolphin = Dolphin
437 & set seBar (vitBar 0.8) 434 & set seBar (vitBar 0.8)
438 & set seReBar (vitBar 0.2) 435 & set seReBar (vitBar 0.2)
439 & set seEffect ( cTable [ (1, 5, death "Rumpf") 436 & set seEffect ( cTable [ (1, 5, death "Rumpf")
440 , (6, 25, Effect "Organschäden" . previews ctx $ over sFatigue (+ 7) . over (sDamage' "Rumpf") (+ 20)) 437 , (6, 25, Effect "Organschäden" . MaybeT . previews ctx $ over sFatigue (+ 7) . over (sDamage' "Rumpf") (+ 20))
441 , (26, 45, effect "Blutung (2 Schaden (Au) Minuten)") 438 , (26, 45, effect "Blutung (2 Schaden (Au) Minuten)")
442 , (46, 75, Effect "Bewusstlos" unconscious) 439 , (46, 75, Effect "Bewusstlos" unconscious)
443 , (76, 100, Effect "Bewusstlos" . unconsciousR $ d 10) 440 , (76, 100, Effect "Bewusstlos" . unconsciousR $ d 10)
@@ -449,7 +446,7 @@ dolphin = Dolphin
449 & set seReBar (vitBar 0.2) 446 & set seReBar (vitBar 0.2)
450 & set seEffect ( cTable [ (1, 10, amputate "Schwanz") 447 & set seEffect ( cTable [ (1, 10, amputate "Schwanz")
451 , (11, 25, effect "Halbierte Bewegung") 448 , (11, 25, effect "Halbierte Bewegung")
452 , (26, 45, Effect "Schmerz" . previews ctx $ over sFatigue (+ 15)) 449 , (26, 45, Effect "Schmerz" . MaybeT . previews ctx $ over sFatigue (+ 15))
453 , (46, 100, effect "Fleischwunde") 450 , (46, 100, effect "Fleischwunde")
454 ]) 451 ])
455 ) 452 )
@@ -508,28 +505,28 @@ silicoid = Silicoid
508 & set seVal (sDamage' "Auge" . to return) 505 & set seVal (sDamage' "Auge" . to return)
509 & set seBar (vitBar 0.2) 506 & set seBar (vitBar 0.2)
510 & set seReBar (vitBar 0.2) 507 & set seReBar (vitBar 0.2)
511 & set seEffect ( cTable [ (1, 25, effect "Explosion") 508 & set seEffect ( cTable [ (1, 25, "Explosion")
512 , (26, 75, effect "Permanent desorientiert (nur rammen in zufällige Richtungen)") 509 , (26, 75, "Permanent desorientiert (nur rammen in zufällige Richtungen)")
513 , (76, 100, effect "Detonation in 3w10 AP") 510 , (76, 100, "Detonation in 3w10 AP")
514 ]) 511 ])
515 ) 512 )
516 , ("Thorax", def 513 , ("Thorax", def
517 & set seVal (sDamage' "Thorax" . to return) 514 & set seVal (sDamage' "Thorax" . to return)
518 & set seBar (vitBar 0.65) 515 & set seBar (vitBar 0.65)
519 & set seReBar (vitBar 0.2) 516 & set seReBar (vitBar 0.2)
520 & set seEffect ( cTable [ (1, 10, effect "Explosion") 517 & set seEffect ( cTable [ (1, 10, "Explosion")
521 , (11, 25, effect "Halbe Bewegung") 518 , (11, 25, "Halbe Bewegung")
522 , (26, 65, effect "10 Schaden, Sprühattacke auf nächsten Charakter (Blut)") 519 , (26, 65, "10 Schaden, Sprühattacke auf nächsten Charakter (Blut)")
523 , (66, 100, effect "3w10 Erschöpfung") 520 , (66, 100, "3w10 Erschöpfung")
524 ]) 521 ])
525 ) 522 )
526 , ("Schwanz", def 523 , ("Schwanz", def
527 & set seVal (sDamage' "Schwanz" . to return) 524 & set seVal (sDamage' "Schwanz" . to return)
528 & set seBar (vitBar 0.2) 525 & set seBar (vitBar 0.2)
529 & set seReBar (vitBar 0.2) 526 & set seReBar (vitBar 0.2)
530 & set seEffect ( cTable [ (1, 25, effect "10 Schaden, Schwanzdrüse unbrauchbar") 527 & set seEffect ( cTable [ (1, 25, "10 Schaden, Schwanzdrüse unbrauchbar")
531 , (26, 60, effect "3 Schaden, Sprühattacke auf nächsten Charakter (Blut)") 528 , (26, 60, "3 Schaden, Sprühattacke auf nächsten Charakter (Blut)")
532 , (61, 100, effect "Amok und Detonation nach 1w10+6 AP") 529 , (61, 100, "Amok und Detonation nach 1w10+6 AP")
533 ]) 530 ])
534 ) 531 )
535 ] <> Map.fromList [(name, bein name) | side <- ["Rechtes", "Linkes"], length <- ["Vorderes", "Mittleres", "Hinteres"], let name = Hitzone . CI.mk $ side ++ " " ++ length ++ " Bein"] 532 ] <> Map.fromList [(name, bein name) | side <- ["Rechtes", "Linkes"], length <- ["Vorderes", "Mittleres", "Hinteres"], let name = Hitzone . CI.mk $ side ++ " " ++ length ++ " Bein"]
diff --git a/src/Sequence/Contact/Tests.hs b/src/Sequence/Contact/Tests.hs
index d10819e..be61ed3 100644
--- a/src/Sequence/Contact/Tests.hs
+++ b/src/Sequence/Contact/Tests.hs
@@ -1,7 +1,8 @@
1{-# LANGUAGE TemplateHaskell, OverloadedStrings, OverloadedLists, ViewPatterns, MultiParamTypeClasses, FlexibleContexts, RankNTypes, TypeSynonymInstances, FlexibleInstances #-} 1{-# LANGUAGE TemplateHaskell, OverloadedStrings, OverloadedLists, ViewPatterns, MultiParamTypeClasses, FlexibleContexts, RankNTypes, TypeSynonymInstances, FlexibleInstances, RecordWildCards #-}
2 2
3module Sequence.Contact.Tests 3module Sequence.Contact.Tests
4 ( enactTest 4 ( enactTest, enactTestMod
5 , critTables
5 ) where 6 ) where
6 7
7import Sequence.Formula 8import Sequence.Formula
@@ -12,6 +13,7 @@ import Sequence.Contact.Types
12import Control.Monad 13import Control.Monad
13import Control.Monad.Reader 14import Control.Monad.Reader
14import Control.Monad.Base 15import Control.Monad.Base
16import Control.Monad.Trans.Maybe
15import Control.Lens 17import Control.Lens
16 18
17import Data.Default 19import Data.Default
@@ -29,6 +31,8 @@ import Data.Traversable (mapM)
29 31
30import Prelude hiding (mapM) 32import Prelude hiding (mapM)
31 33
34import Debug.Trace
35
32tests :: MonadReader Stats m => m (Map (CI String) (FormulaM Stats Test)) 36tests :: MonadReader Stats m => m (Map (CI String) (FormulaM Stats Test))
33tests = do 37tests = do
34 baseTests <- mconcat <$> sequence [ test "Stärke" $ sAStrength . attributeTest 38 baseTests <- mconcat <$> sequence [ test "Stärke" $ sAStrength . attributeTest
@@ -94,6 +98,45 @@ tests = do
94 skillTest = to (\x -> flip (set tBaseDifficulty) def <$> x) 98 skillTest = to (\x -> flip (set tBaseDifficulty) def <$> x)
95 attributeTest = to (\x -> flip (set tBaseDifficulty) def . (* 10) <$> x) 99 attributeTest = to (\x -> flip (set tBaseDifficulty) def . (* 10) <$> x)
96 100
101critTables :: CI String -> (DiceResult -> Table (Maybe Effect))
102critTables skill CritSuccess{..}
103 | skill `elem` ([ "Handfeuerwaffen"
104 , "Schwere Waffen"
105 , "Energiewaffen"
106 , "Archaische Distanzwaffen"
107 ] :: [CI String])
108 || skill == "Fernkampfangriffe"
109 = cTable [ (1, 5, Just "Ziel wird zu Boden geschleudert und verliert 10-(En) AP")
110 , (6, 15, Just "Glückstreffer an einer ungepanzerten Stelle (Schutzwert 0)")
111 , (16, 25, Just "Schwachstelle in der Panzerung getroffen (Halber Schutzwert)")
112 , (26, 35, Just "Lähmender Schmerz (Ziel verliert 12-(En) AP)")
113 , (36, 55, Just "Ziel wird zu Boden geworfen")
114 , (56, 75, Just "Kopfschuss")
115 , (76, 95, Just "1w10 Bonusschaden")
116 , (96, 100, Nothing)
117 ]
118 | otherwise = [(Nothing, 1)]
119critTables skill CritFailure{..}
120 | skill `elem` ([ "Handfeuerwaffen"
121 , "Schwere Waffen"
122 , "Energiewaffen"
123 , "Archaische Distanzwaffen"
124 ] :: [CI String])
125 || skill == "Fernkampfangriffe"
126 = cTable [ (1, 5, Nothing)
127 , (6, 25, Just "Ladehemmung oder andere Fehlfunktion der Waffe. Erfordert zum Beheben die gleiche Anzahl AP wie das vollständige Nachladen der Waffe.")
128 , (26, 45, Just "Waffe wird fallengelassen")
129 , (46, 65, Just "Ein anderer Charakter in der Nähe wird getroffen")
130 , (66, 75, Just "Angreifer schießt sich selbst in den Fuß (voller Schaden, Trefferzone: ein Bein)")
131 , (76, 85, Just "Waffe wird beschädigt und praktisch nutzlos (Qualität -100%)")
132 , (86, 95, Just "Charakter verliert geladene Munition (fällt heraus oder zündet im Magazin)")
133 , (96, 100, Just $ "Unkoordinierter Schuss in eine zufällige Richtung"
134 <> "Waffe wird fallengelassen"
135 )
136 ]
137 | otherwise = [(Nothing, 1)]
138critTables _ _ = [(Nothing, 1)]
139
97 140
98getTest :: String -> Fold Stats (FormulaM Stats Test) 141getTest :: String -> Fold Stats (FormulaM Stats Test)
99getTest (CI.mk -> str) = folding tests' 142getTest (CI.mk -> str) = folding tests'
@@ -108,9 +151,12 @@ instance Argument (FormulaM Stats Test) GameState where
108 arg str = join <$> preuses (gFocus' . eStats) (preview (getTest str)) 151 arg str = join <$> preuses (gFocus' . eStats) (preview (getTest str))
109 152
110enactTest :: Test -> FormulaM Stats TestResult 153enactTest :: Test -> FormulaM Stats TestResult
111enactTest rawTest = do 154enactTest rawTest = enactTestMod rawTest $ val ignored [CI.original (rawTest ^. tName), "Modifier"] False
155
156enactTestMod :: Test -> Formula Stats -> FormulaM Stats TestResult
157enactTestMod rawTest modFormula = do
112 test <- foldM (&) rawTest =<< toListOf (ctx . sModifiers . folded . _Modifier . _2) <$> ask 158 test <- foldM (&) rawTest =<< toListOf (ctx . sModifiers . folded . _Modifier . _2) <$> ask
113 manualMod <- val ignored [CI.original (rawTest ^. tName), "Modifier"] False 159 manualMod <- modFormula
114 let 160 let
115 critFailureBar = 95 - test^.tCritFailureMod 161 critFailureBar = 95 - test^.tCritFailureMod
116 critSuccessBar = 5 + test^.tCritSuccessMod 162 critSuccessBar = 5 + test^.tCritSuccessMod
@@ -123,7 +169,7 @@ enactTest rawTest = do
123 | pw >= critFailureBar = CritFailure 169 | pw >= critFailureBar = CritFailure
124 | otherwise = Failure 170 | otherwise = Failure
125 dResult <- toResult <$> d 100 171 dResult <- toResult <$> d 100
126 TestResult <$> pure dResult <*> (test ^. tEffect) dResult 172 TestResult <$> pure dResult <*> runMaybeT ((test ^. tEffect) dResult)
127 173
128-- hasTest :: Stats -> String -> Bool 174-- hasTest :: Stats -> String -> Bool
129-- hasTest stats str = has (getTest str) stats 175-- hasTest stats str = has (getTest str) stats
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
32import Control.Monad.Reader (ask, local) 32import Control.Monad.Reader (ask, local)
33import Control.Monad.State 33import Control.Monad.State
34import Control.Monad.Trans.Maybe
34 35
35import Sequence.Contact.Types.Internal 36import 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
79instance Default Effect where 80instance Default Effect where
80 def = Effect "" $ preview ctx 81 def = Effect "" mzero
81 82
82instance Monoid Effect where 83instance 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
97effect :: String -> Effect 98effect :: String -> Effect
98effect str = def & set effectName str 99effect str = def & set effectName str
99 100
101instance IsString Effect where
102 fromString = effect
103
100makeLenses ''Test 104makeLenses ''Test
101 105
102instance Default Test where 106instance 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
112deriving instance Eq TestResult 116deriving instance Eq TestResult
@@ -174,7 +178,7 @@ instance Default Stats where
174 } 178 }
175 179
176applyModifier :: String -> (Test -> FormulaM Stats Test) -> Effect 180applyModifier :: String -> (Test -> FormulaM Stats Test) -> Effect
177applyModifier effectName modifier = Effect (CI.mk effectName) $ previews ctx apply 181applyModifier 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
diff --git a/src/Sequence/Contact/Types/Internal.hs b/src/Sequence/Contact/Types/Internal.hs
index eaa1e19..f2052ee 100644
--- a/src/Sequence/Contact/Types/Internal.hs
+++ b/src/Sequence/Contact/Types/Internal.hs
@@ -2,7 +2,7 @@
2 2
3module Sequence.Contact.Types.Internal where 3module Sequence.Contact.Types.Internal where
4 4
5import Sequence.Formula (Formula, FormulaM, Table) 5import Sequence.Formula (Formula, FormulaM, FormulaMT, Table)
6 6
7import Data.Map (Map) 7import Data.Map (Map)
8import Data.Set (Set) 8import Data.Set (Set)
@@ -18,6 +18,8 @@ import Data.CaseInsensitive (CI)
18 18
19import Data.ExtendedReal 19import Data.ExtendedReal
20 20
21import Control.Monad.Trans.Maybe (MaybeT)
22
21newtype Hitzone = Hitzone { _hitzone :: CI String } 23newtype Hitzone = Hitzone { _hitzone :: CI String }
22 deriving (Eq, Ord) 24 deriving (Eq, Ord)
23 25
@@ -60,7 +62,7 @@ data DiceResult = CritSuccess { _rWith, _rBy :: Int }
60 62
61data TestResult = TestResult 63data TestResult = TestResult
62 { _rRoll :: DiceResult 64 { _rRoll :: DiceResult
63 , _rResult :: Effect 65 , _rResult :: Maybe Effect
64 } 66 }
65 67
66data Test = Test 68data Test = Test
@@ -69,12 +71,12 @@ data Test = Test
69 , _tCritFailureMod 71 , _tCritFailureMod
70 , _tBaseDifficulty 72 , _tBaseDifficulty
71 , _tMod :: Int 73 , _tMod :: Int
72 , _tEffect :: DiceResult -> FormulaM Stats Effect 74 , _tEffect :: DiceResult -> FormulaMT MaybeT Stats Effect
73 } 75 }
74 76
75data Modifier = Modifier (CI String) (Test -> FormulaM Stats Test) 77data Modifier = Modifier (CI String) (Test -> FormulaM Stats Test)
76 78
77data Effect = Effect (CI String) (FormulaM Stats (Maybe Stats)) 79data Effect = Effect (CI String) (FormulaMT MaybeT Stats Stats)
78 80
79data SeqVal = SeqVal 81data SeqVal = SeqVal
80 { _seqRound :: Down Int 82 { _seqRound :: Down Int