Merge pull request #744 from kevlahnota/master
Add support for reducing hybrid costs
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -969,6 +969,7 @@ ManaCost * MTGCardInstance::computeNewCost(MTGCardInstance * card,ManaCost * Cos
|
|||||||
int color = 0;
|
int color = 0;
|
||||||
string type = "";
|
string type = "";
|
||||||
ManaCost * original = NEW ManaCost();
|
ManaCost * original = NEW ManaCost();
|
||||||
|
ManaCost * excess = NEW ManaCost();
|
||||||
original->copy(Data);
|
original->copy(Data);
|
||||||
Cost->copy(original);
|
Cost->copy(original);
|
||||||
if (Cost->extraCosts)
|
if (Cost->extraCosts)
|
||||||
@@ -982,9 +983,26 @@ ManaCost * MTGCardInstance::computeNewCost(MTGCardInstance * card,ManaCost * Cos
|
|||||||
{//start1
|
{//start1
|
||||||
if (card->getIncreasedManaCost()->getConvertedCost())
|
if (card->getIncreasedManaCost()->getConvertedCost())
|
||||||
original->add(card->getIncreasedManaCost());
|
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())
|
if (card->getReducedManaCost()->getConvertedCost())
|
||||||
original->remove(card->getReducedManaCost());
|
original->remove(card->getReducedManaCost());
|
||||||
|
//try to reduce hybrid
|
||||||
|
if (excess->getConvertedCost())
|
||||||
|
{
|
||||||
|
original->removeHybrid(excess);
|
||||||
|
}
|
||||||
Cost->copy(original);
|
Cost->copy(original);
|
||||||
if (Cost->extraCosts)
|
if (Cost->extraCosts)
|
||||||
{
|
{
|
||||||
@@ -1128,6 +1146,7 @@ ManaCost * MTGCardInstance::computeNewCost(MTGCardInstance * card,ManaCost * Cos
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
SAFE_DELETE(original);
|
SAFE_DELETE(original);
|
||||||
|
SAFE_DELETE(excess);
|
||||||
return Cost;
|
return Cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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))
|
||||||
|
|||||||
Reference in New Issue
Block a user