-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathM13.hs
1335 lines (1210 loc) · 45.7 KB
/
M13.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DoAndIfThenElse #-}
module Magic.M13 where
import Magic
import Magic.BasicLands (tapToAddMana)
import qualified Magic.IdList as IdList
import Control.Applicative
import Control.Arrow (first)
import Control.Category ((.))
import Control.Monad (void, when)
import Data.Boolean (notB, true, (&&*), (||*))
import qualified Data.Foldable as Foldable
import Data.Label (get)
import Data.Label.Monadic ((=:), asks)
import Data.Maybe (isJust)
import Data.Monoid ((<>), mconcat)
import qualified Data.MultiSet as MultiSet
import qualified Data.Set as Set
import Data.Text (Text, pack)
import qualified Data.Text as Text
import Prelude hiding ((.))
import Data.Traversable (traverse)
-- COMMON ABILITIES
exalted :: TriggeredAbilities
exalted events (Some Battlefield, _) p = return [ mkTrigger p (boostPT r)
| DidDeclareAttackers p' [Attack r _] <- events, p == p' ]
where
boostPT :: ObjectRef TyPermanent -> Magic ()
boostPT (Battlefield, i) = do
t <- tick
will $ InstallLayeredEffect (Some Battlefield, i) $
TemporaryLayeredEffect
{ temporaryTimestamp = t
, temporaryDuration = UntilEndOfTurn
, temporaryEffect = affectingSelf [ModifyPT (\_ -> return (1, 1))]
}
exalted _ _ _ = return []
-- WHITE CARDS
ajani'sSunstriker :: Card
ajani'sSunstriker = mkCard $ do
name =: Just "Ajani's Sunstriker"
types =: creatureTypes [Cat, Cleric]
pt =: Just (2, 2)
play =: Just playObject { manaCost = Just (white 2) }
staticKeywordAbilities =+ [Lifelink]
angel'sMercy :: Card
angel'sMercy = mkCard $ do
name =: Just "Angel's Mercy"
types =: instantType
play =: Just playObject
{ manaCost = Just (generic 2 <> white 2)
, effect = stackSelf $ \_ you -> will (GainLife you 7)
}
angelicBenediction :: Card
angelicBenediction = mkCard $ do
name =: Just "Angelic Benediction"
types =: enchantmentType
play =: Just playObject
{ manaCost = Just (generic 3 <> white 1) }
triggeredAbilities =: exalted <> tapTrigger
where
tapTrigger :: TriggeredAbilities
tapTrigger events (Some Battlefield, _) p =
mconcat [
do
p' <- asks (controller . objectPart . object rAttacker)
if p == p'
then return [mkTapTriggerObject p]
else return []
| DidDeclareAttackers _ [Attack rAttacker _] <- events ]
tapTrigger _ _ _ = return []
mkTapTriggerObject :: PlayerRef -> Magic ()
mkTapTriggerObject p = do
ts <- askTarget p targetCreature
mkTargetTrigger p ts $ \t -> do
shouldTap <- askYesNo p "Do you want to tap target creature?"
when shouldTap $ will (TapPermanent t)
attendedKnight :: Card
attendedKnight = mkCard $ do
name =: Just "Attended Knight"
types =: creatureTypes [Human, Knight]
pt =: Just (2, 2)
play =: Just playObject
{ manaCost = Just (generic 2 <> white 1) }
staticKeywordAbilities =+ [FirstStrike]
triggeredAbilities =: trigger
where
trigger :: TriggeredAbilities
trigger = onSelfETB $ \_ p -> mkTrigger p $ do
t <- tick
void $ executeEffect $ mkSoldierEffect t p
mkSoldierEffect :: Timestamp -> PlayerRef -> OneShotEffect
mkSoldierEffect t p = WillMoveObject Nothing Battlefield $
Permanent o Untapped 0 False Nothing Nothing
where
o = (emptyObject t p)
{ _name = Just "Soldier"
, _colors = Set.singleton White
, _types = creatureTypes [Soldier]
, _pt = Just (1, 1)
}
avenSquire :: Card
avenSquire = mkCard $ do
name =: Just "Aven Squire"
types =: creatureTypes [Bird, Soldier]
pt =: Just (1, 1)
play =: Just playObject { manaCost = Just (generic 1 <> white 1) }
staticKeywordAbilities =+ [Flying]
triggeredAbilities =: exalted
battleflightEagle :: Card
battleflightEagle = mkCard $ do
name =: Just "Battleflight Eagle"
types =: creatureTypes [Bird]
pt =: Just (2, 2)
play =: Just playObject
{ manaCost = Just (generic 4 <> white 1) }
staticKeywordAbilities =+ [Flying]
triggeredAbilities =: onSelfETB createBoostTrigger
where
createBoostTrigger :: Contextual (Magic ())
createBoostTrigger _ p = do
ts <- askTarget p targetCreature
mkTargetTrigger p ts $ \(Battlefield, i) -> do
t <- tick
will $
InstallLayeredEffect (Some Battlefield, i) TemporaryLayeredEffect
{ temporaryTimestamp = t
, temporaryDuration = UntilEndOfTurn
, temporaryEffect = affectingSelf
[ModifyPT (\_ -> return (2, 2)), AddStaticKeywordAbility Flying]
}
captainOfTheWatch :: Card
captainOfTheWatch = mkCard $ do
name =: Just "Captain of the Watch"
types =: creatureTypes [Human, Soldier]
pt =: Just (3, 3)
play =: Just playObject { manaCost =
Just (generic 4 <> white 2) }
staticKeywordAbilities =+ [Vigilance]
layeredEffects =: [boostSoldiers]
triggeredAbilities =: trigger
where
boostSoldiers = LayeredObjectEffect
{ affectedObjects = affectRestOfBattlefield $ \you ->
isControlledBy you &&* hasTypes (creatureTypes [Soldier])
, objectModifications = [ AddStaticKeywordAbility Vigilance
, ModifyPT (\_ -> return (1, 1))]
}
trigger = onSelfETB $ \_ p -> mkTrigger p $ do
t <- tick
void $ executeEffects $ replicate 3 $ mkSoldierEffect t p
captain'sCall :: Card
captain'sCall = mkCard $ do
name =: Just "Captain's Call"
types =: sorceryType
play =: Just playObject
{ manaCost = Just (generic 3 <> white 1)
, effect = stackSelf $ \_ you -> do
t <- tick
void $ executeEffects $ replicate 3 $ mkSoldierEffect t you
}
crusaderOfOdric :: Card
crusaderOfOdric = mkCard $ do
name =: Just "Crusader of Odric"
types =: creatureTypes [Human, Soldier]
play =: Just playObject {
manaCost = Just (generic 2 <> white 1)
}
layeredEffects =: [definePT]
where
definePT :: LayeredEffect
definePT = LayeredObjectEffect
{ affectedObjects = affectSelf
, objectModifications = [DefinePT ( \rSelf ->
do
cards <- (map (get objectPart) . IdList.elems) <$> view (asks (battlefield))
you <- view (asks (controller . objectBase rSelf))
let c = length $ filter (isControlledBy you &&* hasTypes creatureType) cards
return (c, c))]
}
divineFavor :: Card
divineFavor = mkCard $ do
name =: Just "Divine Favor"
types =: auraType
staticKeywordAbilities =+ [EnchantPermanent creatureType]
triggeredAbilities =: gainLifeTrigger
layeredEffects =: [boostEnchanted]
play =: Just playObject { manaCost = Just (generic 1 <> white 1) }
where
gainLifeTrigger = onSelfETB $ \_ you ->
mkTrigger you (will (GainLife you 3))
boostEnchanted = LayeredObjectEffect
{ affectedObjects = affectAttached
, objectModifications = [ModifyPT (\_ -> return (1, 3))]
}
erase :: Card
erase = mkCard $ do
name =: Just "Erase"
types =: instantType
play =: Just playObject
{ manaCost = Just (white 1)
, effect = eraseEffect
}
where
eraseEffect :: Contextual (Magic ())
eraseEffect rSelf you = do
ts <- askTarget you targetEnchantment
stackTargetSelf rSelf you ts $ \t _ _ -> do
ench <- view (asks (objectPart . object t))
void . executeEffect $ willMoveToExile t ench
guardianLions :: Card
guardianLions = mkCard $ do
name =: Just "Guardian Lions"
types =: creatureTypes [Cat]
pt =: Just (1, 6)
play =: Just playObject {
manaCost = Just (generic 4 <> white 1)
}
staticKeywordAbilities =+ [Vigilance]
guardiansOfAkrasa :: Card
guardiansOfAkrasa = mkCard $ do
name =: Just "Guardians of Akrasa"
types =: creatureTypes [Human, Soldier]
pt =: Just (0, 4)
play =: Just playObject {
manaCost = Just (generic 2 <> white 1)
}
staticKeywordAbilities =+ [Defender]
triggeredAbilities =: exalted
healerOfThePride :: Card
healerOfThePride = mkCard $ do
name =: Just "Healer of the Pride"
types =: creatureTypes [Cat, Cleric]
pt =: Just (2, 3)
play =: Just playObject {
manaCost = Just (generic 3 <> white 1)
}
triggeredAbilities =: gainLifeTrigger
where
gainLifeTrigger :: TriggeredAbilities
gainLifeTrigger events (Some Battlefield, _) you =
mconcat [
do
p <- asks (controller . objectPart . object (Battlefield, i))
isCreatureCard <- hasTypes creatureType <$> asks (objectPart . object (Battlefield, i))
if you == p && isCreatureCard
then return [mkTrigger you (will (GainLife you 2))]
else return []
| DidMoveObject _ (Some Battlefield, i) <- events ]
gainLifeTrigger _ _ _ = return []
pacifism :: Card
pacifism = mkCard $ do
name =: Just "Pacifism"
types =: auraType
staticKeywordAbilities =+ [EnchantPermanent creatureType]
play =: Just playObject { manaCost = Just (generic 1 <> white 1) }
layeredEffects =: [eff]
where
eff = LayeredObjectEffect
{ affectedObjects = affectAttached
, objectModifications = [ RestrictAllowAttacks selfCantAttack
, RestrictAllowBlocks selfCantBlock ]
}
planarCleansing :: Card
planarCleansing = mkCard $ do
name =: Just "Planar Cleansing"
types =: sorceryType
play =: Just playObject { manaCost = Just (generic 3 <> white 3),
effect = stackSelf destroyAllPermanents }
where
destroyAllPermanents :: ObjectRef 'TyStackItem -> PlayerRef -> Magic ()
destroyAllPermanents _ _ = do
objects <- IdList.toList <$> view (asks (battlefield))
let objectRefs = map (\pair -> (Battlefield, fst pair)) $ filter (not . hasTypes landType . get objectPart . snd) objects
let destructionEffects = map (\objectRef -> DestroyPermanent objectRef true) objectRefs
void $ executeEffects $ map Will destructionEffects
pillarfieldOx :: Card
pillarfieldOx = mkCard $ do
name =: Just "Pillarfield Ox"
types =: creatureTypes [Ox]
pt =: Just (2, 4)
play =: Just playObject {
manaCost = Just (generic 3 <> white 1)
}
serraAngel :: Card
serraAngel = mkCard $ do
name =: Just "Serra Angel"
types =: creatureTypes [Angel]
pt =: Just (4, 4)
play =: Just playObject {
manaCost = Just (generic 3 <> white 2)
}
staticKeywordAbilities =+ [Flying, Vigilance]
silvercoatLion :: Card
silvercoatLion = mkCard $ do
name =: Just "Silvercoat Lion"
types =: creatureTypes [Cat]
pt =: Just (2, 2)
play =: Just playObject {
manaCost = Just (generic 1 <> white 1)
}
showOfValor :: Card
showOfValor = mkCard $ do
name =: Just "Show of Valor"
types =: instantType
play =: Just playObject
{ manaCost = Just (generic 1 <> white 1)
, effect = showOfValorEffect
}
where
showOfValorEffect rSelf you = do
ts <- askTarget you targetCreature
stackTargetSelf rSelf you ts $ \(zr, i) _stackSelf _stackYou -> do
t <- tick
will $
InstallLayeredEffect (Some zr, i) TemporaryLayeredEffect
{ temporaryTimestamp = t
, temporaryDuration = UntilEndOfTurn
, temporaryEffect = affectingSelf
[ModifyPT (\_ -> return (2, 4))]
}
warFalcon :: Card
warFalcon = mkCard $ do
name =: Just "War Falcon"
types =: creatureTypes[Bird]
pt =: Just (2, 1)
staticKeywordAbilities =+ [Flying]
play =: Just playObject { manaCost = Just (white 1) }
allowAttacks =: controlsKnightOrSoldier
where
controlsKnightOrSoldier :: [Attack] -> Contextual (View Bool)
controlsKnightOrSoldier ats (Some Battlefield, i) p = do
cards <- (map (get objectPart) . IdList.elems) <$> view (asks (battlefield))
let ok = isControlledBy p &&* (hasTypes (creatureTypes [Knight]) ||* hasTypes (creatureTypes [Soldier]))
return $ (Battlefield, i) `notElem` map attacker ats || any ok cards
controlsKnightOrSoldier _ _ _ = true
warPriestOfThune :: Card
warPriestOfThune = mkCard $ do
name =: Just "War Priest of Thune"
types =: creatureTypes [Human, Cleric]
pt =: Just (2, 2)
play =: Just playObject { manaCost = Just (generic 1 <> white 1) }
triggeredAbilities =: onSelfETB warPriestOfThuneTrigger
where
warPriestOfThuneTrigger _rSelf you = do
ench <- askTarget you targetEnchantment
mkTargetTrigger you ench $ \ref -> do
shouldDestroy <- askYesNo you "Destroy target enchantment?"
when shouldDestroy $ will (DestroyPermanent ref True)
-- BLUE
divination :: Card
divination = mkCard $ do
name =: Just "Divination"
types =: sorceryType
play =: Just playObject
{ manaCost = Just (generic 2 <> blue 1)
, effect = stackSelf $ \_ stackYou ->
void $ executeEffects $ replicate 2 (Will (DrawCard stackYou))
}
downpour :: Card
downpour = mkCard $ do
name =: Just "Downpour"
types =: instantType
play =: Just playObject
{ manaCost = Just (generic 1 <> blue 1)
, effect = downpourEffect
}
where
downpourEffect rSelf rYou = do
ts <- askTargetsUpTo 3 rYou targetCreature
stackTargetSelf rSelf rYou ts $ \t _stackSelf _stackYou ->
void. executeEffects $ map (Will . TapPermanent) t
faerieInvaders :: Card
faerieInvaders = mkCard $ do
name =: Just "Faerie Invaders"
types =: creatureTypes [Faerie, Rogue]
staticKeywordAbilities =+ [Flash]
play =: Just playObject
{ manaCost = Just (generic 4 <> blue 1) }
mindSculpt :: Card
mindSculpt = mkCard $ do
name =: Just "Mind Sculpt"
types =: sorceryType
play =: Just playObject
{ manaCost = Just (generic 1 <> blue 1)
, effect = mindSculptEffect
}
where
mindSculptEffect :: Contextual (Magic ())
mindSculptEffect rSelf you = do
ps <- askTarget you (targetOpponent you)
stackTargetSelf rSelf you ps $ \p _ _ -> do
cards <- IdList.toList <$> view (asks (library . player p))
moveCards (take 7 cards) (Library p) (Graveyard p)
tricksOfTheTrade :: Card
tricksOfTheTrade = mkCard $ do
name =: Just "Tricks of the Trade"
types =: auraType
staticKeywordAbilities =+ [EnchantPermanent creatureType]
layeredEffects =: [boostEnchanted]
play =: Just playObject
{ manaCost = Just (generic 3 <> blue 1) }
where
boostEnchanted = LayeredObjectEffect
{ affectedObjects = affectAttached
, objectModifications = [ModifyPT (\_ -> return (2, 0)), RestrictAllowBlocks selfCantBeBlocked]
}
-- BLACK CARDS
bloodHunterBat :: Card
bloodHunterBat = mkCard $ do
name =: Just "Bloodhunter Bat"
types =: creatureTypes [Bat]
pt =: Just (2, 2)
play =: Just playObject { manaCost = Just (generic 3 <> black 1) }
triggeredAbilities =: onSelfETB bloodHunterBatTrigger
where
bloodHunterBatTrigger :: Contextual (Magic ())
bloodHunterBatTrigger _rSelf you = do
opps <- askTarget you (targetOpponent you)
mkTargetTrigger you opps $ \opp ->
void $ executeEffects [Will $ LoseLife opp 2, Will $ GainLife you 2]
cripplingBlight :: Card
cripplingBlight = mkCard $ do
name =: Just "Crippling Blight"
types =: auraType
staticKeywordAbilities =+ [EnchantPermanent creatureType]
layeredEffects =: [boostEnchanted]
play =: Just playObject
{ manaCost = Just (black 1) }
where
boostEnchanted = LayeredObjectEffect
{ affectedObjects = affectAttached
, objectModifications = [ModifyPT (\_ -> return (-1, -1)), RestrictAllowBlocks selfCantBlock]
}
darkFavor :: Card
darkFavor = mkCard $ do
name =: Just "Dark Favor"
types =: auraType
play =: Just playObject
{ manaCost = Just (generic 1 <> black 1) }
triggeredAbilities =: loseLifeTrigger
layeredEffects =: [darkFavorEffect]
where
loseLifeTrigger = onSelfETB $ \_ you ->
mkTrigger you (will (LoseLife you 1))
darkFavorEffect = LayeredObjectEffect
{ affectedObjects = affectAttached
, objectModifications = [ModifyPT (\_ -> return (3, 1))]
}
disentomb :: Card
disentomb = mkCard $ do
name =: Just "Disentomb"
types =: sorceryType
play =: Just playObject
{ manaCost = Just (black 1)
, effect = \rSelf you -> do
ts <- askTarget you (isCreatureCard <?> targetInZone (Graveyard you))
stackTargetSelf rSelf you ts $ \t@(z, i) _ stackYou -> do
card <- view (asks (object t))
void $ executeEffect $
WillMoveObject (Just (Some z, i)) (Hand stackYou) card
}
where
isCreatureCard :: ObjectRef TyCard -> View Bool
isCreatureCard r = hasTypes creatureType <$> asks (objectPart . object r)
essenceDrain :: Card
essenceDrain = mkCard $ do
name =: Just "Essence Drain"
types =: sorceryType
play =: Just playObject
{ manaCost = Just (generic 4 <> black 1)
, effect = essenceDrainEffect
}
where
essenceDrainEffect rSelf you = do
ts <- askTarget you targetCreatureOrPlayer
stackTargetSelf rSelf you ts $ \t rStackSelf stackYou -> do
self <- view (asks (objectPart . object rStackSelf))
let damageEffect = case t of
Left r -> DamageObject self r 3 False True
Right p -> DamagePlayer self p 3 False True
void $ executeEffects [Will damageEffect, Will $ GainLife stackYou 3]
liliana'sShade :: Card
liliana'sShade = mkCard $ do
name =: Just "Liliana's Shade"
types =: creatureTypes [Shade]
pt =: Just (1, 1)
play =: Just playObject { manaCost = Just (generic 2 <> black 2) }
triggeredAbilities =: liliana'sShadeTrigger
activatedAbilities =: [liliana'sShadeAbility]
where
liliana'sShadeTrigger = onSelfETB $ \_ you -> mkTrigger you $ do
doSearch <- askYesNo you "Do you want to search the library for a Swamp card?"
when doSearch $ do
swamp <- searchCard you (Library you) (hasTypes (landTypes [Swamp]))
case swamp of
Just s -> do
let ref = (Library you, s)
refObj <- view (asks (object ref))
void $ executeEffects
[ Will $ RevealCards you [ref]
, WillMoveObject (Just (toSomeObjectRef ref)) (Hand you) refObj
]
will $ ShuffleLibrary you
Nothing -> return ()
plus1plus1 rSelf you = do
t <- tick
mkAbility you $
will $ InstallLayeredEffect rSelf TemporaryLayeredEffect
{ temporaryTimestamp = t
, temporaryDuration = UntilEndOfTurn
, temporaryEffect = affectingSelf [ModifyPT (\_ -> return (1, 1))]
}
liliana'sShadeAbility = ActivatedAbility
{ abilityType = ActivatedAb
, tapCost = NoTapCost
, abilityActivation = defaultActivation
{ effect = plus1plus1
, manaCost = Just (black 1)
}
}
mindRot :: Card
mindRot = mkCard $ do
name =: Just "Mind Rot"
types =: sorceryType
play =: Just playObject
{ manaCost = Just (generic 2 <> black 1)
, effect = mindRotEffect
}
where
mindRotEffect rSelf you = do
tpl <- askTarget you targetPlayer
stackTargetSelf rSelf you tpl $ \tp _rStackSelf _stackYou -> discardCards tp 2
ravenousRats :: Card
ravenousRats = mkCard $ do
name =: Just "Ravenous Rats"
types =: creatureTypes [Rat]
pt =: Just (1, 1)
play =: Just playObject { manaCost = Just (generic 1 <> black 1) }
triggeredAbilities =: onSelfETB ravenousRatsTrigger
where
ravenousRatsTrigger _rSelf you = do
opp <- askTarget you (targetOpponent you)
mkTargetTrigger you opp $ \o -> discardCards o 1
tormentedSoul :: Card
tormentedSoul = mkCard $ do
name =: Just "Tormented Soul"
types =: creatureTypes [Spirit]
play =: Just playObject { manaCost = Just (black 1) }
layeredEffects =: [affectingSelf
[RestrictAllowBlocks (selfCantBlock &&* selfCantBeBlocked)]]
vampireNighthawk :: Card
vampireNighthawk = mkCard $ do
name =: Just "Vampire Nighthawk"
types =: creatureTypes [Vampire, Shaman]
pt =: Just (2, 3)
play =: Just playObject { manaCost = Just (generic 1 <> black 2) }
staticKeywordAbilities =+ [Flying, Deathtouch, Lifelink]
-- RED CARDS
fervor :: Card
fervor = mkCard $ do
name =: Just "Fervor"
types =: enchantmentType
play =: Just playObject
{ manaCost = Just (generic 2 <> red 1) }
layeredEffects =: [grantHaste]
where
grantHaste = LayeredObjectEffect
{ affectedObjects = affectBattlefield $ \you ->
isControlledBy you &&* hasTypes creatureType
, objectModifications = [AddStaticKeywordAbility Haste]
}
fireElemental :: Card
fireElemental = mkCard $ do
name =: Just "Fire Elemental"
types =: creatureTypes [Elemental]
pt =: Just (5, 4)
play =: Just playObject
{ manaCost = Just (generic 3 <> red 2) }
firewingPhoenix :: Card
firewingPhoenix = mkCard $ do
name =: Just "Firewing Phoenix"
types =: creatureTypes [Phoenix]
pt =: Just (4, 2)
staticKeywordAbilities =+ [Flying]
play =: Just playObject
{ manaCost = Just (generic 3 <> red 1) }
activatedAbilities =: [returnFromGraveyard]
where
returnFromGraveyard = ActivatedAbility
{ abilityActivation = defaultActivation
{ available = availableFromGraveyard
, manaCost = Just (generic 1 <> red 3)
, effect = \(Some (Graveyard zr), i) you -> mkAbility you $ do
card <- view (asks (object (Graveyard zr, i)))
void $ executeEffect $
WillMoveObject (Just (Some (Graveyard you), i)) (Hand you) card
}
, tapCost = NoTapCost
, abilityType = ActivatedAb
}
furnaceWhelp :: Card
furnaceWhelp = mkCard $ do
name =: Just "Furnace Whelp"
types =: creatureTypes [Dragon]
pt =: Just (2, 2)
play =: Just playObject {
manaCost = Just (generic 2 <> red 2)
}
activatedAbilities =: [plusOneAbility]
where
plusOneAbility = ActivatedAbility
{ abilityType = ActivatedAb
, tapCost = NoTapCost
, abilityActivation = defaultActivation
{ effect = \rSelf you -> mkAbility you $ do
t <- tick
modifyPTUntilEOT (1, 0) rSelf t
, manaCost = Just (red 1)
}
}
flamesOfTheFirebrand :: Card
flamesOfTheFirebrand = mkCard $ do
name =: Just "Flames of the Firebrand"
types =: sorceryType
play =: Just playObject
{ manaCost = Just (generic 2 <> red 1)
, effect = \rSelf you -> do
ts <- askTargetsFromUpTo 1 3 you targetCreatureOrPlayer
let (trs, _) = evaluateTargetList ts
damages <- case length trs of
1 -> return [3]
3 -> return [1,1,1]
2 -> do
firstTwo <- askDamage you
"Choose the target to deal 2 damage to"
(pack $ show $ head trs)
(pack $ show $ head $ tail trs)
return $ if firstTwo then [2,1] else [1,2]
stackTargetSelf rSelf you ts $ \rs stackSelf _ -> do
self <- view (asks (objectPart . object stackSelf))
void . executeEffects $ zipWith (damageEffect self) damages rs
}
where
damageEffect self dmg t' = case t' of
Left r -> Will $ DamageObject self r dmg False True
Right p -> Will $ DamagePlayer self p dmg False True
askDamage :: PlayerRef -> Text -> Text -> Text -> Magic Bool
askDamage p txt c1 c2 = askQuestion p (AskChoice (Just txt) choices)
where
choices = [(ChoiceText c1, True), (ChoiceText c2, False)]
moggFlunkies :: Card
moggFlunkies = mkCard $ do
name =: Just "Mogg Flunkies"
types =: creatureTypes [Goblin]
pt =: Just (3, 3)
play =: Just playObject { manaCost = Just (generic 1 <> red 1) }
layeredEffects =: [affectingSelf
[ RestrictAllowAttacks selfCantAttackAlone
, RestrictAllowBlocks selfCantBlockAlone ] ]
searingSpear :: Card
searingSpear = mkCard $ do
name =: Just "Searing Spear"
types =: instantType
play =: Just playObject
{ manaCost = Just (generic 1 <> red 1)
, effect = searingSpearEffect
}
where
searingSpearEffect :: Contextual (Magic ())
searingSpearEffect rSelf you = do
ts <- askTarget you targetCreatureOrPlayer
stackTargetSelf rSelf you ts $ \t rStackSelf _stackYou -> do
self <- view (asks (objectPart . object rStackSelf))
will $ case t of
Left r -> DamageObject self r 3 False True
Right p -> DamagePlayer self p 3 False True
smelt :: Card
smelt = mkCard $ do
name =: Just "Smelt"
types =: instantType
play =: Just playObject
{ manaCost = Just (red 1)
, effect = destroyTargetPermanent (hasTypes artifactType)
}
thundermawHellkite :: Card
thundermawHellkite = mkCard $ do
name =: Just "Thundermaw Hellkite"
types =: creatureTypes [Dragon]
pt =: Just (5, 5)
play =: Just playObject
{ manaCost = Just (generic 3 <> red 2)
}
staticKeywordAbilities =+ [Flying, Haste]
triggeredAbilities =: onSelfETB thundermawHellkiteTrigger
where
thundermawHellkiteTrigger :: Contextual (Magic ())
thundermawHellkiteTrigger rSelf you = mkTrigger you $ do
self <- view (asks (objectBase rSelf))
let isAffected = notB (isControlledBy you) &&* hasStaticKeywordAbility Flying
objs <- filter (isAffected . get permanentObject . snd) <$> viewZone Battlefield
let damage r = DamageObject self r 1 False True
let damageAndTap r = [Will (damage r), Will (TapPermanent r)]
void . executeEffects $ concatMap damageAndTap (map fst objs)
torchFiend :: Card
torchFiend = mkCard $ do
name =: Just "Torch Fiend"
types =: creatureTypes [Devil]
pt =: Just (2, 1)
play =: Just playObject
{ manaCost = Just (generic 1 <> red 1)
}
activatedAbilities =: [torchFiendAbility]
where
torchFiendAbility = ActivatedAbility
{ abilityActivation = torchFiendActivation
, abilityType = ActivatedAb
, tapCost = NoTapCost
}
torchFiendActivation = defaultActivation
{ manaCost = Just (red 1)
, effect = torchFiendEffect
}
torchFiendEffect :: Contextual (Magic ())
torchFiendEffect rSelf@(Some Battlefield, i) you = do
ts <- askTarget you $ checkPermanent (hasTypes artifactType) <?> targetPermanent
will (Sacrifice (Battlefield, i))
mkTargetAbility you ts $ \t ->
will $ DestroyPermanent t True
trumpetBlast :: Card
trumpetBlast = mkCard $ do
name =: Just "Trumpet Blast"
types =: instantType
play =: Just playObject
{ manaCost = Just (generic 2 <> red 1)
, effect = stackSelf titanicGrowthEffect
}
where
titanicGrowthEffect _rSelf _you = do
let isAttacking = isJust . get attacking
objs <- map fst . filter (isAttacking . snd) <$> viewZone Battlefield
t <- tick
void $ traverse (\(r, i) -> modifyPTUntilEOT (2, 0) (Some r, i) t) objs
-- GREEN CARDS
acidicSlime :: Card
acidicSlime = mkCard $ do
name =: Just "Acidic Slime"
types =: creatureTypes [Ooze]
pt =: Just (2, 2)
play =: Just playObject { manaCost = Just (generic 3 <> green 2) }
staticKeywordAbilities =+ [Deathtouch]
triggeredAbilities =: onSelfETB acidicSlimeTrigger
where
targetTypes = [artifactType, enchantmentType, landType]
acidicSlimeTrigger _ p = do
ts <- askTarget p $ checkPermanent (hasOneOfTypes targetTypes) <?> targetPermanent
mkTargetTrigger p ts $ \ref -> will $ DestroyPermanent ref True
arborElf :: Card
arborElf = mkCard $ do
name =: Just "Arbor Elf"
types =: creatureTypes [Elf, Druid]
pt =: Just (1, 1)
play =: Just playObject { manaCost = Just (green 1) }
activatedAbilities =: [untapTargetForest]
where
untapTargetForest = tapAbility $ \_ you -> do
ts <- askTarget you $ checkPermanent
(hasTypes (landTypes [Forest])) <?> targetPermanent
mkTargetAbility you ts $ \rForest ->
will (UntapPermanent rForest)
bondBeetle :: Card
bondBeetle = mkCard $ do
name =: Just "Bond Beetle"
types =: creatureTypes [Insect]
pt =: Just (0, 1)
play =: Just playObject { manaCost = Just (green 1) }
triggeredAbilities =: onSelfETB createAddCounterTrigger
where
createAddCounterTrigger :: Contextual (Magic ())
createAddCounterTrigger _ p = do
ts <- askTarget p targetCreature
mkTargetTrigger p ts $ \(Battlefield, i) ->
will $ AddCounter (Some Battlefield, i) Plus1Plus1
bountifulHarvest :: Card
bountifulHarvest = mkCard $ do
name =: Just "Bountiful Harvest"
types =: sorceryType
play =: Just playObject
{ manaCost = Just $ (generic 4 <> green 1)
, effect = bountifulHarvestEffect
}
where
bountifulHarvestEffect :: Contextual (Magic ())
bountifulHarvestEffect = stackSelf $ \_stackSelf stackYou -> do
objs <- IdList.elems <$> view (asks battlefield)
let objectParts = map (get objectPart) objs
lands = flip filter objectParts $ \o ->
get controller o == stackYou && hasTypes landType o
will $ GainLife stackYou (length lands)
centaurCourser :: Card
centaurCourser = mkCard $ do
name =: Just "Centaur Courser"
types =: creatureTypes [Centaur, Warrior]
pt =: Just (3, 3)
play =: Just playObject { manaCost = Just (generic 2 <> green 1) }
deadlyRecluse :: Card
deadlyRecluse = mkCard $ do
name =: Just "Deadly Recluse"
types =: creatureTypes [Spider]
pt =: Just (1, 2)
play =: Just playObject { manaCost = Just (generic 1 <> green 1) }
staticKeywordAbilities =+ [Reach, Deathtouch]
duskdaleWurm :: Card
duskdaleWurm = mkCard $ do
name =: Just "Duskdale Wurm"
types =: creatureTypes [Wurm]
pt =: Just (7, 7)
play =: Just playObject { manaCost = Just (generic 5 <> green 2) }
staticKeywordAbilities =+ [Trample]
elvishArchdruid :: Card
elvishArchdruid = mkCard $ do
name =: Just "Elvish Archdruid"
types =: creatureTypes [Elf, Druid]
pt =: Just (2, 2)
play =: Just playObject { manaCost = Just (generic 1 <> green 2) }
activatedAbilities =: [addManaAbility]
layeredEffects =: [boostYourElves]
where
addManaAbility = tapAbility $ \_rSelf you -> do
cards <- (map (get objectPart) . IdList.elems) <$> view (asks battlefield)
let yourElves = filter (isControlledBy you &&* hasTypes (creatureTypes [Elf])) cards
mkTrigger you $ will $ AddToManaPool you $ MultiSet.insertMany (ColorEl Green) (length yourElves) mempty
boostYourElves = LayeredObjectEffect
{ affectedObjects = affectRestOfBattlefield $ \you ->
isControlledBy you &&* hasTypes (creatureTypes [Elf])
, objectModifications = [ModifyPT (\_ -> return (1, 1))]
}
elvishVisionary :: Card
elvishVisionary = mkCard $ do
name =: Just "Elvish Visionary"
types =: creatureTypes [Elf, Shaman]
pt =: Just (1, 1)
play =: Just playObject { manaCost = Just (generic 1 <> green 1) }
triggeredAbilities =: onSelfETB drawCardEffect
where
drawCardEffect _ you = mkTrigger you $ will $ DrawCard you
farseek :: Card
farseek = mkCard $ do
name =: Just "Farseek"
types =: sorceryType
play =: Just playObject
{ manaCost = Just (generic 1 <> green 1)
, effect = farseekEffect
}
where
farseekEffect = stackSelf $ \_rStackSelf stackYou -> do
let validLandTypes = map (landTypes . (:[])) [Plains, Island, Swamp, Mountain]
maybeId <- searchCard stackYou (Library stackYou) (hasOneOfTypes validLandTypes)
_ <- case maybeId of
Just i -> do
let objectRef = (Some (Library stackYou), i)
land <- view (asks (objectPart . object (Library stackYou, i)))
void . executeEffect $
WillMoveObject (Just objectRef) Battlefield $ Permanent land Tapped 0 False Nothing Nothing
Nothing -> return ()
will $ ShuffleLibrary stackYou
fungalSprouting :: Card
fungalSprouting = mkCard $ do
name =: Just "Fungal Sprouting"
types =: sorceryType
play =: Just playObject
{ manaCost = Just (generic 3 <> green 1)
, effect = makeTokenEffect
}
where
makeTokenEffect = stackSelf $ \_rSelf you -> do
perms <- (map (get objectPart) . IdList.elems) <$> view (asks battlefield)
t <- tick
let yours = filter (isControlledBy you &&* hasTypes creatureType) perms
maxPower = maximum $ 0 : map (maybe 0 fst . get pt) yours
token = simpleCreatureToken t you [Saproling] [Green] (1,1)
void $ executeEffects $ replicate maxPower $
WillMoveObject Nothing Battlefield (Permanent token Untapped 0 False Nothing Nothing)
garrukPrimalHunter :: Card
garrukPrimalHunter = mkCard $ do
name =: Just "Garruk, Primal Hunter"
types =: planeswalkerWithType Garruk
play =: Just playObject { manaCost = Just (generic 2 <> green 3) }
activatedAbilities =: [plusOne, minusThree, minusSix]
loyalty =: Just 3
replacementEffects =: [etbWithLoyaltyCounters]
where
plusOne = loyaltyAbility 1 $ \_ you -> do
mkAbility you $ do
t <- tick
let token = simpleCreatureToken t you [Beast] [Green] (3,3)
void $ executeEffect $ WillMoveObject Nothing Battlefield (Permanent token Untapped 0 False Nothing Nothing)
minusThree = loyaltyAbility (-3) $ \_ you -> do
mkAbility you $ do
objs <- IdList.elems <$> view (asks battlefield)
let n = foldr max 0 [ power
| o <- objs
, get (controller . objectPart) o == you
, let Just (power, _) = get (pt . objectPart) o ]
void $ executeEffects (replicate n (Will (DrawCard you)))
minusSix = loyaltyAbility (-6) $ \_ you -> do
mkAbility you $ do
perms <- IdList.elems <$> view (asks battlefield)
let n = count perms $ \perm ->
let o = get objectPart perm
in get controller o == you && hasTypes landType o
t <- tick