diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 6ffe8833a..2c5df1adf 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -1018,10 +1018,43 @@ public: who = who; tokenId = 0; if (!multiplier) this->multiplier = NEW WParsedInt(1); + //TODO this is a copy/past of other code that's all around the place, everything should be in a dedicated parser class; - PopulateAbilityIndexVector(abilities, sabilities); - PopulateColorIndexVector(colors, sabilities); - PopulateSubtypesIndexVector(types, stypes); + for (int j = 0; j < Constants::NB_BASIC_ABILITIES; j++) + { + size_t found = sabilities.find(Constants::MTGBasicAbilities[j]); + if (found != string::npos) + { + abilities.push_back(j); + } + } + + for (int j = 0; j < Constants::MTG_NB_COLORS; j++) + { + size_t found = sabilities.find(Constants::MTGColorStrings[j]); + if (found != string::npos) + { + colors.push_back(j); + } + } + + string s = stypes; + while (s.size()) + { + size_t found = s.find(" "); + if (found != string::npos) + { + int id = Subtypes::subtypesList->find(s.substr(0, found)); + types.push_back(id); + s = s.substr(found + 1); + } + else + { + int id = Subtypes::subtypesList->find(s); + types.push_back(id); + s = ""; + } + } } int resolve() diff --git a/projects/mtg/include/utils.h b/projects/mtg/include/utils.h index c93edb140..e29344aa7 100644 --- a/projects/mtg/include/utils.h +++ b/projects/mtg/include/utils.h @@ -43,7 +43,7 @@ std::vector &split(const std::string &s, char delim, std::vector split(const std::string &s, char delim); //splits a string with "delim" and returns a vector of strings. std::string wordWrap(std::string s, int width); -void PopulateColorIndexVector( list& colors, const string& colorsString, char delimiter = ' '); +void PopulateColorIndexVector( list& colors, const string& colorsString, char delimiter = ','); void PopulateAbilityIndexVector( list& abilities, const string& abilitiesString, char delimiter = ','); void PopulateSubtypesIndexVector( list& subtypes, const string& subtypesString, char delimiter = ' '); diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index 91612cb60..ab58a0efb 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -631,9 +631,11 @@ AACloner::AACloner(int _id, MTGCardInstance * _source, MTGCardInstance * _target { target = _target; source = _source; - - PopulateAbilityIndexVector(awith, abilitiesStringList); - PopulateColorIndexVector(colors, abilitiesStringList); + if ( abilitiesStringList.size() > 0 ) + { + PopulateAbilityIndexVector(awith, abilitiesStringList); + PopulateColorIndexVector(colors, abilitiesStringList); + } } diff --git a/projects/mtg/src/utils.cpp b/projects/mtg/src/utils.cpp index 561a3b2f5..f20376752 100644 --- a/projects/mtg/src/utils.cpp +++ b/projects/mtg/src/utils.cpp @@ -262,8 +262,7 @@ std::string wordWrap(std::string sentence, int width) return sentence; } - - +// Given a delimited string of abilities, add the ones to the list that are "Basic" MTG abilities void PopulateAbilityIndexVector( list& abilities, const string& abilityStringList, char delimiter ) { vector abilitiesList = split( abilityStringList, delimiter); @@ -276,15 +275,18 @@ void PopulateAbilityIndexVector( list& abilities, const string& abilityStri } } + void PopulateColorIndexVector( list& colors, const string& colorStringList, char delimiter ) { vector abilitiesList = split( colorStringList, delimiter); for ( vector::iterator iter = abilitiesList.begin(); iter != abilitiesList.end(); ++iter) { - int colorIndex = Constants::GetColorStringIndex(*iter); - - if (colorIndex != -1) - colors.push_back(colorIndex); + for (int colorIndex = Constants::MTG_COLOR_ARTIFACT; colorIndex < Constants::MTG_NB_COLORS; ++colorIndex) + { + // if the text is not a basic ability but contains a valid color add it to the color vector + if ( (Constants::GetBasicAbilityIndex( *iter ) != -1) && ((*iter).find( Constants::MTGColorStrings[ colorIndex ] ) != string::npos) ) + colors.push_back(colorIndex); + } } }