use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class CloudstoneCurioEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent triggeringCreature = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (triggeringCreature != null) {
FilterPermanent filter = new FilterPermanent("another permanent you control that shares a permanent type with " + triggeringCreature.getName());
filter.add(Predicates.not(new PermanentIdPredicate(triggeringCreature.getId())));
filter.add(TargetController.YOU.getControllerPredicate());
filter.add(Predicates.or(triggeringCreature.getCardType(game).stream().filter(CardType::isPermanentType).map(CardType::getPredicate).collect(Collectors.toSet())));
TargetPermanent target = new TargetPermanent(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseTarget(outcome, target, source, game)) {
Permanent returningCreature = game.getPermanent(target.getFirstTarget());
if (returningCreature != null) {
controller.moveCards(returningCreature, Zone.HAND, source, game);
}
}
}
return true;
}
return false;
}
use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class CrownOfTheAgesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent aura = game.getPermanent(source.getFirstTarget());
if (aura == null) {
return false;
}
Permanent fromPermanent = game.getPermanent(aura.getAttachedTo());
Player controller = game.getPlayer(source.getControllerId());
if (fromPermanent == null || controller == null) {
return false;
}
boolean passed = true;
FilterCreaturePermanent filterChoice = new FilterCreaturePermanent("another creature");
filterChoice.add(Predicates.not(new PermanentIdPredicate(fromPermanent.getId())));
Target chosenCreatureToAttachAura = new TargetPermanent(filterChoice);
chosenCreatureToAttachAura.setNotTarget(true);
if (chosenCreatureToAttachAura.canChoose(source.getSourceId(), source.getControllerId(), game) && controller.choose(Outcome.Neutral, chosenCreatureToAttachAura, source.getSourceId(), game)) {
Permanent creatureToAttachAura = game.getPermanent(chosenCreatureToAttachAura.getFirstTarget());
if (creatureToAttachAura != null) {
if (passed) {
// Check the target filter
Target target = aura.getSpellAbility().getTargets().get(0);
if (target instanceof TargetPermanent) {
if (!target.getFilter().match(creatureToAttachAura, game)) {
passed = false;
}
}
// Check for protection
MageObject auraObject = game.getObject(aura.getId());
if (auraObject != null && creatureToAttachAura.cantBeAttachedBy(auraObject, source, game, true)) {
passed = false;
}
}
if (passed) {
fromPermanent.removeAttachment(aura.getId(), source, game);
creatureToAttachAura.addAttachment(aura.getId(), source, game);
return true;
}
}
}
return true;
}
use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class ArmoryAutomatonEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (player != null && sourcePermanent != null) {
// dynamic filter (can't selects own attaches and can't selects twice)
FilterPermanent currentFilter = new FilterEquipmentPermanent();
FilterPermanent filterSourceId = new FilterPermanent();
filterSourceId.add(new CardIdPredicate(source.getSourceId()));
currentFilter.add(Predicates.not(new AttachedToPredicate(filterSourceId)));
int countBattlefield = game.getBattlefield().getAllActivePermanents(currentFilter, game).size();
while (player.canRespond() && countBattlefield > 0 && player.chooseUse(Outcome.Benefit, "Select and attach a target Equipment?", source, game)) {
Target targetEquipment = new TargetPermanent(currentFilter);
targetEquipment.setRequired(false);
if (player.choose(Outcome.Benefit, targetEquipment, source.getSourceId(), game) && targetEquipment.getFirstTarget() != null) {
// exclude selected for next time
currentFilter.add(Predicates.not(new PermanentIdPredicate(targetEquipment.getFirstTarget())));
Permanent aura = game.getPermanent(targetEquipment.getFirstTarget());
if (aura != null) {
Permanent attachedTo = game.getPermanent(aura.getAttachedTo());
if (attachedTo != null) {
attachedTo.removeAttachment(aura.getId(), source, game);
}
sourcePermanent.addAttachment(aura.getId(), source, game);
}
} else {
break;
}
countBattlefield = game.getBattlefield().getAllActivePermanents(currentFilter, game).size();
}
return true;
}
return false;
}
use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class BackslideEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Predicate pred = new PermanentIdPredicate(UUID.randomUUID());
for (Target target : source.getTargets()) {
for (UUID targetId : target.getTargets()) {
pred = Predicates.or(pred, new PermanentIdPredicate(targetId));
}
}
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(pred);
game.addEffect(new BecomesFaceDownCreatureAllEffect(filter), source);
return true;
}
use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class DanceOfTheDeadDoIfCostPaidEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent enchantment = game.getPermanent(source.getSourceId());
if (controller != null && enchantment != null) {
Card cardInGraveyard = game.getCard(enchantment.getAttachedTo());
if (cardInGraveyard == null) {
return true;
}
// put card into play
controller.moveCards(cardInGraveyard, Zone.BATTLEFIELD, source, game, true, false, false, null);
Permanent enchantedCreature = game.getPermanent(cardInGraveyard.getId());
FilterCreaturePermanent filter = new FilterCreaturePermanent("enchant creature put onto the battlefield with Dance of the Dead");
filter.add(new PermanentIdPredicate(cardInGraveyard.getId()));
Target target = new TargetCreaturePermanent(filter);
// enchantAbility.setTargetName(target.getTargetName());
if (enchantedCreature != null) {
target.addTarget(enchantedCreature.getId(), source, game);
enchantment.getSpellAbility().getTargets().clear();
enchantment.getSpellAbility().getTargets().add(target);
enchantedCreature.addAttachment(enchantment.getId(), source, game);
}
return true;
}
return false;
}
Aggregations