Fixed the memleaks caused by computeNewCost, moved them to gameobserver where affinity takes place, removed repeative code that was in game observer, moved the game observer components into computenewcost, removed the calls for "new mana" in all alternative play type that were added with this function.
This commit is contained in:
@@ -1049,7 +1049,7 @@ void GameObserver::Affinity()
|
|||||||
{
|
{
|
||||||
MTGGameZone * dzones[] = { players[dd]->game->graveyard, players[dd]->game->hand, players[dd]->game->library, players[dd]->game->exile };
|
MTGGameZone * dzones[] = { players[dd]->game->graveyard, players[dd]->game->hand, players[dd]->game->library, players[dd]->game->exile };
|
||||||
for (int kk = 0; kk < 4; kk++)
|
for (int kk = 0; kk < 4; kk++)
|
||||||
{
|
{
|
||||||
MTGGameZone * zone = dzones[kk];
|
MTGGameZone * zone = dzones[kk];
|
||||||
for (int cc = zone->nb_cards - 1; cc >= 0; cc--)
|
for (int cc = zone->nb_cards - 1; cc >= 0; cc--)
|
||||||
{//start
|
{//start
|
||||||
@@ -1057,208 +1057,115 @@ void GameObserver::Affinity()
|
|||||||
if (!card)
|
if (!card)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
///////////////////////////
|
///////////////////////////
|
||||||
//reset extracost shadows//
|
//reset extracost shadows//
|
||||||
///////////////////////////
|
///////////////////////////
|
||||||
card->isExtraCostTarget = false;
|
card->isExtraCostTarget = false;
|
||||||
if (mExtraPayment != NULL)
|
if (mExtraPayment != NULL)
|
||||||
{
|
{
|
||||||
for (unsigned int ec = 0; ec < mExtraPayment->costs.size(); ec++)
|
for (unsigned int ec = 0; ec < mExtraPayment->costs.size(); ec++)
|
||||||
{
|
|
||||||
|
|
||||||
if (mExtraPayment->costs[ec]->tc)
|
|
||||||
{
|
|
||||||
vector<Targetable*>targetlist = mExtraPayment->costs[ec]->tc->getTargetsFrom();
|
|
||||||
for (vector<Targetable*>::iterator it = targetlist.begin(); it != targetlist.end(); it++)
|
|
||||||
{
|
|
||||||
Targetable * cardMasked = *it;
|
|
||||||
dynamic_cast<MTGCardInstance*>(cardMasked)->isExtraCostTarget = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
////////////////////////////
|
|
||||||
bool NewAffinityFound = false;
|
|
||||||
for (unsigned int na = 0; na < card->cardsAbilities.size(); na++)
|
|
||||||
{
|
|
||||||
if (!card->cardsAbilities[na])
|
|
||||||
break;
|
|
||||||
ANewAffinity * newAff = dynamic_cast<ANewAffinity*>(card->cardsAbilities[na]);
|
|
||||||
if (newAff)
|
|
||||||
{
|
|
||||||
NewAffinityFound = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bool DoReduceIncrease = false;
|
|
||||||
if (card->has(Constants::AFFINITYARTIFACTS) ||
|
|
||||||
card->has(Constants::AFFINITYFOREST) ||
|
|
||||||
card->has(Constants::AFFINITYGREENCREATURES) ||
|
|
||||||
card->has(Constants::AFFINITYISLAND) ||
|
|
||||||
card->has(Constants::AFFINITYMOUNTAIN) ||
|
|
||||||
card->has(Constants::AFFINITYPLAINS) ||
|
|
||||||
card->has(Constants::AFFINITYSWAMP) ||
|
|
||||||
card->has(Constants::TRINISPHERE) ||
|
|
||||||
card->getIncreasedManaCost()->getConvertedCost() ||
|
|
||||||
card->getReducedManaCost()->getConvertedCost() ||
|
|
||||||
NewAffinityFound)
|
|
||||||
DoReduceIncrease = true;
|
|
||||||
if (!DoReduceIncrease)
|
|
||||||
continue;
|
|
||||||
//above we check if there are even any cards that effect cards manacost
|
|
||||||
//if there are none, leave this function. manacost->copy( is a very expensive funtion
|
|
||||||
//1mb a sec to run at all time even when no known reducers or increasers are in play.
|
|
||||||
//memory snapshot shots pointed to this as such a heavy load that games with many cards inplay
|
|
||||||
//would slow to a crawl.
|
|
||||||
//only do any of the following if a card with the stated ability is in your hand.
|
|
||||||
int color = 0;
|
|
||||||
string type = "";
|
|
||||||
|
|
||||||
ManaCost * original = NEW ManaCost();
|
|
||||||
original->copy(card->model->data->getManaCost());
|
|
||||||
if(card->getIncreasedManaCost()->getConvertedCost()||card->getReducedManaCost()->getConvertedCost())
|
|
||||||
{//start1
|
|
||||||
if(card->getIncreasedManaCost()->getConvertedCost())
|
|
||||||
original->add(card->getIncreasedManaCost());
|
|
||||||
if(card->getReducedManaCost()->getConvertedCost())
|
|
||||||
original->remove(card->getReducedManaCost());
|
|
||||||
if(card->getManaCost())
|
|
||||||
card->getManaCost()->copy(original);
|
|
||||||
if(card->getManaCost()->extraCosts)
|
|
||||||
{
|
{
|
||||||
for(unsigned int i = 0; i < card->getManaCost()->extraCosts->costs.size();i++)
|
|
||||||
|
if (mExtraPayment->costs[ec]->tc)
|
||||||
{
|
{
|
||||||
card->getManaCost()->extraCosts->costs[i]->setSource(card);
|
vector<Targetable*>targetlist = mExtraPayment->costs[ec]->tc->getTargetsFrom();
|
||||||
|
for (vector<Targetable*>::iterator it = targetlist.begin(); it != targetlist.end(); it++)
|
||||||
|
{
|
||||||
|
Targetable * cardMasked = *it;
|
||||||
|
dynamic_cast<MTGCardInstance*>(cardMasked)->isExtraCostTarget = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}//end1
|
}
|
||||||
int reducem = 0;
|
////////////////////////////
|
||||||
bool resetCost = false;
|
bool NewAffinityFound = false;
|
||||||
for(unsigned int na = 0; na < card->cardsAbilities.size();na++)
|
for (unsigned int na = 0; na < card->cardsAbilities.size(); na++)
|
||||||
{//start2
|
{
|
||||||
if (!card->cardsAbilities[na])
|
if (!card->cardsAbilities[na])
|
||||||
break;
|
break;
|
||||||
ANewAffinity * newAff = dynamic_cast<ANewAffinity*>(card->cardsAbilities[na]);
|
ANewAffinity * newAff = dynamic_cast<ANewAffinity*>(card->cardsAbilities[na]);
|
||||||
if(newAff)
|
if (newAff)
|
||||||
{
|
{
|
||||||
if(!resetCost)
|
NewAffinityFound = true;
|
||||||
{
|
}
|
||||||
resetCost = true;
|
}
|
||||||
card->getManaCost()->copy(original);
|
bool DoReduceIncrease = false;
|
||||||
if(card->getManaCost()->extraCosts)
|
if (card->has(Constants::AFFINITYARTIFACTS) ||
|
||||||
{
|
card->has(Constants::AFFINITYFOREST) ||
|
||||||
for(unsigned int i = 0; i < card->getManaCost()->extraCosts->costs.size();i++)
|
card->has(Constants::AFFINITYGREENCREATURES) ||
|
||||||
{
|
card->has(Constants::AFFINITYISLAND) ||
|
||||||
card->getManaCost()->extraCosts->costs[i]->setSource(card);
|
card->has(Constants::AFFINITYMOUNTAIN) ||
|
||||||
}
|
card->has(Constants::AFFINITYPLAINS) ||
|
||||||
}
|
card->has(Constants::AFFINITYSWAMP) ||
|
||||||
}
|
card->has(Constants::TRINISPHERE) ||
|
||||||
TargetChooserFactory tf(this);
|
card->getIncreasedManaCost()->getConvertedCost() ||
|
||||||
TargetChooser * tcn = tf.createTargetChooser(newAff->tcString,card,NULL);
|
card->getReducedManaCost()->getConvertedCost() ||
|
||||||
|
NewAffinityFound)
|
||||||
|
DoReduceIncrease = true;
|
||||||
|
if (!DoReduceIncrease)
|
||||||
|
continue;
|
||||||
|
//above we check if there are even any cards that effect cards manacost
|
||||||
|
//if there are none, leave this function. manacost->copy( is a very expensive funtion
|
||||||
|
//1mb a sec to run at all time even when no known reducers or increasers are in play.
|
||||||
|
//memory snapshot shots pointed to this as such a heavy load that games with many cards inplay
|
||||||
|
//would slow to a crawl.
|
||||||
|
//only do any of the following if a card with the stated ability is in your hand.
|
||||||
|
//kicker is an addon to normal cost, suspend is not casting. add cost as needed EXACTLY as seen below.
|
||||||
|
card->getManaCost()->resetCosts();
|
||||||
|
ManaCost * newCost = NEW ManaCost();
|
||||||
|
newCost->copy(card->computeNewCost(card, card->getManaCost(), card->model->data->getManaCost()));
|
||||||
|
card->getManaCost()->copy(newCost);
|
||||||
|
SAFE_DELETE(newCost);
|
||||||
|
if (card->getManaCost()->getAlternative())
|
||||||
|
{
|
||||||
|
card->getManaCost()->getAlternative()->resetCosts();
|
||||||
|
ManaCost * newCost = NEW ManaCost();
|
||||||
|
newCost->copy(card->computeNewCost(card, card->getManaCost()->getAlternative(), card->model->data->getManaCost()->getAlternative()));
|
||||||
|
card->getManaCost()->getAlternative()->copy(newCost);
|
||||||
|
SAFE_DELETE(newCost);
|
||||||
|
}
|
||||||
|
if (card->getManaCost()->getBestow())
|
||||||
|
{
|
||||||
|
card->getManaCost()->getBestow()->resetCosts();
|
||||||
|
ManaCost * newCost = NEW ManaCost();
|
||||||
|
newCost->copy(card->computeNewCost(card, card->getManaCost()->getBestow(), card->model->data->getManaCost()->getBestow()));
|
||||||
|
card->getManaCost()->getBestow()->copy(newCost);
|
||||||
|
SAFE_DELETE(newCost);
|
||||||
|
}
|
||||||
|
if (card->getManaCost()->getRetrace())
|
||||||
|
{
|
||||||
|
card->getManaCost()->getRetrace()->resetCosts();
|
||||||
|
ManaCost * newCost = NEW ManaCost();
|
||||||
|
newCost->copy(card->computeNewCost(card, card->getManaCost()->getRetrace(), card->model->data->getManaCost()->getRetrace()));
|
||||||
|
card->getManaCost()->getRetrace()->copy(newCost);
|
||||||
|
SAFE_DELETE(newCost);
|
||||||
|
}
|
||||||
|
if (card->getManaCost()->getBuyback())
|
||||||
|
{
|
||||||
|
card->getManaCost()->getBuyback()->resetCosts();
|
||||||
|
ManaCost * newCost = NEW ManaCost();
|
||||||
|
newCost->copy(card->computeNewCost(card, card->getManaCost()->getBuyback(), card->model->data->getManaCost()->getBuyback()));
|
||||||
|
card->getManaCost()->getBuyback()->copy(newCost);
|
||||||
|
SAFE_DELETE(newCost);
|
||||||
|
}
|
||||||
|
if (card->getManaCost()->getFlashback())
|
||||||
|
{
|
||||||
|
card->getManaCost()->getFlashback()->resetCosts();
|
||||||
|
ManaCost * newCost = NEW ManaCost();
|
||||||
|
newCost->copy(card->computeNewCost(card, card->getManaCost()->getFlashback(), card->model->data->getManaCost()->getFlashback()));
|
||||||
|
card->getManaCost()->getFlashback()->copy(newCost);
|
||||||
|
SAFE_DELETE(newCost);
|
||||||
|
}
|
||||||
|
if (card->getManaCost()->getMorph())
|
||||||
|
{
|
||||||
|
card->getManaCost()->getMorph()->resetCosts();
|
||||||
|
ManaCost * newCost = NEW ManaCost();
|
||||||
|
newCost->copy(card->computeNewCost(card, card->getManaCost()->getMorph(), card->model->data->getManaCost()->getMorph()));
|
||||||
|
card->getManaCost()->getMorph()->copy(newCost);
|
||||||
|
SAFE_DELETE(newCost);
|
||||||
|
}
|
||||||
|
|
||||||
for (int w = 0; w < 2; ++w)
|
|
||||||
{
|
|
||||||
Player *p = this->players[w];
|
|
||||||
MTGGameZone * zones[] = { p->game->inPlay, p->game->graveyard, p->game->hand, p->game->library, p->game->stack, p->game->exile };
|
|
||||||
for (int k = 0; k < 6; k++)
|
|
||||||
{
|
|
||||||
MTGGameZone * z = zones[k];
|
|
||||||
if (tcn->targetsZone(z))
|
|
||||||
{
|
|
||||||
reducem += z->countByCanTarget(tcn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SAFE_DELETE(tcn);
|
|
||||||
ManaCost * removingCost = ManaCost::parseManaCost(newAff->manaString);
|
|
||||||
for(int j = 0; j < reducem; j++)
|
|
||||||
card->getManaCost()->remove(removingCost);
|
|
||||||
SAFE_DELETE(removingCost);
|
|
||||||
}
|
|
||||||
}//end2
|
|
||||||
if(card->has(Constants::AFFINITYARTIFACTS)||
|
|
||||||
card->has(Constants::AFFINITYFOREST)||
|
|
||||||
card->has(Constants::AFFINITYGREENCREATURES)||
|
|
||||||
card->has(Constants::AFFINITYISLAND)||
|
|
||||||
card->has(Constants::AFFINITYMOUNTAIN)||
|
|
||||||
card->has(Constants::AFFINITYPLAINS)||
|
|
||||||
card->has(Constants::AFFINITYSWAMP))
|
|
||||||
{//start3
|
|
||||||
if (card->has(Constants::AFFINITYARTIFACTS))
|
|
||||||
{
|
|
||||||
type = "artifact";
|
|
||||||
}
|
|
||||||
else if (card->has(Constants::AFFINITYSWAMP))
|
|
||||||
{
|
|
||||||
type = "swamp";
|
|
||||||
}
|
|
||||||
else if (card->has(Constants::AFFINITYMOUNTAIN))
|
|
||||||
{
|
|
||||||
type = "mountain";
|
|
||||||
}
|
|
||||||
else if (card->has(Constants::AFFINITYPLAINS))
|
|
||||||
{
|
|
||||||
type = "plains";
|
|
||||||
}
|
|
||||||
else if (card->has(Constants::AFFINITYISLAND))
|
|
||||||
{
|
|
||||||
type = "island";
|
|
||||||
}
|
|
||||||
else if (card->has(Constants::AFFINITYFOREST))
|
|
||||||
{
|
|
||||||
type = "forest";
|
|
||||||
}
|
|
||||||
else if (card->has(Constants::AFFINITYGREENCREATURES))
|
|
||||||
{
|
|
||||||
color = 1;
|
|
||||||
type = "creature";
|
|
||||||
}
|
|
||||||
card->getManaCost()->copy(original);
|
|
||||||
if(card->getManaCost()->extraCosts)
|
|
||||||
{
|
|
||||||
for(unsigned int i = 0; i < card->getManaCost()->extraCosts->costs.size();i++)
|
|
||||||
{
|
|
||||||
card->getManaCost()->extraCosts->costs[i]->setSource(card);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int reduce = 0;
|
|
||||||
if(card->has(Constants::AFFINITYGREENCREATURES))
|
|
||||||
{
|
|
||||||
TargetChooserFactory tf(this);
|
|
||||||
TargetChooser * tc = tf.createTargetChooser("creature[green]",NULL);
|
|
||||||
reduce = card->controller()->game->battlefield->countByCanTarget(tc);
|
|
||||||
SAFE_DELETE(tc);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
reduce = card->controller()->game->battlefield->countByType(type);
|
|
||||||
}
|
|
||||||
for(int i = 0; i < reduce;i++)
|
|
||||||
{
|
|
||||||
if(card->getManaCost()->getCost(color) > 0)
|
|
||||||
card->getManaCost()->remove(color,1);
|
|
||||||
}
|
|
||||||
}//end3
|
|
||||||
//trinisphere... now how to implement kicker recomputation
|
|
||||||
|
|
||||||
if(card->has(Constants::TRINISPHERE))
|
|
||||||
{
|
|
||||||
for(int jj = card->getManaCost()->getConvertedCost(); jj < 3; jj++)
|
|
||||||
{
|
|
||||||
card->getManaCost()->add(Constants::MTG_COLOR_ARTIFACT, 1);
|
|
||||||
card->countTrini++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(card->countTrini)
|
|
||||||
{
|
|
||||||
card->getManaCost()->remove(Constants::MTG_COLOR_ARTIFACT, card->countTrini);
|
|
||||||
card->countTrini=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SAFE_DELETE(original);
|
|
||||||
}//end
|
}//end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -960,123 +960,156 @@ JQuadPtr MTGCardInstance::getIcon()
|
|||||||
return WResourceManager::Instance()->RetrieveCard(this, CACHE_THUMB);
|
return WResourceManager::Instance()->RetrieveCard(this, CACHE_THUMB);
|
||||||
}
|
}
|
||||||
|
|
||||||
ManaCost * MTGCardInstance::computeNewCost(MTGCardInstance * card,ManaCost * newCost, ManaCost * refCost, bool noTrinisphere)
|
ManaCost * MTGCardInstance::computeNewCost(MTGCardInstance * card,ManaCost * Cost, ManaCost * Data, bool noTrinisphere)
|
||||||
{
|
{
|
||||||
//this function introduces a nasty memleak, it also cant be safe_deleted at the locations if its not used as it leads to a wild nullpointer crash.
|
int color = 0;
|
||||||
if(!card)
|
string type = "";
|
||||||
return NULL;
|
ManaCost * original = NEW ManaCost();
|
||||||
ManaCost * cardUnchangedCost = NEW ManaCost();
|
original->copy(Data);
|
||||||
cardUnchangedCost->copy(newCost);
|
if (card->getIncreasedManaCost()->getConvertedCost() || card->getReducedManaCost()->getConvertedCost())
|
||||||
if(card->getIncreasedManaCost()->getConvertedCost())
|
{//start1
|
||||||
cardUnchangedCost->add(card->getIncreasedManaCost());
|
if (card->getIncreasedManaCost()->getConvertedCost())
|
||||||
if(card->getReducedManaCost()->getConvertedCost())
|
original->add(card->getIncreasedManaCost());
|
||||||
cardUnchangedCost->remove(card->getReducedManaCost());
|
if (card->getReducedManaCost()->getConvertedCost())
|
||||||
if(refCost->extraCosts)
|
original->remove(card->getReducedManaCost());
|
||||||
cardUnchangedCost->extraCosts = refCost->extraCosts;
|
|
||||||
//affinity
|
Cost->copy(original);
|
||||||
int color = 0;
|
if (Cost->extraCosts)
|
||||||
string type = "";
|
{
|
||||||
ManaCost * original = NEW ManaCost();
|
for (unsigned int i = 0; i < Cost->extraCosts->costs.size(); i++)
|
||||||
original->copy(cardUnchangedCost);
|
{
|
||||||
|
Cost->extraCosts->costs[i]->setSource(card);
|
||||||
int reducem = 0;
|
}
|
||||||
bool resetCost = false;
|
}
|
||||||
for(unsigned int na = 0; na < card->cardsAbilities.size();na++)
|
}//end1
|
||||||
{//start2
|
int reducem = 0;
|
||||||
ANewAffinity * newAff = dynamic_cast<ANewAffinity*>(card->cardsAbilities[na]);
|
bool resetCost = false;
|
||||||
if(newAff)
|
for (unsigned int na = 0; na < card->cardsAbilities.size(); na++)
|
||||||
{
|
{//start2
|
||||||
if(!resetCost)
|
if (!card->cardsAbilities[na])
|
||||||
{
|
break;
|
||||||
resetCost = true;
|
ANewAffinity * newAff = dynamic_cast<ANewAffinity*>(card->cardsAbilities[na]);
|
||||||
cardUnchangedCost->copy(original);
|
if (newAff)
|
||||||
}
|
{
|
||||||
TargetChooserFactory tf(observer);
|
if (!resetCost)
|
||||||
TargetChooser * tcn = tf.createTargetChooser(newAff->tcString,card,NULL);
|
{
|
||||||
|
resetCost = true;
|
||||||
for (int w = 0; w < 2; ++w)
|
Cost->copy(original);
|
||||||
{
|
if (Cost->extraCosts)
|
||||||
Player *p = observer->players[w];
|
{
|
||||||
MTGGameZone * zones[] = { p->game->inPlay, p->game->graveyard, p->game->hand, p->game->library, p->game->stack, p->game->exile };
|
for (unsigned int i = 0; i < Cost->extraCosts->costs.size(); i++)
|
||||||
for (int k = 0; k < 6; k++)
|
{
|
||||||
{
|
Cost->extraCosts->costs[i]->setSource(card);
|
||||||
MTGGameZone * z = zones[k];
|
}
|
||||||
if (tcn->targetsZone(z))
|
}
|
||||||
reducem += z->countByCanTarget(tcn);
|
}
|
||||||
}
|
TargetChooserFactory tf(getObserver());
|
||||||
}
|
TargetChooser * tcn = tf.createTargetChooser(newAff->tcString, card, NULL);
|
||||||
SAFE_DELETE(tcn);
|
|
||||||
ManaCost * removingCost = ManaCost::parseManaCost(newAff->manaString);
|
for (int w = 0; w < 2; ++w)
|
||||||
for(int j = 0; j < reducem; j++)
|
{
|
||||||
cardUnchangedCost->remove(removingCost);
|
Player *p = getObserver()->players[w];
|
||||||
SAFE_DELETE(removingCost);
|
MTGGameZone * zones[] = { p->game->inPlay, p->game->graveyard, p->game->hand, p->game->library, p->game->stack, p->game->exile };
|
||||||
}
|
for (int k = 0; k < 6; k++)
|
||||||
}//end2
|
{
|
||||||
if(card->has(Constants::AFFINITYARTIFACTS)||
|
MTGGameZone * z = zones[k];
|
||||||
card->has(Constants::AFFINITYFOREST)||
|
if (tcn->targetsZone(z))
|
||||||
card->has(Constants::AFFINITYGREENCREATURES)||
|
{
|
||||||
card->has(Constants::AFFINITYISLAND)||
|
reducem += z->countByCanTarget(tcn);
|
||||||
card->has(Constants::AFFINITYMOUNTAIN)||
|
}
|
||||||
card->has(Constants::AFFINITYPLAINS)||
|
}
|
||||||
card->has(Constants::AFFINITYSWAMP))
|
}
|
||||||
{//start3
|
SAFE_DELETE(tcn);
|
||||||
if (card->has(Constants::AFFINITYARTIFACTS))
|
ManaCost * removingCost = ManaCost::parseManaCost(newAff->manaString);
|
||||||
type = "artifact";
|
for (int j = 0; j < reducem; j++)
|
||||||
else if (card->has(Constants::AFFINITYSWAMP))
|
original->remove(removingCost);
|
||||||
type = "swamp";
|
SAFE_DELETE(removingCost);
|
||||||
else if (card->has(Constants::AFFINITYMOUNTAIN))
|
}
|
||||||
type = "mountain";
|
}//end2
|
||||||
else if (card->has(Constants::AFFINITYPLAINS))
|
if (card->has(Constants::AFFINITYARTIFACTS) ||
|
||||||
type = "plains";
|
card->has(Constants::AFFINITYFOREST) ||
|
||||||
else if (card->has(Constants::AFFINITYISLAND))
|
card->has(Constants::AFFINITYGREENCREATURES) ||
|
||||||
type = "island";
|
card->has(Constants::AFFINITYISLAND) ||
|
||||||
else if (card->has(Constants::AFFINITYFOREST))
|
card->has(Constants::AFFINITYMOUNTAIN) ||
|
||||||
type = "forest";
|
card->has(Constants::AFFINITYPLAINS) ||
|
||||||
else if (card->has(Constants::AFFINITYGREENCREATURES))
|
card->has(Constants::AFFINITYSWAMP))
|
||||||
{
|
{//start3
|
||||||
color = 1;
|
if (card->has(Constants::AFFINITYARTIFACTS))
|
||||||
type = "creature";
|
{
|
||||||
}
|
type = "artifact";
|
||||||
cardUnchangedCost->copy(original);
|
}
|
||||||
int reduce = 0;
|
else if (card->has(Constants::AFFINITYSWAMP))
|
||||||
if(card->has(Constants::AFFINITYGREENCREATURES))
|
{
|
||||||
{
|
type = "swamp";
|
||||||
TargetChooserFactory tf(observer);
|
}
|
||||||
TargetChooser * tc = tf.createTargetChooser("creature[green]",NULL);
|
else if (card->has(Constants::AFFINITYMOUNTAIN))
|
||||||
reduce = card->controller()->game->battlefield->countByCanTarget(tc);
|
{
|
||||||
SAFE_DELETE(tc);
|
type = "mountain";
|
||||||
}
|
}
|
||||||
else
|
else if (card->has(Constants::AFFINITYPLAINS))
|
||||||
reduce = card->controller()->game->battlefield->countByType(type);
|
{
|
||||||
for(int i = 0; i < reduce;i++)
|
type = "plains";
|
||||||
if(cardUnchangedCost->getCost(color) > 0)
|
}
|
||||||
cardUnchangedCost->remove(color,1);
|
else if (card->has(Constants::AFFINITYISLAND))
|
||||||
}//end3
|
{
|
||||||
|
type = "island";
|
||||||
if(!noTrinisphere)
|
}
|
||||||
{
|
else if (card->has(Constants::AFFINITYFOREST))
|
||||||
//trinisphere... now how to implement kicker recomputation
|
{
|
||||||
if(card->has(Constants::TRINISPHERE))
|
type = "forest";
|
||||||
{
|
}
|
||||||
for(int jj = cardUnchangedCost->getConvertedCost(); jj < 3; jj++)
|
else if (card->has(Constants::AFFINITYGREENCREATURES))
|
||||||
{
|
{
|
||||||
cardUnchangedCost->add(Constants::MTG_COLOR_ARTIFACT, 1);
|
color = 1;
|
||||||
card->countTrini++;
|
type = "creature";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
Cost->copy(original);
|
||||||
{
|
if (Cost->extraCosts)
|
||||||
if(card->countTrini)
|
{
|
||||||
{
|
for (unsigned int i = 0; i < Cost->extraCosts->costs.size(); i++)
|
||||||
cardUnchangedCost->remove(Constants::MTG_COLOR_ARTIFACT, card->countTrini);
|
{
|
||||||
card->countTrini=0;
|
Cost->extraCosts->costs[i]->setSource(card);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
int reduce = 0;
|
||||||
|
if (card->has(Constants::AFFINITYGREENCREATURES))
|
||||||
|
{
|
||||||
|
TargetChooserFactory tf(getObserver());
|
||||||
|
TargetChooser * tc = tf.createTargetChooser("creature[green]", NULL);
|
||||||
|
reduce = card->controller()->game->battlefield->countByCanTarget(tc);
|
||||||
|
SAFE_DELETE(tc);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
reduce = card->controller()->game->battlefield->countByType(type);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < reduce; i++)
|
||||||
|
{
|
||||||
|
if (Cost->getCost(color) > 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);
|
||||||
|
return Cost;
|
||||||
return cardUnchangedCost;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MTGCardInstance * MTGCardInstance::getNextPartner()
|
MTGCardInstance * MTGCardInstance::getNextPartner()
|
||||||
|
|||||||
@@ -709,7 +709,7 @@ int MTGAlternativeCostRule::isReactingToClick(MTGCardInstance * card, ManaCost *
|
|||||||
return 0;//overload has its own rule
|
return 0;//overload has its own rule
|
||||||
if(!card->getManaCost()->getAlternative())
|
if(!card->getManaCost()->getAlternative())
|
||||||
return 0;
|
return 0;
|
||||||
ManaCost * alternateCost = card->computeNewCost(card,card->model->data->getManaCost()->getAlternative(),card->getManaCost()->getAlternative());
|
ManaCost * alternateCost = card->getManaCost()->getAlternative();
|
||||||
if(alternateCost->extraCosts)
|
if(alternateCost->extraCosts)
|
||||||
for(unsigned int i = 0; i < alternateCost->extraCosts->costs.size();i++)
|
for(unsigned int i = 0; i < alternateCost->extraCosts->costs.size();i++)
|
||||||
{
|
{
|
||||||
@@ -773,7 +773,7 @@ int MTGAlternativeCostRule::reactToClick(MTGCardInstance * card)
|
|||||||
if ( !isReactingToClick(card))
|
if ( !isReactingToClick(card))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ManaCost * alternateCost = card->computeNewCost(card,card->model->data->getManaCost()->getAlternative(),card->getManaCost()->getAlternative());
|
ManaCost * alternateCost = card->getManaCost()->getAlternative();
|
||||||
card->paymenttype = MTGAbility::ALTERNATIVE_COST;
|
card->paymenttype = MTGAbility::ALTERNATIVE_COST;
|
||||||
if(alternateCost->extraCosts)
|
if(alternateCost->extraCosts)
|
||||||
for(unsigned int i = 0; i < alternateCost->extraCosts->costs.size();i++)
|
for(unsigned int i = 0; i < alternateCost->extraCosts->costs.size();i++)
|
||||||
@@ -942,7 +942,7 @@ int MTGBuyBackRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
|
|||||||
return 0;
|
return 0;
|
||||||
if(!card->getManaCost()->getBuyback())
|
if(!card->getManaCost()->getBuyback())
|
||||||
return 0;
|
return 0;
|
||||||
ManaCost * buybackCost = card->computeNewCost(card,card->model->data->getManaCost()->getBuyback(),card->getManaCost()->getBuyback());
|
ManaCost * buybackCost = card->getManaCost()->getBuyback();
|
||||||
if(buybackCost->extraCosts)
|
if(buybackCost->extraCosts)
|
||||||
for(unsigned int i = 0; i < buybackCost->extraCosts->costs.size();i++)
|
for(unsigned int i = 0; i < buybackCost->extraCosts->costs.size();i++)
|
||||||
{
|
{
|
||||||
@@ -956,7 +956,7 @@ int MTGBuyBackRule::reactToClick(MTGCardInstance * card)
|
|||||||
if (!isReactingToClick(card))
|
if (!isReactingToClick(card))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ManaCost * buybackCost = card->computeNewCost(card,card->model->data->getManaCost()->getBuyback(),card->getManaCost()->getBuyback());
|
ManaCost * buybackCost = card->getManaCost()->getBuyback();
|
||||||
if(buybackCost->extraCosts)
|
if(buybackCost->extraCosts)
|
||||||
for(unsigned int i = 0; i < buybackCost->extraCosts->costs.size();i++)
|
for(unsigned int i = 0; i < buybackCost->extraCosts->costs.size();i++)
|
||||||
{
|
{
|
||||||
@@ -996,7 +996,7 @@ int MTGFlashBackRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
|
|||||||
return 0;
|
return 0;
|
||||||
if(!card->getManaCost()->getFlashback())
|
if(!card->getManaCost()->getFlashback())
|
||||||
return 0;
|
return 0;
|
||||||
ManaCost * flashbackCost = card->computeNewCost(card,card->model->data->getManaCost()->getFlashback(),card->getManaCost()->getFlashback());
|
ManaCost * flashbackCost = card->getManaCost()->getFlashback();
|
||||||
if(flashbackCost->extraCosts)
|
if(flashbackCost->extraCosts)
|
||||||
for(unsigned int i = 0; i < flashbackCost->extraCosts->costs.size();i++)
|
for(unsigned int i = 0; i < flashbackCost->extraCosts->costs.size();i++)
|
||||||
{
|
{
|
||||||
@@ -1007,7 +1007,7 @@ int MTGFlashBackRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
|
|||||||
|
|
||||||
int MTGFlashBackRule::reactToClick(MTGCardInstance * card)
|
int MTGFlashBackRule::reactToClick(MTGCardInstance * card)
|
||||||
{
|
{
|
||||||
ManaCost * flashbackCost = card->computeNewCost(card,card->model->data->getManaCost()->getFlashback(),card->getManaCost()->getFlashback());
|
ManaCost * flashbackCost = card->getManaCost()->getFlashback();
|
||||||
if(flashbackCost->extraCosts)
|
if(flashbackCost->extraCosts)
|
||||||
for(unsigned int i = 0; i < flashbackCost->extraCosts->costs.size();i++)
|
for(unsigned int i = 0; i < flashbackCost->extraCosts->costs.size();i++)
|
||||||
{
|
{
|
||||||
@@ -1053,7 +1053,7 @@ int MTGRetraceRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
|
|||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
auto retraceCost = card->computeNewCost(card, card->model->data->getManaCost()->getRetrace(), card->getManaCost()->getRetrace());
|
auto retraceCost = card->getManaCost()->getRetrace();
|
||||||
if(retraceCost->extraCosts)
|
if(retraceCost->extraCosts)
|
||||||
for(unsigned int i = 0; i < retraceCost->extraCosts->costs.size();i++)
|
for(unsigned int i = 0; i < retraceCost->extraCosts->costs.size();i++)
|
||||||
{
|
{
|
||||||
@@ -1068,7 +1068,7 @@ int MTGRetraceRule::reactToClick(MTGCardInstance * card)
|
|||||||
if (!isReactingToClick(card))
|
if (!isReactingToClick(card))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ManaCost * retraceCost = card->computeNewCost(card,card->model->data->getManaCost()->getRetrace(),card->getManaCost()->getRetrace());
|
ManaCost * retraceCost = card->getManaCost()->getRetrace();
|
||||||
if(retraceCost->extraCosts)
|
if(retraceCost->extraCosts)
|
||||||
for(unsigned int i = 0; i < retraceCost->extraCosts->costs.size();i++)
|
for(unsigned int i = 0; i < retraceCost->extraCosts->costs.size();i++)
|
||||||
{
|
{
|
||||||
@@ -1245,7 +1245,7 @@ int MTGMorphCostRule::isReactingToClick(MTGCardInstance * card, ManaCost *)
|
|||||||
if (card->controller()->game->playRestrictions->canPutIntoZone(card, card->controller()->game->stack) == PlayRestriction::CANT_PLAY)
|
if (card->controller()->game->playRestrictions->canPutIntoZone(card, card->controller()->game->stack) == PlayRestriction::CANT_PLAY)
|
||||||
return 0;
|
return 0;
|
||||||
ManaCost * playerMana = player->getManaPool();
|
ManaCost * playerMana = player->getManaPool();
|
||||||
ManaCost * morph = card->computeNewCost(card,card->model->data->getManaCost()->getMorph(),card->getManaCost()->getMorph());
|
ManaCost * morph = card->getManaCost()->getMorph();
|
||||||
if(morph->extraCosts)
|
if(morph->extraCosts)
|
||||||
for(unsigned int i = 0; i < morph->extraCosts->costs.size();i++)
|
for(unsigned int i = 0; i < morph->extraCosts->costs.size();i++)
|
||||||
{
|
{
|
||||||
@@ -1274,7 +1274,7 @@ int MTGMorphCostRule::reactToClick(MTGCardInstance * card)
|
|||||||
Player * player = game->currentlyActing();
|
Player * player = game->currentlyActing();
|
||||||
ManaCost * cost = card->getManaCost();
|
ManaCost * cost = card->getManaCost();
|
||||||
ManaCost * playerMana = player->getManaPool();
|
ManaCost * playerMana = player->getManaPool();
|
||||||
ManaCost * morph = card->computeNewCost(card,card->model->data->getManaCost()->getMorph(),card->getManaCost()->getMorph());
|
ManaCost * morph = card->getManaCost()->getMorph();
|
||||||
if(morph->extraCosts)
|
if(morph->extraCosts)
|
||||||
for(unsigned int i = 0; i < morph->extraCosts->costs.size();i++)
|
for(unsigned int i = 0; i < morph->extraCosts->costs.size();i++)
|
||||||
{
|
{
|
||||||
@@ -1446,7 +1446,7 @@ int MTGOverloadRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
|
|||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
ManaCost * newCost = card->computeNewCost(card, card->model->data->getManaCost()->getAlternative(), card->getManaCost()->getAlternative());
|
ManaCost * newCost = card->getManaCost()->getAlternative();
|
||||||
if(newCost->extraCosts)
|
if(newCost->extraCosts)
|
||||||
for(unsigned int i = 0; i < newCost->extraCosts->costs.size();i++)
|
for(unsigned int i = 0; i < newCost->extraCosts->costs.size();i++)
|
||||||
{
|
{
|
||||||
@@ -1462,7 +1462,7 @@ int MTGOverloadRule::reactToClick(MTGCardInstance * card)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ManaCost * cost = NEW ManaCost(card->model->data->getManaCost()->getAlternative());
|
ManaCost * cost = NEW ManaCost(card->model->data->getManaCost()->getAlternative());
|
||||||
ManaCost * newCost = card->computeNewCost(card, card->model->data->getManaCost()->getAlternative(), card->getManaCost()->getAlternative());
|
ManaCost * newCost = card->getManaCost()->getAlternative();
|
||||||
if(newCost->extraCosts)
|
if(newCost->extraCosts)
|
||||||
for(unsigned int i = 0; i < newCost->extraCosts->costs.size();i++)
|
for(unsigned int i = 0; i < newCost->extraCosts->costs.size();i++)
|
||||||
{
|
{
|
||||||
@@ -1508,7 +1508,7 @@ int MTGBestowRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
|
|||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
ManaCost * newCost = card->computeNewCost(card, card->model->data->getManaCost()->getBestow(), card->getManaCost()->getBestow());
|
ManaCost * newCost = card->getManaCost()->getBestow();
|
||||||
if (newCost->extraCosts)
|
if (newCost->extraCosts)
|
||||||
for (unsigned int i = 0; i < newCost->extraCosts->costs.size(); i++)
|
for (unsigned int i = 0; i < newCost->extraCosts->costs.size(); i++)
|
||||||
{
|
{
|
||||||
@@ -1523,7 +1523,7 @@ int MTGBestowRule::reactToClick(MTGCardInstance * card)
|
|||||||
return 0;
|
return 0;
|
||||||
//this new method below in all alternative cost type causes a memleak, however, you cant safedelete the cost here as it cause a crash
|
//this new method below in all alternative cost type causes a memleak, however, you cant safedelete the cost here as it cause a crash
|
||||||
//TODO::::we need to get to the source of this leak and fix it.
|
//TODO::::we need to get to the source of this leak and fix it.
|
||||||
ManaCost * newCost = card->computeNewCost(card, card->model->data->getManaCost()->getBestow(), card->getManaCost()->getBestow());
|
ManaCost * newCost = card->getManaCost()->getBestow();
|
||||||
|
|
||||||
if (newCost->extraCosts)
|
if (newCost->extraCosts)
|
||||||
for (unsigned int i = 0; i < newCost->extraCosts->costs.size(); i++)
|
for (unsigned int i = 0; i < newCost->extraCosts->costs.size(); i++)
|
||||||
|
|||||||
@@ -601,6 +601,7 @@ void ManaCost::copy(ManaCost * _manaCost)
|
|||||||
hybrids = _manaCost->hybrids;
|
hybrids = _manaCost->hybrids;
|
||||||
|
|
||||||
SAFE_DELETE(extraCosts);
|
SAFE_DELETE(extraCosts);
|
||||||
|
|
||||||
if (_manaCost->extraCosts)
|
if (_manaCost->extraCosts)
|
||||||
{
|
{
|
||||||
extraCosts = _manaCost->extraCosts->clone();
|
extraCosts = _manaCost->extraCosts->clone();
|
||||||
|
|||||||
Reference in New Issue
Block a user