refactored a little of a token gen, enumed the who and removed redundent code, also the new method allows you to token cards by id to WHO.

This commit is contained in:
omegablast2002@yahoo.com
2011-04-17 18:18:29 +00:00
parent 158164d694
commit 18acf3ad8d
2 changed files with 55 additions and 79 deletions

View File

@@ -2721,6 +2721,12 @@ public:
class ATokenCreator: public ActivatedAbility
{
public:
enum
{
ATOKEN_WHO_CONTROLLER = 0,
ATOKEN_WHO_OPPONENT = 1,
ATOKEN_WHO_TARGETCONTROLLER = 2
};
list<int> abilities;
list<int> types;
list<int> colors;
@@ -2736,6 +2742,7 @@ public:
bool battleReady;
MTGCardInstance * myToken;
vector<MTGAbility *> currentAbilities;
Player * tokenReciever;
ATokenCreator(int _id, MTGCardInstance * _source, Targetable * _target, ManaCost * _cost, int tokenId, int _doTap,string starfound, WParsedInt * multiplier = NULL,
int who = 0,bool aLivingWeapon = false) :
ActivatedAbility(_id, _source, _cost, 0, _doTap), tokenId(tokenId), starfound(starfound),multiplier(multiplier), who(who),aLivingWeapon(aLivingWeapon)
@@ -2809,13 +2816,13 @@ public:
}
if(!spt.empty())
{
vector<string> powertoughness = split( spt, '/');
WParsedInt * NewPow = NEW WParsedInt(powertoughness[0].c_str(),NULL,source);
WParsedInt * NewTou = NEW WParsedInt(powertoughness[1].c_str(),NULL,source);
power = NewPow->getValue();
toughness = NewTou->getValue();
SAFE_DELETE(NewPow);
SAFE_DELETE(NewTou);
vector<string> powertoughness = split( spt, '/');
WParsedInt * NewPow = NEW WParsedInt(powertoughness[0].c_str(),NULL,source);
WParsedInt * NewTou = NEW WParsedInt(powertoughness[1].c_str(),NULL,source);
power = NewPow->getValue();
toughness = NewTou->getValue();
SAFE_DELETE(NewPow);
SAFE_DELETE(NewTou);
}
for (int i = 0; i < multiplier->getValue(); ++i)
{
@@ -2823,8 +2830,8 @@ public:
if (tokenId)
{
MTGCard * card = MTGCollection()->getCardById(tokenId);
myToken = NEW MTGCardInstance(card, source->controller()->game);
setTokenOwner();
myToken = NEW MTGCardInstance(card, tokenReciever->game);
}
else
{
@@ -2855,64 +2862,49 @@ public:
tokenText.append( sourcename);
myToken->text = tokenText;
}
if (who == 0 && who != 1 && who != 2)
setTokenOwner();
tokenReciever->game->temp->addCard(myToken);
Spell * spell = NEW Spell(myToken);
spell->resolve();
myToken = spell->source;
spell->source->owner = tokenReciever;
spell->source->isToken = 1;
spell->source->fresh = 1;
if(aLivingWeapon)
{
source->controller()->game->temp->addCard(myToken);
Spell * spell = NEW Spell(myToken);
spell->resolve();
spell->source->isToken = 1;
spell->source->fresh = 1;
if(aLivingWeapon)
{
livingWeaponToken(spell->source);
}
if(battleReady)
{
battleReadyToken(spell->source);
}
delete spell;
livingWeaponToken(spell->source);
}
else if (who == 1 && who != 0 && who != 2)
if(battleReady)
{
source->controller()->opponent()->game->temp->addCard(myToken);
Spell * spell = NEW Spell(myToken);
spell->resolve();
spell->source->owner = spell->source->controller();
spell->source->isToken = 1;
spell->source->fresh = 1;
if(aLivingWeapon)
{
livingWeaponToken(spell->source);
}
if(battleReady)
{
battleReadyToken(spell->source);
}
delete spell;
}
else
{
((MTGCardInstance*)target)->controller()->game->temp->addCard(myToken);
Spell * spell = NEW Spell(myToken);
spell->resolve();
spell->source->owner = ((MTGCardInstance*)target)->controller();
spell->source->isToken = 1;
spell->source->fresh = 1;
myToken = spell->source;
if(aLivingWeapon)
{
livingWeaponToken(spell->source);
}
if(battleReady)
{
battleReadyToken(spell->source);
}
delete spell;
battleReadyToken(spell->source);
}
delete spell;
}
return 1;
}
void setTokenOwner()
{
switch(who)
{
case ATokenCreator::ATOKEN_WHO_CONTROLLER:
tokenReciever = source->controller();
break;
case ATokenCreator::ATOKEN_WHO_OPPONENT:
tokenReciever = source->controller()->opponent();
break;
case ATokenCreator::ATOKEN_WHO_TARGETCONTROLLER:
if(target)
{
tokenReciever = ((MTGCardInstance*)target)->controller();
break;
}
default:
tokenReciever = source->controller();
break;
}
}
void livingWeaponToken(MTGCardInstance * card)
{
GameObserver * g = g->GetInstance();
@@ -2936,7 +2928,7 @@ public:
}
const char * getMenuText()
{
{
sprintf(menuText, "Create %s", name.c_str());
return menuText;
}

View File

@@ -1798,16 +1798,16 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
size_t opponent = s.find("opponent");
if (opponent != string::npos)
{
who = 1;
who = ATokenCreator::ATOKEN_WHO_OPPONENT;
}
else
{
who = 0;
who = ATokenCreator::ATOKEN_WHO_CONTROLLER;
}
size_t targetcontroller = s.find("targetcontroller");
if (targetcontroller != string::npos)
{
who = 2;
who = ATokenCreator::ATOKEN_WHO_TARGETCONTROLLER;
}
if (tokenId)
{
@@ -1848,22 +1848,6 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
}
parsePowerToughness(spt, &power, &toughness);
string sabilities = s.substr(end + 1);
if (s.find("opponent"))
{
if (opponent != string::npos)
{
who = 1;
}
else
{
who = 0;
}
}
targetcontroller = s.find("targetcontroller");
if (targetcontroller != string::npos)
{
who = 2;
}
ATokenCreator * tok = NEW ATokenCreator(id, card,target, NULL, sname, stypes, power + value, toughness + value, sabilities, 0,starfound,
multiplier, who,aLivingWeapon,spt);
tok->oneShot = 1;