From c5128b35e086f850d763e225d09899fd3d3d8ac7 Mon Sep 17 00:00:00 2001 From: "omegablast2002@yahoo.com" Date: Mon, 26 Mar 2012 11:48:22 +0000 Subject: [PATCH] fix for sorins destroy andability, actually a fix for and(( in general..have to hide the and(( string from the parser till we need it. --- projects/mtg/include/MTGAbility.h | 1 + projects/mtg/src/MTGAbility.cpp | 63 ++++++++++++++++--------------- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/projects/mtg/include/MTGAbility.h b/projects/mtg/include/MTGAbility.h index 7f32ae897..c8290f09d 100644 --- a/projects/mtg/include/MTGAbility.h +++ b/projects/mtg/include/MTGAbility.h @@ -445,6 +445,7 @@ class AbilityFactory { private: string storedString; + string storedAndAbility; int countCards(TargetChooser * tc, Player * player = NULL, int option = 0); TriggeredAbility * parseTrigger(string s, string magicText, int id, Spell * spell, MTGCardInstance *card, Targetable * target); MTGAbility * getAlternateCost( string s, int id, Spell *spell, MTGCardInstance *card ); diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 3b785ed37..22d1431e6 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -1018,6 +1018,19 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG s.erase(sIndex, real_end - sIndex); } + found = s.find("and(("); + if (found != string::npos && found + 6 != ')' && storedAndAbility.empty()) + { + vector splitAnd = parseBetween(s, "and((", " ))",false); + if(splitAnd.size()) + { + storedAndAbility.append(splitAnd[1]); + size_t real_end = s.find("))", found); + size_t sIndex = found + 5; + s.erase(sIndex, real_end - sIndex); + } + } + vector splitTrigger = parseBetween(s, "@", ":"); if (splitTrigger.size()) { @@ -1867,13 +1880,11 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG MTGAbility * a = NEW AAMover(observer, id, card, target, splitMove[1]); a->oneShot = true; - if(s.find("and(") != string::npos) + if(storedAndAbility.size()) { - vector splitAnd = parseBetween(s, "and((", " ))",false); - if(splitAnd.size()) - { - ((AAMover*)a)->andAbility = parseMagicLine(splitAnd[1], id, spell, card); - } + string stored = storedAndAbility; + storedAndAbility.clear(); + ((AAMover*)a)->andAbility = parseMagicLine(stored, id, spell, card); } return a; } @@ -1944,13 +1955,11 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { MTGAbility *a = NEW AABuryCard(observer, id, card, target); a->oneShot = 1; - if(s.find("and(") != string::npos) + if(storedAndAbility.size()) { - vector splitAnd = parseBetween(s, "and((", " ))",false); - if(splitAnd.size()) - { - ((AABuryCard*)a)->andAbility = parseMagicLine(splitAnd[1], id, spell, card); - } + string stored = storedAndAbility; + storedAndAbility.clear(); + ((AABuryCard*)a)->andAbility = parseMagicLine(stored, id, spell, card); } return a; } @@ -1959,13 +1968,11 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { MTGAbility * a = NEW AADestroyCard(observer, id, card, target); a->oneShot = 1; - if(s.find("and(") != string::npos) + if(storedAndAbility.size()) { - vector splitAnd = parseBetween(s, "and((", " ))",false); - if(splitAnd.size()) - { - ((AADestroyCard*)a)->andAbility = parseMagicLine(splitAnd[1], id, spell, card); - } + string stored = storedAndAbility; + storedAndAbility.clear(); + ((AADestroyCard*)a)->andAbility = parseMagicLine(stored, id, spell, card); } return a; } @@ -1974,13 +1981,11 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { MTGAbility *a = NEW AASacrificeCard(observer, id, card, target); a->oneShot = 1; - if(s.find("and(") != string::npos) + if(storedAndAbility.size()) { - vector splitAnd = parseBetween(s, "and((", " ))",false); - if(splitAnd.size()) - { - ((AASacrificeCard*)a)->andAbility = parseMagicLine(splitAnd[1], id, spell, card); - } + string stored = storedAndAbility; + storedAndAbility.clear(); + ((AASacrificeCard*)a)->andAbility = parseMagicLine(stored, id, spell, card); } return a; } @@ -1989,13 +1994,11 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { MTGAbility *a = NEW AADiscardCard(observer, id, card, target); a->oneShot = 1; - if(s.find("and(") != string::npos) + if(storedAndAbility.size()) { - vector splitAnd = parseBetween(s, "and((", " ))",false); - if(splitAnd.size()) - { - ((AADiscardCard*)a)->andAbility = parseMagicLine(splitAnd[1], id, spell, card); - } + string stored = storedAndAbility; + storedAndAbility.clear(); + ((AADiscardCard*)a)->andAbility = parseMagicLine(stored, id, spell, card); } return a; }