refactor Legendary Rule

This commit is contained in:
Anthony Calosa
2017-02-01 09:49:36 +08:00
parent c0afb3b95e
commit 7b0fdcd721
6 changed files with 72 additions and 70 deletions
@@ -10,6 +10,7 @@ inplay:22897
[DO] [DO]
106525 106525
choice 0 choice 0
106525
[ASSERT] [ASSERT]
FIRSTMAIN FIRSTMAIN
[PLAYER1] [PLAYER1]
+1
View File
@@ -250,6 +250,7 @@ public:
int getCurrentToughness(); int getCurrentToughness();
int LKIpower; int LKIpower;
int LKItoughness; int LKItoughness;
int countDuplicateCardNames();
void cdaPT(int p = 0, int t = 0); void cdaPT(int p = 0, int t = 0);
bool isCDA; bool isCDA;
void switchPT(bool apply = false); void switchPT(bool apply = false);
+9 -9
View File
@@ -423,19 +423,19 @@ public:
}; };
/* /*
* Rule 420.5e (Legend Rule) * 704.5k If a player controls two or more legendary permanents with the same name,
* If two or more legendary permanents with the same name are in play, all are put into their * that player chooses one of them, and the rest are put into their owners graveyards.
* owners' graveyards. This is called the "legend rule." If only one of those permanents is * This is called the legend rule.
* legendary, this rule doesn't apply.
*/ */
class MTGLegendRule: public ListMaintainerAbility class MTGLegendRule: public PermanentAbility
{ {
public: public:
TargetChooser * tcL;
MTGAbility * Legendrule;
MTGAbility * LegendruleAbility;
MTGAbility * LegendruleGeneric;
MTGLegendRule(GameObserver* observer, int _id); MTGLegendRule(GameObserver* observer, int _id);
int canBeInList(MTGCardInstance * card); int receiveEvent(WEvent * event);
int added(MTGCardInstance * card);
int removed(MTGCardInstance * card);
int testDestroy();
virtual ostream& toString(ostream& out) const; virtual ostream& toString(ostream& out) const;
virtual MTGLegendRule * clone() const; virtual MTGLegendRule * clone() const;
}; };
+5
View File
@@ -79,6 +79,11 @@ struct WEventDamageStackResolved : public WEvent {
WEventDamageStackResolved(); WEventDamageStackResolved();
}; };
struct WEventGameStateBasedChecked : public WEvent {
WEventGameStateBasedChecked();
};
struct WEventPhasePreChange : public WEvent { struct WEventPhasePreChange : public WEvent {
Phase * from; Phase * from;
Phase * to; Phase * to;
+16
View File
@@ -828,6 +828,22 @@ int MTGCardInstance::getCurrentToughness()
return toughness; return toughness;
} }
int MTGCardInstance::countDuplicateCardNames()
{
int count = 0;
if(observer)
{
int nb_cards = controller()->game->battlefield->nb_cards;
for(int x = 0; x < nb_cards; x++)
{
if(controller()->game->battlefield->cards[x]->name == this->name)
count+=1;
}
}
return count;
}
//check stack //check stack
bool MTGCardInstance::StackIsEmptyandSorcerySpeed() bool MTGCardInstance::StackIsEmptyandSorcerySpeed()
{ {
+34 -55
View File
@@ -3205,76 +3205,55 @@ MTGTokensCleanup * MTGTokensCleanup::clone() const
/* Legend Rule */ /* Legend Rule */
MTGLegendRule::MTGLegendRule(GameObserver* observer, int _id) : MTGLegendRule::MTGLegendRule(GameObserver* observer, int _id) :
ListMaintainerAbility(observer, _id) PermanentAbility(observer, _id)
{ {
tcL = NULL;
Legendrule = NULL;
LegendruleAbility = NULL;
LegendruleGeneric = NULL;
} }
; ;
int MTGLegendRule::canBeInList(MTGCardInstance * card) int MTGLegendRule::receiveEvent(WEvent * event)
{ {
if(card->isPhased) WEventGameStateBasedChecked * e = dynamic_cast<WEventGameStateBasedChecked*> (event);
return 0; if (e)
if (card->hasType(Subtypes::TYPE_LEGENDARY) && card->controller()->game->inPlay->hasCard(card)) {
for (int i = 0; i < 2; i++)
{
MTGGameZone * zone = game->players[i]->game->inPlay;
for (int k = zone->nb_cards - 1; k >= 0; k--)
{
MTGCardInstance * card = zone->cards[k];
if (card && card->hasType(Subtypes::TYPE_LEGENDARY) && !card->isPhased)
{ {
if(card->has(Constants::NOLEGEND)||card->controller()->opponent()->inPlay()->hasAbility(Constants::NOLEGENDRULE)||card->controller()->inPlay()->hasAbility(Constants::NOLEGENDRULE)) if(card->has(Constants::NOLEGEND)||card->controller()->opponent()->inPlay()->hasAbility(Constants::NOLEGENDRULE)||card->controller()->inPlay()->hasAbility(Constants::NOLEGENDRULE))
return 0; ;
else else
return 1; if(card->countDuplicateCardNames() > 1)
}
return 0;
}
int MTGLegendRule::added(MTGCardInstance * card)
{
map<MTGCardInstance *, bool>::iterator it;
int destroy = 0;
vector<MTGCardInstance*>oldCards;
for (it = cards.begin(); it != cards.end(); it++)
{
MTGCardInstance * comparison = (*it).first;
if (comparison != card && comparison->controller() == card->controller() && !(comparison->getName().compare(card->getName())))
{
oldCards.push_back(comparison);
destroy = 1;
}
}
if (game->mLayers->stackLayer()->count(0, NOT_RESOLVED) != 0)
destroy = 0;
if (game->mLayers->actionLayer()->menuObject)
destroy = 0;
if (game->getCurrentTargetChooser() || game->mLayers->actionLayer()->isWaitingForAnswer())
destroy = 0;
if(destroy)
{ {
vector<MTGAbility*>selection; vector<MTGAbility*>selection;
MultiAbility * multi = NEW MultiAbility(game, game->mLayers->actionLayer()->getMaxId(), card, card, NULL); TargetChooserFactory tfL(game);
for(unsigned int i = 0;i < oldCards.size();i++) tcL = tfL.createTargetChooser("*[share!name!]|mybattlefield",card->clone());
{ tcL->targetter = NULL;
AAMover *a = NEW AAMover(game, game->mLayers->actionLayer()->getMaxId(), card, oldCards[i],"ownergraveyard","Keep New"); tcL->maxtargets = card->countDuplicateCardNames()-1;
a->oneShot = true; Legendrule = NEW AAMover(game, game->mLayers->actionLayer()->getMaxId(), card, NULL,"ownergraveyard","Put in Graveyard");
multi->Add(a); Legendrule->oneShot = true;
} Legendrule->canBeInterrupted = false;
multi->oneShot = 1; LegendruleAbility = NEW GenericTargetAbility(game, "","",game->mLayers->actionLayer()->getMaxId(), card,tcL, Legendrule->clone());
MTGAbility * a1 = multi; LegendruleAbility->oneShot = true;
selection.push_back(a1); LegendruleAbility->canBeInterrupted = false;
AAMover *b = NEW AAMover(game, game->mLayers->actionLayer()->getMaxId(), card, card,"ownergraveyard","Keep Old"); LegendruleGeneric = NEW GenericAddToGame(game, game->mLayers->actionLayer()->getMaxId(), card,NULL,LegendruleAbility->clone());
b->oneShot = true; LegendruleGeneric->oneShot = true;
MTGAbility * b1 = b; selection.push_back(LegendruleGeneric->clone());
selection.push_back(b1);
MTGAbility * menuChoice = NEW MenuAbility(game, game->mLayers->actionLayer()->getMaxId(), card, card,true,selection,card->controller(),"Legendary Rule"); MTGAbility * menuChoice = NEW MenuAbility(game, game->mLayers->actionLayer()->getMaxId(), card, card,true,selection,card->controller(),"Legendary Rule");
menuChoice->addToGame(); menuChoice->addToGame();
}
return 1; return 1;
} }
int MTGLegendRule::removed(MTGCardInstance *)
{
return 0;
} }
}
int MTGLegendRule::testDestroy() }
{ }
return 0; return 0;
} }