fix and completely reworked affinity AGAIN.
moved it out of rules, it was FAR to error prone and after fixing bugs on this ability about 12 times, im done with it. noticed yesterday that it was removing the completely wrong amounts, and not maintaining its cost AT ALL. so i got sick of adjusting it as a rule, its now a statebased effect, called through gamestatebasedeffect as a side function. the new affinity is less then 100 lines of code, down from 300. to acomplish the effect with FAR less effort. it is also FAR easier to maintain in the future if i die or leave the scene or whatever. added a new count tool for MTGGameZones canByCanTarget...which allows for returns of amounts based on if it can be targetted by a tc. much like how listmaintainer does it. affinitygreencreature will not be the only ability to use this function, just a heads up. its just the first to do so. hopefully this much more accurate affinity will be the last version...considering adding the other types which old affinity couldnt handle :D
This commit is contained in:
@@ -1457,294 +1457,7 @@ MTGUnearthRule * MTGUnearthRule::clone() const
|
||||
a->isClone = 1;
|
||||
return a;
|
||||
}
|
||||
//----------------------------------------------------------------------
|
||||
//Affinity rule------------------------------------------------------
|
||||
//this rule is for Affinity cards.
|
||||
|
||||
MTGAffinityRule::MTGAffinityRule(int _id) :
|
||||
MTGAbility(_id, NULL)
|
||||
{
|
||||
}
|
||||
;
|
||||
int MTGAffinityRule::receiveEvent(WEvent * event)
|
||||
{
|
||||
if (event->type == WEvent::CHANGE_ZONE)
|
||||
{
|
||||
WEventZoneChange * e = (WEventZoneChange *) event;
|
||||
MTGCardInstance * card = e->card->previous;
|
||||
if (e && card)
|
||||
{
|
||||
int color = -1;
|
||||
string type = "";
|
||||
int ok = 0;
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
Player * p = game->players[i];
|
||||
if (e->to == p->game->hand)
|
||||
ok = 1;//affinity card enters hand
|
||||
//---------
|
||||
//when cards with affinity enter you hand from anywhere a redux is applied to them for the artifacts in play.
|
||||
if (ok == 1)
|
||||
{//enters play from anywhere
|
||||
if (e->from == p->game->graveyard
|
||||
|| e->from == p->game->hand
|
||||
|| e->from == p->game->library
|
||||
|| e->from == p->game->exile
|
||||
|| e->from == p->game->stack
|
||||
|| e->from == p->opponent()->game->battlefield
|
||||
|| e->from == p->game->temp
|
||||
|| e->from == p->game->battlefield
|
||||
)
|
||||
{
|
||||
// TODO:
|
||||
// what happens if there are any cards with two or more affinity abilities? If no such card exist
|
||||
// then could this block be changed to use else if? That will save on the number of operations.
|
||||
MTGCardInstance * card = e->card->previous;
|
||||
if (card && card->has(Constants::AFFINITYARTIFACTS))
|
||||
{
|
||||
color = 0;
|
||||
type = "artifact";
|
||||
}
|
||||
if (card && card->has(Constants::AFFINITYSWAMP))
|
||||
{
|
||||
color = 0;
|
||||
type = "swamp";
|
||||
}
|
||||
if (card && card->has(Constants::AFFINITYMOUNTAIN))
|
||||
{
|
||||
color = 0;
|
||||
type = "mountain";
|
||||
}
|
||||
if (card && card->has(Constants::AFFINITYPLAINS))
|
||||
{
|
||||
color = 0;
|
||||
type = "plains";
|
||||
}
|
||||
if (card && card->has(Constants::AFFINITYISLAND))
|
||||
{
|
||||
color = 0;
|
||||
type = "island";
|
||||
}
|
||||
if (card && card->has(Constants::AFFINITYFOREST))
|
||||
{
|
||||
color = 0;
|
||||
type = "forest";
|
||||
}
|
||||
if (card && card->has(Constants::AFFINITYGREENCREATURES))
|
||||
{
|
||||
color = 1;
|
||||
type = "creature";
|
||||
}
|
||||
//--redux effect
|
||||
MTGGameZone * z = card->controller()->game->battlefield;
|
||||
int nbcards = z->nb_cards;
|
||||
for (int j = 0; j < nbcards; ++j)
|
||||
{
|
||||
MTGCardInstance * c = z->cards[j];
|
||||
int check = e->card->getManaCost()->getConvertedCost();
|
||||
if ((e->card->has(Constants::AFFINITYARTIFACTS) && c->hasSubtype("artifact"))
|
||||
|| (e->card->has(Constants::AFFINITYSWAMP) && c->hasSubtype("swamp"))
|
||||
|| (e->card->has(Constants::AFFINITYMOUNTAIN) && c->hasSubtype("moutain"))
|
||||
|| (e->card->has(Constants::AFFINITYPLAINS) && c->hasSubtype("plains"))
|
||||
|| (e->card->has(Constants::AFFINITYISLAND) && c->hasSubtype("island"))
|
||||
|| (e->card->has(Constants::AFFINITYFOREST) && c->hasSubtype("forest"))
|
||||
|| (e->card->has(Constants::AFFINITYGREENCREATURES) && c->hasColor(1) && c->isCreature())
|
||||
)
|
||||
{
|
||||
if (check > 0)
|
||||
{
|
||||
if (color > 0 && !e->card->getManaCost()->hasColor(color))
|
||||
{//do nothing if its colored redux and the cards dont have the color
|
||||
}
|
||||
else
|
||||
{
|
||||
//do normal redux
|
||||
e->card->getManaCost()->remove(color, 1);
|
||||
}//one less colorless to cast
|
||||
}
|
||||
else
|
||||
{
|
||||
e->card->reduxamount += 1;
|
||||
}
|
||||
}
|
||||
}//--end of redux bracket
|
||||
}
|
||||
}//if ok == 1
|
||||
//-------------maintaining cost----------------------------------------------------------------
|
||||
ok = 0;
|
||||
if (e->to == p->game->battlefield)
|
||||
ok = 2;//card enters play
|
||||
if (ok == 2)
|
||||
{//enters play from anywhere
|
||||
if (e->from == p->game->graveyard
|
||||
|| e->from == p->game->hand
|
||||
|| e->from == p->game->library
|
||||
|| e->from == p->game->exile
|
||||
|| e->from == p->game->stack
|
||||
|| e->from == p->game->temp
|
||||
)
|
||||
{
|
||||
//--redux effect
|
||||
MTGGameZone * z = card->controller()->game->hand;
|
||||
int nbcards = z->nb_cards;
|
||||
int colored = 0;
|
||||
string etype = "";
|
||||
MTGCardInstance * card = e->card->previous;
|
||||
if (card && card->hasSubtype("artifact"))
|
||||
{
|
||||
etype.append("art");
|
||||
}
|
||||
if (card && card->hasSubtype("swamp"))
|
||||
{
|
||||
etype.append("swa");
|
||||
}
|
||||
if (card && card->hasSubtype("mountain"))
|
||||
{
|
||||
etype.append("mou");
|
||||
}
|
||||
if (card && card->hasSubtype("plains"))
|
||||
{
|
||||
etype.append("pla");
|
||||
}
|
||||
if (card && card->hasSubtype("island"))
|
||||
{
|
||||
etype.append("isl");
|
||||
}
|
||||
if (card && card->hasSubtype("forest"))
|
||||
{
|
||||
etype.append("for");
|
||||
}
|
||||
if (card && card->hasSubtype("creature") && card->hasColor(1))
|
||||
{
|
||||
etype.append("cre");
|
||||
colored = 1;
|
||||
}
|
||||
for (int j = 0; j < nbcards; ++j)
|
||||
{
|
||||
MTGCardInstance * c = z->cards[j];
|
||||
if ((c->has(Constants::AFFINITYARTIFACTS) && etype.find("art") != string::npos)
|
||||
|| (c->has(Constants::AFFINITYSWAMP) && etype.find("swa") != string::npos)
|
||||
|| (c->has(Constants::AFFINITYMOUNTAIN) && etype.find("mou") != string::npos)
|
||||
|| (c->has(Constants::AFFINITYPLAINS) && etype.find("pla") != string::npos)
|
||||
|| (c->has(Constants::AFFINITYISLAND) && etype.find("isl") != string::npos)
|
||||
|| (c->has(Constants::AFFINITYFOREST) && etype.find("for") != string::npos)
|
||||
|| (c->has(Constants::AFFINITYGREENCREATURES) && etype.find("cre") != string::npos)
|
||||
)
|
||||
{
|
||||
if (c->getManaCost()->getConvertedCost() > 0)
|
||||
{
|
||||
c->getManaCost()->remove(colored, 1);//one less colorless to cast
|
||||
}
|
||||
else
|
||||
{
|
||||
c->reduxamount += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}//--end of redux bracket ok == 2
|
||||
//---------
|
||||
ok = 0;
|
||||
if (e->to == p->game->graveyard
|
||||
|| e->to == p->game->hand
|
||||
|| e->to == p->game->library
|
||||
|| e->to == p->game->exile
|
||||
|| e->to == p->game->stack
|
||||
|| e->to == p->opponent()->game->battlefield
|
||||
)
|
||||
ok = 3;//card leaves play
|
||||
|
||||
if (ok == 3)
|
||||
{//leave play from your battlefield
|
||||
if (e->from == p->game->battlefield)
|
||||
{
|
||||
int colored = 0;
|
||||
MTGGameZone * z = card->controller()->game->hand;
|
||||
int nbcards = z->nb_cards;
|
||||
string etype = "";
|
||||
MTGCardInstance * card = e->card->previous;
|
||||
if (card && card->hasSubtype("artifact"))
|
||||
{
|
||||
etype.append("art");
|
||||
}
|
||||
if (card && card->hasSubtype("swamp"))
|
||||
{
|
||||
etype.append("swa");
|
||||
}
|
||||
if (card && card->hasSubtype("mountain"))
|
||||
{
|
||||
etype.append("mou");
|
||||
}
|
||||
if (card && card->hasSubtype("plains"))
|
||||
{
|
||||
etype.append("pla");
|
||||
}
|
||||
if (card && card->hasSubtype("island"))
|
||||
{
|
||||
etype.append("isl");
|
||||
}
|
||||
if (card && card->hasSubtype("forest"))
|
||||
{
|
||||
etype.append("for");
|
||||
}
|
||||
if (card && card->hasSubtype("creature") && card->hasColor(1))
|
||||
{
|
||||
etype.append("cre");
|
||||
colored = 1;
|
||||
}
|
||||
for (int j = 0; j < nbcards; ++j)
|
||||
{
|
||||
MTGCardInstance * c = z->cards[j];
|
||||
if (c && ((c->has(Constants::AFFINITYARTIFACTS) && etype.find("art") != string::npos)
|
||||
|| (c->has(Constants::AFFINITYSWAMP) && etype.find("swa") != string::npos)
|
||||
|| (c->has(Constants::AFFINITYMOUNTAIN) && etype.find("mou") != string::npos)
|
||||
|| (c->has(Constants::AFFINITYPLAINS) && etype.find("pla") != string::npos)
|
||||
|| (c->has(Constants::AFFINITYISLAND) && etype.find("isl") != string::npos)
|
||||
|| (c->has(Constants::AFFINITYFOREST) && etype.find("for") != string::npos)
|
||||
|| (c->has(Constants::AFFINITYGREENCREATURES) && etype.find("cre") != string::npos))
|
||||
)
|
||||
{
|
||||
if (c->reduxamount > 0)
|
||||
{
|
||||
c->reduxamount -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
c->getManaCost()->add(colored, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
//-------------------------------
|
||||
}
|
||||
}//---ok == 3
|
||||
//----------------------------------------
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
ostream& MTGAffinityRule::toString(ostream& out) const
|
||||
{
|
||||
out << "MTGAffinityRule ::: (";
|
||||
return MTGAbility::toString(out) << ")";
|
||||
}
|
||||
|
||||
int MTGAffinityRule::testDestroy()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
MTGAffinityRule * MTGAffinityRule::clone() const
|
||||
{
|
||||
MTGAffinityRule * a = NEW MTGAffinityRule(*this);
|
||||
a->isClone = 1;
|
||||
return a;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
//token clean up
|
||||
MTGTokensCleanup::MTGTokensCleanup(int _id) :
|
||||
MTGAbility(_id, NULL)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user