use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class ColossalWhaleExileEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getSourceId().equals(this.getSourceId())) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls");
UUID defenderId = game.getCombat().getDefenderId(sourceId);
filter.add(new ControllerIdPredicate(defenderId));
this.getTargets().clear();
TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
this.addTarget(target);
return true;
}
return false;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class ArmWithAetherTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Player opponent = game.getPlayer(event.getPlayerId());
if (opponent != null && event.getSourceId().equals(this.sourceId)) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature " + opponent.getLogName() + " controls");
filter.add(new ControllerIdPredicate(opponent.getId()));
this.getTargets().clear();
this.addTarget(new TargetCreaturePermanent(filter));
return true;
}
return false;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class CulturalExchangeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player1 = game.getPlayer(targetPointer.getTargets(game, source).get(0));
Player player2 = game.getPlayer(targetPointer.getTargets(game, source).get(1));
Player controller = game.getPlayer(source.getControllerId());
if (player1 == null || player2 == null || controller == null) {
return false;
}
FilterCreaturePermanent filter1 = new FilterCreaturePermanent("creatures " + player1.getLogName() + " controls");
FilterCreaturePermanent filter2 = new FilterCreaturePermanent("creatures " + player2.getLogName() + " controls");
filter1.add(new ControllerIdPredicate(player1.getId()));
filter2.add(new ControllerIdPredicate(player2.getId()));
int creatureCount1 = game.getBattlefield().count(filter1, source.getSourceId(), source.getControllerId(), game);
int creatureCount2 = game.getBattlefield().count(filter2, source.getSourceId(), source.getControllerId(), game);
int creaturesToSwitch = Math.min(creatureCount1, creatureCount2);
if (creaturesToSwitch == 0) {
return true;
}
TargetCreaturePermanent target1 = new TargetCreaturePermanent(0, creaturesToSwitch, filter1, true);
if (target1.choose(Outcome.Benefit, controller.getId(), source.getSourceId(), game)) {
int otherToSwitch = target1.getTargets().size();
TargetCreaturePermanent target2 = new TargetCreaturePermanent(otherToSwitch, otherToSwitch, filter2, true);
if (target2.choose(Outcome.Benefit, controller.getId(), source.getSourceId(), game)) {
for (UUID creatureId : target1.getTargets()) {
Permanent creature = game.getPermanent(creatureId);
if (creature != null) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, player2.getId());
game.informPlayers(player2.getLogName() + " gains control of " + creature.getLogName());
effect.setTargetPointer(new FixedTarget(creature, game));
game.addEffect(effect, source);
}
}
for (UUID creatureId : target2.getTargets()) {
Permanent creature = game.getPermanent(creatureId);
if (creature != null) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, player1.getId());
game.informPlayers(player1.getLogName() + " gains control of " + creature.getLogName());
effect.setTargetPointer(new FixedTarget(creature, game));
game.addEffect(effect, source);
}
}
}
}
return true;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class AzraOddsmakerDelayedTriggeredAbility method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Permanent permanent = null;
TargetCreaturePermanent target = new TargetCreaturePermanent();
target.setNotTarget(true);
if (player.choose(Outcome.DrawCard, target, source.getSourceId(), game)) {
permanent = game.getPermanent(target.getFirstTarget());
}
if (permanent == null) {
return false;
}
game.addDelayedTriggeredAbility(new AzraOddsmakerDelayedTriggeredAbility(new MageObjectReference(permanent, game), permanent.getName()), source);
return true;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class CherishedHatchlingTriggeredAbility method getEffectToAdd.
private static Effect getEffectToAdd() {
Ability abilityToAdd = new EntersBattlefieldTriggeredAbility(new FightTargetSourceEffect().setText("you may have it fight another target creature"), true);
abilityToAdd.addTarget(new TargetCreaturePermanent(filter));
Effect effect = new GainAbilityTargetEffect(abilityToAdd, Duration.EndOfTurn, "it gains \"When this creature enters the battlefield, you may have it fight another target creature.\"", true);
return effect;
}
Aggregations