diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index ef0b8b31a..fc4e7db8c 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -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(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; diff --git a/projects/mtg/include/MTGCardInstance.h b/projects/mtg/include/MTGCardInstance.h index 723013148..5e92c3a02 100644 --- a/projects/mtg/include/MTGCardInstance.h +++ b/projects/mtg/include/MTGCardInstance.h @@ -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(); diff --git a/projects/mtg/include/utils.h b/projects/mtg/include/utils.h index 25a4c392d..41e21c7a7 100644 --- a/projects/mtg/include/utils.h +++ b/projects/mtg/include/utils.h @@ -121,6 +121,7 @@ bool fileExists(const char * filename); bool FileExists(const string & filename); std::string buildFilePath(const vector & folders, const string & filename); std::string ensureFolder(const string & folderName); +std::string cReplaceString(string subject, const string& search, const string& replace); /* template istream& operator>>(istream& in, T& p) { diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index 8f46e5728..80df4716e 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -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; } diff --git a/projects/mtg/src/CardGui.cpp b/projects/mtg/src/CardGui.cpp index 29291784f..61c6ab2c3 100644 --- a/projects/mtg/src/CardGui.cpp +++ b/projects/mtg/src/CardGui.cpp @@ -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(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; diff --git a/projects/mtg/src/Counters.cpp b/projects/mtg/src/Counters.cpp index a1111c928..b01c57644 100644 --- a/projects/mtg/src/Counters.cpp +++ b/projects/mtg/src/Counters.cpp @@ -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; diff --git a/projects/mtg/src/GameStateDuel.cpp b/projects/mtg/src/GameStateDuel.cpp index 2af6be905..2d902c8b8 100644 --- a/projects/mtg/src/GameStateDuel.cpp +++ b/projects/mtg/src/GameStateDuel.cpp @@ -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(); diff --git a/projects/mtg/src/MTGCardInstance.cpp b/projects/mtg/src/MTGCardInstance.cpp index 88458bcb1..616757249 100644 --- a/projects/mtg/src/MTGCardInstance.cpp +++ b/projects/mtg/src/MTGCardInstance.cpp @@ -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) diff --git a/projects/mtg/src/utils.cpp b/projects/mtg/src/utils.cpp index 2217b6143..ce846d21c 100644 --- a/projects/mtg/src/utils.cpp +++ b/projects/mtg/src/utils.cpp @@ -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