diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index cd1ecd793..d51d1fddd 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -3214,6 +3214,15 @@ public: } }; +/* create a parent child association between cards */ +class AAConnect: public ActivatedAbility +{ +public: + AAConnect(int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost = NULL); + int resolve(); + AAConnect * clone() const; +}; + // Add life of gives damage if a given zone has more or less than [condition] cards at the beginning of [phase] //Ex : the rack, ivory tower... class ALifeZoneLink: public MTGAbility diff --git a/projects/mtg/include/MTGCardInstance.h b/projects/mtg/include/MTGCardInstance.h index 5a7cbf979..58f13d174 100644 --- a/projects/mtg/include/MTGCardInstance.h +++ b/projects/mtg/include/MTGCardInstance.h @@ -43,6 +43,9 @@ protected: int removeBlocker(MTGCardInstance * c); int init(); public: + vectorparentCards; + vectorchildrenCards; + int setAttacker(int value); int setDefenser(MTGCardInstance * c); MTGGameZone * currentZone; diff --git a/projects/mtg/include/MTGRules.h b/projects/mtg/include/MTGRules.h index 9b46d6503..7eeecc7f4 100644 --- a/projects/mtg/include/MTGRules.h +++ b/projects/mtg/include/MTGRules.h @@ -408,6 +408,17 @@ public: virtual MTGDeathtouchRule * clone() const; }; +/* handling parentchild */ +class ParentChildRule: public MTGAbility +{ +public: + ParentChildRule(int _id); + map > victems; + int receiveEvent(WEvent * event); + virtual ostream& toString(ostream& out) const; + int testDestroy(); + virtual ParentChildRule * clone() const; +}; /* HUD Display */ class HUDString diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index 260341037..103ab9082 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -3831,6 +3831,36 @@ ABlinkGeneric::~ABlinkGeneric() SAFE_DELETE(ability); } +// target becomes a parent of card(source) +AAConnect::AAConnect(int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost) : +ActivatedAbility(id, card, _cost, 0) +{ + target = _target; +} + +int AAConnect::resolve() +{ + MTGCardInstance * _target = (MTGCardInstance *) target; + if (_target) + { + while (_target->next) + _target = _target->next; + _target->childrenCards.push_back(source); + source->parentCards.push_back(_target); + if(source->target) + source->target = NULL; + //clearing the source target allows us to use target= line + //without creating side effects on any other abilities a card has + //connect has to be the first ability in the cards lines unless you want it to do effects to the targeted card!!! + + } + return 1; +} + +AAConnect * AAConnect::clone() const +{ + return NEW AAConnect(*this); +} //Tutorial Messaging diff --git a/projects/mtg/src/DuelLayers.cpp b/projects/mtg/src/DuelLayers.cpp index 92bb67239..ccca246bf 100644 --- a/projects/mtg/src/DuelLayers.cpp +++ b/projects/mtg/src/DuelLayers.cpp @@ -44,6 +44,7 @@ void DuelLayers::init() action->Add(NEW MTGDeathtouchRule(-1)); action->Add(NEW OtherAbilitiesEventReceiver(-1)); action->Add(NEW MTGMorphCostRule(-1)); + action->Add(NEW ParentChildRule(-1)); //Other display elements action->Add(NEW HUDDisplay(-1)); diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index ad075fd9e..b66a4106f 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -2397,6 +2397,15 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG return a; } + //create an association between cards. + found = s.find("connect"); + if (found != string::npos) + { + MTGAbility * a = NEW AAConnect(id, card, target); + a->oneShot = 1; + return a; + } + DebugTrace(" no matching ability found. " << s); return NULL; } diff --git a/projects/mtg/src/MTGRules.cpp b/projects/mtg/src/MTGRules.cpp index 0d337e55e..f374bfc9d 100644 --- a/projects/mtg/src/MTGRules.cpp +++ b/projects/mtg/src/MTGRules.cpp @@ -2319,3 +2319,61 @@ MTGDeathtouchRule * MTGDeathtouchRule::clone() const { return NEW MTGDeathtouchRule(*this); } +// +//kai mod +ParentChildRule::ParentChildRule(int _id) : +MTGAbility(_id, NULL) +{ +} +; + +int ParentChildRule::receiveEvent(WEvent * event) +{ + WEventZoneChange * z = dynamic_cast (event); + if (z) + { + MTGCardInstance * card = z->card->previous; + if(!card) + { + 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++) + { + MTGCardInstance * child = card->childrenCards[w]; + if(child == NULL) + continue; + if(child->parentCards.size() < 2) + 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++) + { + if(child->parentCards[myParent] == card) + child->parentCards.erase(child->parentCards.begin() + myParent); + } + } + } + } + return 1; + } + return 0; +} + +ostream& ParentChildRule::toString(ostream& out) const +{ + out << "ParentChildRule ::: ("; + return MTGAbility::toString(out) << ")"; +} +int ParentChildRule::testDestroy() +{ + return 0; +} +ParentChildRule * ParentChildRule::clone() const +{ + return NEW ParentChildRule(*this); +} \ No newline at end of file