From 18cd8b508204f9be0148b5d8e9fa3dbbbe95bda4 Mon Sep 17 00:00:00 2001 From: "omegablast2002@yahoo.com" Date: Sat, 7 Apr 2012 05:16:55 +0000 Subject: [PATCH] added limiting of x to a color to fix Consume Spirit from being able to use any color.. {x:black} {x:color} creating a snapshot of a card instance in garbage for stored cards, the issue with previous version was it was using base model value instead of what the storedcard was actually at the time it was in battlefield. example, animal boneyard test was coming up 1 toughness short becuase the creature storedcard pointed to was sent to graveyard for the sacrifice. changed myStored TargetChooser to use storedSourceCard instead, as this is supposed to point to the actual card and not a snapshot. --- projects/mtg/include/AllAbilities.h | 2 +- projects/mtg/include/MTGCardInstance.h | 2 + projects/mtg/include/ManaCost.h | 3 ++ projects/mtg/src/ExtraCost.cpp | 22 +++++----- projects/mtg/src/MTGAbility.cpp | 2 +- projects/mtg/src/MTGCardInstance.cpp | 12 +++++- projects/mtg/src/MTGGameZones.cpp | 1 + projects/mtg/src/ManaCost.cpp | 60 +++++++++++++++++++++++++- projects/mtg/src/TargetChooser.cpp | 2 +- 9 files changed, 91 insertions(+), 15 deletions(-) diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index bc455e7c5..76fc9045a 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -2917,7 +2917,7 @@ public: setAbilityOwner(); myDummy->setObserver(abilityReciever->getObserver()); myDummy->owner = abilityReciever; - myDummy->storedCard = source; + myDummy->storedSourceCard = source; vectormagictextlines = split(sabilities,'_'); if(magictextlines.size()) { diff --git a/projects/mtg/include/MTGCardInstance.h b/projects/mtg/include/MTGCardInstance.h index f14aa1d07..fbf8a2184 100644 --- a/projects/mtg/include/MTGCardInstance.h +++ b/projects/mtg/include/MTGCardInstance.h @@ -155,6 +155,8 @@ public: int isAttacker(); Targetable * isAttacking; MTGCardInstance * storedCard; + MTGCardInstance * createSnapShot(); + MTGCardInstance * storedSourceCard; MTGCardInstance * isDefenser(); int initAttackersDefensers(); MTGCardInstance * getNextOpponent(MTGCardInstance * previous=NULL); diff --git a/projects/mtg/include/ManaCost.h b/projects/mtg/include/ManaCost.h index ae8b93820..f7e56f343 100644 --- a/projects/mtg/include/ManaCost.h +++ b/projects/mtg/include/ManaCost.h @@ -56,6 +56,9 @@ public: virtual void resetCosts(); void x(); int hasX(); + void specificX(int color = 0); + int hasSpecificX(); + int xColor; int hasAnotherCost(); ManaCost(std::vector& _cost, int nb_elems = 1); ManaCost(); diff --git a/projects/mtg/src/ExtraCost.cpp b/projects/mtg/src/ExtraCost.cpp index ac7fcbd52..2cb204bce 100644 --- a/projects/mtg/src/ExtraCost.cpp +++ b/projects/mtg/src/ExtraCost.cpp @@ -186,7 +186,7 @@ int DiscardRandomCost::doPay() MTGCardInstance * _target = (MTGCardInstance *) target; if (target) { - source->storedCard = target; + source->storedCard = target->createSnapShot(); _target->controller()->game->discardRandom(_target->controller()->game->hand, source); target = NULL; if (tc) @@ -215,7 +215,7 @@ int DiscardCost::doPay() MTGCardInstance * _target = (MTGCardInstance *) target; if (target) { - source->storedCard = target; + source->storedCard = target->createSnapShot(); WEvent * e = NEW WEventCardDiscard(target); GameObserver * game = target->owner->getObserver(); game->receiveEvent(e); @@ -279,7 +279,7 @@ int ToLibraryCost::doPay() MTGCardInstance * _target = (MTGCardInstance *) target; if (target) { - source->storedCard = target; + source->storedCard = target->createSnapShot(); _target->controller()->game->putInLibrary(target); target = NULL; if (tc) @@ -317,7 +317,7 @@ int MillCost::doPay() MTGCardInstance * _target = (MTGCardInstance *) target; if (target) { - source->storedCard = (MTGCardInstance*)_target->controller()->game->library->cards[_target->controller()->game->library->nb_cards - 1]; + source->storedCard = (MTGCardInstance*)_target->controller()->game->library->cards[_target->controller()->game->library->nb_cards - 1]->createSnapShot(); _target->controller()->game->putInZone( _target->controller()->game->library->cards[_target->controller()->game->library->nb_cards - 1], _target->controller()->game->library, _target->controller()->game->graveyard); @@ -339,7 +339,7 @@ MillExileCost::MillExileCost(TargetChooser *_tc) int MillExileCost::doPay() { MTGCardInstance * _target = (MTGCardInstance *) target; - source->storedCard = (MTGCardInstance*)_target->controller()->game->library->cards[_target->controller()->game->library->nb_cards - 1]; + source->storedCard = (MTGCardInstance*)_target->controller()->game->library->cards[_target->controller()->game->library->nb_cards - 1]->createSnapShot(); if (target) { _target->controller()->game->putInZone( @@ -457,7 +457,7 @@ int TapTargetCost::isPaymentSet() int TapTargetCost::doPay() { MTGCardInstance * _target = (MTGCardInstance *) target; - source->storedCard = target; + source->storedCard = target->createSnapShot(); if (target) { _target->tap(); @@ -500,7 +500,7 @@ int UnTapTargetCost::isPaymentSet() int UnTapTargetCost::doPay() { MTGCardInstance * _target = (MTGCardInstance *) target; - source->storedCard = target; + source->storedCard = target->createSnapShot(); if (target) { _target->untap(); @@ -531,7 +531,7 @@ int ExileTargetCost::doPay() if (target) { - source->storedCard = target; + source->storedCard = target->createSnapShot(); target->controller()->game->putInExile(target); target = NULL; if (tc) @@ -560,7 +560,7 @@ int BounceTargetCost::doPay() if (target) { - source->storedCard = target; + source->storedCard = target->createSnapShot(); target->controller()->game->putInHand(target); target = NULL; if (tc) @@ -640,7 +640,7 @@ int SacrificeCost::doPay() if (target) { MTGCardInstance * beforeCard = target; - source->storedCard = target; + source->storedCard = target->createSnapShot(); target->controller()->game->putInGraveyard(target); WEvent * e = NEW WEventCardSacrifice(beforeCard,target); GameObserver * game = target->owner->getObserver(); @@ -882,7 +882,9 @@ int ExtraCosts::doPay() for (size_t i = 0; i < costs.size(); i++) { if(costs[i]->target) + { costs[i]->target->isExtraCostTarget = false; + } result += costs[i]->doPay(); } return result; diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index ae04011aa..d54b06ca7 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -3004,7 +3004,7 @@ int AbilityFactory::abilityEfficiency(MTGAbility * a, Player * p, int mode, Targ MTGCardInstance * testDummy = NEW MTGCardInstance(); testDummy->setObserver(targetedPlyr->getObserver()); testDummy->owner = targetedPlyr; - testDummy->storedCard = atac->source; + testDummy->storedSourceCard = atac->source; vectormagictextlines = split(atac->sabilities,'_'); if(magictextlines.size()) { diff --git a/projects/mtg/src/MTGCardInstance.cpp b/projects/mtg/src/MTGCardInstance.cpp index e41ffd72b..fcd638037 100644 --- a/projects/mtg/src/MTGCardInstance.cpp +++ b/projects/mtg/src/MTGCardInstance.cpp @@ -51,6 +51,15 @@ MTGCardInstance::MTGCardInstance(MTGCard * card, MTGPlayerCards * arg_belongs_to castMethod = Constants::NOT_CAST; } + MTGCardInstance * MTGCardInstance::createSnapShot() + { + MTGCardInstance * snapShot = NEW MTGCardInstance(*this); + snapShot->previous = NULL; + snapShot->counters = NEW Counters(snapShot); + controller()->game->garbage->addCard(snapShot); + return snapShot; + } + void MTGCardInstance::copy(MTGCardInstance * card) { MTGCard * source = card->model; @@ -81,7 +90,7 @@ void MTGCardInstance::copy(MTGCardInstance * card) int backupid = mtgid; int castMethodBackUP = this->castMethod; mtgid = source->getId(); - MTGCardInstance * oldStored = this->storedCard; + MTGCardInstance * oldStored = this->storedSourceCard; Spell * spell = NEW Spell(observer, this); observer = card->observer; AbilityFactory af(observer); @@ -159,6 +168,7 @@ void MTGCardInstance::initMTGCI() coinSide = -1; isAttacking = NULL; storedCard = NULL; + storedSourceCard = NULL; for (int i = 0; i < ManaCost::MANA_PAID_WITH_RETRACE +1; i++) alternateCostPaid[i] = 0; diff --git a/projects/mtg/src/MTGGameZones.cpp b/projects/mtg/src/MTGGameZones.cpp index 73c25253f..d01832bc4 100644 --- a/projects/mtg/src/MTGGameZones.cpp +++ b/projects/mtg/src/MTGGameZones.cpp @@ -475,6 +475,7 @@ MTGCardInstance * MTGGameZone::removeCard(MTGCardInstance * card, int createCopy copy->castX = card->castX; copy->kicked = card->kicked; copy->storedCard = card->storedCard; + copy->storedSourceCard = card->storedSourceCard; //stupid bug with tokens... if (card->model == card) diff --git a/projects/mtg/src/ManaCost.cpp b/projects/mtg/src/ManaCost.cpp index 92f144559..152f0483f 100644 --- a/projects/mtg/src/ManaCost.cpp +++ b/projects/mtg/src/ManaCost.cpp @@ -25,6 +25,7 @@ ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstan { manaCost = NEW ManaCost(); } + manaCost->xColor = -1; int state = 0; size_t start = 0; size_t end = 0; @@ -91,8 +92,27 @@ ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstan switch (value[0]) { case 'x': - manaCost->x(); + if(value == "x") + manaCost->x(); + else + { + vectorcolorSplit = parseBetween(value,"x:"," ",false); + if(colorSplit.size()) + { + int color = -1; + const string ColorStrings[] = { Constants::kManaColorless, Constants::kManaGreen, Constants::kManaBlue, Constants::kManaRed, Constants::kManaBlack, Constants::kManaWhite }; + for (unsigned int i = 0; i < sizeof(ColorStrings)/sizeof(ColorStrings[0]); ++i) + { + if (s.find(ColorStrings[i]) != string::npos) + { + color = i; + } + } + manaCost->specificX(color); + } + } break; + case 't': //Tap if (value == "t") { @@ -296,6 +316,7 @@ ManaCost::ManaCost(ManaCost * manaCost) suspend = NEW ManaCost( manaCost->suspend ); extraCosts = manaCost->extraCosts ? manaCost->extraCosts->clone() : NULL; + xColor = manaCost->xColor; } // Copy Constructor @@ -322,6 +343,7 @@ ManaCost::ManaCost(const ManaCost& manaCost) suspend = NEW ManaCost( manaCost.suspend ); extraCosts = manaCost.extraCosts ? manaCost.extraCosts->clone() : NULL; + xColor = manaCost.xColor; } // operator= @@ -341,6 +363,7 @@ ManaCost & ManaCost::operator= (const ManaCost & manaCost) FlashBack = manaCost.FlashBack; morph = manaCost.morph; suspend = manaCost.suspend; + xColor = manaCost.xColor; } return *this; } @@ -377,10 +400,34 @@ int ManaCost::hasX() DebugTrace("Seems ManaCost was not properly initialized"); return 0; } + if(xColor > 0) + return 0; return cost[Constants::NB_Colors]; } +void ManaCost::specificX(int color) +{ + if (cost.size() <= (size_t)Constants::NB_Colors) + { + DebugTrace("Seems ManaCost was not properly initialized"); + return; + } + xColor = color; + cost[Constants::NB_Colors] = 1; +} +int ManaCost::hasSpecificX() +{ + if (cost.size() <= (size_t)Constants::NB_Colors) + { + DebugTrace("Seems ManaCost was not properly initialized"); + return 0; + } + if(xColor > 0) + return cost[Constants::NB_Colors]; + return 0; +} + int ManaCost::hasAnotherCost() { if (cost.size() <= (size_t)Constants::NB_Colors) @@ -501,6 +548,7 @@ void ManaCost::copy(ManaCost * _manaCost) suspend = NEW ManaCost(); suspend->copy(_manaCost->suspend); } + xColor = _manaCost->xColor; } int ManaCost::getCost(int color) @@ -815,6 +863,16 @@ ManaCost * ManaCost::Diff(ManaCost * _cost) } } } + //cost x where x is specific. + if (_cost->hasSpecificX()) + { + diff[Constants::NB_Colors * 2 + 1] = 0; + if (diff[_cost->xColor * 2 + 1] > 0) + { + diff[Constants::NB_Colors * 2 + 1] += diff[_cost->xColor * 2 + 1]; + diff[_cost->xColor * 2 + 1] = 0; + } + } ManaCost * result = NEW ManaCost(diff, Constants::NB_Colors + 1); return result; diff --git a/projects/mtg/src/TargetChooser.cpp b/projects/mtg/src/TargetChooser.cpp index 44c5a1428..1b3a03652 100644 --- a/projects/mtg/src/TargetChooser.cpp +++ b/projects/mtg/src/TargetChooser.cpp @@ -673,7 +673,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta } else if (typeName.compare("mystored") == 0) { - return NEW CardTargetChooser(observer, card->storedCard, card, zones, nbzones); + return NEW CardTargetChooser(observer, card->storedSourceCard, card, zones, nbzones); } else {