diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-06-11 01:34:07 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-06-11 01:34:07 +0200 |
commit | fb065aeac90ce0766a3f74b84c34547cd087da77 (patch) | |
tree | a84887655dc8cc0e66ff32162ac81e1124f8c7d1 /src | |
parent | 49d5fbcf0ac5322ba010230f0340b701d89d7fc2 (diff) | |
download | 2017-01-16_17:13:37-fb065aeac90ce0766a3f74b84c34547cd087da77.tar 2017-01-16_17:13:37-fb065aeac90ce0766a3f74b84c34547cd087da77.tar.gz 2017-01-16_17:13:37-fb065aeac90ce0766a3f74b84c34547cd087da77.tar.bz2 2017-01-16_17:13:37-fb065aeac90ce0766a3f74b84c34547cd087da77.tar.xz 2017-01-16_17:13:37-fb065aeac90ce0766a3f74b84c34547cd087da77.zip |
trigger effects on taking damage
Diffstat (limited to 'src')
-rw-r--r-- | src/Main.hs | 53 | ||||
-rw-r--r-- | src/Sequence/Contact/Archetypes.hs | 1 | ||||
-rw-r--r-- | src/Sequence/Contact/Types.hs | 1 | ||||
-rw-r--r-- | src/Sequence/Contact/Types/Internal.hs | 5 | ||||
-rw-r--r-- | src/Sequence/Formula.hs | 4 | ||||
-rw-r--r-- | src/Sequence/Types.hs | 4 | ||||
-rw-r--r-- | src/Sequence/Utils.hs | 2 |
7 files changed, 62 insertions, 8 deletions
diff --git a/src/Main.hs b/src/Main.hs index e239bec..de97603 100644 --- a/src/Main.hs +++ b/src/Main.hs | |||
@@ -252,7 +252,54 @@ addNote :: String -> Sh GameState () | |||
252 | addNote note = withFocus $ \focusId -> gEntities . ix focusId . eNotes %= (note :) | 252 | addNote note = withFocus $ \focusId -> gEntities . ix focusId . eNotes %= (note :) |
253 | 253 | ||
254 | takeHit :: Int -> Completable (Set Hitzone) -> Sh GameState () | 254 | takeHit :: Int -> Completable (Set Hitzone) -> Sh GameState () |
255 | takeHit dmg = withArg $ \zones -> withFocus $ \focusId -> forM_ zones $ \zone -> gEntities . ix focusId . eStats . sDamage . ix zone += dmg | 255 | takeHit dmg = withArg $ \zones -> withFocus $ \focusId -> forM_ zones $ \zone -> do |
256 | 256 | let | |
257 | lStats :: Traversal' GameState Stats | ||
258 | lStats = gEntities . ix focusId . eStats | ||
259 | lStats . sDamage . ix zone += dmg | ||
260 | name <- toName focusId | ||
261 | void . runMaybeT $ do | ||
262 | cripple <- MaybeT . preuse $ lStats . sCripple . ix zone | ||
263 | let evalF formula = do | ||
264 | stats <- MaybeT $ preuse lStats | ||
265 | (nStats, x) <- (evalFormula name :: Stats -> FormulaM Stats a -> MaybeT (Sh GameState) (Stats, a)) stats formula | ||
266 | lStats .= nStats | ||
267 | return x | ||
268 | cVar cLens = evalF =<< MaybeT (preuse $ lStats . (cripple ^. cLens)) | ||
269 | bar <- cVar seBar | ||
270 | val <- cVar seVal | ||
271 | reBar <- cVar seReBar | ||
272 | if cripple ^. seApplied | ||
273 | then guard $ dmg >= reBar | ||
274 | else guard $ val >= bar | ||
275 | (CI.original -> effectName, effect) <- view _Effect <$> (evalF . table $ cripple ^. seEffect) | ||
276 | lStats <~ (MaybeT . fmap join . runMaybeT $ evalF effect) | ||
277 | lift $ shellPutStrLn effectName | ||
278 | lift . addNote $ "Effect: " ++ effectName | ||
279 | |||
257 | takeFatigue :: Int -> Sh GameState () | 280 | takeFatigue :: Int -> Sh GameState () |
258 | takeFatigue dmg = withFocus $ \focusId -> gEntities . ix focusId . eStats . sFatigue += dmg | 281 | takeFatigue dmg = withFocus $ \focusId -> do |
282 | let | ||
283 | lStats :: Traversal' GameState Stats | ||
284 | lStats = gEntities . ix focusId . eStats | ||
285 | gEntities . ix focusId . eStats . sFatigue += dmg | ||
286 | name <- toName focusId | ||
287 | void . runMaybeT $ do | ||
288 | fShock <- MaybeT . preuse $ lStats . sFatigueShock | ||
289 | let evalF formula = do | ||
290 | stats <- MaybeT $ preuse lStats | ||
291 | (nStats, x) <- (evalFormula name :: Stats -> FormulaM Stats a -> MaybeT (Sh GameState) (Stats, a)) stats formula | ||
292 | lStats .= nStats | ||
293 | return x | ||
294 | fVar cLens = evalF =<< MaybeT (preuse $ lStats . (fShock ^. cLens)) | ||
295 | bar <- fVar seBar | ||
296 | val <- fVar seVal | ||
297 | reBar <- fVar seReBar | ||
298 | if fShock ^. seApplied | ||
299 | then guard $ dmg >= reBar | ||
300 | else guard $ val >= bar | ||
301 | (CI.original -> effectName, effect) <- view _Effect <$> (evalF . table $ fShock ^. seEffect) | ||
302 | lStats <~ (MaybeT . fmap join . runMaybeT $ evalF effect) | ||
303 | lift $ shellPutStrLn effectName | ||
304 | lift . addNote $ "Effect: " ++ effectName | ||
305 | |||
diff --git a/src/Sequence/Contact/Archetypes.hs b/src/Sequence/Contact/Archetypes.hs index 30aa2b6..1ad26bb 100644 --- a/src/Sequence/Contact/Archetypes.hs +++ b/src/Sequence/Contact/Archetypes.hs | |||
@@ -110,6 +110,7 @@ human = Humanoid | |||
110 | , _sCripple = fromJust . flip Map.lookup [ ("Kopf", def | 110 | , _sCripple = fromJust . flip Map.lookup [ ("Kopf", def |
111 | & set seVal (sDamage' "Kopf" . to return) | 111 | & set seVal (sDamage' "Kopf" . to return) |
112 | & set seBar (sMaxVitality . mapping (scaled 0.5)) | 112 | & set seBar (sMaxVitality . mapping (scaled 0.5)) |
113 | & set seReBar (sMaxVitality . mapping (scaled 0.2)) | ||
113 | & set seEffect (cTable [ (1, 10, Effect "Tod" headshot) | 114 | & set seEffect (cTable [ (1, 10, Effect "Tod" headshot) |
114 | , (11, 25, effect "Blind") | 115 | , (11, 25, effect "Blind") |
115 | , (26, 35, effect "Blind, Rechts") | 116 | , (26, 35, effect "Blind, Rechts") |
diff --git a/src/Sequence/Contact/Types.hs b/src/Sequence/Contact/Types.hs index 47687b7..9854d92 100644 --- a/src/Sequence/Contact/Types.hs +++ b/src/Sequence/Contact/Types.hs | |||
@@ -107,6 +107,7 @@ instance Default ShockEffect where | |||
107 | def = ShockEffect { _seApplied = False | 107 | def = ShockEffect { _seApplied = False |
108 | , _seVal = ignored | 108 | , _seVal = ignored |
109 | , _seBar = ignored | 109 | , _seBar = ignored |
110 | , _seReBar = ignored | ||
110 | , _seEffect = def | 111 | , _seEffect = def |
111 | } | 112 | } |
112 | 113 | ||
diff --git a/src/Sequence/Contact/Types/Internal.hs b/src/Sequence/Contact/Types/Internal.hs index e4a2eef..0fe6266 100644 --- a/src/Sequence/Contact/Types/Internal.hs +++ b/src/Sequence/Contact/Types/Internal.hs | |||
@@ -55,8 +55,9 @@ data SeqVal = SeqVal | |||
55 | 55 | ||
56 | data ShockEffect = ShockEffect | 56 | data ShockEffect = ShockEffect |
57 | { _seApplied :: Bool | 57 | { _seApplied :: Bool |
58 | , _seVal :: Getting (First (Formula Stats)) Stats (Formula Stats) | 58 | , _seVal |
59 | , _seBar :: Getting (First (Formula Stats)) Stats (Formula Stats) | 59 | , _seBar |
60 | , _seReBar :: Getting (First (Formula Stats)) Stats (Formula Stats) | ||
60 | , _seEffect :: Table Effect | 61 | , _seEffect :: Table Effect |
61 | } | 62 | } |
62 | 63 | ||
diff --git a/src/Sequence/Formula.hs b/src/Sequence/Formula.hs index ca945f8..4f2e61b 100644 --- a/src/Sequence/Formula.hs +++ b/src/Sequence/Formula.hs | |||
@@ -28,6 +28,7 @@ import Data.Bool | |||
28 | import Data.List | 28 | import Data.List |
29 | import Data.Maybe | 29 | import Data.Maybe |
30 | import Data.Either | 30 | import Data.Either |
31 | import Data.Tuple | ||
31 | 32 | ||
32 | import Data.Set (Set) | 33 | import Data.Set (Set) |
33 | import qualified Data.Set as Set | 34 | import qualified Data.Set as Set |
@@ -109,6 +110,9 @@ evalFormula = evalFormula' [] | |||
109 | Left q@(Question{..}) -> askQuestion promptPref input q >>= flip (flip evalFormula' promptPref $ bool (pure . set (ctx' . answer) $ throwError q) mempty keepResult ++ finalChanges) formula | 110 | Left q@(Question{..}) -> askQuestion promptPref input q >>= flip (flip evalFormula' promptPref $ bool (pure . set (ctx' . answer) $ throwError q) mempty keepResult ++ finalChanges) formula |
110 | Right result -> return (foldr ($) input finalChanges, result) | 111 | Right result -> return (foldr ($) input finalChanges, result) |
111 | 112 | ||
113 | evalFormula' :: (MonadIO m, sInput :<: lInput, MonadState lInput m) => String -> FormulaM sInput a -> m a | ||
114 | evalFormula' promptPref formula = uncurry (<$) . over _2 put . swap =<< flip (evalFormula promptPref) formula =<< get | ||
115 | |||
112 | val :: Integral a => Traversal' input (Formula input) -> String -> Bool -> Formula input | 116 | val :: Integral a => Traversal' input (Formula input) -> String -> Bool -> Formula input |
113 | val answer prompt keepResult = do | 117 | val answer prompt keepResult = do |
114 | gets (Set.member prompt) >>= bool (modify $ Set.insert prompt) (modify (Set.delete prompt) >> throwError Question{..}) | 118 | gets (Set.member prompt) >>= bool (modify $ Set.insert prompt) (modify (Set.delete prompt) >> throwError Question{..}) |
diff --git a/src/Sequence/Types.hs b/src/Sequence/Types.hs index 6594f78..59397d5 100644 --- a/src/Sequence/Types.hs +++ b/src/Sequence/Types.hs | |||
@@ -78,8 +78,8 @@ instance Default Entity where | |||
78 | eSeqVal :: Lens' Entity (Maybe SeqVal) | 78 | eSeqVal :: Lens' Entity (Maybe SeqVal) |
79 | eSeqVal = eStats . sSequence | 79 | eSeqVal = eStats . sSequence |
80 | 80 | ||
81 | instance (Entity :<: a) => Stats :<: a where | 81 | instance Stats :<: Entity where |
82 | ctx' = ctx' . eStats | 82 | ctx' = eStats |
83 | 83 | ||
84 | newtype EntityName = EntityName { _entityName :: CI String } | 84 | newtype EntityName = EntityName { _entityName :: CI String } |
85 | deriving (Show, Eq, Ord) | 85 | deriving (Show, Eq, Ord) |
diff --git a/src/Sequence/Utils.hs b/src/Sequence/Utils.hs index bbd1477..8b205ea 100644 --- a/src/Sequence/Utils.hs +++ b/src/Sequence/Utils.hs | |||
@@ -112,5 +112,5 @@ instance Argument (Set Hitzone) GameState where | |||
112 | ws = Set.fromList . map CI.mk . filter (not . null) . map trim . split $ protoWs | 112 | ws = Set.fromList . map CI.mk . filter (not . null) . map trim . split $ protoWs |
113 | hasGlob = Set.member "*" ws | 113 | hasGlob = Set.member "*" ws |
114 | hitzones <- Set.map (view _Hitzone) . Map.keysSet <$> MaybeT (preuse $ gFocus' . eStats . sHitzones) | 114 | hitzones <- Set.map (view _Hitzone) . Map.keysSet <$> MaybeT (preuse $ gFocus' . eStats . sHitzones) |
115 | guard (hasGlob || hitzones `Set.isSubsetOf` ws) | 115 | guard (hasGlob || ws `Set.isSubsetOf` hitzones) |
116 | return . Set.map (review _Hitzone) $ if hasGlob then hitzones else ws | 116 | return . Set.map (review _Hitzone) $ if hasGlob then hitzones else ws |