diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 6fe516e39..1a55e9326 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -2245,14 +2245,26 @@ public: aType = MTGAbility::STANDARD_TEACH; } - int canBeInList(MTGCardInstance * card) - { - if(card->isPhased || source->isPhased) + int canBeInList(MTGCardInstance * card) + { + if(card->isPhased || source->isPhased) + return 0; + if(tc->canTarget(card) && card != tc->source) + { + if ((tc->source->hasSubtype(Subtypes::TYPE_AURA) || tc->source->hasSubtype(Subtypes::TYPE_EQUIPMENT) || tc->source->hasSubtype("instant") + || tc->source->hasSubtype("sorcery")) && card == tc->source->target ) + return 1; + if(tc->source->hasSubtype(Subtypes::TYPE_CREATURE)) + { + for(size_t myChild = 0; myChild < tc->source->parentCards.size();++myChild) + { + if(tc->source->parentCards[myChild] == card) + return 1; + } + } + } return 0; - if ((tc->source->hasSubtype(Subtypes::TYPE_AURA) || tc->source->hasSubtype(Subtypes::TYPE_EQUIPMENT) || tc->source->hasSubtype("instant") - || tc->source->hasSubtype("sorcery")) && tc->canTarget(card) && card == tc->source->target && card != tc->source) return 1; - return 0; - } + } int resolve() { @@ -2289,7 +2301,10 @@ public: } else { - return 0; + if(tc->source->hasSubtype(Subtypes::TYPE_CREATURE)) + a->target = d; + else + return 0; } if (a->oneShot) @@ -2426,8 +2441,11 @@ public: { if (source->target && !game->isInPlay(source->target)) unequip(); + if(!game->connectRule) + { if (source->target && TargetAbility::tc && !TargetAbility::tc->canTarget((Targetable *)source->target,true)) unequip(); + } return TargetAbility::testDestroy(); } @@ -3543,11 +3561,12 @@ public: class ACounterTracker: public MTGAbility { public: - Counter * counter; + string scounter; int removed; - ACounterTracker(int id, MTGCardInstance * source, MTGCardInstance * target, Counter * counter = NULL); + ACounterTracker(int id, MTGCardInstance * source, MTGCardInstance * target, string scounter = ""); int addToGame(); int destroy(); + int testDestroy(); ACounterTracker * clone() const; ~ACounterTracker(); }; diff --git a/projects/mtg/include/GameObserver.h b/projects/mtg/include/GameObserver.h index 9552718e9..e670e90b7 100644 --- a/projects/mtg/include/GameObserver.h +++ b/projects/mtg/include/GameObserver.h @@ -88,6 +88,7 @@ class GameObserver{ void ButtonPressed(PlayGuiObject*); int receiveEvent(WEvent * event); + bool connectRule; }; #endif diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index bcdc2cb5e..87450b5f1 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -417,8 +417,8 @@ ACounterShroud::~ACounterShroud() } //sheild a card from a certain type of counter. -ACounterTracker::ACounterTracker(int id, MTGCardInstance * source, MTGCardInstance * target, Counter * counter) : -MTGAbility(id, source, target),counter(counter) +ACounterTracker::ACounterTracker(int id, MTGCardInstance * source, MTGCardInstance * target, string scounter) : +MTGAbility(id, source, target),scounter(scounter) { removed = 0; } @@ -426,6 +426,13 @@ MTGAbility(id, source, target),counter(counter) int ACounterTracker::addToGame() { MTGCardInstance * _target = (MTGCardInstance*)target; + Counter * counter = NULL; + AbilityFactory af; + counter = af.parseCounter(scounter, _target, (Spell*)source); + if (!counter) + { + return 0; + } if(_target && !removed) { if(_target->counters->hasCounter(counter->name.c_str(),counter->power,counter->toughness) && _target->counters->hasCounter(counter->name.c_str(),counter->power,counter->toughness)->nb >= counter->nb) @@ -436,14 +443,23 @@ int ACounterTracker::addToGame() removed++; } } + SAFE_DELETE(counter); return 1; } + SAFE_DELETE(counter); return 0; } int ACounterTracker::destroy() { MTGCardInstance * _target = (MTGCardInstance*)target; + Counter * counter = NULL; + AbilityFactory af; + counter = af.parseCounter(scounter, _target, (Spell*)source); + if (!counter) + { + return 0; + } if(_target) { if(removed == counter->nb) @@ -454,20 +470,25 @@ int ACounterTracker::destroy() } } } - removeFromGame(); + SAFE_DELETE(counter); + return 1; +} + +int ACounterTracker::testDestroy() +{ + if(this->source->isInPlay()) + return 0; return 1; } ACounterTracker * ACounterTracker::clone() const { ACounterTracker * a = NEW ACounterTracker(*this); - a->counter = this->counter; return a; } ACounterTracker::~ACounterTracker() { - SAFE_DELETE(counter); } //removeall counters of a certain type or all. diff --git a/projects/mtg/src/GameObserver.cpp b/projects/mtg/src/GameObserver.cpp index d4fe3722c..7c404d0bf 100644 --- a/projects/mtg/src/GameObserver.cpp +++ b/projects/mtg/src/GameObserver.cpp @@ -49,6 +49,7 @@ GameObserver::GameObserver(Player * _players[], int _nb_players) replacementEffects = NEW ReplacementEffects(); combatStep = BLOCKERS; mRules = NULL; + connectRule = false; } int GameObserver::getCurrentGamePhase() @@ -473,10 +474,13 @@ void GameObserver::gameStateBasedEffects() check = card->childrenCards[wC]; for(size_t wCC = 0; wCC < card->childrenCards.size();wCC++) { - if(check->getName() == card->childrenCards[wCC]->getName() && check != card->childrenCards[wCC]) + if(check->isInPlay()) { - card->isDualWielding = true; - matched = card->childrenCards[wCC]; + if(check->getName() == card->childrenCards[wCC]->getName() && check != card->childrenCards[wCC]) + { + card->isDualWielding = true; + matched = card->childrenCards[wCC]; + } } } if(matched) diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 8aff0a0f4..11ebcadb7 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -1913,14 +1913,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG if (splitCounterTracking.size()) { string splitCounterTrack = splitCounterTracking[1]; - Counter * counter = NULL; - counter = parseCounter(splitCounterTrack, target, spell); - if (!counter) - { - DebugTrace("MTGAbility: can't parse counter:" << s); - return NULL; - } - return NEW ACounterTracker(id, card, target,counter); + return NEW ACounterTracker(id, card, target,splitCounterTrack); } //removes all counters of the specifified type. vector splitRemoveCounter = parseBetween(s, "removeallcounters(", ")"); @@ -2286,6 +2279,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG { GameObserver * game = GameObserver::GetInstance(); game->addObserver(NEW ParentChildRule(-1)); + game->connectRule = true; return NULL; } //create an association between cards. diff --git a/projects/mtg/src/MTGRules.cpp b/projects/mtg/src/MTGRules.cpp index f374bfc9d..0d85a01ae 100644 --- a/projects/mtg/src/MTGRules.cpp +++ b/projects/mtg/src/MTGRules.cpp @@ -2337,12 +2337,22 @@ int ParentChildRule::receiveEvent(WEvent * event) { return 0; } - if(!card->childrenCards.size()) - return 0; Player * p = card->controller(); if (z->from == p->game->inPlay) { - for(unsigned int w = 0;w < card->childrenCards.size();w++) + for(size_t myChildCheck = 0;myChildCheck < card->parentCards.size();myChildCheck++) + { + MTGCardInstance * pCard = card->parentCards[myChildCheck]; + for(size_t myC = 0;myC < pCard->childrenCards.size();myC++) + { + if(pCard->childrenCards[myC] == card) + { + pCard->childrenCards.erase(pCard->childrenCards.begin() + myC); + } + } + } + + for(size_t w = 0;w < card->childrenCards.size();w++) { MTGCardInstance * child = card->childrenCards[w]; if(child == NULL) @@ -2351,10 +2361,12 @@ int ParentChildRule::receiveEvent(WEvent * event) child->controller()->game->putInGraveyard(child); else//allows a card to declare 2 homes, as long as it has a home it can stay inplay. { - for(unsigned int myParent = 0;myParent < child->parentCards.size();myParent++) + for(size_t myParent = 0;myParent < child->parentCards.size();myParent++) { if(child->parentCards[myParent] == card) + { child->parentCards.erase(child->parentCards.begin() + myParent); + } } } }