Merge pull request #744 from kevlahnota/master

Add support for reducing hybrid costs
This commit is contained in:
Anthony Calosa
2016-07-11 08:33:15 +08:00
committed by GitHub
5 changed files with 231 additions and 161 deletions

View File

@@ -108,6 +108,7 @@ public:
int getManaSymbols(int color);
int getManaSymbolsHybridMerged(int color);
int countHybridsNoPhyrexian();
void removeHybrid(ManaCost * _cost);
//Returns NULL if i is greater than nbhybrids
ManaCostHybrid * getHybridCost(unsigned int i);

View File

@@ -20,6 +20,7 @@ public:
int getConvertedCost();
int getManaSymbols(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);

View File

@@ -969,6 +969,7 @@ ManaCost * MTGCardInstance::computeNewCost(MTGCardInstance * card,ManaCost * Cos
int color = 0;
string type = "";
ManaCost * original = NEW ManaCost();
ManaCost * excess = NEW ManaCost();
original->copy(Data);
Cost->copy(original);
if (Cost->extraCosts)
@@ -982,9 +983,26 @@ ManaCost * MTGCardInstance::computeNewCost(MTGCardInstance * card,ManaCost * Cos
{//start1
if (card->getIncreasedManaCost()->getConvertedCost())
original->add(card->getIncreasedManaCost());
//before removing get the diff for excess
if(card->getReducedManaCost()->getConvertedCost())
{
for(int xc = 0; xc < 7;xc++)
{//if the diff is more than 0
if(card->getReducedManaCost()->getCost(xc) > original->getCost(xc))
{
int count = card->getReducedManaCost()->getCost(xc) - original->getCost(xc);
excess->add(xc,count);
}
}
}
//apply reduced
if (card->getReducedManaCost()->getConvertedCost())
original->remove(card->getReducedManaCost());
//try to reduce hybrid
if (excess->getConvertedCost())
{
original->removeHybrid(excess);
}
Cost->copy(original);
if (Cost->extraCosts)
{
@@ -1128,6 +1146,7 @@ ManaCost * MTGCardInstance::computeNewCost(MTGCardInstance * card,ManaCost * Cos
}
}
SAFE_DELETE(original);
SAFE_DELETE(excess);
return Cost;
}

View File

@@ -719,6 +719,37 @@ int ManaCost::countHybridsNoPhyrexian()
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)
{
switch (symbol)

View File

@@ -66,6 +66,24 @@ int ManaCostHybrid::getManaSymbolsHybridMerged(int color)
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)
{
if (((color1 == color) && value1) || ((color2 == color) && value2))