From 87515de57f875302a8de6503796eef47fbe4b806 Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Sat, 4 Jun 2016 21:50:49 +0800 Subject: [PATCH] Affinity affects other costs Affinity should affect other costs such as flashback, buyback, to cast since its also a cost reducer... --- projects/mtg/include/MTGCardInstance.h | 2 +- projects/mtg/src/GameObserver.cpp | 12 ++-- projects/mtg/src/MTGCardInstance.cpp | 91 +++++++++++++++++++++++++- 3 files changed, 95 insertions(+), 10 deletions(-) diff --git a/projects/mtg/include/MTGCardInstance.h b/projects/mtg/include/MTGCardInstance.h index 9bb0edc92..52f61a807 100644 --- a/projects/mtg/include/MTGCardInstance.h +++ b/projects/mtg/include/MTGCardInstance.h @@ -255,7 +255,7 @@ public: bool isTargetter(); int cardistargetter; int myconvertedcost; - ManaCost * computeNewCost(MTGCardInstance * card,ManaCost * oldCost, ManaCost * refCost); + ManaCost * computeNewCost(MTGCardInstance * card,ManaCost * oldCost, ManaCost * refCost,bool onlyTrinisphere = false); void eventattacked(); void eventattackedAlone(); diff --git a/projects/mtg/src/GameObserver.cpp b/projects/mtg/src/GameObserver.cpp index 25d10a428..e52576bd6 100644 --- a/projects/mtg/src/GameObserver.cpp +++ b/projects/mtg/src/GameObserver.cpp @@ -1017,7 +1017,7 @@ void GameObserver::Affinity() ManaCost * original = NEW ManaCost(); original->copy(card->model->data->getManaCost()); if(card->getIncreasedManaCost()->getConvertedCost()||card->getReducedManaCost()->getConvertedCost()) - { + {//start1 if(card->getIncreasedManaCost()->getConvertedCost()) original->add(card->getIncreasedManaCost()); if(card->getReducedManaCost()->getConvertedCost()) @@ -1031,11 +1031,11 @@ void GameObserver::Affinity() card->getManaCost()->extraCosts->costs[i]->setSource(card); } } - } + }//end1 int reducem = 0; bool resetCost = false; for(unsigned int na = 0; na < card->cardsAbilities.size();na++) - { + {//start2 ANewAffinity * newAff = dynamic_cast(card->cardsAbilities[na]); if(newAff) { @@ -1073,7 +1073,7 @@ void GameObserver::Affinity() card->getManaCost()->remove(removingCost); SAFE_DELETE(removingCost); } - } + }//end2 if(card->has(Constants::AFFINITYARTIFACTS)|| card->has(Constants::AFFINITYFOREST)|| card->has(Constants::AFFINITYGREENCREATURES)|| @@ -1081,7 +1081,7 @@ void GameObserver::Affinity() card->has(Constants::AFFINITYMOUNTAIN)|| card->has(Constants::AFFINITYPLAINS)|| card->has(Constants::AFFINITYSWAMP)) - { + {//start3 if (card->has(Constants::AFFINITYARTIFACTS)) { type = "artifact"; @@ -1136,7 +1136,7 @@ void GameObserver::Affinity() if(card->getManaCost()->getCost(color) > 0) card->getManaCost()->remove(color,1); } - } + }//end3 SAFE_DELETE(original); }//end } diff --git a/projects/mtg/src/MTGCardInstance.cpp b/projects/mtg/src/MTGCardInstance.cpp index 4fd86e04c..956f60a35 100644 --- a/projects/mtg/src/MTGCardInstance.cpp +++ b/projects/mtg/src/MTGCardInstance.cpp @@ -12,6 +12,9 @@ #include "Counters.h" #include "Subtypes.h" + +#include "AIPlayerBaka.h" + using namespace std; SUPPORT_OBJECT_ANALYTICS(MTGCardInstance) @@ -919,20 +922,102 @@ JQuadPtr MTGCardInstance::getIcon() return WResourceManager::Instance()->RetrieveCard(this, CACHE_THUMB); } -ManaCost * MTGCardInstance::computeNewCost(MTGCardInstance * card,ManaCost * newCost, ManaCost * refCost) +ManaCost * MTGCardInstance::computeNewCost(MTGCardInstance * card,ManaCost * newCost, ManaCost * refCost, bool onlyTrinisphere) { if(!card) return NULL; + if(!onlyTrinisphere) + { if(card->getIncreasedManaCost()->getConvertedCost()) newCost->add(card->getIncreasedManaCost()); if(card->getReducedManaCost()->getConvertedCost()) newCost->remove(card->getReducedManaCost()); if(refCost->extraCosts) newCost->extraCosts = refCost->extraCosts; - //trinisphere must be here below// + //affinity + int color = 0; + string type = ""; + ManaCost * original = NEW ManaCost(); + original->copy(newCost); + int reducem = 0; + bool resetCost = false; + for(unsigned int na = 0; na < card->cardsAbilities.size();na++) + {//start2 + ANewAffinity * newAff = dynamic_cast(card->cardsAbilities[na]); + if(newAff) + { + if(!resetCost) + { + resetCost = true; + newCost->copy(original); + } + TargetChooserFactory tf(observer); + TargetChooser * tcn = tf.createTargetChooser(newAff->tcString,card,NULL); + + for (int w = 0; w < 2; ++w) + { + Player *p = observer->players[w]; + MTGGameZone * zones[] = { p->game->inPlay, p->game->graveyard, p->game->hand, p->game->library, p->game->stack, p->game->exile }; + for (int k = 0; k < 6; k++) + { + MTGGameZone * z = zones[k]; + if (tcn->targetsZone(z)) + reducem += z->countByCanTarget(tcn); + } + } + SAFE_DELETE(tcn); + ManaCost * removingCost = ManaCost::parseManaCost(newAff->manaString); + for(int j = 0; j < reducem; j++) + newCost->remove(removingCost); + SAFE_DELETE(removingCost); + } + }//end2 + if(card->has(Constants::AFFINITYARTIFACTS)|| + card->has(Constants::AFFINITYFOREST)|| + card->has(Constants::AFFINITYGREENCREATURES)|| + card->has(Constants::AFFINITYISLAND)|| + card->has(Constants::AFFINITYMOUNTAIN)|| + card->has(Constants::AFFINITYPLAINS)|| + card->has(Constants::AFFINITYSWAMP)) + {//start3 + if (card->has(Constants::AFFINITYARTIFACTS)) + type = "artifact"; + else if (card->has(Constants::AFFINITYSWAMP)) + type = "swamp"; + else if (card->has(Constants::AFFINITYMOUNTAIN)) + type = "mountain"; + else if (card->has(Constants::AFFINITYPLAINS)) + type = "plains"; + else if (card->has(Constants::AFFINITYISLAND)) + type = "island"; + else if (card->has(Constants::AFFINITYFOREST)) + type = "forest"; + else if (card->has(Constants::AFFINITYGREENCREATURES)) + { + color = 1; + type = "creature"; + } + newCost->copy(original); + int reduce = 0; + if(card->has(Constants::AFFINITYGREENCREATURES)) + { + TargetChooserFactory tf(observer); + TargetChooser * tc = tf.createTargetChooser("creature[green]",NULL); + reduce = card->controller()->game->battlefield->countByCanTarget(tc); + SAFE_DELETE(tc); + } + else + reduce = card->controller()->game->battlefield->countByType(type); + for(int i = 0; i < reduce;i++) + if(newCost->getCost(color) > 0) + newCost->remove(color,1); + }//end3 + SAFE_DELETE(original); + } + /*//trinisphere must be here below// if(card->has(Constants::TRINISPHERE)) for(int jj = newCost->getConvertedCost(); jj < 3; jj++) - newCost->add(Constants::MTG_COLOR_ARTIFACT, 1); + newCost->add(Constants::MTG_COLOR_ARTIFACT, 1);*/ return newCost; }