Add support for reducing Hybrid cost

it doesn't remove the hybrid icons but it reduces the cost.
This commit is contained in:
Anthony Calosa
2016-07-11 07:55:12 +08:00
parent a72fb6f01a
commit 69db7f7384
5 changed files with 231 additions and 161 deletions
+1
View File
@@ -108,6 +108,7 @@ public:
int getManaSymbols(int color); int getManaSymbols(int color);
int getManaSymbolsHybridMerged(int color); int getManaSymbolsHybridMerged(int color);
int countHybridsNoPhyrexian(); int countHybridsNoPhyrexian();
void removeHybrid(ManaCost * _cost);
//Returns NULL if i is greater than nbhybrids //Returns NULL if i is greater than nbhybrids
ManaCostHybrid * getHybridCost(unsigned int i); ManaCostHybrid * getHybridCost(unsigned int i);
+1
View File
@@ -20,6 +20,7 @@ public:
int getConvertedCost(); int getConvertedCost();
int getManaSymbols(int color); int getManaSymbols(int color);
int getManaSymbolsHybridMerged(int color); int getManaSymbolsHybridMerged(int color);
void reduceValue(int color, int value);
friend std::ostream& operator<<(std::ostream& out, ManaCostHybrid& m); friend std::ostream& operator<<(std::ostream& out, ManaCostHybrid& m);
friend std::ostream& operator<<(std::ostream& out, ManaCostHybrid* m); friend std::ostream& operator<<(std::ostream& out, ManaCostHybrid* m);
+180 -161
View File
@@ -966,168 +966,187 @@ JQuadPtr MTGCardInstance::getIcon()
ManaCost * MTGCardInstance::computeNewCost(MTGCardInstance * card,ManaCost * Cost, ManaCost * Data, bool noTrinisphere) ManaCost * MTGCardInstance::computeNewCost(MTGCardInstance * card,ManaCost * Cost, ManaCost * Data, bool noTrinisphere)
{ {
int color = 0; int color = 0;
string type = ""; string type = "";
ManaCost * original = NEW ManaCost(); ManaCost * original = NEW ManaCost();
original->copy(Data); ManaCost * excess = NEW ManaCost();
Cost->copy(original); original->copy(Data);
if (Cost->extraCosts) Cost->copy(original);
{ if (Cost->extraCosts)
for (unsigned int i = 0; i < Cost->extraCosts->costs.size(); i++) {
{ for (unsigned int i = 0; i < Cost->extraCosts->costs.size(); i++)
Cost->extraCosts->costs[i]->setSource(card); {
} Cost->extraCosts->costs[i]->setSource(card);
} }
if (card->getIncreasedManaCost()->getConvertedCost() || card->getReducedManaCost()->getConvertedCost()) }
{//start1 if (card->getIncreasedManaCost()->getConvertedCost() || card->getReducedManaCost()->getConvertedCost())
if (card->getIncreasedManaCost()->getConvertedCost()) {//start1
original->add(card->getIncreasedManaCost()); if (card->getIncreasedManaCost()->getConvertedCost())
if (card->getReducedManaCost()->getConvertedCost()) original->add(card->getIncreasedManaCost());
original->remove(card->getReducedManaCost()); //before removing get the diff for excess
if(card->getReducedManaCost()->getConvertedCost())
Cost->copy(original); {
if (Cost->extraCosts) for(int xc = 0; xc < 7;xc++)
{ {//if the diff is more than 0
for (unsigned int i = 0; i < Cost->extraCosts->costs.size(); i++) if(card->getReducedManaCost()->getCost(xc) > original->getCost(xc))
{ {
Cost->extraCosts->costs[i]->setSource(card); int count = card->getReducedManaCost()->getCost(xc) - original->getCost(xc);
} excess->add(xc,count);
} }
}//end1 }
int reducem = 0; }
bool resetCost = false; //apply reduced
for (unsigned int na = 0; na < card->cardsAbilities.size(); na++) if (card->getReducedManaCost()->getConvertedCost())
{//start2 original->remove(card->getReducedManaCost());
if (!card->cardsAbilities[na]) //try to reduce hybrid
break; if (excess->getConvertedCost())
ANewAffinity * newAff = dynamic_cast<ANewAffinity*>(card->cardsAbilities[na]); {
if (newAff) original->removeHybrid(excess);
{ }
if (!resetCost) Cost->copy(original);
{ if (Cost->extraCosts)
resetCost = true; {
Cost->copy(original); for (unsigned int i = 0; i < Cost->extraCosts->costs.size(); i++)
if (Cost->extraCosts) {
{ Cost->extraCosts->costs[i]->setSource(card);
for (unsigned int i = 0; i < Cost->extraCosts->costs.size(); i++) }
{ }
Cost->extraCosts->costs[i]->setSource(card); }//end1
} int reducem = 0;
} bool resetCost = false;
} for (unsigned int na = 0; na < card->cardsAbilities.size(); na++)
TargetChooserFactory tf(getObserver()); {//start2
TargetChooser * tcn = tf.createTargetChooser(newAff->tcString, card, NULL); if (!card->cardsAbilities[na])
break;
for (int w = 0; w < 2; ++w) ANewAffinity * newAff = dynamic_cast<ANewAffinity*>(card->cardsAbilities[na]);
{ if (newAff)
Player *p = getObserver()->players[w]; {
MTGGameZone * zones[] = { p->game->inPlay, p->game->graveyard, p->game->hand, p->game->library, p->game->stack, p->game->exile }; if (!resetCost)
for (int k = 0; k < 6; k++) {
{ resetCost = true;
MTGGameZone * z = zones[k]; Cost->copy(original);
if (tcn->targetsZone(z)) if (Cost->extraCosts)
{ {
reducem += z->countByCanTarget(tcn); for (unsigned int i = 0; i < Cost->extraCosts->costs.size(); i++)
} {
} Cost->extraCosts->costs[i]->setSource(card);
} }
SAFE_DELETE(tcn); }
ManaCost * removingCost = ManaCost::parseManaCost(newAff->manaString); }
for (int j = 0; j < reducem; j++) TargetChooserFactory tf(getObserver());
original->remove(removingCost); TargetChooser * tcn = tf.createTargetChooser(newAff->tcString, card, NULL);
SAFE_DELETE(removingCost);
} for (int w = 0; w < 2; ++w)
}//end2 {
if (card->has(Constants::AFFINITYARTIFACTS) || Player *p = getObserver()->players[w];
card->has(Constants::AFFINITYFOREST) || MTGGameZone * zones[] = { p->game->inPlay, p->game->graveyard, p->game->hand, p->game->library, p->game->stack, p->game->exile };
card->has(Constants::AFFINITYGREENCREATURES) || for (int k = 0; k < 6; k++)
card->has(Constants::AFFINITYISLAND) || {
card->has(Constants::AFFINITYMOUNTAIN) || MTGGameZone * z = zones[k];
card->has(Constants::AFFINITYPLAINS) || if (tcn->targetsZone(z))
card->has(Constants::AFFINITYSWAMP)) {
{//start3 reducem += z->countByCanTarget(tcn);
if (card->has(Constants::AFFINITYARTIFACTS)) }
{ }
type = "artifact"; }
} SAFE_DELETE(tcn);
else if (card->has(Constants::AFFINITYSWAMP)) ManaCost * removingCost = ManaCost::parseManaCost(newAff->manaString);
{ for (int j = 0; j < reducem; j++)
type = "swamp"; original->remove(removingCost);
} SAFE_DELETE(removingCost);
else if (card->has(Constants::AFFINITYMOUNTAIN)) }
{ }//end2
type = "mountain"; if (card->has(Constants::AFFINITYARTIFACTS) ||
} card->has(Constants::AFFINITYFOREST) ||
else if (card->has(Constants::AFFINITYPLAINS)) card->has(Constants::AFFINITYGREENCREATURES) ||
{ card->has(Constants::AFFINITYISLAND) ||
type = "plains"; card->has(Constants::AFFINITYMOUNTAIN) ||
} card->has(Constants::AFFINITYPLAINS) ||
else if (card->has(Constants::AFFINITYISLAND)) card->has(Constants::AFFINITYSWAMP))
{ {//start3
type = "island"; if (card->has(Constants::AFFINITYARTIFACTS))
} {
else if (card->has(Constants::AFFINITYFOREST)) type = "artifact";
{ }
type = "forest"; else if (card->has(Constants::AFFINITYSWAMP))
} {
else if (card->has(Constants::AFFINITYGREENCREATURES)) type = "swamp";
{ }
color = 1; else if (card->has(Constants::AFFINITYMOUNTAIN))
type = "creature"; {
} type = "mountain";
}
Cost->copy(original); else if (card->has(Constants::AFFINITYPLAINS))
if (Cost->extraCosts) {
{ type = "plains";
for (unsigned int i = 0; i < Cost->extraCosts->costs.size(); i++) }
{ else if (card->has(Constants::AFFINITYISLAND))
Cost->extraCosts->costs[i]->setSource(card); {
} type = "island";
} }
if (Cost->extraCosts) else if (card->has(Constants::AFFINITYFOREST))
{ {
for (unsigned int i = 0; i < Cost->extraCosts->costs.size(); i++) type = "forest";
{ }
Cost->extraCosts->costs[i]->setSource(card); else if (card->has(Constants::AFFINITYGREENCREATURES))
} {
} color = 1;
int reduce = 0; type = "creature";
if (card->has(Constants::AFFINITYGREENCREATURES)) }
{
TargetChooserFactory tf(getObserver()); Cost->copy(original);
TargetChooser * tc = tf.createTargetChooser("creature[green]", NULL); if (Cost->extraCosts)
reduce = card->controller()->game->battlefield->countByCanTarget(tc); {
SAFE_DELETE(tc); for (unsigned int i = 0; i < Cost->extraCosts->costs.size(); i++)
} {
else Cost->extraCosts->costs[i]->setSource(card);
{ }
reduce = card->controller()->game->battlefield->countByType(type); }
} if (Cost->extraCosts)
for (int i = 0; i < reduce; i++) {
{ for (unsigned int i = 0; i < Cost->extraCosts->costs.size(); i++)
if (Cost->getCost(color) > 0) {
Cost->remove(color, 1); Cost->extraCosts->costs[i]->setSource(card);
} }
}//end3 }
//trinisphere... now how to implement kicker recomputation int reduce = 0;
if (card->has(Constants::AFFINITYGREENCREATURES))
if (card->has(Constants::TRINISPHERE)) {
{ TargetChooserFactory tf(getObserver());
for (int jj = Cost->getConvertedCost(); jj < 3; jj++) TargetChooser * tc = tf.createTargetChooser("creature[green]", NULL);
{ reduce = card->controller()->game->battlefield->countByCanTarget(tc);
Cost->add(Constants::MTG_COLOR_ARTIFACT, 1); SAFE_DELETE(tc);
card->countTrini++; }
} else
} {
else reduce = card->controller()->game->battlefield->countByType(type);
{ }
if (card->countTrini) for (int i = 0; i < reduce; i++)
{ {
Cost->remove(Constants::MTG_COLOR_ARTIFACT, card->countTrini); if (Cost->getCost(color) > 0)
card->countTrini = 0; Cost->remove(color, 1);
} }
} }//end3
//trinisphere... now how to implement kicker recomputation
if (card->has(Constants::TRINISPHERE))
{
for (int jj = Cost->getConvertedCost(); jj < 3; jj++)
{
Cost->add(Constants::MTG_COLOR_ARTIFACT, 1);
card->countTrini++;
}
}
else
{
if (card->countTrini)
{
Cost->remove(Constants::MTG_COLOR_ARTIFACT, card->countTrini);
card->countTrini = 0;
}
}
SAFE_DELETE(original); SAFE_DELETE(original);
SAFE_DELETE(excess);
return Cost; return Cost;
} }
+31
View File
@@ -719,6 +719,37 @@ int ManaCost::countHybridsNoPhyrexian()
return result; return result;
} }
void ManaCost::removeHybrid(ManaCost * _manaCost)
{
if (!_manaCost)
return;
vector<int> colors;
int match = 0;
for(int j = 0; j < 7; j++)
{//populate colors values
colors.push_back(_manaCost->getCost(j));
}
for (size_t i = 0; i < hybrids.size(); i++)
{
for(int j = 0; j < 7; j++)
{
if(colors[j])
{
if(hybrids[i].hasColor(j))
{
hybrids[i].reduceValue(j, colors[j]);
colors[j] -= 1;
match++;
}
}
}
}
return;
}
int ManaCost::parseManaSymbol(char symbol) int ManaCost::parseManaSymbol(char symbol)
{ {
switch (symbol) switch (symbol)
+18
View File
@@ -66,6 +66,24 @@ int ManaCostHybrid::getManaSymbolsHybridMerged(int color)
return 0; return 0;
} }
void ManaCostHybrid::reduceValue(int color, int value)
{
if(((color1 == color) && value1))
{
if((value1 - value) < 0)
value1 = 0;
else
value1 -= value;
}
else if(((color2 == color) && value2))
{
if((value2 - value) < 0)
value2 = 0;
else
value2 -= value;
}
}
int ManaCostHybrid::hasColor(int color) int ManaCostHybrid::hasColor(int color)
{ {
if (((color1 == color) && value1) || ((color2 == color) && value2)) if (((color1 == color) && value1) || ((color2 == color) && value2))