use of mage.target.TargetPlayer in project mage by magefree.
the class NightmareIncursionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (controller == null || targetPlayer == null) {
return false;
}
int amount = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game);
TargetCardInLibrary target = new TargetCardInLibrary(0, amount, StaticFilters.FILTER_CARD);
if (controller.searchLibrary(target, source, game, targetPlayer.getId())) {
Cards cards = new CardsImpl(target.getTargets());
controller.moveCards(cards, Zone.EXILED, source, game);
}
targetPlayer.shuffleLibrary(source, game);
return true;
}
use of mage.target.TargetPlayer in project mage by magefree.
the class WrenchMindEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
if (targetPlayer == null || targetPlayer.getHand().isEmpty()) {
return false;
}
if (targetPlayer.getHand().count(StaticFilters.FILTER_CARD_ARTIFACT, game) < 1 || !targetPlayer.chooseUse(Outcome.Benefit, "Discard an artifact card?", source, game)) {
return !targetPlayer.discard(2, false, false, source, game).isEmpty();
}
TargetDiscard target = new TargetDiscard(StaticFilters.FILTER_CARD_ARTIFACT_AN, targetPlayer.getId());
targetPlayer.choose(Outcome.Discard, target, source.getSourceId(), game);
Card card = targetPlayer.getHand().get(target.getFirstTarget(), game);
if (card != null && targetPlayer.discard(card, false, source, game)) {
return true;
}
return !targetPlayer.discard(2, false, false, source, game).isEmpty();
}
use of mage.target.TargetPlayer in project mage by magefree.
the class AssistEffect method addSpecialAction.
@Override
public void addSpecialAction(Ability source, Game game, ManaCost unpaid) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && source.getAbilityType() == AbilityType.SPELL && unpaid.getMana().getGeneric() >= 1 && game.getState().getValue(source.getSourceId().toString() + game.getState().getZoneChangeCounter(source.getSourceId()) + "_assisted") == null) {
SpecialAction specialAction = new AssistSpecialAction(unpaid, this);
specialAction.setControllerId(source.getControllerId());
specialAction.setSourceId(source.getSourceId());
Target target = new TargetPlayer(1, 1, true, filter);
specialAction.addTarget(target);
if (specialAction.canActivate(source.getControllerId(), game).canActivate()) {
game.getState().getSpecialActions().add(specialAction);
}
}
}
use of mage.target.TargetPlayer in project mage by magefree.
the class CapricopianEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (player == null || permanent == null) {
return false;
}
if (!player.chooseUse(outcome, "Reselect attacker for " + permanent.getIdName() + "?", source, game)) {
return false;
}
FilterPlayer filterPlayer = new FilterPlayer();
filterPlayer.add(Predicates.not(new PlayerIdPredicate(permanent.getControllerId())));
filterPlayer.add(Predicates.not(new PlayerIdPredicate(game.getCombat().getDefenderId(permanent.getId()))));
TargetPlayer targetPlayer = new TargetPlayer(0, 1, true, filterPlayer);
player.choose(outcome, targetPlayer, source.getSourceId(), game);
Player newPlayer = game.getPlayer(targetPlayer.getFirstTarget());
if (newPlayer == null) {
return false;
}
game.getCombat().removeAttacker(permanent.getId(), game);
return game.getCombat().addAttackingCreature(permanent.getId(), game, newPlayer.getId());
}
use of mage.target.TargetPlayer in project mage by magefree.
the class DoOrDieEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (player != null && targetPlayer != null) {
int count = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURES, targetPlayer.getId(), game);
TargetCreaturePermanent creatures = new TargetCreaturePermanent(0, count, new FilterCreaturePermanent("creatures to put in the first pile"), true);
List<Permanent> pile1 = new ArrayList<>();
creatures.setRequired(false);
if (player.choose(Outcome.Neutral, creatures, source.getSourceId(), game)) {
List<UUID> targets = creatures.getTargets();
for (UUID targetId : targets) {
Permanent p = game.getPermanent(targetId);
if (p != null) {
pile1.add(p);
}
}
}
List<Permanent> pile2 = new ArrayList<>();
for (Permanent p : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, targetPlayer.getId(), game)) {
if (!pile1.contains(p)) {
pile2.add(p);
}
}
boolean choice = targetPlayer.choosePile(Outcome.DestroyPermanent, "Choose a pile to destroy.", pile1, pile2, game);
if (choice) {
destroyPermanents(pile1, game, source);
} else {
destroyPermanents(pile2, game, source);
}
return true;
}
return false;
}
Aggregations