refactor canproducemana

This commit is contained in:
Anthony Calosa
2017-02-16 16:55:13 +08:00
parent 5a3a32462d
commit 0a68a056d8
5 changed files with 69 additions and 31 deletions
+2 -2
View File
@@ -70,12 +70,12 @@ class CardDescriptor: public MTGCardInstance
int CDdamager; int CDdamager;
int CDgeared; int CDgeared;
int CDblocked; int CDblocked;
/*int CDcanProduceC; int CDcanProduceC;
int CDcanProduceG; int CDcanProduceG;
int CDcanProduceU; int CDcanProduceU;
int CDcanProduceR; int CDcanProduceR;
int CDcanProduceB; int CDcanProduceB;
int CDcanProduceW;*/ int CDcanProduceW;
int CDnocolor; int CDnocolor;
}; };
+1 -6
View File
@@ -285,12 +285,7 @@ public:
int imprintR; int imprintR;
int imprintB; int imprintB;
int imprintW; int imprintW;
int canproduceG; int canproduceMana(int color = -1);
int canproduceU;
int canproduceR;
int canproduceB;
int canproduceW;
int canproduceC;
int entersBattlefield; int entersBattlefield;
string currentimprintName; string currentimprintName;
vector<string>imprintedNames; vector<string>imprintedNames;
+21 -13
View File
@@ -28,12 +28,12 @@ CardDescriptor::CardDescriptor()
CDdamager = 0; CDdamager = 0;
CDgeared = 0; CDgeared = 0;
CDblocked = 0; CDblocked = 0;
/*CDcanProduceC = 0; CDcanProduceC = 0;
CDcanProduceG = 0; CDcanProduceG = 0;
CDcanProduceU = 0; CDcanProduceU = 0;
CDcanProduceR = 0; CDcanProduceR = 0;
CDcanProduceB = 0; CDcanProduceB = 0;
CDcanProduceW = 0;*/ CDcanProduceW = 0;
CDnocolor = 0; CDnocolor = 0;
} }
@@ -262,37 +262,45 @@ MTGCardInstance * CardDescriptor::match(MTGCardInstance * card)
match = NULL; 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; 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; 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; 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; 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; match = NULL;
} }
if ((CDcanProduceW == -1 && card->canproduceW == 1) || (CDcanProduceW == 1 && card->canproduceW == 0))
{
match = NULL;
}
*/
if ((CDnocolor == -1 && card->getColor() == 0)) if ((CDnocolor == -1 && card->getColor() == 0))
{ {
match = NULL; match = NULL;
+36 -7
View File
@@ -98,7 +98,11 @@ MTGCardInstance::MTGCardInstance(MTGCard * card, MTGPlayerCards * arg_belongs_to
void MTGCardInstance::copy(MTGCardInstance * card) void MTGCardInstance::copy(MTGCardInstance * card)
{ {
MTGCard * source = NULL; 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 if(card->getMTGId() > 0)//not generated token
source = MTGCollection()->getCardById(card->getMTGId()); source = MTGCollection()->getCardById(card->getMTGId());
@@ -263,12 +267,6 @@ void MTGCardInstance::initMTGCI()
imprintR = 0; imprintR = 0;
imprintB = 0; imprintB = 0;
imprintW = 0; imprintW = 0;
canproduceG = 0;
canproduceU = 0;
canproduceR = 0;
canproduceB = 0;
canproduceW = 0;
canproduceC = 0;
entersBattlefield = 0; entersBattlefield = 0;
currentimprintName = ""; currentimprintName = "";
imprintedNames.clear(); imprintedNames.clear();
@@ -851,6 +849,37 @@ int MTGCardInstance::countDuplicateCardNames()
return count; 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<AManaProducer*> (cardsAbilities[j]) && dynamic_cast<AManaProducer*> (cardsAbilities[j])->output->hasColor(color))
count++;
}
}
if(count)
return 1;
return 0;
}
//check stack //check stack
bool MTGCardInstance::StackIsEmptyandSorcerySpeed() bool MTGCardInstance::StackIsEmptyandSorcerySpeed()
{ {
+8 -2
View File
@@ -579,7 +579,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta
{ {
cd->CDdamager = 1; cd->CDdamager = 1;
} }
}/* }
//can produce mana //can produce mana
else if (attribute.find("cmana") != string::npos) else if (attribute.find("cmana") != string::npos)
{ {
@@ -591,6 +591,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta
{ {
cd->CDcanProduceC = 1; cd->CDcanProduceC = 1;
} }
cd->mode = CardDescriptor::CD_OR;
} }
else if (attribute.find("manag") != string::npos) else if (attribute.find("manag") != string::npos)
{ {
@@ -602,6 +603,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta
{ {
cd->CDcanProduceG = 1; cd->CDcanProduceG = 1;
} }
cd->mode = CardDescriptor::CD_OR;
} }
else if (attribute.find("manau") != string::npos) else if (attribute.find("manau") != string::npos)
{ {
@@ -613,6 +615,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta
{ {
cd->CDcanProduceU = 1; cd->CDcanProduceU = 1;
} }
cd->mode = CardDescriptor::CD_OR;
} }
else if (attribute.find("manar") != string::npos) else if (attribute.find("manar") != string::npos)
{ {
@@ -624,6 +627,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta
{ {
cd->CDcanProduceR = 1; cd->CDcanProduceR = 1;
} }
cd->mode = CardDescriptor::CD_OR;
} }
else if (attribute.find("manab") != string::npos) else if (attribute.find("manab") != string::npos)
{ {
@@ -635,6 +639,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta
{ {
cd->CDcanProduceB = 1; cd->CDcanProduceB = 1;
} }
cd->mode = CardDescriptor::CD_OR;
} }
else if (attribute.find("manaw") != string::npos) else if (attribute.find("manaw") != string::npos)
{ {
@@ -646,7 +651,8 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta
{ {
cd->CDcanProduceW = 1; cd->CDcanProduceW = 1;
} }
}*/ cd->mode = CardDescriptor::CD_OR;
}
else if (attribute.find("multicolor") != string::npos) else if (attribute.find("multicolor") != string::npos)
{ {
//card is multicolored? //card is multicolored?