use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class RelicOfProgenitusEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (targetPlayer != null) {
FilterCard filter = new FilterCard("card from your graveyard");
filter.add(new OwnerIdPredicate(targetPlayer.getId()));
TargetCardInGraveyard target = new TargetCardInGraveyard(filter);
if (targetPlayer.chooseTarget(Outcome.Exile, target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
targetPlayer.moveCardToExileWithInfo(card, null, "", source, game, Zone.GRAVEYARD, true);
}
return true;
}
}
return false;
}
use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class TemptWithImmortalityEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
returnCreatureFromGraveToBattlefield(controller, source, game);
int opponentsReturnedCreatures = 0;
for (UUID playerId : game.getOpponents(controller.getId())) {
Player opponent = game.getPlayer(playerId);
if (opponent != null) {
FilterCard filter = new FilterCreatureCard("creature card from your graveyard");
filter.add(new OwnerIdPredicate(opponent.getId()));
Target targetCardOpponent = new TargetCardInGraveyard(filter);
if (targetCardOpponent.canChoose(source.getSourceId(), opponent.getId(), game)) {
if (opponent.chooseUse(outcome, "Return a creature card from your graveyard to the battlefield?", source, game)) {
if (opponent.chooseTarget(outcome, targetCardOpponent, source, game)) {
Card card = game.getCard(targetCardOpponent.getFirstTarget());
if (card != null) {
opponentsReturnedCreatures++;
opponent.moveCards(card, Zone.BATTLEFIELD, source, game);
}
}
}
}
}
}
if (opponentsReturnedCreatures > 0) {
for (int i = 0; i < opponentsReturnedCreatures; i++) {
returnCreatureFromGraveToBattlefield(controller, source, game);
}
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class VirtussManeuverEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
ChooseFriendsAndFoes choice = new ChooseFriendsAndFoes();
if (controller != null && !choice.chooseFriendOrFoe(controller, source, game)) {
return false;
}
Map<UUID, Card> getBackMap = new HashMap<>();
for (Player player : choice.getFriends()) {
if (player == null) {
continue;
}
FilterCard filter = new FilterCreatureCard("creature card in your graveyard");
filter.add(new OwnerIdPredicate(player.getId()));
TargetCardInGraveyard target = new TargetCardInGraveyard(filter);
getBackMap.put(player.getId(), null);
if (player.choose(Outcome.ReturnToHand, target, source.getSourceId(), game)) {
getBackMap.put(player.getId(), game.getCard(target.getFirstTarget()));
}
}
for (Player player : choice.getFriends()) {
if (player == null) {
continue;
}
Card card = getBackMap.getOrDefault(player.getId(), null);
if (card == null) {
continue;
}
player.moveCards(card, Zone.HAND, source, game);
}
List<UUID> perms = new ArrayList<>();
for (Player player : choice.getFoes()) {
if (player == null) {
continue;
}
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, StaticFilters.FILTER_CONTROLLED_A_CREATURE, true);
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
perms.addAll(target.getTargets());
}
for (UUID permID : perms) {
Permanent permanent = game.getPermanent(permID);
if (permanent != null) {
permanent.sacrifice(source, game);
}
}
return true;
}
use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class AuraReplacementEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Zone fromZone = ((ZoneChangeEvent) event).getFromZone();
Card card = game.getCard(event.getTargetId());
if (card == null) {
return false;
}
Card firstCardFace = null;
if (game.getState().getValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + card.getId()) != null) {
firstCardFace = card;
card = card.getSecondCardFace();
if (!card.isEnchantment(game) || !card.hasSubtype(SubType.AURA, game)) {
return false;
}
}
// Aura cards that go to battlefield face down (Manifest) don't have to select targets
if (card.isFaceDown(game)) {
return false;
}
// Aura enters the battlefield attached
Object object = game.getState().getValue("attachTo:" + card.getId());
if (object != null) {
if (object instanceof Permanent) {
// Aura is attached to a permanent on the battlefield
return false;
}
if (object instanceof UUID) {
Player player = game.getPlayer((UUID) object);
if (player != null) {
// Aura is attached to a player
return false;
}
}
}
UUID targetId = null;
MageObject sourceObject = game.getObject(event.getSourceId());
boolean enchantCardInGraveyard = false;
if (sourceObject instanceof StackAbility) {
StackAbility stackAbility = (StackAbility) sourceObject;
if (!stackAbility.getEffects().isEmpty()) {
targetId = stackAbility.getEffects().get(0).getTargetPointer().getFirst(game, stackAbility);
}
}
// So continuousEffects are removed if previous effect of the same ability did move objects that cause continuous effects
game.applyEffects();
Player controllingPlayer = null;
if (targetId == null) {
SpellAbility spellAbility = card.getSpellAbility();
if (spellAbility.getTargets().isEmpty()) {
for (Ability ability : card.getAbilities(game)) {
if ((ability instanceof SpellAbility) && SpellAbilityType.BASE_ALTERNATE == ((SpellAbility) ability).getSpellAbilityType() && !ability.getTargets().isEmpty()) {
spellAbility = (SpellAbility) ability;
break;
}
}
}
if (spellAbility.getTargets().isEmpty()) {
return false;
}
Target target = spellAbility.getTargets().get(0).copy();
Outcome auraOutcome = Outcome.BoostCreature;
for (Effect effect : spellAbility.getEffects()) {
if (effect instanceof AttachEffect) {
auraOutcome = effect.getOutcome();
break;
}
}
enchantCardInGraveyard = target instanceof TargetCardInGraveyard;
if (target != null) {
// always not target because this way it's not handled targeted
target.setNotTarget(true);
// necessary if e.g. aura is blinked multiple times
target.clearChosen();
}
if (event.getPlayerId() != null) {
controllingPlayer = game.getPlayer(event.getPlayerId());
} else {
controllingPlayer = game.getPlayer(card.getOwnerId());
}
if (target != null && controllingPlayer != null && controllingPlayer.choose(auraOutcome, target, card.getId(), game)) {
targetId = target.getFirstTarget();
}
}
Card targetCard = null;
Permanent targetPermanent = null;
if (enchantCardInGraveyard) {
targetCard = game.getCard(targetId);
} else {
targetPermanent = game.getPermanent(targetId);
}
Player targetPlayer = game.getPlayer(targetId);
if (targetCard != null || targetPermanent != null || targetPlayer != null) {
if (firstCardFace != null) {
// transforming card. remove first face (original card) from old zone
firstCardFace.removeFromZone(game, fromZone, source);
} else {
card.removeFromZone(game, fromZone, source);
}
PermanentCard permanent = new PermanentCard(card, (controllingPlayer == null ? card.getOwnerId() : controllingPlayer.getId()), game);
ZoneChangeEvent zoneChangeEvent = new ZoneChangeEvent(permanent, event.getPlayerId(), fromZone, Zone.BATTLEFIELD);
permanent.updateZoneChangeCounter(game, zoneChangeEvent);
game.addPermanent(permanent, 0);
card.setZone(Zone.BATTLEFIELD, game);
if (permanent.entersBattlefield(source, game, fromZone, true)) {
String attachToName = null;
if (targetCard != null) {
permanent.attachTo(targetCard.getId(), source, game);
attachToName = targetCard.getLogName();
} else if (targetPermanent != null) {
targetPermanent.addAttachment(permanent.getId(), source, game);
attachToName = targetPermanent.getLogName();
} else if (targetPlayer != null) {
targetPlayer.addAttachment(permanent.getId(), source, game);
attachToName = targetPlayer.getLogName();
}
game.applyEffects();
game.fireEvent(zoneChangeEvent);
if (!game.isSimulation()) {
if (controllingPlayer != null && fromZone != null && permanent != null) {
game.informPlayers(controllingPlayer.getLogName() + " puts " + (card.getLogName()) + " from " + fromZone.toString().toLowerCase(Locale.ENGLISH) + " onto the Battlefield attached to " + attachToName);
}
}
return true;
}
}
return false;
}
use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class TasigurTheGoldenFangEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
UUID opponentId = null;
if (game.getOpponents(controller.getId()).size() > 1) {
Target target = new TargetOpponent(true);
if (controller.chooseTarget(outcome, target, source, game)) {
opponentId = target.getFirstTarget();
}
} else {
opponentId = game.getOpponents(controller.getId()).iterator().next();
}
if (opponentId != null) {
Player opponent = game.getPlayer(opponentId);
if (opponent != null) {
FilterNonlandCard filter = new FilterNonlandCard("nonland card from " + controller.getLogName() + " graveyard");
filter.add(new OwnerIdPredicate(controller.getId()));
Target target = new TargetCardInGraveyard(filter);
target.setNotTarget(true);
opponent.chooseTarget(outcome, target, source, game);
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
controller.moveCards(card, Zone.HAND, source, game);
}
}
}
return true;
}
return false;
}
Aggregations