use of mage.target.common.TargetCreaturePermanent 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.target.common.TargetCreaturePermanent in project mage by magefree.
the class LedevChampionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int tappedAmount = 0;
TargetCreaturePermanent target = new TargetCreaturePermanent(0, Integer.MAX_VALUE, filter, true);
if (target.canChoose(source.getSourceId(), source.getControllerId(), game) && target.choose(Outcome.Tap, source.getControllerId(), source.getSourceId(), game)) {
for (UUID creatureId : target.getTargets()) {
Permanent creature = game.getPermanent(creatureId);
if (creature != null) {
creature.tap(source, game);
tappedAmount++;
}
}
}
if (tappedAmount > 0) {
game.addEffect(new BoostSourceEffect(tappedAmount, tappedAmount, Duration.EndOfTurn), source);
return true;
}
return false;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class MageRingResponderAbility 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 MagusOfTheAbyssTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Player player = game.getPlayer(event.getPlayerId());
if (player != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("nonartifact creature you control");
filter.add(Predicates.not(CardType.ARTIFACT.getPredicate()));
filter.add(new ControllerIdPredicate(player.getId()));
Target target = new TargetCreaturePermanent(filter);
target.setAbilityController(getControllerId());
target.setTargetController(player.getId());
this.getTargets().clear();
this.getTargets().add(target);
return true;
}
return false;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class OrderOfSuccessionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Map<UUID, UUID> playerCreature = new HashMap<>(2);
Choice choice = new ChoiceLeftOrRight();
if (!controller.choose(Outcome.Neutral, choice, game)) {
return false;
}
boolean left = choice.getChoice().equals("Left");
PlayerList playerList = game.getState().getPlayerList().copy();
// set playerlist to controller
while (!playerList.get().equals(source.getControllerId()) && controller.canRespond()) {
playerList.getNext();
}
Player currentPlayer = game.getPlayer(playerList.get());
Player nextPlayer;
UUID firstNextPlayer = null;
while (!getNextPlayerInDirection(left, playerList, game).equals(firstNextPlayer) && controller.canRespond()) {
nextPlayer = game.getPlayer(playerList.get());
if (nextPlayer == null) {
return false;
}
// save first next player to check for iteration stop
if (firstNextPlayer == null) {
firstNextPlayer = nextPlayer.getId();
}
if (!nextPlayer.canRespond()) {
continue;
}
// if player is in range they choose a creature to control
if (currentPlayer != null && game.getState().getPlayersInRange(controller.getId(), game).contains(currentPlayer.getId())) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature controlled by " + nextPlayer.getLogName());
filter.add(new ControllerIdPredicate(nextPlayer.getId()));
Target target = new TargetCreaturePermanent(filter);
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), currentPlayer.getId(), game)) {
if (currentPlayer.chooseTarget(outcome, target, source, game)) {
playerCreature.put(currentPlayer.getId(), target.getFirstTarget());
}
}
}
currentPlayer = nextPlayer;
}
// change control of targets
for (Map.Entry<UUID, UUID> entry : playerCreature.entrySet()) {
Player player = game.getPlayer(entry.getKey());
if (player != null) {
Permanent creature = game.getPermanent(entry.getValue());
if (creature != null) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame, player.getId());
effect.setTargetPointer(new FixedTarget(creature.getId(), game));
game.addEffect(effect, source);
game.informPlayers(new StringBuilder(player.getLogName()).append(" gains control of ").append(creature.getName()).toString());
}
}
}
return true;
}
return false;
}
Aggregations