public static boolean haveSameNames(String name1, String name2) { return haveSameNames(name1, name2, false); }
public static boolean haveSameNames(MageObject object1, MageObject object2) { return object1 != null && object2 != null && haveSameNames(object1.getName(), object2.getName()); }
@Override public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) { Permanent permanent = input.getObject(); Permanent twin = game.getPermanent(input.getSourceId()); return CardUtil.haveSameNames(permanent, twin); }
@Override public boolean applies(GameEvent event, Ability source, Game game) { if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { MageObject object = game.getObject(event.getSourceId()); String needName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); return object != null && CardUtil.haveSameNames(object.getName(), needName); } return false; } }
@Override public boolean applies(Ability abilityToModify, Ability source, Game game) { if ((abilityToModify instanceof SpellAbility) && abilityToModify.isControlledBy(source.getControllerId())) { Card card = game.getCard(abilityToModify.getSourceId()); if (card != null) { String needName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); return CardUtil.haveSameNames(card.getName(), needName); } } return false; }
@Override public boolean applies(GameEvent event, Ability source, Game game) { Card card = game.getCard(event.getSourceId()); if (card != null) { Spell spell = game.getState().getStack().getSpell(event.getSourceId()); if (spell != null && spell.isFaceDown(game)) { return false; // Face Down cast spell (Morph creature) has no name } return CardUtil.haveSameNames(card.getName(), creatureName) && Objects.equals(ownerId, card.getOwnerId()); } return false; }
@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)); } } } } } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Player targetPlayer = game.getPlayer(source.getFirstTarget()); String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); if (controller != null && targetPlayer != null && cardName != null && !cardName.isEmpty()) { Card card = targetPlayer.getLibrary().getFromTop(game); if (card != null) { controller.moveCards(card, Zone.GRAVEYARD, source, game); if (CardUtil.haveSameNames(card.getName(), cardName)) { controller.drawCards(1, game); } } return true; } return false; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Player targetPlayer = game.getPlayer(source.getFirstTarget()); String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); if (controller != null && targetPlayer != null && cardName != null && !cardName.isEmpty()) { int amount = 1; Card card = targetPlayer.getLibrary().getFromTop(game); if (card != null) { controller.moveCards(card, Zone.GRAVEYARD, source, game); if (CardUtil.haveSameNames(card.getName(), cardName)) { amount = 2; } } controller.drawCards(amount, game); return true; } return false; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Player targetPlayer = game.getPlayer(source.getFirstTarget()); String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); if (controller != null && targetPlayer != null && cardName != null && !cardName.isEmpty()) { Card card = targetPlayer.getLibrary().getFromTop(game); if (card != null) { controller.moveCards(card, Zone.GRAVEYARD, source, game); if (CardUtil.haveSameNames(card.getName(), cardName)) { controller.gainLife(card.getConvertedManaCost(), game, source); } } return true; } return false; }
@Override public boolean applies(GameEvent event, Ability source, Game game) { if (event.getType() == EventType.CAST_SPELL && game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { MageObject object = game.getObject(event.getSourceId()); if (object != null) { ExileZone exileZone = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source)); if ((exileZone != null)) { for (Card card : exileZone.getCards(game)) { if (CardUtil.haveSameNames(card, object)) { return true; } } } } } return false; } }
@Override public boolean applies(GameEvent event, Ability source, Game game) { if (event.getType() == GameEvent.EventType.DAMAGE_PLAYER && event.getPlayerId().equals(source.getControllerId())) { return true; } if (event.getType() == GameEvent.EventType.DAMAGE_CREATURE || event.getType() == GameEvent.EventType.DAMAGE_PLANESWALKER) { Permanent targetPermanent = game.getPermanent(event.getTargetId()); Permanent sourcePermanent = game.getPermanent(source.getSourceId()); if (targetPermanent != null && targetPermanent.isControlledBy(source.getControllerId()) && !CardUtil.haveSameNames(targetPermanent, sourcePermanent)) { // no redirection from or to other Palisade Giants return true; } } return false; }
@Override public boolean checkTrigger(GameEvent event, Game game) { if (event.getPlayerId().equals(this.getControllerId())) { Spell spell = game.getStack().getSpell(event.getTargetId()); if (isControlledInstantOrSorcery(spell)) { Card sourceCard = game.getCard(spell.getSourceId()); if (sourceCard != null) { for (UUID uuid : game.getPlayer(this.getControllerId()).getGraveyard()) { if (!uuid.equals(sourceCard.getId())) { Card card = game.getCard(uuid); if (CardUtil.haveSameNames(card, sourceCard)) { return true; } } } } } } return false; }
@Override public boolean apply(Game game, Ability source) { Player opponent = game.getPlayer(targetPointer.getFirst(game, source)); MageObject sourceObject = game.getObject(source.getSourceId()); String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); if (opponent != null && sourceObject != null && !cardName.isEmpty()) { if (!opponent.getHand().isEmpty()) { Cards revealed = new CardsImpl(); Card card = opponent.getHand().getRandom(game); if (card != null) { revealed.add(card); opponent.revealCards(sourceObject.getName(), revealed, game); if (CardUtil.haveSameNames(card.getName(), cardName)) { opponent.discard(card, source, game); } } } 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) { 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) { Spell targetSpell = game.getStack().getSpell(source.getFirstTarget()); if (targetSpell == null) { return true; } Player player = game.getPlayer(targetSpell.getControllerId()); Object object = game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); if (player != null && object instanceof String) { player.revealCards("Denied!", player.getHand(), game, true); String namedCard = (String) object; for (Card card : player.getHand().getCards(game)) { if (card != null && CardUtil.haveSameNames(card.getName(), namedCard)) { game.getStack().counter(targetSpell.getId(), source.getSourceId(), game); break; } } return true; } return false; }
@Override public boolean apply(Game game, Ability source) { Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source)); Player controller = game.getPlayer(source.getControllerId()); MageObject sourceObject = game.getObject(source.getSourceId()); String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); if (targetPlayer != null && controller != null && sourceObject != null && cardName != null) { boolean hasDiscarded = false; for (Card card : targetPlayer.getHand().getCards(game)) { if (CardUtil.haveSameNames(card.getName(), cardName)) { targetPlayer.discard(card, source, game); hasDiscarded = true; break; } } if (!hasDiscarded) { controller.drawCards(1, game); } controller.lookAtCards(sourceObject.getName() + " Hand", targetPlayer.getHand(), game); } return true; }
@Override public boolean checkTrigger(GameEvent event, Game game) { Player controller = game.getPlayer(getControllerId()); if (controller != null && controller.hasOpponent(event.getPlayerId(), game)) { Spell spell = game.getStack().getSpell(event.getSourceId()); if (spell != null && !spell.isFaceDown(game) && (spell.isCreature() || spell.isPlaneswalker())) { Player opponent = game.getPlayer(event.getPlayerId()); if(opponent != null) { boolean sameName = false; for (Card graveCard : opponent.getGraveyard().getCards(game)) { if (CardUtil.haveSameNames(graveCard, spell)) { sameName = true; break; } } if (sameName) { this.getEffects().get(0).setTargetPointer(new FixedTarget(event.getPlayerId())); return true; } } } } return false; }
@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; }