use of mage.filter.predicate.permanent.ControllerIdPredicate in project mage by magefree.
the class FallOfTheImpostorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(source.getFirstTarget());
if (controller != null && opponent != null) {
List<Permanent> permanents = game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, opponent.getId(), game);
Integer maxPower = null;
for (Permanent permanent : permanents) {
if (permanent != null) {
int power = permanent.getPower().getValue();
if (maxPower == null || power > maxPower) {
maxPower = power;
}
}
}
if (maxPower != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(new ControllerIdPredicate(opponent.getId()));
filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, maxPower));
TargetCreaturePermanent target = new TargetCreaturePermanent(1, 1, filter, true);
controller.chooseTarget(outcome, target, source, game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
controller.moveCardsToExile(permanent, source, game, true, null, null);
return true;
}
}
}
return false;
}
use of mage.filter.predicate.permanent.ControllerIdPredicate in project mage by magefree.
the class FlamesOfTheRazeBoarEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent == null) {
return false;
}
permanent.damage(4, source.getSourceId(), source, game);
if (!FerociousCondition.instance.apply(game, source)) {
return true;
}
FilterPermanent filter = new FilterCreaturePermanent();
filter.add(new ControllerIdPredicate(permanent.getControllerId()));
filter.add(Predicates.not(new PermanentIdPredicate(permanent.getId())));
return new DamageAllEffect(2, filter).apply(game, source);
}
use of mage.filter.predicate.permanent.ControllerIdPredicate in project mage by magefree.
the class GraspOfTheHieromancerTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (game.getCombat().getAttackers().contains(getSourceId())) {
UUID defendingPlayerId = game.getCombat().getDefendingPlayerId(getSourceId(), game);
if (defendingPlayerId != null) {
this.getTargets().clear();
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls");
UUID defenderId = game.getCombat().getDefenderId(getSourceId());
filter.add(new ControllerIdPredicate(defenderId));
TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
this.addTarget(target);
return true;
}
}
return false;
}
use of mage.filter.predicate.permanent.ControllerIdPredicate in project mage by magefree.
the class GrandMoffTarkinEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (game.getOpponents(controllerId).contains(event.getPlayerId())) {
Player opponent = game.getPlayer(event.getPlayerId());
if (opponent != null) {
this.getTargets().clear();
FilterCreaturePermanent filter = new FilterCreaturePermanent("target creature that player controls");
filter.add(new ControllerIdPredicate(event.getPlayerId()));
TargetPermanent target = new TargetPermanent(filter);
this.addTarget(target);
return true;
}
}
return false;
}
use of mage.filter.predicate.permanent.ControllerIdPredicate in project mage by magefree.
the class HansErikssonEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Card card = player.getLibrary().getFromTop(game);
if (card == null) {
return false;
}
player.revealCards(source, new CardsImpl(card), game);
if (!card.isCreature(game)) {
return player.moveCards(card, Zone.HAND, source, game);
}
player.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
Permanent permanent = game.getPermanent(card.getId());
if (permanent == null) {
return true;
}
UUID defendingPlayerId = getTargetPointer().getFirst(game, source);
UUID defenderId;
if (game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_PERMANENT_PLANESWALKER, source.getSourceId(), defendingPlayerId, game) < 1) {
defenderId = defendingPlayerId;
} else {
FilterPlayerOrPlaneswalker filter = new FilterPlayerOrPlaneswalker("defending player or a planeswalker they control");
filter.getPlayerFilter().add(new PlayerIdPredicate(defendingPlayerId));
filter.getPermanentFilter().add(new ControllerIdPredicate(defendingPlayerId));
TargetPlayerOrPlaneswalker target = new TargetPlayerOrPlaneswalker(filter);
target.setNotTarget(true);
player.choose(outcome, target, source.getSourceId(), game);
defenderId = target.getFirstTarget();
}
if (defenderId != null) {
game.getCombat().addAttackerToCombat(permanent.getId(), defenderId, game);
}
Effect fightEffect = new FightTargetSourceEffect();
fightEffect.setTargetPointer(new FixedTarget(permanent, game));
ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(fightEffect, false, "When you put a creature card onto the battlefield this way, it fights {this}");
game.fireReflexiveTriggeredAbility(ability, source);
return true;
}
Aggregations