diff --git a/projects/mtg/bin/Res/test/_tests.txt b/projects/mtg/bin/Res/test/_tests.txt index d4825b312..6c7e61a2a 100644 --- a/projects/mtg/bin/Res/test/_tests.txt +++ b/projects/mtg/bin/Res/test/_tests.txt @@ -504,9 +504,10 @@ Zombie_Infestation.txt zombie_master.txt zombify.txt ######################## -#Momir Basic Tests +#Momir Tests ######################## momir/keldon_warlord.txt +momir/persist_i304.txt momir/overcost.txt ######################## #AI Tests diff --git a/projects/mtg/bin/Res/test/momir/persist_i304.txt b/projects/mtg/bin/Res/test/momir/persist_i304.txt new file mode 100644 index 000000000..630bb62c7 --- /dev/null +++ b/projects/mtg/bin/Res/test/momir/persist_i304.txt @@ -0,0 +1,37 @@ +#Creatures with persist shouldn't go back from the graveyard if they are tokens +MOMIR +[INIT] +SECONDMAIN +[PLAYER1] +hand:plains +manapool:{3} +[PLAYER2] +inplay:Rock Badger +[DO] +plains -momir- Rendclaw Trow +eot +next +#upkeep +next +#draw +next +#main +next +#combat begins +next +#attackers +Rock Badger +next +#blockers +Rendclaw Trow +next +#damage +next +#end combat +[ASSERT] +COMBATEND +[PLAYER1] +graveyard:plains +[PLAYER2] +inplay:rock badger +[END] \ No newline at end of file diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 045ee9b65..2d71c9e63 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -116,10 +116,10 @@ public: // Triggers When a card gets added to a zone (@movedTo) class TrCardAddedToZone:public TriggeredAbility{ public: - TargetChooser * toTc; - TargetZoneChooser * fromTcZone; - TargetChooser * fromTcCard; - TrCardAddedToZone(int id, MTGCardInstance * source, TargetChooser * toTc, TargetZoneChooser * fromTcZone = NULL,TargetChooser * fromTcCard = NULL):TriggeredAbility(id,source), toTc(toTc), fromTcZone(fromTcZone), fromTcCard(fromTcCard){} + TargetZoneChooser * toTcZone, * fromTcZone; + TargetChooser * toTcCard, * fromTcCard; + TrCardAddedToZone(int id, MTGCardInstance * source, TargetZoneChooser * toTcZone, TargetChooser * toTcCard , TargetZoneChooser * fromTcZone = NULL,TargetChooser * fromTcCard = NULL) + :TriggeredAbility(id,source), toTcZone(toTcZone), fromTcZone(fromTcZone), toTcCard(toTcCard), fromTcCard(fromTcCard){}; int resolve(){ return 0; //This is a trigger, this function should not be called @@ -129,7 +129,8 @@ public: WEventZoneChange * e = dynamic_cast(event); if (!e) return 0; - if (!toTc->canTarget(e->card)) return 0; + if (!toTcZone->targetsZone(e->to)) return 0; + if (!toTcCard->canTarget(e->card)) return 0; if (fromTcZone && !fromTcZone->targetsZone(e->from)) return 0; if (fromTcCard && !fromTcCard->canTarget(e->card->previous)) return 0; @@ -143,7 +144,8 @@ public: } ~TrCardAddedToZone(){ - SAFE_DELETE(toTc); + SAFE_DELETE(toTcZone); + SAFE_DELETE(toTcCard); SAFE_DELETE(fromTcZone); SAFE_DELETE(fromTcCard); } diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index c16ebc567..8269e5443 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -305,9 +305,8 @@ int AIPlayer::interruptIfICan(){ int AIPlayer::effectBadOrGood(MTGCardInstance * card, int mode, TargetChooser * tc){ int id = card->getMTGId(); - AbilityFactory * af = NEW AbilityFactory(); - int autoGuess = af->magicText(id,NULL,card, mode, tc); - delete af; + AbilityFactory af; + int autoGuess = af.magicText(id,NULL,card, mode, tc); if (autoGuess) return autoGuess; return BAKA_EFFECT_DONTKNOW; } @@ -632,9 +631,8 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty int currentCost = card->getManaCost()->getConvertedCost(); int hasX = card->getManaCost()->hasX(); if ((currentCost > maxCost || hasX) && pMana->canAfford(card->getManaCost())){ - TargetChooserFactory * tcf = NEW TargetChooserFactory(); - TargetChooser * tc = tcf->createTargetChooser(card); - delete tcf; + TargetChooserFactory tcf; + TargetChooser * tc = tcf.createTargetChooser(card); int shouldPlayPercentage = 10; if (tc){ int hasTarget = (chooseTarget(tc)); @@ -653,7 +651,7 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty if (hasX){ int xDiff = pMana->getConvertedCost() - currentCost; if (xDiff < 0) xDiff = 0; - shouldPlayPercentage = shouldPlayPercentage - ((shouldPlayPercentage * 1.9) / (1 + xDiff)); + shouldPlayPercentage = shouldPlayPercentage - ((shouldPlayPercentage * 1.9f) / (1 + xDiff)); } if (WRand() % 100 > shouldPlayPercentage) continue; @@ -682,7 +680,7 @@ AIPlayerBaka::AIPlayerBaka(MTGPlayerCards * deck, string file, string fileSmall, } void AIPlayerBaka::initTimer(){ - timer = 0.1; + timer = 0.1f; } int AIPlayerBaka::computeActions(){ diff --git a/projects/mtg/src/CardSelector.cpp b/projects/mtg/src/CardSelector.cpp index 60a80bc83..1b4093e83 100644 --- a/projects/mtg/src/CardSelector.cpp +++ b/projects/mtg/src/CardSelector.cpp @@ -38,9 +38,9 @@ void CardSelector::Add(CardSelector::Target* target) if (NULL == limitor || limitor->select(active)) active = target; CardView* c = dynamic_cast(target); - if (c) c->zoom = 1.0; + if (c) c->zoom = 1.0f; c = dynamic_cast(active); - if (c) c->zoom = 1.4; + if (c) c->zoom = 1.4f; cards.push_back(target); } template<> @@ -51,9 +51,9 @@ void CardSelector::Remove(CardSelector::Target* card) { if (active == *it) { - CardView* c = dynamic_cast(active); if (c) c->zoom = 1.0; + CardView* c = dynamic_cast(active); if (c) c->zoom = 1.0f; active = closest(cards, limitor, active); - c = dynamic_cast(active); if (c) c->zoom = 1.4; + c = dynamic_cast(active); if (c) c->zoom = 1.4f; } if (active == *it) active = NULL; cards.erase(it); @@ -89,8 +89,8 @@ void CardSelector::Pop() { if (nullZone != oldowner) lasts[oldowner] = SelectorMemory(oldactive); } if (active != oldactive) { - { CardView* c = dynamic_cast(oldactive); if (c) c->zoom = 1.0; } //Is this needed, I think it is one in Leaving(0) ? - { CardView* c = dynamic_cast(active); if (c) c->zoom = 1.4; } //Is this needed, I think it is one in Entering() ? + { CardView* c = dynamic_cast(oldactive); if (c) c->zoom = 1.0f; } //Is this needed, I think it is one in Leaving(0) ? + { CardView* c = dynamic_cast(active); if (c) c->zoom = 1.4f; } //Is this needed, I think it is one in Entering() ? if (oldactive) oldactive->Leaving(JGE_BTN_NONE); if (active) active->Entering(); } @@ -159,8 +159,8 @@ bool CardSelector::CheckUserInput(JButton key) } } if (active != oldactive) { - { CardView* c = dynamic_cast(oldactive); if (c) c->zoom = 1.0; } - { CardView* c = dynamic_cast(active); if (c) c->zoom = 1.4; } + { CardView* c = dynamic_cast(oldactive); if (c) c->zoom = 1.0f; } + { CardView* c = dynamic_cast(active); if (c) c->zoom = 1.4f; } if (oldactive) oldactive->Leaving(JGE_BTN_NONE); if (active) active->Entering(); } @@ -223,8 +223,8 @@ void CardSelector::Limit(LimitorFunctor* limitor, SelectorZone destzone) } if (active != oldactive) { - { CardView* c = dynamic_cast(oldactive); if (c) c->zoom = 1.0; } - { CardView* c = dynamic_cast(active); if (c) c->zoom = 1.4; } + { CardView* c = dynamic_cast(oldactive); if (c) c->zoom = 1.0f; } + { CardView* c = dynamic_cast(active); if (c) c->zoom = 1.4f; } if (oldactive) oldactive->Leaving(JGE_BTN_NONE); if (active) active->Entering(); } diff --git a/projects/mtg/src/DuelLayers.cpp b/projects/mtg/src/DuelLayers.cpp index 745418dea..bd11e01ec 100644 --- a/projects/mtg/src/DuelLayers.cpp +++ b/projects/mtg/src/DuelLayers.cpp @@ -28,6 +28,7 @@ void DuelLayers::init(){ action->Add(NEW MTGAttackRule(-1)); action->Add(NEW MTGBlockRule(-1)); action->Add(NEW MTGLegendRule(-1)); + action->Add(NEW MTGTokensCleanup(-1)); // needs to be before persist action->Add(NEW MTGPersistRule(-1)); action->Add(NEW MTGAffinityRule(-1)); action->Add(NEW MTGUnearthRule(-1)); @@ -36,7 +37,7 @@ void DuelLayers::init(){ action->Add(NEW MTGLifelinkRule(-1)); action->Add(NEW MTGDeathtouchRule(-1)); action->Add(NEW OtherAbilitiesEventReceiver(-1)); - action->Add(NEW MTGTokensCleanup(-1)); + //Other display elements action->Add(NEW HUDDisplay(-1)); diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 780da30a0..57a0fcd12 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -100,9 +100,21 @@ TriggeredAbility * AbilityFactory::parseTrigger(string magicText, int id, Spell if (found != string::npos){ size_t end = s.find (")"); string starget = s.substr(found+8,end - found - 8); - if (starget.find("|") == string::npos) starget.insert(0,"*|"); TargetChooserFactory tcf; - TargetChooser *toTc = tcf.createTargetChooser(starget,card); + + TargetChooser *toTc = NULL; + TargetChooser *toTcCard = NULL; + end = starget.find ("|"); + if (end == string::npos) { + toTcCard = tcf.createTargetChooser("*",card); + found = 0; + }else{ + toTcCard = tcf.createTargetChooser(starget.substr(0, end).append("|*"),card); + found = end + 1; + } + toTcCard->setAllZones(); + starget = starget.substr(found,end - found).insert(0,"*|"); + toTc = tcf.createTargetChooser(starget,card); toTc->targetter = NULL; TargetChooser *fromTc = NULL; @@ -123,7 +135,7 @@ TriggeredAbility * AbilityFactory::parseTrigger(string magicText, int id, Spell fromTc = tcf.createTargetChooser(starget,card); fromTc->targetter = NULL; } - return NEW TrCardAddedToZone(id,card,toTc,(TargetZoneChooser *)fromTc,fromTcCard); + return NEW TrCardAddedToZone(id,card,(TargetZoneChooser *)toTc, toTcCard,(TargetZoneChooser *)fromTc,fromTcCard); } //Card Tapped diff --git a/projects/mtg/src/MTGRules.cpp b/projects/mtg/src/MTGRules.cpp index 97d1e58df..b46799165 100644 --- a/projects/mtg/src/MTGRules.cpp +++ b/projects/mtg/src/MTGRules.cpp @@ -1398,7 +1398,8 @@ int MTGTokensCleanup::receiveEvent(WEvent * e){ if (!event->card->isToken) return 0; if (event->to == game->players[0]->game->inPlay || event->to == game->players[1]->game->inPlay) return 0; if (event->to == game->players[0]->game->garbage || event->to == game->players[1]->game->garbage) return 0; - list.push_back(event->card); + MTGCardInstance * c = event->card; + c->controller()->game->putInZone(c,c->currentZone, c->controller()->game->garbage); return 1; } return 0; @@ -1406,14 +1407,6 @@ int MTGTokensCleanup::receiveEvent(WEvent * e){ int MTGTokensCleanup::testDestroy(){return 0;} -void MTGTokensCleanup::Update(float dt){ - MTGAbility::Update(dt); - for(size_t i= 0; i < list.size(); ++i){ - MTGCardInstance * c = list[i]; - c->controller()->game->putInZone(c,c->currentZone, c->controller()->game->garbage); - } - list.clear(); -} MTGTokensCleanup * MTGTokensCleanup::clone() const{ MTGTokensCleanup * a = NEW MTGTokensCleanup(*this);