From 6097b1282bc297ca7b20c2a0c9013c268af13d54 Mon Sep 17 00:00:00 2001 From: "wagic.laurent" Date: Mon, 29 Jun 2009 11:11:41 +0000 Subject: [PATCH] Laurent - Added draw/token to the foreach parser (allow to sligthly reduce the number of lines in MTGAbility.cpp and also add few cards to different cards.dat.) NOTE that all these additions to the foreach parser are only available for the "inplay" area... "countcards" will need to be updated in order to have thing such as graveyard or hand to be taken into consideration (but when it will be done cards such as Spontaneous Generation - MRQ, could be added) Also updated (tentatively) the "cantbeblockedby" in the parser it still does not work...ARG... but I can feel that I'm not far away from the solution... We need also to go through some of the cards.dat to be sure we are not missing any possible addition ... --- projects/mtg/bin/Res/sets/10E/_cards.dat | 2 +- projects/mtg/bin/Res/sets/EVE/_cards.dat | 12 +++ projects/mtg/bin/Res/sets/EVE/todo.dat | 11 --- projects/mtg/bin/Res/sets/ICE/todo.dat | 14 ++- projects/mtg/bin/Res/sets/LEG/_cards.dat | 2 +- projects/mtg/bin/Res/sets/LRW/_cards.dat | 1 + projects/mtg/bin/Res/sets/MRQ/_cards.dat | 9 ++ projects/mtg/bin/Res/sets/MRQ/todo.dat | 8 -- projects/mtg/bin/Res/sets/POR/_cards.dat | 11 ++- projects/mtg/bin/Res/sets/POR/todo.dat | 8 -- projects/mtg/bin/Res/sets/RAV/_cards.dat | 1 + projects/mtg/bin/Res/sets/SHM/_cards.dat | 3 +- projects/mtg/include/MTGAbility.h | 1 + projects/mtg/src/MTGAbility.cpp | 109 ++++++++++------------- 14 files changed, 99 insertions(+), 93 deletions(-) diff --git a/projects/mtg/bin/Res/sets/10E/_cards.dat b/projects/mtg/bin/Res/sets/10E/_cards.dat index 7b97e2148..fb6fbff4c 100644 --- a/projects/mtg/bin/Res/sets/10E/_cards.dat +++ b/projects/mtg/bin/Res/sets/10E/_cards.dat @@ -701,7 +701,7 @@ mana={3}{U}{U} text=Elven Riders can't be blocked except by Walls and/or creatures with flying. id=135266 name=Elven Riders -auto=cantbeblockedby(creature[-flying]) +auto=cantbeblockedby(creature[-flying],-walls) rarity=U color=Green type=Creature diff --git a/projects/mtg/bin/Res/sets/EVE/_cards.dat b/projects/mtg/bin/Res/sets/EVE/_cards.dat index cdd673ad8..dc1afcf37 100644 --- a/projects/mtg/bin/Res/sets/EVE/_cards.dat +++ b/projects/mtg/bin/Res/sets/EVE/_cards.dat @@ -291,6 +291,18 @@ type=Instant mana={2}{R} [/card] [card] +text=When Regal Force comes into play, draw a card for each green creature you control. +id=147373 +name=Regal Force +auto=foreach(creature[green]|myinplay)draw:1 +rarity=R +type=Creature +mana={4}{G}{G}{G} +power=5 +subtype=Elemental +toughness=5 +[/card] +[card] text=Wither (This deals damage to creatures in the form of -1/-1 counters.) Persist (When this creature is put into a graveyard from play, if it had no -1/-1 counters on it, return it to play under its owner's control with a -1/-1 counter on it.) abilities=wither,persist id=158902 diff --git a/projects/mtg/bin/Res/sets/EVE/todo.dat b/projects/mtg/bin/Res/sets/EVE/todo.dat index 88074e8d6..06b64a016 100644 --- a/projects/mtg/bin/Res/sets/EVE/todo.dat +++ b/projects/mtg/bin/Res/sets/EVE/todo.dat @@ -1042,17 +1042,6 @@ mana={2}{W} subtype=Aura [/card] [card] -text=When Regal Force comes into play, draw a card for each green creature you control. -id=147373 -name=Regal Force -rarity=R -type=Creature -mana={4}{G}{G}{G} -power=5 -subtype=Elemental -toughness=5 -[/card] -[card] text=Rekindled Flame deals 4 damage to target creature or player. At the beginning of your upkeep, if an opponent has no cards in hand, you may return Rekindled Flame from your graveyard to your hand. target=creature,player id=158108 diff --git a/projects/mtg/bin/Res/sets/ICE/todo.dat b/projects/mtg/bin/Res/sets/ICE/todo.dat index ad1359538..ba29811c3 100644 --- a/projects/mtg/bin/Res/sets/ICE/todo.dat +++ b/projects/mtg/bin/Res/sets/ICE/todo.dat @@ -72,6 +72,8 @@ mana={3} [card] text={W}, Sacrifice an enchantment: Destroy target enchantment. {3}{U}{U}: Counter target enchantment spell. id=2663 +auto={W}{S(Enchantment|myinplay)}:destroy target(enchantment) +auto={3}{U}{U}:fizzle target(enchantment|stack) name=Arenson's Aura rarity=C type=Enchantment @@ -170,6 +172,8 @@ mana={1} [card] text=Untap all white creatures you control. Whenever a creature blocks this turn, it gets +0/+1 until end of turn. id=2665 +auto=untap all(creature[white]|myinplay) +auto=lord(creature[blocking])0/1 name=Battle Cry rarity=U type=Instant @@ -187,6 +191,9 @@ subtype=Aura [card] text=Enchant creature Enchanted creature can't be blocked by black creatures. Enchanted creature gets +2/+2 as long as an opponent controls a black permanent. id=2666 +target=creature +auto=cantbeblockedby(creature[black]) +auto=aslongas(*[black]|opponentinplay)2/2 name=Black Scarab rarity=U type=Enchantment @@ -216,6 +223,9 @@ mana={G}{G} [card] text=Enchant creature Enchanted creature can't be blocked by blue creatures. Enchanted creature gets +2/+2 as long as an opponent controls a blue permanent. id=2669 +target=creature +auto=cantbeblockedby(creature[blue]) +auto=aslongas(*[blue]|opponentinplay)2/2 name=Blue Scarab rarity=U type=Enchantment @@ -390,6 +400,8 @@ mana={2} [card] text=When Curse of Marit Lage comes into play, tap all Islands. Islands don't untap during their controllers' untap steps. id=2617 +auto=tap all(island) +auto=lord(island)doesntuntap name=Curse of Marit Lage rarity=R type=Enchantment @@ -622,7 +634,7 @@ text=Foul Familiar can't block. {B}, Pay 1 life: Return Foul Familiar to its id=2450 name=Foul Familiar abilities=cantblock -auto={B} +auto={B}:moveto(ownerhand) && damage:1 && controller rarity=C type=Creature mana={2}{B} diff --git a/projects/mtg/bin/Res/sets/LEG/_cards.dat b/projects/mtg/bin/Res/sets/LEG/_cards.dat index 1a123243b..9b6e169a1 100644 --- a/projects/mtg/bin/Res/sets/LEG/_cards.dat +++ b/projects/mtg/bin/Res/sets/LEG/_cards.dat @@ -460,7 +460,7 @@ type=Enchantment [card] text=Target creature gets +0/+X until end of turn, where X is its converted mana cost. id=1614 -taget=creature +target=creature name=Great Defender rarity=U type=Instant diff --git a/projects/mtg/bin/Res/sets/LRW/_cards.dat b/projects/mtg/bin/Res/sets/LRW/_cards.dat index 5bc94f36b..0e602faaa 100644 --- a/projects/mtg/bin/Res/sets/LRW/_cards.dat +++ b/projects/mtg/bin/Res/sets/LRW/_cards.dat @@ -128,6 +128,7 @@ toughness=1 text=Put a 1/1 green Elf Warrior creature token into play for each Elf you control. id=139676 name=Elvish Promenade +auto=foreach(elf|myinplay)token(Elf Warrior,creature Elf Warrior,1/1,green) rarity=U type=Sorcery mana={3}{G} diff --git a/projects/mtg/bin/Res/sets/MRQ/_cards.dat b/projects/mtg/bin/Res/sets/MRQ/_cards.dat index b5dad1387..e6799d5b1 100644 --- a/projects/mtg/bin/Res/sets/MRQ/_cards.dat +++ b/projects/mtg/bin/Res/sets/MRQ/_cards.dat @@ -214,6 +214,15 @@ toughness=1 abilities=flying,cloud [/card] [card] +text=Draw a card for each creature you control. +id=19739 +auto=foreach(creature|myinplay)draw:1 +name=Collective Unconscious +rarity=R +type=Sorcery +mana={4}{G}{G} +[/card] +[card] text=Counter target spell. target=*|stack auto=fizzle diff --git a/projects/mtg/bin/Res/sets/MRQ/todo.dat b/projects/mtg/bin/Res/sets/MRQ/todo.dat index b39b23005..94981f693 100644 --- a/projects/mtg/bin/Res/sets/MRQ/todo.dat +++ b/projects/mtg/bin/Res/sets/MRQ/todo.dat @@ -412,14 +412,6 @@ type=Enchantment mana={2}{U}{U} [/card] [card] -text=Draw a card for each creature you control. -id=19739 -name=Collective Unconscious -rarity=R -type=Sorcery -mana={4}{G}{G} -[/card] -[card] text=Nonartifact creatures get +2/+2 as long as they all share a color. id=19665 name=Common Cause diff --git a/projects/mtg/bin/Res/sets/POR/_cards.dat b/projects/mtg/bin/Res/sets/POR/_cards.dat index 5ec16a1ae..0589ad4ef 100644 --- a/projects/mtg/bin/Res/sets/POR/_cards.dat +++ b/projects/mtg/bin/Res/sets/POR/_cards.dat @@ -1195,7 +1195,7 @@ toughness=4 text=Spitting Earth deals damage equal to the number of Mountains you control to target creature. id=4362 target=creature -alias=136509 +auto=foreach(moutain|myinplay)damage:1 name=Spitting Earth rarity=C type=Sorcery @@ -1297,6 +1297,15 @@ mana={2}{U} type=Sorcery [/card] [card] +text=Draw a card for each tapped creature target opponent controls. +id=4279 +name=Theft of Dreams +auto=foreach(creature[tapped]|opponentinplay)draw:1 +rarity=U +type=Sorcery +mana={2}{U} +[/card] +[card] text=Put target creature on top of its owner's library. target=creature auto=moveTo(ownerLibrary) diff --git a/projects/mtg/bin/Res/sets/POR/todo.dat b/projects/mtg/bin/Res/sets/POR/todo.dat index 8880a656f..8ebbe4cfd 100644 --- a/projects/mtg/bin/Res/sets/POR/todo.dat +++ b/projects/mtg/bin/Res/sets/POR/todo.dat @@ -539,14 +539,6 @@ type=Sorcery mana={1}{W} [/card] [card] -text=Draw a card for each tapped creature target opponent controls. -id=4279 -name=Theft of Dreams -rarity=U -type=Sorcery -mana={2}{U} -[/card] -[card] text=Whenever Thing from the Deep attacks, sacrifice it unless you sacrifice an Island. id=4280 name=Thing from the Deep diff --git a/projects/mtg/bin/Res/sets/RAV/_cards.dat b/projects/mtg/bin/Res/sets/RAV/_cards.dat index 9e12c301e..4bab216db 100644 --- a/projects/mtg/bin/Res/sets/RAV/_cards.dat +++ b/projects/mtg/bin/Res/sets/RAV/_cards.dat @@ -286,6 +286,7 @@ subtype=Aura text=Draw a card for each Island you control. id=87978 name=Flow of Ideas +auto=foreach(island|myinplay)draw:1 rarity=U type=Sorcery mana={5}{U} diff --git a/projects/mtg/bin/Res/sets/SHM/_cards.dat b/projects/mtg/bin/Res/sets/SHM/_cards.dat index e21ee3efd..c13aa2a18 100644 --- a/projects/mtg/bin/Res/sets/SHM/_cards.dat +++ b/projects/mtg/bin/Res/sets/SHM/_cards.dat @@ -306,7 +306,7 @@ mana={2R}{2R}{2R} [card] text=Draw a card for each Island you control. id=158692 -alias=87978 +auto=foreach(island|myinplay)draw:1 name=Flow of Ideas rarity=U type=Sorcery @@ -443,6 +443,7 @@ toughness=1 text=Put a 2/2 green Wolf creature token into play for each Forest you control. id=153996 name=Howl of the Night Pack +auto=foreach(forest|myinplay)token(Wolf,creature wolf,2/2,green) rarity=U type=Sorcery mana={6}{G} diff --git a/projects/mtg/include/MTGAbility.h b/projects/mtg/include/MTGAbility.h index 5174380df..03de2d5a3 100644 --- a/projects/mtg/include/MTGAbility.h +++ b/projects/mtg/include/MTGAbility.h @@ -234,6 +234,7 @@ class AbilityFactory{ int moveAll(TargetChooser * tc, string destinationZone); int damageAll(TargetChooser * tc, int damage); int TapAll(TargetChooser * tc); + int CantBlock(TargetChooser * tc); int UntapAll(TargetChooser * tc); void addAbilities(int _id, Spell * spell); }; diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 0faf02ab2..1a3ed9839 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -50,6 +50,19 @@ int AbilityFactory::destroyAllInPlay(TargetChooser * tc, int bury){ return 1; } +int AbilityFactory::CantBlock(TargetChooser * tc){ + GameObserver * g = GameObserver::GetInstance(); + MTGCardInstance * source = tc->source; + for (int j = g->opponent()->game->inPlay->nb_cards-1; j >=0 ; j--){ + MTGCardInstance * current = g->opponent()->game->inPlay->cards[j]; + if (tc->canTarget(current)){ + current->canBlock(source); + return 0; + } + } + return 1; +} + int AbilityFactory::damageAll(TargetChooser * tc, int damage){ MTGCardInstance * source = tc->source; tc->source = NULL; // This is to prevent protection from... as objects that destroy all do not actually target @@ -84,6 +97,8 @@ int AbilityFactory::moveAll(TargetChooser * tc, string destinationZone){ } + + int AbilityFactory::TapAll(TargetChooser * tc){ MTGCardInstance * source = tc->source; tc->source = NULL; // This is to prevent protection from... @@ -443,7 +458,15 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){ int multiplier = 1; found = s.find("*"); if (found != string::npos)multiplier = atoi(s.substr(found+1).c_str()); - if(cost || doTap){ + if (lordType == PARSER_FOREACH){ + int nbtoken = countCards(lordTargets); + ATokenCreator * tok = NEW ATokenCreator(id,card,cost,sname,stypes,power,toughness,sabilities,doTap); + for (int i=0; i < nbtoken; i++){ + tok->resolve(); + } + delete tok; + }else{ + if(cost || doTap){ game->addObserver(NEW ATokenCreator(id,card,cost,sname,stypes,power,toughness,sabilities,doTap)); }else{ ATokenCreator * tok = NEW ATokenCreator(id,card,cost,sname,stypes,power,toughness,sabilities,doTap); @@ -451,7 +474,8 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){ tok->resolve(); } delete tok; - } + } + } result++; continue; } @@ -699,6 +723,10 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){ dryModeResult = BAKA_EFFECT_GOOD; break; } + if (lordType == PARSER_FOREACH){ + int multiplier = countCards(lordTargets); + game->mLayers->stackLayer()->addDraw(card->controller(),multiplier);; + }else{ if (trigger){ DrawEvent * action = NEW DrawEvent(card->controller(),nbcards); game->addObserver(NEW GenericTriggeredAbility(id, card,trigger,action)); @@ -710,12 +738,13 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){ game->mLayers->stackLayer()->addDraw(card->controller(),nbcards); }else{ game->addObserver(NEW ADrawer(id,card,cost,nbcards,doTap)); - } - } - } + } + } + } + } result++; continue; - } + } //Deplete found = s.find("deplete:"); @@ -748,31 +777,20 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){ } result++; continue; - } + } //CannotBeBlockedBy found = s.find("cantbeblockedby("); if (found != string::npos){ - int end = s.find(")",found+1); - string starget = s.substr(found + 18,end - found - 18); - TargetChooserFactory tcf; - tc = tcf.createTargetChooser(starget,card); - if (dryMode){ - dryModeResult = BAKA_EFFECT_GOOD; - break; - } - for (int i = 0; i < 2 ; i++){ - for (int j = game->players[i]->game->inPlay->nb_cards-1; j >=0 ; j--){ - MTGCardInstance * current = game->players[i]->game->inPlay->cards[j]; - if (tc->canTarget(current)){ - MTGCardInstance * canBlock = tc->source; - current->canBlock(); - } - } - } - result++; - continue; - } + int end = s.find(")",found); + string starget = s.substr(16, end - 16); + TargetChooserFactory tcf; + tc = tcf.createTargetChooser(starget,card); + CantBlock(tc); + result++; + continue; + } + @@ -830,9 +848,9 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){ dryModeResult = BAKA_EFFECT_GOOD; }else{ dryModeResult = BAKA_EFFECT_BAD; - } + } break; - } + } int MaxOpponent = atoi(s.substr(end+1,end+2).c_str()); if(tc){ //TODO?? @@ -1080,10 +1098,8 @@ void AbilityFactory::addAbilities(int _id, Spell * spell){ } case 1094: //Ank Of Mishra { - // AAnkhOfMishra * ability = NEW AAnkhOfMishra(_id,card); - // game->addObserver(ability); game->addObserver (NEW ALifeModifierPutinplay(_id,card,"land",-2,2,1)); - break; + break; } case 1095: //Armageddon clock { @@ -1091,14 +1107,12 @@ void AbilityFactory::addAbilities(int _id, Spell * spell){ game->addObserver(ability); break; } - case 1096: //Basalt Monolith { int cost[] = {Constants::MTG_COLOR_ARTIFACT, 3}; AManaProducer * ability = NEW AManaProducer(_id, card, NEW ManaCost(cost,1)); AUntapManaBlocker * ability2 = NEW AUntapManaBlocker(_id+1, card, NEW ManaCost(cost,1)); AUnBlocker * ability3 = NEW AUnBlocker(_id+1, card,card, NEW ManaCost(cost,1)); - game->addObserver(ability); game->addObserver(ability2); game->addObserver(ability3); @@ -2116,16 +2130,6 @@ void AbilityFactory::addAbilities(int _id, Spell * spell){ //--- addon shm--- - case 153996: // Howl of the Night Pack - { - int x = card->controller()->game->inPlay->countByType("Forest"); - ATokenCreator * tok = NEW ATokenCreator(id,card,NEW ManaCost(),"Wolf","Creature Wolf",2,2,"green",0); - for (int i=0; i < x-1; i++){ - tok->resolve(); - } - break; - } - case 147427: // Poison the Well { card->target->controller()->life-=2; @@ -2175,24 +2179,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell){ break; } -// --- addon Lorwynn--- - case 139676: // Elvish Promenade - { - int x = card->controller()->game->inPlay->countByType("Elf"); - ATokenCreator * tok = NEW ATokenCreator(id,card,NEW ManaCost(),"Elf Warrior","creature Elf Warrior",1,1,"green",0); - for (int i=0; i < x-1; i++){ - tok->resolve(); - } - break; - } - // --- addon Ravnica--- - case 87978: // Flow of Ideas - { - int nbcards = card->controller()->game->inPlay->countByType("Island"); - game->mLayers->stackLayer()->addDraw(card->controller(),nbcards); - break; - } case 89114: //Psychic Drain {