diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 8cb2fdacc..4df9cf46e 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -4378,6 +4378,18 @@ public: }; +class AManaPoolSaver: public MTGAbility +{ +public: + string Color; + bool OtherPlayer; + AManaPoolSaver(GameObserver* observer, int id, MTGCardInstance * source,string Color = "",bool otherPlayer = false); + int addToGame(); + int destroy(); + AManaPoolSaver * clone() const; + ~AManaPoolSaver(); +}; + class ADrawReplacer: public MTGAbility { public: diff --git a/projects/mtg/include/MTGAbility.h b/projects/mtg/include/MTGAbility.h index 5f2284931..fdd321af7 100644 --- a/projects/mtg/include/MTGAbility.h +++ b/projects/mtg/include/MTGAbility.h @@ -519,7 +519,8 @@ public: ManaCost * output; int tap; string Producing; - AManaProducer(GameObserver* observer, int id, MTGCardInstance * card, Targetable * t, ManaCost * _output, ManaCost * _cost = NULL, int who = TargetChooser::UNSET,string producing = ""); + bool DoesntEmpty; + AManaProducer(GameObserver* observer, int id, MTGCardInstance * card, Targetable * t, ManaCost * _output, ManaCost * _cost = NULL, int who = TargetChooser::UNSET,string producing = "",bool doesntEmpty = false); int isReactingToClick(MTGCardInstance * _card, ManaCost * mana = NULL); int resolve(); int reactToClick(MTGCardInstance* _card); diff --git a/projects/mtg/include/Player.h b/projects/mtg/include/Player.h index b60045725..63f02f4f4 100644 --- a/projects/mtg/include/Player.h +++ b/projects/mtg/include/Player.h @@ -66,7 +66,8 @@ public: MTGInPlay * inPlay(); ManaPool * getManaPool(); void takeMulligan(); - + ManaCost * doesntEmpty; + ManaCost * poolDoesntEmpty; void cleanupPhase(); virtual int Act(float dt) { diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index e91e57139..dfe84b3ee 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -1112,6 +1112,35 @@ AASetCoin::~AASetCoin() { } +//saves a listed mana type until end of turn. +AManaPoolSaver::AManaPoolSaver(GameObserver* observer, int id, MTGCardInstance * source,string color, bool otherPlayer) : +MTGAbility(observer, id, source),Color(color),OtherPlayer(otherPlayer) +{ +} + +int AManaPoolSaver::addToGame() +{ + int colorInt = Constants::GetColorStringIndex(Color.c_str()); + source->controller()->poolDoesntEmpty->add(colorInt,1); + return 1; +} + +int AManaPoolSaver::destroy() +{ + int colorInt = Constants::GetColorStringIndex(Color.c_str()); + source->controller()->poolDoesntEmpty->remove(colorInt,1); + return 1; +} + +AManaPoolSaver * AManaPoolSaver::clone() const +{ + AManaPoolSaver * a = NEW AManaPoolSaver(*this); + return a; +} + +AManaPoolSaver::~AManaPoolSaver() +{ +} //replace drawing a card with activation of an ability ADrawReplacer::ADrawReplacer(GameObserver* observer, int id, MTGCardInstance * source, MTGAbility * replace, bool otherPlayer) : @@ -2817,15 +2846,54 @@ int AARemoveMana::resolve() { if (mManaDesc) // Remove all mana Matching a description { - for (int i = 0; i < Constants::NB_Colors; i++) - { - if (mManaDesc->hasColor(i)) - manaPool->removeAll(i); - } + for (int i = 0; i < Constants::NB_Colors; i++) + { + if (mManaDesc->hasColor(i)) + manaPool->removeAll(i); + } } else //Remove all mana { - manaPool->Empty(); + if(game->getCurrentGamePhase() != MTG_PHASE_ENDOFTURN) + { + if (player->doesntEmpty->getConvertedCost() && !player->poolDoesntEmpty->getConvertedCost()) + { + ManaCost * toRemove = manaPool->Diff(player->doesntEmpty); + player->getManaPool()->pay(manaPool->Diff(player->doesntEmpty)); + } + else if(!player->doesntEmpty->getConvertedCost() && player->poolDoesntEmpty->getConvertedCost()) + { + ManaCost * toSave = NEW ManaCost(); + for(int k = Constants::MTG_COLOR_ARTIFACT; k < Constants::NB_Colors;k++) + { + if(player->poolDoesntEmpty->getCost(k)) + toSave->add(k,manaPool->getCost(k)); + } + player->getManaPool()->pay(manaPool->Diff(toSave)); + delete(toSave); + } + else if(player->doesntEmpty->getConvertedCost() && player->poolDoesntEmpty->getConvertedCost()) + { + ManaCost * toSave = NEW ManaCost(); + for(int k = Constants::MTG_COLOR_ARTIFACT; k < Constants::NB_Colors;k++) + { + if(player->poolDoesntEmpty->getCost(k)) + { + toSave->add(k,manaPool->getCost(k));//save the whole amount of k; + } + else if(player->doesntEmpty->getCost(k)) + { + toSave->add(k,player->doesntEmpty->getCost(k));//save the amount of doesnt empty + } + } + player->getManaPool()->pay(manaPool->Diff(toSave));//remove the manacost equal to the difference of toSave and the manapool. + delete(toSave); + } + + } + else + manaPool->Empty(); + } } else //remove a "standard" mana Description diff --git a/projects/mtg/src/GameObserver.cpp b/projects/mtg/src/GameObserver.cpp index c370f7058..e755af2c5 100644 --- a/projects/mtg/src/GameObserver.cpp +++ b/projects/mtg/src/GameObserver.cpp @@ -230,6 +230,8 @@ void GameObserver::nextGamePhase() mLayers->actionLayer()->Update(0); currentPlayer->lifeLostThisTurn = 0; currentPlayer->opponent()->lifeLostThisTurn = 0; + currentPlayer->doesntEmpty->remove(currentPlayer->doesntEmpty); + currentPlayer->opponent()->doesntEmpty->remove(currentPlayer->opponent()->doesntEmpty); nextPlayer(); return nextGamePhase(); } diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index e4317746e..857a7b3ad 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -1725,6 +1725,13 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG return NULL; } + //mana of the listed type doesnt get emptied from the pools. + vectorcolorType = parseBetween(s,"poolsave(",")",false); + if (colorType.size()) + { + return NEW AManaPoolSaver(observer,id, card,colorType[1],s.find("opponentpool")!=string::npos); + } + //opponent replace draw with found = s.find("opponentreplacedraw "); if (found != string::npos) @@ -2710,9 +2717,10 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG found = s.find("add"); if (found != string::npos) { + bool doesntEmptyTilueot = s.find("doesntempty") != string::npos; ManaCost * output = ManaCost::parseManaCost(s.substr(found),NULL,card); Targetable * t = spell ? spell->getNextTarget() : NULL; - MTGAbility * a = NEW AManaProducer(observer, id, card, t, output, NULL, who,s.substr(found)); + MTGAbility * a = NEW AManaProducer(observer, id, card, t, output, NULL, who,s.substr(found),doesntEmptyTilueot); a->oneShot = 1; if(newName.size()) ((AManaProducer*)a)->menutext = newName; @@ -5232,7 +5240,7 @@ GenericTriggeredAbility* GenericTriggeredAbility::clone() const */ AManaProducer::AManaProducer(GameObserver* observer, int id, MTGCardInstance * card, Targetable * t, ManaCost * _output, ManaCost * _cost, - int who,string producing) : + int who,string producing,bool doesntEmpty) : ActivatedAbilityTP(observer, id, card, t, _cost, who) { @@ -5241,6 +5249,7 @@ AManaProducer::AManaProducer(GameObserver* observer, int id, MTGCardInstance * c output = _output; Producing = producing; menutext = ""; + DoesntEmpty = doesntEmpty; } int AManaProducer::isReactingToClick(MTGCardInstance * _card, ManaCost * mana) @@ -5268,6 +5277,8 @@ int AManaProducer::resolve() return 0; player->getManaPool()->add(output, source); + if(DoesntEmpty) + player->doesntEmpty->add(output); return 1; } diff --git a/projects/mtg/src/MTGDefinitions.cpp b/projects/mtg/src/MTGDefinitions.cpp index cff0036b1..1ebf044f8 100644 --- a/projects/mtg/src/MTGDefinitions.cpp +++ b/projects/mtg/src/MTGDefinitions.cpp @@ -155,7 +155,7 @@ int Constants::GetColorStringIndex(string mtgColor) { for (int idx = 0; idx < Constants::NB_Colors; ++idx) { - if (Constants::MTGColorStrings[idx]) + if (Constants::MTGColorStrings[idx] == mtgColor) return idx; } diff --git a/projects/mtg/src/Player.cpp b/projects/mtg/src/Player.cpp index b6504664e..d32b18a07 100644 --- a/projects/mtg/src/Player.cpp +++ b/projects/mtg/src/Player.cpp @@ -32,6 +32,8 @@ Player::Player(GameObserver *observer, string file, string fileSmall, MTGDeck * playMode = MODE_HUMAN; skippingTurn = 0; extraTurn = 0; + doesntEmpty = NEW ManaCost(); + poolDoesntEmpty = NEW ManaCost(); if (deck != NULL) { game = NEW MTGPlayerCards(deck); @@ -63,6 +65,8 @@ void Player::End() Player::~Player() { SAFE_DELETE(manaPool); + SAFE_DELETE(doesntEmpty); + SAFE_DELETE(poolDoesntEmpty); SAFE_DELETE(game); if(mAvatarTex && observer->getResourceManager()) observer->getResourceManager()->Release(mAvatarTex);