diff --git a/projects/mtg/bin/Res/sets/ALA/_cards.dat b/projects/mtg/bin/Res/sets/ALA/_cards.dat index 3c895a660..d27653e9f 100644 --- a/projects/mtg/bin/Res/sets/ALA/_cards.dat +++ b/projects/mtg/bin/Res/sets/ALA/_cards.dat @@ -691,7 +691,7 @@ toughness=* [/card] [card] text=Whenever an opponent plays a spell, that player puts the top two cards of his or her library into his or her graveyard. -auto=@movedTo(*[-land]|opponentstack):deplete:2 opponent +auto=@movedTo(*|opponentstack):deplete:2 opponent id=175108 name=Memory Erosion rarity=R diff --git a/projects/mtg/bin/Res/test/_tests.txt b/projects/mtg/bin/Res/test/_tests.txt index cf6f70409..ac7eca8ee 100644 --- a/projects/mtg/bin/Res/test/_tests.txt +++ b/projects/mtg/bin/Res/test/_tests.txt @@ -136,6 +136,7 @@ living_lands.txt lord_of_the_pit.txt lord_of_the_pit2.txt master_of_etherium.txt +memory_erosion.txt millstone.txt #mind_rot.txt mobile_fort.txt diff --git a/projects/mtg/bin/Res/test/memory_erosion.txt b/projects/mtg/bin/Res/test/memory_erosion.txt new file mode 100644 index 000000000..b659c6852 --- /dev/null +++ b/projects/mtg/bin/Res/test/memory_erosion.txt @@ -0,0 +1,18 @@ +#Bug: Lands use thestack +[INIT] +FIRSTMAIN +[PLAYER1] +hand:plains +library:swamp,mountains +[PLAYER2] +inplay:memory erosion +[DO] +plains +[ASSERT] +FIRSTMAIN +[PLAYER1] +inplay:plains +library:swamp,mountains +[PLAYER2] +inplay:memory erosion +[END] \ No newline at end of file diff --git a/projects/mtg/include/ActionStack.h b/projects/mtg/include/ActionStack.h index 20f286f88..7d58fd7a0 100644 --- a/projects/mtg/include/ActionStack.h +++ b/projects/mtg/include/ActionStack.h @@ -76,6 +76,7 @@ class Spell: public Interruptible { protected: public: + MTGGameZone * from; TargetChooser * tc; ManaCost * cost; Spell(MTGCardInstance* _source); diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index fe156feb0..3dca82d1e 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -475,10 +475,8 @@ public: for ( it=abilities.begin() ; it != abilities.end(); it++ ){ myToken->basicAbilities[*it] = 1; } - source->controller()->game->stack->addCard(myToken); + source->controller()->game->temp->addCard(myToken); Spell * spell = NEW Spell(myToken); - - spell->resolve(); delete spell; } @@ -524,9 +522,8 @@ public: //inplay is a special zone ! for (int i=0; i < 2; i++){ if (destZone == g->players[i]->game->inPlay && fromZone != g->players[i]->game->inPlay && fromZone != g->players[i]->opponent()->game->inPlay){ - MTGCardInstance * copy = g->players[i]->game->putInZone(_target, fromZone, g->players[i]->game->stack); + MTGCardInstance * copy = g->players[i]->game->putInZone(_target, fromZone, g->players[i]->game->temp); Spell * spell = NEW Spell(copy); - spell->resolve(); delete spell; return 1; @@ -2656,10 +2653,8 @@ class AAnimateDead:public MTGAbility{ //Put the card in play again, with all its abilities ! //AbilityFactory af; - MTGCardInstance * copy = source->controller()->game->putInZone(card, _target->controller()->game->graveyard, source->controller()->game->stack); + MTGCardInstance * copy = source->controller()->game->putInZone(card, _target->controller()->game->graveyard, source->controller()->game->temp); Spell * spell = NEW Spell(copy); - //af.addAbilities(game->mLayers->actionLayer()->getMaxId(), spell); - spell->resolve(); target = spell->source; card = spell->source; diff --git a/projects/mtg/include/MTGGameZones.h b/projects/mtg/include/MTGGameZones.h index 872e6f22a..a893797d6 100644 --- a/projects/mtg/include/MTGGameZones.h +++ b/projects/mtg/include/MTGGameZones.h @@ -152,6 +152,7 @@ class MTGPlayerCards { MTGRemovedFromGame * removedFromGame; MTGRemovedFromGame * exile; //alias to removedFromZone MTGGameZone * garbage; + MTGGameZone * temp; MTGAllCards * collection; diff --git a/projects/mtg/src/ActionStack.cpp b/projects/mtg/src/ActionStack.cpp index b2310a14f..2f43634d6 100644 --- a/projects/mtg/src/ActionStack.cpp +++ b/projects/mtg/src/ActionStack.cpp @@ -110,6 +110,7 @@ Spell::Spell(MTGCardInstance * _source): Interruptible(0){ type = ACTION_SPELL; cost = NEW ManaCost(); tc = NULL; + from = _source->getCurrentZone(); } @@ -117,6 +118,7 @@ Spell::Spell(int id, MTGCardInstance * _source, TargetChooser * tc, ManaCost * _ source = _source; mHeight = 40; type = ACTION_SPELL; + from = _source->getCurrentZone(); } @@ -132,11 +134,13 @@ Spell::~Spell(){ int Spell::resolve(){ GameObserver * game = GameObserver::GetInstance(); //TODO Remove target if it's not targettable anymore - while (source->next){ + /* while (source->next){ source = source->next; - } - if (!source->hasType("instant") && !source->hasType("sorcery")){ - source = source->controller()->game->putInPlay(source); + }*/ + if (!source->hasType("instant") && !source->hasType("sorcery")){ + Player * p = source->controller(); + source = p->game->putInZone(source,from,p->game->battlefield); + from = p->game->battlefield; } diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 0131ac14c..1dec73d3e 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -748,7 +748,7 @@ void AbilityFactory::addAbilities(int _id, Spell * spell){ card->target = spell->getNextCardTarget(); if (card->target && !spell->tc->canTarget(card->target)){ MTGPlayerCards * zones = card->controller()->game; - zones->putInGraveyard(card); + zones->putInZone(card,spell->from,card->owner->game->graveyard); return; //fizzle } } @@ -1523,13 +1523,13 @@ void AbilityFactory::addAbilities(int _id, Spell * spell){ { Player * player = spell->getNextPlayerTarget(); if (player->life < (INT_MAX / 4) ) player->life += player->life; - zones->putInZone(card,zones->stack,zones->library); + zones->putInZone(card,spell->from,zones->library); zones->library->shuffle(); break; } case 135262:// Beacon of Destruction & unrest { - zones->putInZone(card,zones->stack,zones->library); + zones->putInZone(card,spell->from,zones->library); zones->library->shuffle(); break; } diff --git a/projects/mtg/src/MTGCardInstance.cpp b/projects/mtg/src/MTGCardInstance.cpp index c06e2e804..4157376b1 100644 --- a/projects/mtg/src/MTGCardInstance.cpp +++ b/projects/mtg/src/MTGCardInstance.cpp @@ -159,8 +159,8 @@ MTGGameZone * MTGCardInstance::getCurrentZone(){ GameObserver * game = GameObserver::GetInstance(); for (int i = 0; i < 2; i++){ MTGPlayerCards * g = game->players[i]->game; - MTGGameZone * zones[] = {g->inPlay,g->graveyard,g->hand, g->library}; - for (int k = 0; k < 4; k++){ + MTGGameZone * zones[] = {g->inPlay,g->graveyard,g->hand, g->library, g->stack, g->temp}; + for (int k = 0; k < 6; k++){ MTGGameZone * zone = zones[k]; if (zone->hasCard(this)) return zone; } @@ -299,6 +299,7 @@ Player * MTGCardInstance::controller(){ if (game->players[i]->game->graveyard->hasCard(this)) return game->players[i]; if (game->players[i]->game->hand->hasCard(this)) return game->players[i]; if (game->players[i]->game->library->hasCard(this)) return game->players[i]; + if (game->players[i]->game->temp->hasCard(this)) return game->players[i]; } return lastController; } diff --git a/projects/mtg/src/MTGGameZones.cpp b/projects/mtg/src/MTGGameZones.cpp index 8e70937b1..9162d6edd 100644 --- a/projects/mtg/src/MTGGameZones.cpp +++ b/projects/mtg/src/MTGGameZones.cpp @@ -49,6 +49,7 @@ MTGPlayerCards::~MTGPlayerCards(){ SAFE_DELETE(stack); SAFE_DELETE(removedFromGame); SAFE_DELETE(garbage); + SAFE_DELETE(temp); } void MTGPlayerCards::setOwner(Player * player){ @@ -59,6 +60,7 @@ void MTGPlayerCards::setOwner(Player * player){ removedFromGame->setOwner(player); stack->setOwner(player); garbage->setOwner(player); + temp->setOwner(player); } void MTGPlayerCards::initGame(int shuffle, int draw){ @@ -71,13 +73,12 @@ void MTGPlayerCards::initGame(int shuffle, int draw){ } void MTGPlayerCards::drawFromLibrary(){ - MTGCardInstance * drownCard = library->draw(); - if(drownCard){ - hand->addCard(drownCard); + MTGCardInstance * drawnCard = library->draw(); + if(drawnCard){ + hand->addCard(drawnCard); GameObserver *g = GameObserver::GetInstance(); - WEvent * e = NEW WEventZoneChange(drownCard,library,hand); + WEvent * e = NEW WEventZoneChange(drawnCard,library,hand); g->receiveEvent(e); - //delete e; } } @@ -92,6 +93,7 @@ void MTGPlayerCards::init(){ removedFromGame = NEW MTGRemovedFromGame(); exile = removedFromGame; garbage = NEW MTGGameZone(); + temp = NEW MTGGameZone(); } diff --git a/projects/mtg/src/MTGRules.cpp b/projects/mtg/src/MTGRules.cpp index 8f267c3bc..d5f4b5dc8 100644 --- a/projects/mtg/src/MTGRules.cpp +++ b/projects/mtg/src/MTGRules.cpp @@ -54,7 +54,7 @@ int MTGPutInPlayRule::reactToClick(MTGCardInstance * card){ ManaCost * spellCost = previousManaPool->Diff(player->getManaPool()); delete previousManaPool; if (card->hasType("land")){ - MTGCardInstance * copy = player->game->putInZone(card, player->game->hand, player->game->stack); + MTGCardInstance * copy = player->game->putInZone(card, player->game->hand, player->game->temp); Spell * spell = NEW Spell(copy); spell->resolve(); delete spellCost; @@ -62,13 +62,13 @@ int MTGPutInPlayRule::reactToClick(MTGCardInstance * card){ player->canPutLandsIntoPlay--; }else{ Spell * spell = NULL; - if (game->targetChooser){ - spell = game->mLayers->stackLayer()->addSpell(card,game->targetChooser, spellCost); - game->targetChooser = NULL; - }else - spell = game->mLayers->stackLayer()->addSpell(card,NULL, spellCost); MTGCardInstance * copy = player->game->putInZone(card, player->game->hand, player->game->stack); - spell->source = copy; + if (game->targetChooser){ + spell = game->mLayers->stackLayer()->addSpell(copy,game->targetChooser, spellCost); + game->targetChooser = NULL; + }else{ + spell = game->mLayers->stackLayer()->addSpell(copy,NULL, spellCost); + } } return 1; }