use of mage.target.Target in project mage by magefree.
the class MudslideEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (player != null && sourcePermanent != null) {
int countBattlefield = game.getBattlefield().getAllActivePermanents(filter, game.getActivePlayerId(), game).size();
while (player.canRespond() && countBattlefield > 0 && player.chooseUse(Outcome.Benefit, "Pay {2} and untap a tapped creature without flying under your control?", source, game)) {
Target tappedCreatureTarget = new TargetControlledCreaturePermanent(1, 1, filter, true);
if (player.choose(Outcome.Untap, tappedCreatureTarget, source.getSourceId(), game)) {
Cost cost = ManaUtil.createManaCost(2, false);
Permanent tappedCreature = game.getPermanent(tappedCreatureTarget.getFirstTarget());
if (tappedCreature != null && cost.pay(source, game, source, player.getId(), false)) {
tappedCreature.untap(game);
} else {
break;
}
} else {
break;
}
countBattlefield = game.getBattlefield().getAllActivePermanents(filter, game.getActivePlayerId(), game).size();
}
return true;
}
return false;
}
use of mage.target.Target in project mage by magefree.
the class OathOfGhoulsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceObject = game.getObject(source.getSourceId());
Player firstPlayer = game.getPlayer(game.getActivePlayerId());
if (sourceObject == null || firstPlayer == null) {
return false;
}
FilterCard filter = new FilterCreatureCard("creature card");
filter.add(new OwnerIdPredicate(firstPlayer.getId()));
Target target = new TargetCardInGraveyard(filter);
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), firstPlayer.getId(), game) && firstPlayer.chooseUse(outcome, "Return a creature card from your graveyard to your hand?", source, game) && firstPlayer.chooseTarget(Outcome.ReturnToHand, target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
firstPlayer.moveCards(card, Zone.HAND, source, game);
}
}
return true;
}
use of mage.target.Target in project mage by magefree.
the class PathToTheWorldTreeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
controller.gainLife(2, game, source);
controller.drawCards(2, source, game);
}
for (UUID targetId : source.getTargets().stream().map(Target::getTargets).flatMap(Collection::stream).collect(Collectors.toList())) {
Player player = game.getPlayer(targetId);
if (player != null) {
player.loseLife(2, game, source, false);
}
Permanent permanent = game.getPermanent(targetId);
if (permanent != null) {
permanent.damage(2, source.getSourceId(), source, game);
}
}
new BearToken().putOntoBattlefield(1, game, source, source.getControllerId());
return true;
}
use of mage.target.Target in project mage by magefree.
the class PrimalEmpathyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int highestPower = game.getBattlefield().getActivePermanents(source.getControllerId(), game).stream().filter(permanent1 -> permanent1.isCreature(game)).map(Permanent::getPower).mapToInt(MageInt::getValue).max().orElse(0);
boolean flag = game.getBattlefield().getAllActivePermanents(source.getControllerId()).stream().filter(permanent1 -> permanent1.isCreature(game)).map(Permanent::getPower).mapToInt(MageInt::getValue).anyMatch(i -> i >= highestPower);
if (flag) {
return player.drawCards(1, source, game) > 0;
}
Target target = new TargetControlledCreaturePermanent();
target.setNotTarget(true);
if (!player.choose(outcome, target, source.getSourceId(), game)) {
return false;
}
Permanent permanent = game.getPermanent(target.getFirstTarget());
return permanent != null && permanent.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
}
use of mage.target.Target in project mage by magefree.
the class OpponentGainControlEffect method init.
@Override
public void init(Ability source, Game game) {
super.init(source, game);
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (controller != null && permanent != null) {
if (game.getOpponents(controller.getId()).size() == 1) {
opponentId = game.getOpponents(controller.getId()).iterator().next();
} else {
Target target = new TargetOpponent(true);
controller.chooseTarget(outcome, target, source, game);
opponentId = target.getFirstTarget();
}
}
Player targetOpponent = game.getPlayer(opponentId);
if (targetOpponent != null && permanent != null) {
game.informPlayers(permanent.getLogName() + " is now controlled by " + targetOpponent.getLogName());
} else {
discard();
}
}
Aggregations