Merge pull request #626 from kevlahnota/master

PT Switch like Layer 7e and Token Indicator
This commit is contained in:
Anthony Calosa
2015-09-20 00:04:25 +08:00
11 changed files with 187 additions and 43 deletions

View File

@@ -0,0 +1,36 @@
#Testing PT Switch. Windreaver and Screaming Fury... Layer 7e
#A 1/3 creature is given +0/+1 by an effect. Then another effect switches the
#creatures power and toughness. Its new power and toughness is 4/1. A new effect gives
#the creature +5/+0. Its “unswitched” power and toughness would be 6/4, so its actual
#power and toughness is 4/6.
[INIT]
FIRSTMAIN
[PLAYER1]
hand:Screaming Fury
inplay:Windreaver, Mountain, Plains, Swamp, Island, Forest
[PLAYER2]
[DO]
Plains
Windreaver
choice 1
Island
Windreaver
choice 0
Mountain
Forest
Swamp
Screaming Fury
Windreaver
next
next
Windreaver
next
eot
[ASSERT]
UNTAP
[PLAYER1]
inplay:Windreaver, Mountain, Plains, Swamp, Island, Forest
graveyard:Screaming Fury
[PLAYER2]
life:16
[END]

View File

@@ -536,6 +536,7 @@ prowess_of_the_fair.txt
prowess_of_the_fair2.txt
prowess_of_the_fair3.txt
PTInstant.txt
PTswitch.txt
PT_M15_errata.txt
PT_M15_errata2.txt
pygmy_troll.txt

View File

