first moved regenerate lower on the parser, 2nd fixed an unforeseen bug with the newability subkeyword and the parser, i now store the string value of the transforms ability and remove it from the main string until transforms is parsed, if I leave it during the whole parsing any ability listed above transforms will not work correctly when granted with this ability.
also noticed issues with transforms parsing which i was able to easily correct by making it parse transforms in double brackets, transforms((effects))...updated primitive in next revision. test suite passes, and varified that the fix doesn't effect how "&&" ability works with transforms.
This commit is contained in:
@@ -368,7 +368,8 @@ class GenericTriggeredAbility:public TriggeredAbility, public NestedAbility{
|
|||||||
/* Ability Factory */
|
/* Ability Factory */
|
||||||
class AbilityFactory{
|
class AbilityFactory{
|
||||||
private:
|
private:
|
||||||
int countCards(TargetChooser * tc, Player * player = NULL, int option = 0);
|
string storedString;
|
||||||
|
int countCards(TargetChooser * tc, Player * player = NULL, int option = 0);
|
||||||
TriggeredAbility * parseTrigger(string s, string magicText, int id, Spell * spell, MTGCardInstance *card, Targetable * target);
|
TriggeredAbility * parseTrigger(string s, string magicText, int id, Spell * spell, MTGCardInstance *card, Targetable * target);
|
||||||
int parseRestriction(string s);
|
int parseRestriction(string s);
|
||||||
MTGAbility * getAlternateCost( string s, int id, Spell *spell, MTGCardInstance *card );
|
MTGAbility * getAlternateCost( string s, int id, Spell *spell, MTGCardInstance *card );
|
||||||
|
|||||||
@@ -835,6 +835,22 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
if (!target)
|
if (!target)
|
||||||
target = card;
|
target = card;
|
||||||
|
|
||||||
|
//need to remove the section inside the transforms ability from the string before parsing
|
||||||
|
//TODO: store string values of "&&" so we can remove the classes added just to add support
|
||||||
|
//the current parser finds other abilities inside what should be nested abilities, and converts them into
|
||||||
|
//actual abilities, this is a limitation.
|
||||||
|
found = s.find("transforms((");
|
||||||
|
if (found != string::npos && storedString.empty())
|
||||||
|
{
|
||||||
|
size_t real_end = s.find("))", found);
|
||||||
|
size_t end = s.find(",", found);
|
||||||
|
if (end == string::npos)
|
||||||
|
end = real_end;
|
||||||
|
size_t stypesStartIndex = found + 12;
|
||||||
|
storedString.append(s.substr(stypesStartIndex, real_end - stypesStartIndex).c_str());
|
||||||
|
s.erase(stypesStartIndex, real_end - stypesStartIndex);
|
||||||
|
}
|
||||||
|
|
||||||
found = s.find("@");
|
found = s.find("@");
|
||||||
if (found != string::npos)
|
if (found != string::npos)
|
||||||
{
|
{
|
||||||
@@ -1708,14 +1724,6 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Regeneration
|
|
||||||
found = s.find("regenerate");
|
|
||||||
if (found != string::npos)
|
|
||||||
{
|
|
||||||
MTGAbility * a = NEW AStandardRegenerate(id, card, target);
|
|
||||||
a->oneShot = 1;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
bool aLivingWeapon = false;
|
bool aLivingWeapon = false;
|
||||||
//livingweapon
|
//livingweapon
|
||||||
size_t secondaryFound = s.find("livingweapon");
|
size_t secondaryFound = s.find("livingweapon");
|
||||||
@@ -1936,13 +1944,13 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
if (s.find(" owner") != string::npos)
|
if (s.find(" owner") != string::npos)
|
||||||
who = TargetChooser::OWNER;
|
who = TargetChooser::OWNER;
|
||||||
|
|
||||||
found = s.find("ueot");
|
found = s.find(" ueot");
|
||||||
if (found != string::npos)
|
if (found != string::npos)
|
||||||
forceUEOT = 1;
|
forceUEOT = 1;
|
||||||
found = s.find("oneshot");
|
found = s.find(" oneshot");
|
||||||
if (found != string::npos)
|
if (found != string::npos)
|
||||||
oneShot = 1;
|
oneShot = 1;
|
||||||
found = s.find("forever");
|
found = s.find(" forever");
|
||||||
if (found != string::npos)
|
if (found != string::npos)
|
||||||
forceFOREVER = 1;
|
forceFOREVER = 1;
|
||||||
|
|
||||||
@@ -2509,15 +2517,11 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
return getManaReduxAbility(s.substr(s.find("altercost(") + 10), id, spell, card, target);
|
return getManaReduxAbility(s.substr(s.find("altercost(") + 10), id, spell, card, target);
|
||||||
|
|
||||||
//transform....(hivestone,living enchantment)
|
//transform....(hivestone,living enchantment)
|
||||||
found = s.find("transforms(");
|
found = s.find("transforms((");
|
||||||
if (found != string::npos)
|
if (found != string::npos)
|
||||||
{
|
{
|
||||||
size_t real_end = s.find(")", found);
|
size_t stypesStartIndex = found + 12;
|
||||||
size_t end = s.find(",", found);
|
string transformsParamsString = storedString;//the string between found and real end is removed at start.
|
||||||
if (end == string::npos)
|
|
||||||
end = real_end;
|
|
||||||
size_t stypesStartIndex = found + 11;
|
|
||||||
string transformsParamsString = s.substr(stypesStartIndex, real_end - stypesStartIndex);
|
|
||||||
vector<string> effectParameters = split( transformsParamsString, ',');
|
vector<string> effectParameters = split( transformsParamsString, ',');
|
||||||
string stypes = effectParameters[0];
|
string stypes = effectParameters[0];
|
||||||
|
|
||||||
@@ -2552,6 +2556,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
newAbilitiesList.push_back(parseMagicLine(newAbilities, id, spell, card));
|
newAbilitiesList.push_back(parseMagicLine(newAbilities, id, spell, card));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
storedString.erase();
|
||||||
MTGAbility * a;
|
MTGAbility * a;
|
||||||
if (forceFOREVER)
|
if (forceFOREVER)
|
||||||
{
|
{
|
||||||
@@ -2567,6 +2572,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
}
|
}
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Change Power/Toughness
|
//Change Power/Toughness
|
||||||
WParsedPT * wppt = NEW WParsedPT(s, spell, card);
|
WParsedPT * wppt = NEW WParsedPT(s, spell, card);
|
||||||
if (wppt->ok)
|
if (wppt->ok)
|
||||||
@@ -2728,6 +2734,15 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Regeneration
|
||||||
|
found = s.find("regenerate");
|
||||||
|
if (found != string::npos)
|
||||||
|
{
|
||||||
|
MTGAbility * a = NEW AStandardRegenerate(id, card, target);
|
||||||
|
a->oneShot = 1;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
//Gain/loose simple Ability
|
//Gain/loose simple Ability
|
||||||
for (int j = 0; j < Constants::NB_BASIC_ABILITIES; j++)
|
for (int j = 0; j < Constants::NB_BASIC_ABILITIES; j++)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user