From 0a68a056d81e9dbb568b1c69d1f8534e91178dcb Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Thu, 16 Feb 2017 16:55:13 +0800 Subject: [PATCH] refactor canproducemana --- projects/mtg/include/CardDescriptor.h | 4 +-- projects/mtg/include/MTGCardInstance.h | 7 +---- projects/mtg/src/CardDescriptor.cpp | 36 ++++++++++++--------- projects/mtg/src/MTGCardInstance.cpp | 43 +++++++++++++++++++++----- projects/mtg/src/TargetChooser.cpp | 10 ++++-- 5 files changed, 69 insertions(+), 31 deletions(-) diff --git a/projects/mtg/include/CardDescriptor.h b/projects/mtg/include/CardDescriptor.h index daa9aa365..383a35439 100644 --- a/projects/mtg/include/CardDescriptor.h +++ b/projects/mtg/include/CardDescriptor.h @@ -70,12 +70,12 @@ class CardDescriptor: public MTGCardInstance int CDdamager; int CDgeared; int CDblocked; - /*int CDcanProduceC; + int CDcanProduceC; int CDcanProduceG; int CDcanProduceU; int CDcanProduceR; int CDcanProduceB; - int CDcanProduceW;*/ + int CDcanProduceW; int CDnocolor; }; diff --git a/projects/mtg/include/MTGCardInstance.h b/projects/mtg/include/MTGCardInstance.h index 3e6f60620..098c77dc0 100644 --- a/projects/mtg/include/MTGCardInstance.h +++ b/projects/mtg/include/MTGCardInstance.h @@ -285,12 +285,7 @@ public: int imprintR; int imprintB; int imprintW; - int canproduceG; - int canproduceU; - int canproduceR; - int canproduceB; - int canproduceW; - int canproduceC; + int canproduceMana(int color = -1); int entersBattlefield; string currentimprintName; vectorimprintedNames; diff --git a/projects/mtg/src/CardDescriptor.cpp b/projects/mtg/src/CardDescriptor.cpp index 5be1448a7..02f6baec6 100644 --- a/projects/mtg/src/CardDescriptor.cpp +++ b/projects/mtg/src/CardDescriptor.cpp @@ -28,12 +28,12 @@ CardDescriptor::CardDescriptor() CDdamager = 0; CDgeared = 0; CDblocked = 0; - /*CDcanProduceC = 0; + CDcanProduceC = 0; CDcanProduceG = 0; CDcanProduceU = 0; CDcanProduceR = 0; CDcanProduceB = 0; - CDcanProduceW = 0;*/ + CDcanProduceW = 0; CDnocolor = 0; } @@ -262,37 +262,45 @@ MTGCardInstance * CardDescriptor::match(MTGCardInstance * card) match = NULL; } } - /* - if ((CDcanProduceC == -1 && card->canproduceC == 1) || (CDcanProduceC == 1 && card->canproduceC == 0)) + + if (CDcanProduceC == -1) + { + int count = card->canproduceMana(Constants::MTG_COLOR_ARTIFACT) + card->canproduceMana(Constants::MTG_COLOR_WASTE); + if (count) + match = NULL; + } + if (CDcanProduceC == 1) + { + int count = card->canproduceMana(Constants::MTG_COLOR_ARTIFACT) + card->canproduceMana(Constants::MTG_COLOR_WASTE); + if (!count) + match = NULL; + } + + if ((CDcanProduceG == -1 && card->canproduceMana(Constants::MTG_COLOR_GREEN) == 1) || (CDcanProduceG == 1 && card->canproduceMana(Constants::MTG_COLOR_GREEN) == 0)) { match = NULL; } - if ((CDcanProduceG == -1 && card->canproduceG == 1) || (CDcanProduceG == 1 && card->canproduceG == 0)) + if ((CDcanProduceU == -1 && card->canproduceMana(Constants::MTG_COLOR_BLUE) == 1) || (CDcanProduceU == 1 && card->canproduceMana(Constants::MTG_COLOR_BLUE) == 0)) { match = NULL; } - if ((CDcanProduceU == -1 && card->canproduceU == 1) || (CDcanProduceU == 1 && card->canproduceU == 0)) + if ((CDcanProduceR == -1 && card->canproduceMana(Constants::MTG_COLOR_RED) == 1) || (CDcanProduceR == 1 && card->canproduceMana(Constants::MTG_COLOR_RED) == 0)) { match = NULL; } - if ((CDcanProduceR == -1 && card->canproduceR == 1) || (CDcanProduceR == 1 && card->canproduceR == 0)) + if ((CDcanProduceB == -1 && card->canproduceMana(Constants::MTG_COLOR_BLACK) == 1) || (CDcanProduceB == 1 && card->canproduceMana(Constants::MTG_COLOR_BLACK) == 0)) { match = NULL; } - if ((CDcanProduceB == -1 && card->canproduceB == 1) || (CDcanProduceB == 1 && card->canproduceB == 0)) + if ((CDcanProduceW == -1 && card->canproduceMana(Constants::MTG_COLOR_WHITE) == 1) || (CDcanProduceW == 1 && card->canproduceMana(Constants::MTG_COLOR_WHITE) == 0)) { match = NULL; } - - if ((CDcanProduceW == -1 && card->canproduceW == 1) || (CDcanProduceW == 1 && card->canproduceW == 0)) - { - match = NULL; - } - */ + if ((CDnocolor == -1 && card->getColor() == 0)) { match = NULL; diff --git a/projects/mtg/src/MTGCardInstance.cpp b/projects/mtg/src/MTGCardInstance.cpp index d05eaf718..b9f40f860 100644 --- a/projects/mtg/src/MTGCardInstance.cpp +++ b/projects/mtg/src/MTGCardInstance.cpp @@ -98,7 +98,11 @@ MTGCardInstance::MTGCardInstance(MTGCard * card, MTGPlayerCards * arg_belongs_to void MTGCardInstance::copy(MTGCardInstance * card) { MTGCard * source = NULL; - if(card->isToken || card->hasCopiedToken) + if(card->isACopier && card->copiedID) + { + source = MTGCollection()->getCardById(card->copiedID); + } + else if(card->isToken || card->hasCopiedToken) { if(card->getMTGId() > 0)//not generated token source = MTGCollection()->getCardById(card->getMTGId()); @@ -263,12 +267,6 @@ void MTGCardInstance::initMTGCI() imprintR = 0; imprintB = 0; imprintW = 0; - canproduceG = 0; - canproduceU = 0; - canproduceR = 0; - canproduceB = 0; - canproduceW = 0; - canproduceC = 0; entersBattlefield = 0; currentimprintName = ""; imprintedNames.clear(); @@ -851,6 +849,37 @@ int MTGCardInstance::countDuplicateCardNames() return count; } +//check can produce mana +int MTGCardInstance::canproduceMana(int color) +{ + int count = 0; + + //start + if(hasSubtype("forest") && color == 1) + count++; + if(hasSubtype("island") && color == 2) + count++; + if(hasSubtype("mountain") && color == 3) + count++; + if(hasSubtype("swamp") && color == 4) + count++; + if(hasSubtype("plains") && color == 5) + count++; + if(cardsAbilities.size()) + { + for(unsigned int j = 0; j < cardsAbilities.size(); j++) + { + if(dynamic_cast (cardsAbilities[j]) && dynamic_cast (cardsAbilities[j])->output->hasColor(color)) + count++; + } + } + + if(count) + return 1; + + return 0; +} + //check stack bool MTGCardInstance::StackIsEmptyandSorcerySpeed() { diff --git a/projects/mtg/src/TargetChooser.cpp b/projects/mtg/src/TargetChooser.cpp index a80822c21..8a82bbf35 100644 --- a/projects/mtg/src/TargetChooser.cpp +++ b/projects/mtg/src/TargetChooser.cpp @@ -579,7 +579,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta { cd->CDdamager = 1; } - }/* + } //can produce mana else if (attribute.find("cmana") != string::npos) { @@ -591,6 +591,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta { cd->CDcanProduceC = 1; } + cd->mode = CardDescriptor::CD_OR; } else if (attribute.find("manag") != string::npos) { @@ -602,6 +603,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta { cd->CDcanProduceG = 1; } + cd->mode = CardDescriptor::CD_OR; } else if (attribute.find("manau") != string::npos) { @@ -613,6 +615,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta { cd->CDcanProduceU = 1; } + cd->mode = CardDescriptor::CD_OR; } else if (attribute.find("manar") != string::npos) { @@ -624,6 +627,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta { cd->CDcanProduceR = 1; } + cd->mode = CardDescriptor::CD_OR; } else if (attribute.find("manab") != string::npos) { @@ -635,6 +639,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta { cd->CDcanProduceB = 1; } + cd->mode = CardDescriptor::CD_OR; } else if (attribute.find("manaw") != string::npos) { @@ -646,7 +651,8 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta { cd->CDcanProduceW = 1; } - }*/ + cd->mode = CardDescriptor::CD_OR; + } else if (attribute.find("multicolor") != string::npos) { //card is multicolored?