Search in sources :

Example 6 with TargetCardInOpponentsGraveyard

use of mage.target.common.TargetCardInOpponentsGraveyard in project mage by magefree.

the class AgadeemOccultistEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    int allycount = 0;
    for (Permanent permanent : game.getBattlefield().getAllActivePermanents(source.getControllerId())) {
        if (permanent.hasSubtype(SubType.ALLY, game)) {
            allycount++;
        }
    }
    FilterCard filter = new FilterCard("creature card in an opponent's graveyard");
    filter.add(CardType.CREATURE.getPredicate());
    TargetCardInOpponentsGraveyard target = new TargetCardInOpponentsGraveyard(1, 1, filter);
    if (controller != null) {
        if (target.canChoose(source.getSourceId(), source.getControllerId(), game) && controller.choose(Outcome.GainControl, target, source.getSourceId(), game)) {
            if (!target.getTargets().isEmpty()) {
                Card card = game.getCard(target.getFirstTarget());
                if (card != null) {
                    if (card.getManaValue() <= allycount) {
                        return controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCardInOpponentsGraveyard(mage.target.common.TargetCardInOpponentsGraveyard) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Aggregations

TargetCardInOpponentsGraveyard (mage.target.common.TargetCardInOpponentsGraveyard)6 FilterCard (mage.filter.FilterCard)4 Player (mage.players.Player)4 Card (mage.cards.Card)3 UUID (java.util.UUID)2 ApprovingObject (mage.ApprovingObject)1 Ability (mage.abilities.Ability)1 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)1 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)1 PermanentsOnTheBattlefieldCondition (mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition)1 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)1 ConditionalAsThoughEffect (mage.abilities.decorator.ConditionalAsThoughEffect)1 ContinuousEffect (mage.abilities.effects.ContinuousEffect)1 PlayFromNotOwnHandZoneTargetEffect (mage.abilities.effects.common.asthought.PlayFromNotOwnHandZoneTargetEffect)1 OwnerIdPredicate (mage.filter.predicate.card.OwnerIdPredicate)1 Permanent (mage.game.permanent.Permanent)1 Target (mage.target.Target)1 TargetCard (mage.target.TargetCard)1 TargetPlayer (mage.target.TargetPlayer)1 TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)1