added parents and children TargetChooser

ok this target chooser is set apart from the others becuase it focuses on relationship between cards instead of other forms of checking, also i made sure to add a method for deeper Targeting.
it is the same as any other target chooser when it comes to writeing the syntax and can be used in almost every way a normal one can.
here is what i mean by deeper targeting
this targetchooser allows you to denote a nested targetchooser.

target(children[targerchooser])
all(parents[targetchooser])

it is plural becuase i do allow maxtargeting to be denoted here. lets say you want to have a domain that lets you do the following
"2 of my target inhabitants get +1/+1 until end of turn"
you can do this...
auto={0}:target(<2>children) +1/+1 ueot
how about even more complex?
auto={0}:target(<2>children[elf[power=1]]) +1/+1

2 of my children that are elves with power equal to 1.
the same goes for parents, you can also lord( with this targetchooser.

if you want to say 
"the inhabitants of this domain gain flying"
auto=lord(children) flying

here are some example coding that you can play around with.

[card]
name=Forest
text=G
auto=lord(children[elf]) +3/+3
auto={0}:target(<2>children) +12/+12
type=Basic Land
subtype=Forest
[/card]

[card]
name=Tidal Kraken
abilities=unblockable
target=land|mybattlefield
auto=connect
auto={0}:target(parents) destroy
text=Tidal Kraken is unblockable.
mana={0}
type=Creature
subtype=Kraken
power=6
toughness=6
[/card]

[card]
name=Arbor Elf
target=<upto:3>land|mybattlefield
auto=connect
auto=foreach(parents[forest]) 1/1
mana={0}
type=creature
subtype=elf
power=1
toughness=1
[/card]
*above, arbor elf can target upto 3 domains...for each one you choose to connect him to that is a forest, arbor elf would gain 1/1..

so as you can see it is pretty indepth.

note: all test pass.
This commit is contained in:
omegablast2002@yahoo.com
2011-09-10 23:23:40 +00:00
parent 6a8f7374cb
commit 1e0268eb07
2 changed files with 102 additions and 0 deletions

View File

@@ -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

View File

@@ -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;
vector<string>deepTc = 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<ParentChildChooser *> (tc);
if (!dtc)
return false;
return TypeTargetChooser::equals(tc);
}
ParentChildChooser::~ParentChildChooser()
{
SAFE_DELETE(deeperTargeting);
}