From 6a8f7374cb05c7eecdac8a1de88971af47ea3fc1 Mon Sep 17 00:00:00 2001 From: "omegablast2002@yahoo.com" Date: Sat, 10 Sep 2011 21:28:20 +0000 Subject: [PATCH] added weapon handling for connect, please be sure to code these weapons as follows target=*|mybattlefield auto={0}:equip auto=connect notice i declare the equip before the connect, this is becuase connect will use the equip ability of the card to handle it. target= can be used for connecting them now as the first time equip. please remember to use teach( or autoskill= to avoid giving abilities forever to a target...this makes equipments hybrid auras. also, moved parentchildrule init from original init to rules.txt... in yourrules.txt should look like this: include mtg.txt name=Classic [INIT] mode=mtg auto=connectrule [PLAYERS] auto=shuffle auto=draw:7 i did this becuase i want to reuse the parentchild associations for mtgabilities...and if parents will always kill thier children, i won't be able to use it :P changed connect into an instant ability, i don't want this ability to be done by menu choice. --- projects/mtg/include/AllAbilities.h | 30 ++++++++++++++++++---------- projects/mtg/include/MTGRules.h | 1 - projects/mtg/src/AllAbilities.cpp | 31 ++++++++++++++++++++++------- projects/mtg/src/DuelLayers.cpp | 1 - projects/mtg/src/MTGAbility.cpp | 9 +++++++++ 5 files changed, 53 insertions(+), 19 deletions(-) diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index d51d1fddd..d53142dcf 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -2330,6 +2330,15 @@ public: }; // +/* create a parent child association between cards */ +class AAConnect: public InstantAbility +{ +public: + AAConnect(int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost = NULL); + int resolve(); + AAConnect * clone() const; +}; + //equipment class AEquip: public TargetAbility { @@ -2347,12 +2356,19 @@ public: if (source->target) { source->target->equipment -= 1; + source->parentCards.clear(); + for(unsigned int w = 0;w < source->target->childrenCards.size();w++) + { + MTGCardInstance * child = source->target->childrenCards[w]; + if(child == source) + source->target->childrenCards.erase(source->target->childrenCards.begin() + w); + } } source->target = NULL; for (size_t i = 0; i < currentAbilities.size(); ++i) { MTGAbility * a = currentAbilities[i]; - if (dynamic_cast (a) || dynamic_cast (a) || (a->aType == MTGAbility::STANDARD_TOKENCREATOR && a->oneShot)) + if (dynamic_cast (a) || dynamic_cast (a) || dynamic_cast (a) || (a->aType == MTGAbility::STANDARD_TOKENCREATOR && a->oneShot)) { SAFE_DELETE(a); continue; @@ -2367,6 +2383,8 @@ public: { source->target = equipped; source->target->equipment += 1; + source->parentCards.push_back((MTGCardInstance*)target); + source->target->childrenCards.push_back((MTGCardInstance*)source); AbilityFactory af; af.getAbilities(¤tAbilities, NULL, source); for (size_t i = 0; i < currentAbilities.size(); ++i) @@ -2374,6 +2392,7 @@ public: MTGAbility * a = currentAbilities[i]; if (dynamic_cast (a)) continue; if (dynamic_cast (a)) continue; + if (dynamic_cast (a)) continue; if (a->aType == MTGAbility::STANDARD_TOKENCREATOR && a->oneShot) { a->forceDestroy = 1; @@ -3214,15 +3233,6 @@ 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/MTGRules.h b/projects/mtg/include/MTGRules.h index 7eeecc7f4..f1aa85d55 100644 --- a/projects/mtg/include/MTGRules.h +++ b/projects/mtg/include/MTGRules.h @@ -413,7 +413,6 @@ class ParentChildRule: public MTGAbility { public: ParentChildRule(int _id); - map > victems; int receiveEvent(WEvent * event); virtual ostream& toString(ostream& out) const; int testDestroy(); diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index 103ab9082..1f6cfcf07 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -3833,7 +3833,7 @@ ABlinkGeneric::~ABlinkGeneric() // target becomes a parent of card(source) AAConnect::AAConnect(int id, MTGCardInstance * card, MTGCardInstance * _target, ManaCost * _cost) : -ActivatedAbility(id, card, _cost, 0) +InstantAbility(id, card, target) { target = _target; } @@ -3847,12 +3847,29 @@ int AAConnect::resolve() _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!!! - + //weapon + if(source->hasSubtype(Subtypes::TYPE_EQUIPMENT)) + { + GameObserver * g = GameObserver::GetInstance(); + for (size_t i = 1; i < g->mLayers->actionLayer()->mObjects.size(); i++) + { + MTGAbility * a = ((MTGAbility *) g->mLayers->actionLayer()->mObjects[i]); + AEquip * eq = dynamic_cast (a); + if (eq && eq->source == source) + { + ((AEquip*)a)->unequip(); + ((AEquip*)a)->equip(_target); + } + } + } + else + { + 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; } diff --git a/projects/mtg/src/DuelLayers.cpp b/projects/mtg/src/DuelLayers.cpp index ccca246bf..92bb67239 100644 --- a/projects/mtg/src/DuelLayers.cpp +++ b/projects/mtg/src/DuelLayers.cpp @@ -44,7 +44,6 @@ 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 b66a4106f..758b8edda 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -11,6 +11,7 @@ #include "Translate.h" #include "ThisDescriptor.h" #include "ExtraCost.h" +#include "MTGRules.h" //Used for Lord/This parsing @@ -2397,6 +2398,14 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG return a; } + //adds the rule to destroy children if parent dies + found = s.find("connectrule"); + if(found != string::npos) + { + GameObserver * game = GameObserver::GetInstance(); + game->addObserver(NEW ParentChildRule(-1)); + return NULL; + } //create an association between cards. found = s.find("connect"); if (found != string::npos)