From 99ab44a20e2c1c2af1a453357044c6986573240e Mon Sep 17 00:00:00 2001 From: "omegablast2002@yahoo.com" Date: Thu, 2 Feb 2012 03:52:20 +0000 Subject: [PATCH] added moverandom(tc) from(zone) to(zone) ability...example moverandom(creature[green]) from(mygraveyard) to(opponentbattlefield) example card [card] name=Tariel, Reckoner of Souls auto={t}:moverandom(creature) from(opponentgraveyard) to(mybattlefield) mana={4}{W}{B}{R} abilities=Flying,vigilance type=Legendary Creature subtype=Angel power=4 toughness=7 text=Flying, vigilance {T}: Choose a creature card at random from target opponent's graveyard. Put that card onto the battlefield under your control. [/card] --- projects/mtg/include/AllAbilities.h | 15 ++++++ projects/mtg/src/AllAbilities.cpp | 80 +++++++++++++++++++++++++++++ projects/mtg/src/MTGAbility.cpp | 15 +++++- 3 files changed, 109 insertions(+), 1 deletion(-) diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 5eefb1ccf..197bf77ad 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -1047,6 +1047,21 @@ public: ~AAMover(); }; +// AARandomMover +class AARandomMover: public ActivatedAbility +{ +public: + string abilityTC; + string fromZone; + string toZone; + AARandomMover(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target, string tcs, string from, string to); + MTGGameZone * destinationZone(Targetable * target = NULL,string zone = ""); + int resolve(); + const char * getMenuText(); + AARandomMover * clone() const; + ~AARandomMover(); +}; + //----------------------------------------------------------------------------------------------- class AABuryCard: public ActivatedAbility diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index 81a4ceea3..af01f63e3 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -2028,6 +2028,86 @@ AAMover::~AAMover() SAFE_DELETE(andAbility); } +//random movement of a card from zone to zone +AARandomMover::AARandomMover(GameObserver* observer, int _id, MTGCardInstance * _source, MTGCardInstance * _target, string _tcs, string _from, string _to) : + ActivatedAbility(observer, _id, _source, NULL, 0), abilityTC(_tcs),fromZone(_from),toZone(_to) +{ + if (_target) + target = _target; +} + +MTGGameZone * AARandomMover::destinationZone(Targetable * target,string zone) +{ + MTGCardInstance * _target = (MTGCardInstance *) target; + return MTGGameZone::stringToZone(game, zone, source, _target); +} + +int AARandomMover::resolve() +{ + MTGCardInstance * _target = (MTGCardInstance *) target; + if (target) + { + Player* p = _target->controller(); + if (p) + { + MTGGameZone * fromDest = destinationZone(target,fromZone); + MTGGameZone * toDest = destinationZone(target,toZone); + + if (!fromDest->nb_cards) + return 0; + + TargetChooserFactory tcf(game); + TargetChooser * rTc = tcf.createTargetChooser(abilityTC, source); + rTc->targetter = NULL; + rTc->setAllZones(); + vectorselectedCards; + for(unsigned int i = 0; i < fromDest->cards.size();++i) + { + if(rTc->canTarget(fromDest->cards[i])) + selectedCards.push_back(fromDest->cards[i]); + } + SAFE_DELETE(rTc); + if(!selectedCards.size()) + return 0; + int r = fromDest->owner->getObserver()->getRandomGenerator()->random() % (selectedCards.size()); + MTGCardInstance * toMove = selectedCards[r]; + + + //inplay is a special zone ! + for (int i = 0; i < 2; i++) + { + if (toDest == game->players[i]->game->inPlay && fromDest != game->players[i]->game->inPlay && fromDest + != game->players[i]->opponent()->game->inPlay) + { + MTGCardInstance * copy = game->players[i]->game->putInZone(toMove, fromDest, game->players[i]->game->temp); + Spell * spell = NEW Spell(game, copy); + spell->resolve(); + delete spell; + return 1; + } + } + p->game->putInZone(toMove, fromDest, toDest); + return 1; + } + } + return 0; +} + +const char * AARandomMover::getMenuText() +{ + return "Dig"; +} + +AARandomMover * AARandomMover::clone() const +{ + AARandomMover * a = NEW AARandomMover(*this); + return a; +} + +AARandomMover::~AARandomMover() +{ +} + //Random Discard AARandomDiscarder::AARandomDiscarder(GameObserver* observer, int _id, MTGCardInstance * card, Targetable * _target,string nbcardsStr, ManaCost * _cost, int who) : diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 33d87657d..e8df964a5 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -1744,7 +1744,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG target = card; MTGAbility * a = NEW AAMover(observer, id, card, target, splitMove[1]); - a->oneShot = 1; + a->oneShot = true; if(s.find("and(") != string::npos) { vector splitAnd = parseBetween(s, "and((", " ))",false); @@ -1756,6 +1756,19 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG return a; } + //random mover + vector splitRandomMove = parseBetween(s, "moverandom(", ")"); + if (splitRandomMove.size()) + { + vector splitfrom = parseBetween(splitRandomMove[2], "from(", ")"); + vector splitto = parseBetween(splitRandomMove[2], "to(", ")"); + if(!splitfrom.size() || !splitto.size()) + return NULL; + MTGAbility * a = NEW AARandomMover(observer, id, card, target, splitRandomMove[1],splitfrom[1],splitto[1]); + a->oneShot = true; + return a; + } + //Copy a target found = s.find("copy"); if (found != string::npos)