/** * Face down cards and their copy tokens don't have names and that's "empty" names is not equals */ public static boolean haveSameNames(String name1, String name2, Boolean ignoreMtgRuleForEmptyNames) { if (ignoreMtgRuleForEmptyNames) { // simple compare for tests and engine return name1 != null && name2 != null && name1.equals(name2); } else { // mtg logic compare for game (empty names can't be same) return !haveEmptyName(name1) && !haveEmptyName(name2) && name1.equals(name2); } }
public static boolean haveEmptyName(MageObject object) { return object == null || haveEmptyName(object.getName()); } }
@Override public void init(Ability source, Game game) { super.init(source, game); affectedObjectList.clear(); if (this.affectedObjectsSet) { Permanent target = game.getPermanent(getTargetPointer().getFirst(game, source)); if (target != null) { if (CardUtil.haveEmptyName(target)) { // face down creature affectedObjectList.add(new MageObjectReference(target, game)); } else { String name = target.getName(); for (Permanent perm : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) { if (CardUtil.haveSameNames(perm.getName(), name)) { affectedObjectList.add(new MageObjectReference(perm, game)); } } } } } }
Set<Card> cardsToExile = new HashSet<>(); int nonTokenCount = 0; if (CardUtil.haveEmptyName(targetPermanent)) { // face down creature cardsToExile.add(targetPermanent); if (!(targetPermanent instanceof PermanentToken)) {
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source)); if (targetCreature != null) { controller.moveCards(targetCreature, Zone.HAND, source, game); if (!CardUtil.haveEmptyName(targetCreature)) { // if the creature had no name, no restrict effect will be created game.addEffect(new ExclusionRitualReplacementEffect(targetCreature.getName(), targetCreature.getOwnerId()), source); } } return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Permanent targetPermanent = game.getPermanent(targetPointer.getFirst(game, source)); if (targetPermanent != null) { FilterCreaturePermanent filter = new FilterCreaturePermanent(); if (CardUtil.haveEmptyName(targetPermanent)) { filter.add(new PermanentIdPredicate(targetPermanent.getId())); // if no name (face down creature) only the creature itself is selected } else { filter.add(new NamePredicate(targetPermanent.getName())); } ContinuousEffect effect = new BoostAllEffect(-2, -2, Duration.EndOfTurn, filter, false); game.addEffect(effect, source); return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Permanent targetPermanent = game.getPermanent(targetPointer.getFirst(game, source)); if (targetPermanent != null) { FilterCreaturePermanent filter = new FilterCreaturePermanent(); if (CardUtil.haveEmptyName(targetPermanent)) { filter.add(new PermanentIdPredicate(targetPermanent.getId())); // if no name (face down creature) only the creature itself is selected } else { filter.add(new NamePredicate(targetPermanent.getName())); } ContinuousEffect effect = new BoostAllEffect(2, 2, Duration.EndOfTurn, filter, false); game.addEffect(effect, source); return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source)); if (controller != null && permanent != null) { permanent.destroy(source.getSourceId(), game, false); if (!CardUtil.haveEmptyName(permanent)) { // in case of face down enchantment creature for (Permanent perm : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) { if (!perm.getId().equals(permanent.getId()) && CardUtil.haveSameNames(perm, permanent) && perm.isEnchantment()) { perm.destroy(source.getSourceId(), game, false); } } } return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source)); if (controller != null && permanent != null) { permanent.destroy(source.getSourceId(), game, false); if (!CardUtil.haveEmptyName(permanent)) { // in case of face down artifact creature for (Permanent perm : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) { if (!perm.getId().equals(permanent.getId()) && CardUtil.haveSameNames(perm, permanent) && perm.isArtifact()) { perm.destroy(source.getSourceId(), game, false); } } } return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Permanent targetPermanent = game.getPermanent(source.getFirstTarget()); if (targetPermanent == null) { return false; } FilterCreaturePermanent filter = new FilterCreaturePermanent(); if (CardUtil.haveEmptyName(targetPermanent)) { filter.add(new PermanentIdPredicate(targetPermanent.getId())); // if no name (face down creature) only the creature itself is selected } else { filter.add(new NamePredicate(targetPermanent.getName())); } for (Permanent creature : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) { if (creature != null) { creature.damage(4, source.getSourceId(), game, false, true); } } return true; }
@Override public boolean apply(Game game, Ability source) { Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source)); if (targetPermanent == null) { return false; } FilterPermanent filter = new FilterPermanent(); if (CardUtil.haveEmptyName(targetPermanent)) { filter.add(new PermanentIdPredicate(targetPermanent.getId())); // if no name (face down creature) only the creature itself is selected } else { filter.add(new NamePredicate(targetPermanent.getName())); } for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) { perm.destroy(source.getSourceId(), game, false); } return true; }
@Override public boolean apply(Game game, Ability source) { Permanent targetPermanent = game.getPermanent(targetPointer.getFirst(game, source)); if (targetPermanent != null) { FilterCreaturePermanent filter = new FilterCreaturePermanent(); if (CardUtil.haveEmptyName(targetPermanent)) { filter.add(new PermanentIdPredicate(targetPermanent.getId())); // if no name (face down creature) only the creature itself is selected } else { filter.add(new NamePredicate(targetPermanent.getName())); } for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { permanent.damage(1, source.getSourceId(), game, false, true); } return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Permanent targetPermanent = game.getPermanent(targetPointer.getFirst(game, source)); if (controller != null && targetPermanent != null) { FilterCreaturePermanent filter = new FilterCreaturePermanent(); if (CardUtil.haveEmptyName(targetPermanent)) { filter.add(new PermanentIdPredicate(targetPermanent.getId())); // if no name (face down creature) only the creature itself is selected } else { filter.add(new NamePredicate(targetPermanent.getName())); } for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { controller.moveCardToExileWithInfo(permanent, null, "", source.getSourceId(), game, Zone.BATTLEFIELD, true); } return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Permanent permanent = game.getPermanent(source.getFirstTarget()); if (controller != null && permanent != null) { FilterPermanent filter = new FilterPermanent(); if (CardUtil.haveEmptyName(permanent)) { filter.add(new PermanentIdPredicate(permanent.getId())); // if no name (face down creature) only the creature itself is selected } else { filter.add(new NamePredicate(permanent.getName())); } Cards cardsToHand = new CardsImpl(); for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) { cardsToHand.add(perm); } controller.moveCards(cardsToHand, Zone.HAND, source, game); return true; } return true; }
@Override public boolean apply(Game game, Ability source) { UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()); Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source)); Player controller = game.getPlayer(source.getControllerId()); MageObject sourceObject = game.getObject(source.getSourceId()); if (sourceObject != null && exileId != null && targetPermanent != null && controller != null) { if (CardUtil.haveEmptyName(targetPermanent)) { // face down creature controller.moveCardToExileWithInfo(targetPermanent, exileId, sourceObject.getIdName(), source.getSourceId(), game, Zone.BATTLEFIELD, true); } else { String name = targetPermanent.getName(); for (Permanent permanent : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) { if (permanent != null && CardUtil.haveSameNames(permanent.getName(), name)) { controller.moveCardToExileWithInfo(permanent, exileId, sourceObject.getIdName(), source.getSourceId(), game, Zone.BATTLEFIELD, true); } } } return true; } return false; }