Affinity affects other costs

Affinity should affect other costs such as flashback, buyback,  to cast
since its also a cost reducer...
This commit is contained in:
Anthony Calosa
2016-06-04 21:50:49 +08:00
parent 719a8b3420
commit 87515de57f
3 changed files with 95 additions and 10 deletions

View File

@@ -12,6 +12,9 @@
#include "Counters.h"
#include "Subtypes.h"
#include "AIPlayerBaka.h"
using namespace std;
SUPPORT_OBJECT_ANALYTICS(MTGCardInstance)
@@ -919,20 +922,102 @@ JQuadPtr MTGCardInstance::getIcon()
return WResourceManager::Instance()->RetrieveCard(this, CACHE_THUMB);
}
ManaCost * MTGCardInstance::computeNewCost(MTGCardInstance * card,ManaCost * newCost, ManaCost * refCost)
ManaCost * MTGCardInstance::computeNewCost(MTGCardInstance * card,ManaCost * newCost, ManaCost * refCost, bool onlyTrinisphere)
{
if(!card)
return NULL;
if(!onlyTrinisphere)
{
if(card->getIncreasedManaCost()->getConvertedCost())
newCost->add(card->getIncreasedManaCost());
if(card->getReducedManaCost()->getConvertedCost())
newCost->remove(card->getReducedManaCost());
if(refCost->extraCosts)
newCost->extraCosts = refCost->extraCosts;
//trinisphere must be here below//
//affinity
int color = 0;
string type = "";
ManaCost * original = NEW ManaCost();
original->copy(newCost);
int reducem = 0;
bool resetCost = false;
for(unsigned int na = 0; na < card->cardsAbilities.size();na++)
{//start2
ANewAffinity * newAff = dynamic_cast<ANewAffinity*>(card->cardsAbilities[na]);
if(newAff)
{
if(!resetCost)
{
resetCost = true;
newCost->copy(original);
}
TargetChooserFactory tf(observer);
TargetChooser * tcn = tf.createTargetChooser(newAff->tcString,card,NULL);
for (int w = 0; w < 2; ++w)
{
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 (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++)
newCost->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";
}
newCost->copy(original);
int reduce = 0;
if(card->has(Constants::AFFINITYGREENCREATURES))
{
TargetChooserFactory tf(observer);
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(newCost->getCost(color) > 0)
newCost->remove(color,1);
}//end3
SAFE_DELETE(original);
}
/*//trinisphere must be here below//
if(card->has(Constants::TRINISPHERE))
for(int jj = newCost->getConvertedCost(); jj < 3; jj++)
newCost->add(Constants::MTG_COLOR_ARTIFACT, 1);
newCost->add(Constants::MTG_COLOR_ARTIFACT, 1);*/
return newCost;
}