diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 688935c57..3b82857d1 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -970,6 +970,19 @@ public: Generic classes */ +//if/ifnot Cond then EFFECT +class IfThenAbility: public MTGAbility +{ +public: + string delayAbility; + int type; + string Cond; + IfThenAbility(int _id,string delayAbility = "", MTGCardInstance * _source=NULL, int type = 1,string Cond = ""); + int resolve(); + const char * getMenuText(); + IfThenAbility * clone() const; +}; + //MayAbility: May do ... class MayAbility: public MTGAbility, public NestedAbility { diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index 3b380081f..c0edcc5ac 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -2065,6 +2065,48 @@ AAWinGame * AAWinGame::clone() const //Generic Abilities + +//IfThenEffect +IfThenAbility::IfThenAbility(int _id, string delayAbility, MTGCardInstance * _source, int type,string Cond) : +MTGAbility(_id, _source),delayAbility(delayAbility), type(type),Cond(Cond) +{ +} + +int IfThenAbility::resolve() +{ + MTGCardInstance * card = (MTGCardInstance*)source; + AbilityFactory af; + int checkCond = af.parseCastRestrictions(card,card->controller(),Cond); + if((checkCond && type == 1)||(!checkCond && type == 2)) + { + MTGAbility * a1 = af.parseMagicLine(delayAbility, this->GetId(), NULL, card); + if (!a1) + return 0; + if(a1->oneShot) + { + a1->resolve(); + SAFE_DELETE(a1); + } + else + a1->addToGame(); + return 1; + } + return 0; +} + +const char * IfThenAbility::getMenuText() +{ + return ""; +} + +IfThenAbility * IfThenAbility::clone() const +{ + IfThenAbility * a = NEW IfThenAbility(*this); + a->isClone = 1; + return a; +} +// + //May Abilities MayAbility::MayAbility(int _id, MTGAbility * _ability, MTGCardInstance * _source, bool must) : MTGAbility(_id, _source), NestedAbility(_ability), must(must) diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index c64fbc224..c8665e4bf 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -906,6 +906,24 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG return parseMagicLine(s.substr(kAlternateCostKeywords[i].length()), id, spell, card); } } + + //if/ifnot COND then DO EFFECT. + const string ifKeywords[] = {"if ", "ifnot "}; + int checkIf[] = { 1, 2 }; + for (size_t i =0; i < sizeof(checkIf)/sizeof(checkIf[0]); ++i) + { + if (sWithoutTc.find(ifKeywords[i]) == 0) + { + string cond = sWithoutTc.substr(ifKeywords[i].length(),ifKeywords[i].length() + sWithoutTc.find(" then ")-6); + string s1 = s.substr(s.find(" then ")+6); + MTGAbility * a = NEW IfThenAbility(id, s1, card,checkIf[i],cond); + a->canBeInterrupted = false; + a->oneShot = true; + if(tc) + SAFE_DELETE(tc); + return a; + } + } //When...comes into play, you may... //When...comes into play, choose one...