@@ -2398,45 +2398,42 @@ 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)
return;
if(!cda || (cda && (((MTGCardInstance *) target)->isSettingBase < 1)))
{
if(((MTGCardInstance *) target)->isSwitchedPT)
((MTGCardInstance *) target)->switchPT(false);//revert
((MTGCardInstance *) target)->power -= wppt->power.getValue();
((MTGCardInstance *) target)->addToToughness(-wppt->toughness.getValue());
if(PT.size())
{
SAFE_DELETE(wppt);
if(cda)
wppt = NEW WParsedPT(ReplaceString(PT, " cdaactive", ""),NULL,(MTGCardInstance *) source);
wppt = NEW WParsedPT(cReplaceString(PT, " cdaactive", ""),NULL,(MTGCardInstance *) source);
else
wppt = NEW WParsedPT(ReplaceString(PT, " nonstatic", ""),NULL,(MTGCardInstance *) source);
wppt = NEW WParsedPT(cReplaceString(PT, " nonstatic", ""),NULL,(MTGCardInstance *) source);
}
MTGCardInstance * _target = (MTGCardInstance *) target;
_target->power += wppt->power.getValue();
_target->addToToughness(wppt->toughness.getValue());
if(_target->isSwitchedPT)
_target->switchPT(true);//reaapply
}
if(cda)
if(cda)
{//update but not apply
if(PT.size())
{
SAFE_DELETE(wppt);
if(cda)
wppt = NEW WParsedPT(ReplaceString(PT, " cdaactive", ""),NULL,(MTGCardInstance *) source);
wppt = NEW WParsedPT(cReplaceString(PT, " cdaactive", ""),NULL,(MTGCardInstance *) source);
else
wppt = NEW WParsedPT(ReplaceString(PT, " nonstatic", ""),NULL,(MTGCardInstance *) source);
wppt = NEW WParsedPT(cReplaceString(PT, " nonstatic", ""),NULL,(MTGCardInstance *) source);
}
((MTGCardInstance *) target)->origpower = wppt->power.getValue();
((MTGCardInstance *) target)->origtoughness = (wppt->toughness.getValue() + ((MTGCardInstance *) target)->life)-((MTGCardInstance *) target)->life;//what?
@@ -2449,22 +2446,37 @@ public:
{
SAFE_DELETE(wppt);
if(cda)
wppt = NEW WParsedPT(ReplaceString(PT, " cdaactive", ""),NULL,(MTGCardInstance *) source);
wppt = NEW WParsedPT(cReplaceString(PT, " cdaactive", ""),NULL,(MTGCardInstance *) source);
else
wppt = NEW WParsedPT(ReplaceString(PT, " nonstatic", ""),NULL,(MTGCardInstance *) source);
wppt = NEW WParsedPT(cReplaceString(PT, " nonstatic", ""),NULL,(MTGCardInstance *) source);
}
if(cda)
{//Characteristic-defining abilities
_target->cdaPT(wppt->power.getValue(),wppt->toughness.getValue());
if(_target->isSwitchedPT)
{
_target->switchPT(false);
_target->cdaPT(wppt->power.getValue(),wppt->toughness.getValue());
_target->switchPT(true);
}
else
_target->cdaPT(wppt->power.getValue(),wppt->toughness.getValue());
_target->isCDA = true;
}
else
else
{
_target->addptbonus(wppt->power.getValue(),wppt->toughness.getValue());
if(_target->isSwitchedPT)
{
_target->switchPT(false);
_target->addptbonus(wppt->power.getValue(),wppt->toughness.getValue());
_target->switchPT(true);
}
else
_target->addptbonus(wppt->power.getValue(),wppt->toughness.getValue());
}
if(_target->has(Constants::INDESTRUCTIBLE) && wppt->toughness.getValue() < 0 && _target->toughness <= 0)
{
_target->controller()->game->putInGraveyard(_target);
_target->controller()->game->putInGraveyard(_target);
}
return MTGAbility::addToGame();
}
@@ -2486,9 +2498,9 @@ public:
{
SAFE_DELETE(wppt);
if(cda)
wppt = NEW WParsedPT(ReplaceString(PT, " cdaactive", ""),NULL,(MTGCardInstance *) source);
wppt = NEW WParsedPT(cReplaceString(PT, " cdaactive", ""),NULL,(MTGCardInstance *) source);
else
wppt = NEW WParsedPT(ReplaceString(PT, " nonstatic", ""),NULL,(MTGCardInstance *) source);
wppt = NEW WParsedPT(cReplaceString(PT, " nonstatic", ""),NULL,(MTGCardInstance *) source);
}
sprintf(menuText, "%i/%i", wppt->power.getValue(), wppt->toughness.getValue());
return menuText;
@@ -4213,8 +4225,6 @@ string menu;
class ASwapPT: public InstantAbility
{
public:
int oldP;
int oldT;
ASwapPT(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target) :
InstantAbility(observer, _id, _source, _target)
{
@@ -4229,11 +4239,16 @@ public:
while (_target->next)
_target = _target->next; //This is for cards such as rampant growth
oldP = _target->power;
oldT = _target->toughness;
_target->addToToughness(oldP);
_target->addToToughness(-oldT);
_target->setPower(oldT);
if(!_target->isSwitchedPT)
{
_target->isSwitchedPT = true;
_target->switchPT(true);
}
else
{
_target->isSwitchedPT = false;
_target->switchPT(false);
}
}
return 1;
}
@@ -4246,12 +4261,11 @@ public:
while (_target->next)
_target = _target->next; //This is for cards such as rampant growth
oldP = _target->power;
oldT = _target->toughness;
_target->addToToughness(oldP);
_target->addToToughness(-oldT);
_target->setPower(oldT);
if(_target->isSwitchedPT)
{
_target->isSwitchedPT = false;
_target->switchPT(false);
}
}
return 1;
}
@@ -5832,14 +5846,29 @@ public:
{
nbOpponents = source->blockers.size();
if (nbOpponents <= MaxOpponent) return 0;
source->addptbonus(PowerModifier * (nbOpponents - MaxOpponent),ToughnessModifier * (nbOpponents - MaxOpponent));
if(source->isSwitchedPT)
{
source->switchPT(false);
source->addptbonus(PowerModifier * (nbOpponents - MaxOpponent),ToughnessModifier * (nbOpponents - MaxOpponent));
source->switchPT(true);
}
else
source->addptbonus(PowerModifier * (nbOpponents - MaxOpponent),ToughnessModifier * (nbOpponents - MaxOpponent));
}
else if (WEventPhaseChange* pe = dynamic_cast<WEventPhaseChange*>(event))
{
if (MTG_PHASE_AFTER_EOT == pe->to->id && nbOpponents > MaxOpponent)
{
source->removeptbonus(PowerModifier * (nbOpponents - MaxOpponent),ToughnessModifier * (nbOpponents - MaxOpponent));
nbOpponents = 0;
if(source->isSwitchedPT)
{
source->switchPT(false);
source->removeptbonus(PowerModifier * (nbOpponents - MaxOpponent),ToughnessModifier * (nbOpponents - MaxOpponent));
source->switchPT(true);
}
else
source->removeptbonus(PowerModifier * (nbOpponents - MaxOpponent),ToughnessModifier * (nbOpponents - MaxOpponent));
nbOpponents = 0;
}
}
return 1;

View File

