diff --git a/projects/mtg/bin/Res/test/_tests.txt b/projects/mtg/bin/Res/test/_tests.txt index 3563e4425..60944f0c0 100644 --- a/projects/mtg/bin/Res/test/_tests.txt +++ b/projects/mtg/bin/Res/test/_tests.txt @@ -88,6 +88,7 @@ drift_of_the_dead.txt dross_harvester.txt elvish_piper.txt elvish_promenade.txt +farhaven_elf.txt fastbond.txt fastbond2.txt fault_line.txt diff --git a/projects/mtg/bin/Res/test/farhaven_elf.txt b/projects/mtg/bin/Res/test/farhaven_elf.txt new file mode 100644 index 000000000..75e0133c5 --- /dev/null +++ b/projects/mtg/bin/Res/test/farhaven_elf.txt @@ -0,0 +1,23 @@ +#Bug:farhaven elf taps itself +[INIT] +SECONDMAIN +[PLAYER1] +hand:farhaven elf +library:forest +manapool:{2}{G} +[PLAYER2] +inplay:royal assassin +[DO] +farhaven elf +choice 0 +forest +eot +royal assassin +farhaven elf +[ASSERT] +UNTAP +[PLAYER1] +inplay:farhaven elf,forest +[PLAYER2] +inplay:royal assassin +[END] \ No newline at end of file diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 7231ffc11..fe156feb0 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -217,10 +217,13 @@ public: } ~MultiAbility(){ - vector::size_type sz = abilities.size(); - for (unsigned int i = 0; i < sz; i++){ - delete abilities[i]; + if (!isClone){ + vector::size_type sz = abilities.size(); + for (unsigned int i = 0; i < sz; i++){ + delete abilities[i]; + } } + abilities.clear(); } const char * getMenuText(){ diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 7a0e157af..0131ac14c 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -142,6 +142,11 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG s.erase(found+1); else return NULL; + found=s.find_first_not_of(whitespaces); + if (found!=string::npos) + s.erase(0,found); + else return NULL; + //TODO This block redundant with calling function if (!card && spell) card = spell->source; if (!card) return NULL; @@ -213,6 +218,25 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG } + //When...comes into play, you may... + found = s.find("may "); + if (found == 0){ + string s1 = s.substr(found+4); + MTGAbility * a1 = parseMagicLine(s1,id,spell, card); + if (!a1) return NULL; + TargetChooser * tc = NULL; + //Target Abilities + found = s.find("target("); + if (found != string::npos){ + int end = s.find(")", found); + string starget = s.substr(found + 7,end - found - 7); + TargetChooserFactory tcf; + tc = tcf.createTargetChooser(starget, card); + } + if (tc) a1 = NEW GenericTargetAbility(id, card, tc, a1); + return NEW MayAbility(id,a1,card); + } + //Multiple abilities for ONE cost found = s.find("&&"); @@ -287,26 +311,6 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG return NULL; } - //When...comes into play, you may... - found = s.find("may "); - if (found != string::npos){ - string s1 = s.substr(found+4); - MTGAbility * a1 = parseMagicLine(s1,id,spell, card); - if (!a1) return NULL; - TargetChooser * tc = NULL; - //Target Abilities - found = s.find("target("); - if (found != string::npos){ - int end = s.find(")", found); - string starget = s.substr(found + 7,end - found - 7); - TargetChooserFactory tcf; - tc = tcf.createTargetChooser(starget, card); - } - if (tc) a1 = NEW GenericTargetAbility(id, card, tc, a1); - return NEW MayAbility(id,a1,card); - } - - //Fizzle (counterspell...) found = s.find("fizzle");