diff --git a/projects/mtg/include/TargetChooser.h b/projects/mtg/include/TargetChooser.h index 0752b1c69..6b70724d7 100644 --- a/projects/mtg/include/TargetChooser.h +++ b/projects/mtg/include/TargetChooser.h @@ -255,4 +255,26 @@ public: virtual ProliferateChooser * clone() const; virtual bool equals(TargetChooser * tc); }; + +class ParentChildChooser: public TypeTargetChooser +{ +public: + bool withoutProtections; + int type; + TargetChooser * deeperTargeting; + ParentChildChooser(int * _zones, int _nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1,TargetChooser * deepTc = NULL,int type = 1, bool other = false, bool targetMin = false) : + TypeTargetChooser("*",_zones, _nbzones, card, _maxtargets, other, targetMin),deeperTargeting(deepTc),type(type) + { + } + ; + ParentChildChooser(MTGCardInstance * card = NULL, int _maxtargets = 1,TargetChooser * deepTc = NULL,int type = 1, bool other = false,bool targetMin = false) : + TypeTargetChooser("*", card, _maxtargets, other,targetMin),deeperTargeting(deepTc),type(type) + { + } + ; + virtual bool canTarget(Targetable * target, bool withoutProtections = false); + virtual ParentChildChooser * clone() const; + virtual bool equals(TargetChooser * tc); + ~ParentChildChooser(); +}; #endif diff --git a/projects/mtg/src/TargetChooser.cpp b/projects/mtg/src/TargetChooser.cpp index ea1d5549b..42701de2d 100644 --- a/projects/mtg/src/TargetChooser.cpp +++ b/projects/mtg/src/TargetChooser.cpp @@ -187,6 +187,18 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta } } + if (s1.find("children") != string::npos || s1.find("parents") != string::npos) + { + TargetChooser * deeperTc = NULL; + if(s1.find("[") != string::npos) + { + AbilityFactory af; + vectordeepTc = parseBetween(s1,"[","]"); + deeperTc = createTargetChooser(deepTc[1],card); + } + return NEW ParentChildChooser(card, maxtargets,deeperTc,s1.find("parents") != string::npos?2:1); + } + while (s1.size()) { found = s1.find(","); @@ -1442,4 +1454,72 @@ bool ProliferateChooser::equals(TargetChooser * tc) return false; return TypeTargetChooser::equals(tc); +} + +/*parents or children Target */ +bool ParentChildChooser::canTarget(Targetable * target,bool withoutProtections) +{ + if (target->typeAsTarget() == TARGET_CARD) + { + MTGCardInstance * card = (MTGCardInstance*)target; + if(type == 1) + { + if(!source->childrenCards.size()) + return false; + for(unsigned int w = 0;w < source->childrenCards.size();w++) + { + MTGCardInstance * child = source->childrenCards[w]; + if(child == target) + { + if(deeperTargeting) + { + if(!deeperTargeting->canTarget(child)) + return false; + } + return true; + } + } + } + else + { + if(!source->parentCards.size()) + return false; + for(unsigned int w = 0;w < source->parentCards.size();w++) + { + MTGCardInstance * parent = source->parentCards[w]; + if(parent == target) + { + if(deeperTargeting) + { + if(!deeperTargeting->canTarget(parent)) + return false; + } + return true; + } + } + } + return false; + } + return TypeTargetChooser::canTarget(target,withoutProtections); +} + +ParentChildChooser* ParentChildChooser::clone() const +{ + ParentChildChooser * a = NEW ParentChildChooser(*this); + return a; +} + +bool ParentChildChooser::equals(TargetChooser * tc) +{ + + ParentChildChooser * dtc = dynamic_cast (tc); + if (!dtc) + return false; + + return TypeTargetChooser::equals(tc); +} + +ParentChildChooser::~ParentChildChooser() +{ + SAFE_DELETE(deeperTargeting); } \ No newline at end of file