revised token id (tnum:num parameter)

this should not conflict like earlier version.
ex:
[card]
name=Fable of Wolf and Owl
auto=@movedTo(*[green]|mystack):may token(Wolf,Creature
Wolf,2/2,green,tnum:11)
auto=@movedTo(*[blue]|mystack):may token(Bird,Creature
Bird,1/1,flying,blue,tnum:12)
text=Whenever you cast a green spell, you may put a 2/2 green Wolf
creature token onto the battlefield. -- Whenever you cast a blue spell,
you may put a 1/1 blue Bird creature token with flying onto the
battlefield.
mana={3}{GU}{GU}{GU}
type=Enchantment
[/card]
tnum uses -source id  & tnum (concatenated)
This commit is contained in:
Anthony Calosa
2016-08-08 13:49:24 +08:00
parent de44abd529
commit eb0ecedecf
4 changed files with 26 additions and 20 deletions
+2 -2
View File
@@ -35313,8 +35313,8 @@ toughness=4
[/card] [/card]
[card] [card]
name=Fable of Wolf and Owl name=Fable of Wolf and Owl
auto=@movedTo(*[green]|mystack):may token(-15208711) auto=@movedTo(*[green]|mystack):may token(Wolf,Creature Wolf,2/2,green,tnum:11)
auto=@movedTo(*[blue]|mystack):may token(-15208712) auto=@movedTo(*[blue]|mystack):may token(Bird,Creature Bird,1/1,flying,blue,tnum:12)
text=Whenever you cast a green spell, you may put a 2/2 green Wolf creature token onto the battlefield. -- Whenever you cast a blue spell, you may put a 1/1 blue Bird creature token with flying onto the battlefield. text=Whenever you cast a green spell, you may put a 2/2 green Wolf creature token onto the battlefield. -- Whenever you cast a blue spell, you may put a 1/1 blue Bird creature token with flying onto the battlefield.
mana={3}{GU}{GU}{GU} mana={3}{GU}{GU}{GU}
type=Enchantment type=Enchantment
+15 -1
View File
@@ -3547,6 +3547,7 @@ public:
vector<MTGAbility *> currentAbilities; vector<MTGAbility *> currentAbilities;
MTGAbility * andAbility; MTGAbility * andAbility;
Player * tokenReciever; Player * tokenReciever;
string cID;
//by id //by id
ATokenCreator(GameObserver* observer, int _id, MTGCardInstance * _source, Targetable *, ManaCost * _cost, int tokenId,string starfound, WParsedInt * multiplier = NULL, ATokenCreator(GameObserver* observer, int _id, MTGCardInstance * _source, Targetable *, ManaCost * _cost, int tokenId,string starfound, WParsedInt * multiplier = NULL,
int who = 0,bool aLivingWeapon = false) : int who = 0,bool aLivingWeapon = false) :
@@ -3557,6 +3558,7 @@ public:
if (card) name = card->data->getName(); if (card) name = card->data->getName();
battleReady = false; battleReady = false;
andAbility = NULL; andAbility = NULL;
cID = "";
} }
//by name, card still require valid card.dat info, this just makes the primitive code far more readable. token(Eldrazi scion) instead of token(-1234234)... //by name, card still require valid card.dat info, this just makes the primitive code far more readable. token(Eldrazi scion) instead of token(-1234234)...
ATokenCreator(GameObserver* observer, int _id, MTGCardInstance * _source, Targetable *, ManaCost * _cost, string cardName, string starfound, WParsedInt * multiplier = NULL, ATokenCreator(GameObserver* observer, int _id, MTGCardInstance * _source, Targetable *, ManaCost * _cost, string cardName, string starfound, WParsedInt * multiplier = NULL,
@@ -3569,10 +3571,11 @@ public:
if (card) name = card->data->getName(); if (card) name = card->data->getName();
battleReady = false; battleReady = false;
andAbility = NULL; andAbility = NULL;
cID = "";
} }
//by construction //by construction
ATokenCreator(GameObserver* observer, int _id, MTGCardInstance * _source, Targetable *, ManaCost * _cost, string sname, string stypes, int _power, int _toughness, ATokenCreator(GameObserver* observer, int _id, MTGCardInstance * _source, Targetable *, ManaCost * _cost, string sname, string stypes, int _power, int _toughness,
string sabilities, string starfound,WParsedInt * multiplier = NULL, int _who = 0,bool aLivingWeapon = false,string spt = "") : string sabilities, string starfound,WParsedInt * multiplier = NULL, int _who = 0,bool aLivingWeapon = false,string spt = "", string tnum = "") :
ActivatedAbility(observer, _id, _source, _cost, 0),sabilities(sabilities),starfound(starfound), multiplier(multiplier), who(_who),aLivingWeapon(aLivingWeapon),spt(spt) ActivatedAbility(observer, _id, _source, _cost, 0),sabilities(sabilities),starfound(starfound), multiplier(multiplier), who(_who),aLivingWeapon(aLivingWeapon),spt(spt)
{ {
power = _power; power = _power;
@@ -3582,6 +3585,7 @@ public:
aType = MTGAbility::STANDARD_TOKENCREATOR; aType = MTGAbility::STANDARD_TOKENCREATOR;
battleReady = false; battleReady = false;
andAbility = NULL; andAbility = NULL;
cID = tnum;
if (!multiplier) this->multiplier = NEW WParsedInt(1); 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; //TODO this is a copy/past of other code that's all around the place, everything should be in a dedicated parser class;
@@ -3668,6 +3672,16 @@ public:
else else
{ {
myToken = NEW Token(name, source, power, toughness); myToken = NEW Token(name, source, power, toughness);
if(!cID.empty())
{
string customId = "";
ostringstream tokID;
tokID << abs(myToken->getId());
customId.append(""+tokID.str()+cID);
customId = cReplaceString(customId," ","");
WParsedInt newID(customId, NULL, source);
myToken->setMTGId(-newID.getValue());
}
list<int>::iterator it; list<int>::iterator it;
for (it = types.begin(); it != types.end(); it++) for (it = types.begin(); it != types.end(); it++)
{ {
+9 -3
View File
@@ -2394,7 +2394,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
string tokenDesc = splitToken[1]; string tokenDesc = splitToken[1];
vector<string> tokenParameters = split(tokenDesc, ','); vector<string> tokenParameters = split(tokenDesc, ',');
//lets try finding a token by card name. //lets try finding a token by card name.
if (splitToken[1].size() && tokenParameters.size() ==1) if (splitToken[1].size() && tokenParameters.size() <3)
{ {
string cardName = splitToken[1]; string cardName = splitToken[1];
MTGCard * safetycard = MTGCollection()->getCardByName(cardName); MTGCard * safetycard = MTGCollection()->getCardByName(cardName);
@@ -2420,7 +2420,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
string sname = tokenParameters[0]; string sname = tokenParameters[0];
string stypes = tokenParameters[1]; string stypes = tokenParameters[1];
string spt = tokenParameters[2]; string spt = tokenParameters[2];
string cID = "";
//reconstructing string abilities from the split version, //reconstructing string abilities from the split version,
// then we re-split it again in the token constructor, // then we re-split it again in the token constructor,
// this needs to be improved // this needs to be improved
@@ -2430,6 +2430,12 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
sabilities.append(","); sabilities.append(",");
sabilities.append(tokenParameters[i]); sabilities.append(tokenParameters[i]);
} }
if(sabilities.find(",tnum:") != string::npos)
{
size_t begins = sabilities.find(",tnum:");
cID = sabilities.substr(begins+6);
sabilities = cReplaceString(sabilities,",tnum:"+cID,"");
}
int value = 0; int value = 0;
if (spt.find("xx/xx") != string::npos) if (spt.find("xx/xx") != string::npos)
value = card->X / 2; value = card->X / 2;
@@ -2441,7 +2447,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
ATokenCreator * tok = NEW ATokenCreator( ATokenCreator * tok = NEW ATokenCreator(
observer, id, card,target, NULL, sname, stypes, power + value, toughness + value, observer, id, card,target, NULL, sname, stypes, power + value, toughness + value,
sabilities, starfound, multiplier, who, aLivingWeapon, spt); sabilities, starfound, multiplier, who, aLivingWeapon, spt, cID);
tok->oneShot = 1; tok->oneShot = 1;
if(aLivingWeapon) if(aLivingWeapon)
tok->forceDestroy = 1; tok->forceDestroy = 1;
-14
View File
@@ -149,20 +149,6 @@ void MTGCardInstance::copy(MTGCardInstance * card)
backupTargets = this->backupTargets; backupTargets = this->backupTargets;
storedCard = oldStored; storedCard = oldStored;
miracle = false; miracle = false;
if (card->TokenAndAbility)
{
MTGAbility * andAbilityClone = card->TokenAndAbility->clone();
andAbilityClone->target = this;
if(card->TokenAndAbility->oneShot)
{
andAbilityClone->resolve();
SAFE_DELETE(andAbilityClone);
}
else
{
andAbilityClone->addToGame();
}
}
} }
MTGCardInstance::~MTGCardInstance() MTGCardInstance::~MTGCardInstance()