@@ -235,6 +235,10 @@ public:
void revertbaseT();
void cdaPT(int p = 0, int t = 0);
bool isCDA;
void switchPT(bool apply = false);
int swapP;
int swapT;
bool isSwitchedPT;
void eventattacked();
void eventattackedAlone();

View File

@@ -121,6 +121,7 @@ bool fileExists(const char * filename);
bool FileExists(const string & filename);
std::string buildFilePath(const vector<string> & folders, const string & filename);
std::string ensureFolder(const string & folderName);
std::string cReplaceString(string subject, const string& search, const string& replace);
/*
template <class T> istream& operator>>(istream& in, T& p)
{

View File

@@ -4197,7 +4197,14 @@ for (it = types.begin(); it != types.end(); it++)
if(newpowerfound )
{
WParsedInt * val = NEW WParsedInt(newpower,NULL, source);
_target->addbaseP(val->getValue());
if(_target->isSwitchedPT)
{
_target->switchPT(false);
_target->addbaseP(val->getValue());
_target->switchPT(true);
}
else
_target->addbaseP(val->getValue());
delete val;
}
if(newtoughnessfound )
@@ -4205,7 +4212,14 @@ for (it = types.begin(); it != types.end(); it++)
//and you turn it into 1/1, the 1 damage is still there and the creature must die...
//the toughness is intact but what we see in the game is the life...
WParsedInt * val = NEW WParsedInt(newtoughness,NULL, source);
_target->addbaseT(val->getValue());
if(_target->isSwitchedPT)
{
_target->switchPT(false);
_target->addbaseT(val->getValue());
_target->switchPT(true);
}
else
_target->addbaseT(val->getValue());
delete val;
}

View File

@@ -302,6 +302,17 @@ void CardGui::Render()
mFont->SetScale(1);
}
if(card->getRarity() == Constants::RARITY_T)
{
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
char buffer[200];
sprintf(buffer, "T");
mFont->SetColor(ARGB(static_cast<unsigned char>(actA),255,222,173));//Navajo
mFont->SetScale(0.8f);
mFont->DrawString(buffer, actX - 10 * actZ, actY - (18 * actZ));
mFont->SetScale(1);
}
if (card->counters->mCount > 0)
{
unsigned c = -1;

View File

@@ -56,7 +56,14 @@ int Counter::added()
{
if (power != 0 || toughness != 0)
{
target->addcounter(power, toughness);
if(target->isSwitchedPT)
{
target->switchPT(false);
target->addcounter(power, toughness);
target->switchPT(true);
}
else
target->addcounter(power, toughness);
}
return 1;
}
@@ -65,6 +72,13 @@ int Counter::removed()
{
if (power != 0 || toughness != 0)
{
if(target->isSwitchedPT)
{
target->switchPT(false);
target->removecounter(power, toughness);
target->switchPT(true);
}
else
target->removecounter(power, toughness);
}
return 1;

View File

@@ -1857,7 +1857,9 @@ int Tournament::getRandomDeck(bool noEasyDecks)
while(isDouble && decks.size()>0)
{
isDouble=false;
k = rand() % (int)decks.size();
int lowest=0, highest = (int)decks.size();
int range=(highest-lowest);
k = lowest+int(range*rand()/(RAND_MAX + 1.0));
random = decks.at(k);
deckNumber = deckList->at(random)->getDeckId();

View File

@@ -55,6 +55,7 @@ MTGCardInstance::MTGCardInstance(MTGCard * card, MTGPlayerCards * arg_belongs_to
castMethod = Constants::NOT_CAST;
isSettingBase = 0;
isCDA = false;
isSwitchedPT = false;
}
MTGCardInstance * MTGCardInstance::createSnapShot()
@@ -695,6 +696,26 @@ void MTGCardInstance::cdaPT(int p, int t)
applyPTbonus();
}
void MTGCardInstance::switchPT(bool apply)
{
stripPTbonus();
swapP = power;
swapT = toughness;
power += origpower;
power -= swapP;
addToToughness(origtoughness);
addToToughness(-swapT);
applyPTbonus();
if(apply)
{
swapP = toughness;
swapT = power;
addToToughness(swapT);
addToToughness(-swapP);
setPower(swapP);
}
}
int MTGCardInstance::canBlock()
{
if (tapped)

View File

@@ -98,6 +98,17 @@ bool FileExists(const string & filename)
return JFileSystem::GetInstance()->FileExists(filename);
}
std::string cReplaceString(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;
}
/*
#ifdef LINUX