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;
}
Aggregations