Fix for token cloning

Some tokens when cloned produces miscalculated PT(Using foreach,
aslongas and others that needs CDA). This should fix the issue. TODO:
add tests and updated mtg.txt ...
This commit is contained in:
Anthony Calosa
2015-09-16 20:36:58 +08:00
parent 8e057379ce
commit 425b51de08
3 changed files with 41 additions and 8 deletions

View File

@@ -2319,7 +2319,17 @@ public:
{
aType = MTGAbility::STANDARD_PUMP;
cda = PT.find("cdaactive") != string::npos;
}
}
string ReplaceString(string subject, const string& search, const string& replace)
{
size_t pos = 0;
while ((pos = subject.find(search, pos)) != string::npos)
{
subject.replace(pos, search.length(), replace);
pos += replace.length();
}
return subject;
}
void Update(float)
{
if(!nonstatic)
@@ -2331,7 +2341,10 @@ public:
if(PT.size())
{
SAFE_DELETE(wppt);
wppt = NEW WParsedPT(PT,NULL,(MTGCardInstance *) source);
if(cda)
wppt = NEW WParsedPT(ReplaceString(PT, "cdaactive", ""),NULL,(MTGCardInstance *) source);
else
wppt = NEW WParsedPT(ReplaceString(PT, "nonstatic", ""),NULL,(MTGCardInstance *) source);
}
MTGCardInstance * _target = (MTGCardInstance *) target;
_target->power += wppt->power.getValue();
@@ -2342,7 +2355,10 @@ public:
if(PT.size())
{
SAFE_DELETE(wppt);
wppt = NEW WParsedPT(PT,NULL,(MTGCardInstance *) source);
if(cda)
wppt = NEW WParsedPT(ReplaceString(PT, "cdaactive", ""),NULL,(MTGCardInstance *) source);
else
wppt = NEW WParsedPT(ReplaceString(PT, "nonstatic", ""),NULL,(MTGCardInstance *) source);
}
((MTGCardInstance *) target)->origpower = wppt->power.getValue();
((MTGCardInstance *) target)->origtoughness = (wppt->toughness.getValue() + ((MTGCardInstance *) target)->life)-((MTGCardInstance *) target)->life;//what?
@@ -2354,7 +2370,10 @@ public:
if(PT.size())
{
SAFE_DELETE(wppt);
wppt = NEW WParsedPT(PT,NULL,(MTGCardInstance *) source);
if(cda)
wppt = NEW WParsedPT(ReplaceString(PT, "cdaactive", ""),NULL,(MTGCardInstance *) source);
else
wppt = NEW WParsedPT(ReplaceString(PT, "nonstatic", ""),NULL,(MTGCardInstance *) source);
}
if(cda)
{//Characteristic-defining abilities
@@ -2402,7 +2421,10 @@ public:
if(PT.size())
{
SAFE_DELETE(wppt);
wppt = NEW WParsedPT(PT,NULL,(MTGCardInstance *) source);
if(cda)
wppt = NEW WParsedPT(ReplaceString(PT, "cdaactive", ""),NULL,(MTGCardInstance *) source);
else
wppt = NEW WParsedPT(ReplaceString(PT, "nonstatic", ""),NULL,(MTGCardInstance *) source);
}
sprintf(menuText, "%i/%i", wppt->power.getValue(), wppt->toughness.getValue());
return menuText;

View File

@@ -2536,12 +2536,13 @@ int AACloner::resolve()
spell->source->fresh = 1;
spell->source->model = spell->source;
spell->source->model->data = spell->source;
if(_target->isToken)
//commenting this out fixes some problems when duplicating tokens 9/16/2015
/*if(_target->isToken)
{
spell->source->power = _target->origpower;
spell->source->toughness = _target->origtoughness;
spell->source->life = _target->origtoughness;
}
}*/
list<int>::iterator it;
for (it = awith.begin(); it != awith.end(); it++)
{

View File

@@ -13,6 +13,8 @@ Token::Token(string _name, MTGCardInstance * source, int _power, int _toughness)
lifeOrig = life;
origpower = _power;
origtoughness = _toughness;
basepower = power;
basetoughness = toughness;
rarity = Constants::RARITY_T;
name = _name;
if (name.size() && name[0] >= 97 && name[0] <= 122) name[0] -= 32; //Poor man's camelcase. We assume strings we get are either Camelcased or lowercase
@@ -25,6 +27,9 @@ Token::Token(string _name, MTGCardInstance * source, int _power, int _toughness)
attacker = 0;
defenser = NULL;
banding = NULL;
pbonus = 0;
tbonus = 0;
isSettingBase = 0;
}
Token::Token(int id) :
@@ -45,7 +50,11 @@ Token::Token(const Token& source) :
life = source.life;
lifeOrig = source.life;
origpower = source.origpower;
origtoughness = source.origpower;
origtoughness = source.origtoughness;
basepower = source.origpower;
basetoughness = source.origpower;
pbonus = source.pbonus;
tbonus = source.tbonus;
rarity = source.rarity;
name = source.name;
setId = source.setId;
@@ -56,6 +65,7 @@ Token::Token(const Token& source) :
attacker = source.attacker;
defenser = source.defenser;
banding = source.banding;
isSettingBase = source.isSettingBase;
}