@Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { DamageEvent damageEvent = (DamageEvent) event; Permanent sourcePermanent = game.getPermanent(source.getSourceId()); if (sourcePermanent != null) { // get name of old target Permanent targetPermanent = game.getPermanent(event.getTargetId()); StringBuilder message = new StringBuilder(); message.append(sourcePermanent.getName()).append(": gets "); message.append(damageEvent.getAmount()).append(" damage redirected from "); if (targetPermanent != null) { message.append(targetPermanent.getName()); } else { Player targetPlayer = game.getPlayer(event.getTargetId()); if (targetPlayer != null) { message.append(targetPlayer.getName()); } else { message.append("unknown"); } } game.informPlayers(message.toString()); // redirect damage this.used = true; sourcePermanent.damage( damageEvent.getAmount(), damageEvent.getSourceId(), game, damageEvent.isPreventable(), damageEvent.isCombatDamage(), event.getAppliedEffects()); return true; } return false; }
@Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { GameEvent preventEvent = new GameEvent( GameEvent.EventType.PREVENT_DAMAGE, source.getControllerId(), source.getId(), source.getControllerId(), event.getAmount(), false); if (!game.replaceEvent(preventEvent)) { int damage = event.getAmount(); if (damage > 0) { event.setAmount(damage - 1); this.used = true; game.fireEvent( GameEvent.getEvent( GameEvent.EventType.PREVENTED_DAMAGE, source.getControllerId(), source.getId(), source.getControllerId(), 1)); } } return false; }
@Override public boolean checkTrigger(GameEvent event, Game game) { return GameEvent.EventType.DISCARDED_CARD.equals(event.getType()) && game.getOpponents(this.getControllerId()) .contains(game.getControllerId(event.getSourceId())) && getSourceId().equals(event.getTargetId()); }
@Override public void watch(GameEvent event, Game game) { if (event.getType() == GameEvent.EventType.ZONE_CHANGE && ((ZoneChangeEvent) event).isDiesEvent()) { cards.add(event.getTargetId()); } }
@Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { PreventionEffectData preventionResult = preventDamageAction(event, source, game); if (preventionResult.getPreventedDamage() > 0) { Permanent redirectTo = game.getPermanent(getTargetPointer().getFirst(game, source)); if (redirectTo != null) { game.informPlayers( "Dealing " + preventionResult.getPreventedDamage() + " to " + redirectTo.getLogName() + " instead."); DamageEvent damageEvent = (DamageEvent) event; redirectTo.damage( preventionResult.getPreventedDamage(), event.getSourceId(), game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects()); } discard(); // (only once) } return false; }
@Override public boolean applies(GameEvent event, Ability source, Game game) { if (event.getType() == EventType.DAMAGE_PLAYER) { DamageEvent damageEvent = (DamageEvent) event; UUID playerId = getSourceControllerId(event.getSourceId(), game); if (!damageEvent.isCombatDamage() && game.getOpponents(event.getTargetId()).contains(playerId)) { Player target = game.getPlayer(event.getTargetId()); Player player = game.getPlayer(playerId); if (target != null && player != null) { int numPlaneswalkers = game.getBattlefield().countAll(filter, target.getId(), game); if (numPlaneswalkers > 0 && player.chooseUse(outcome, "Redirect damage to planeswalker?", game)) { redirectTarget = new TargetPermanent(filter); if (numPlaneswalkers == 1) { redirectTarget.add( game.getBattlefield() .getAllActivePermanents(filter, target.getId(), game) .get(0) .getId(), game); } else { player.choose(Outcome.Damage, redirectTarget, null, game); } return true; } } } } return false; }
@Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { GameEvent preventEvent = new GameEvent( GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), event.getAmount(), false); if (!game.replaceEvent(preventEvent)) { int damage = event.getAmount(); Permanent permanent = game.getPermanent(event.getSourceId()); StringBuilder message = new StringBuilder(); if (permanent != null) { message.append(" from ").append(permanent.getName()); } message.insert(0, "Damage").append(" has been prevented: ").append(damage); event.setAmount(0); game.informPlayers(message.toString()); game.fireEvent( GameEvent.getEvent( GameEvent.EventType.PREVENTED_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), damage)); } return false; }
@Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { boolean retValue = false; GameEvent preventEvent = new GameEvent( GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), event.getAmount(), false); int damage = event.getAmount(); if (!game.replaceEvent(preventEvent)) { event.setAmount(0); game.fireEvent( GameEvent.getEvent( GameEvent.EventType.PREVENTED_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), damage)); retValue = true; } Permanent permanent = game.getPermanent(source.getSourceId()); if (permanent != null) { permanent.removeCounters(CounterType.P1P1.createInstance(damage), game); } return retValue; }
@Override public boolean checkTrigger(GameEvent event, Game game) { return event.getPlayerId().equals(this.getControllerId()) && game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD) .getCardType() .contains(CardType.CREATURE); }
@Override public boolean checkTrigger(GameEvent event, Game game) { if (!event.getTargetId().equals(getSourceId())) { MageObject sourceObj = this.getSourceObject(game); if (sourceObj != null) { if (sourceObj instanceof Card && ((Card) sourceObj).isFaceDown(game)) { // if face down and it's not itself that is turned face up, it does not trigger return false; } } else { // Permanent is and was not on the battlefield return false; } } Permanent permanent = game.getPermanent(event.getTargetId()); if (filter.match(permanent, getSourceId(), getControllerId(), game)) { if (setTargetPointer) { for (Effect effect : getEffects()) { effect.setTargetPointer(new FixedTarget(event.getTargetId())); } } return true; } return false; }
@Override public boolean checkTrigger(GameEvent event, Game game) { if (event.getType() == GameEvent.EventType.END_TURN_STEP_PRE && game.getOpponents(controllerId).contains(event.getPlayerId())) { return true; } return false; }
@Override public boolean applies(GameEvent event, Ability source, Game game) { if (event.getSourceId().equals(source.getSourceId())) { Player controller = game.getPlayer(source.getControllerId()); return controller.hasOpponent(event.getTargetId(), game); } return false; }
@Override public boolean checkTrigger(GameEvent event, Game game) { if (event.getType() == GameEvent.EventType.DREW_CARD && event.getPlayerId().equals(controllerId)) { return true; } return false; }
@Override public void watch(GameEvent event, Game game) { if (condition == true) return; if (event.getType() == GameEvent.EventType.ATTACKER_DECLARED && event.getSourceId().equals(sourceId)) { condition = true; } }
@Override public boolean checkTrigger(GameEvent event, Game game) { if (event.getType() == GameEvent.EventType.SPELL_CAST) { this.getEffects().get(0).setTargetPointer(new FixedTarget(event.getPlayerId())); return true; } return false; }
Cards ProteanHulkSearch(Game game, Ability source) { Cards cardsPicked = new CardsImpl(Zone.PICK); Player player = game.getPlayer(source.getControllerId()); if (player != null) { GameEvent event = GameEvent.getEvent( GameEvent.EventType.SEARCH_LIBRARY, source.getControllerId(), source.getControllerId(), source.getControllerId(), Integer.MAX_VALUE); if (!game.replaceEvent(event)) { int manaCostLeftToFetch = 6; int librarySearchLimit = event.getAmount(); FilterCard filter = new FilterCreatureCard( "number of creature cards with total converted mana cost 6 or less (6 CMC left)"); filter.add( new ConvertedManaCostPredicate(ComparisonType.LessThan, manaCostLeftToFetch + 1)); TargetCardInLibrary target = new TargetCardInLibrary(0, 1, filter); target.setCardLimit(librarySearchLimit); while (target.canChoose(source.getSourceId(), source.getControllerId(), game)) { target.choose( Outcome.PutCreatureInPlay, source.getControllerId(), source.getControllerId(), game); Card card = player.getLibrary().remove(target.getFirstTarget(), game); if (card == null) { break; } cardsPicked.add(card); game.setZone(card.getId(), Zone.PICK); game.getState().getLookedAt(source.getControllerId()).add("Protean Hulk", cardsPicked); librarySearchLimit--; if (librarySearchLimit == 0) { break; } manaCostLeftToFetch -= card.getManaCost().convertedManaCost(); filter = new FilterCreatureCard( "number of creature cards with total converted mana cost 6 or less (" + manaCostLeftToFetch + " CMC left)"); filter.add( new ConvertedManaCostPredicate(ComparisonType.LessThan, manaCostLeftToFetch + 1)); target = new TargetCardInLibrary(0, 1, filter); target.setCardLimit(librarySearchLimit); } game.fireEvent( GameEvent.getEvent( GameEvent.EventType.LIBRARY_SEARCHED, source.getControllerId(), source.getControllerId())); } } return cardsPicked; }
@Override public boolean applies(GameEvent event, Ability source, Game game) { if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD && game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { Card c = game.getCard(event.getTargetId()); if (c != null && c.getCardType().contains(CardType.CREATURE)) return true; } return false; }
@Override public boolean checkTrigger(GameEvent event, Game game) { Spell spell = game.getStack().getSpell(event.getTargetId()); if (spell != null && spell.getCardType().contains(CardType.ARTIFACT)) { this.getEffects().get(0).setTargetPointer(new FixedTarget(event.getPlayerId())); return true; } return false; }
@Override public boolean checkTrigger(GameEvent event, Game game) { if ((event.getType() == GameEvent.EventType.PRECOMBAT_MAIN_PHASE_PRE || event.getType() == GameEvent.EventType.POSTCOMBAT_MAIN_PHASE_PRE) && event.getPlayerId().equals(this.controllerId)) { return true; } return false; }
@Override public boolean checkTrigger(GameEvent event, Game game) { if (event.getType() == EventType.ATTACKER_DECLARED && event.getSourceId().equals(this.getSourceId())) { return true; } return event.getType() == EventType.ENTERS_THE_BATTLEFIELD && event.getTargetId().equals(this.getSourceId()); }
@Override public boolean checkTrigger(GameEvent event, Game game) { if (event.getType() == GameEvent.EventType.DAMAGED_CREATURE && event.getTargetId().equals(this.sourceId)) { this.getEffects().get(0).setValue("damageAmount", event.getAmount()); return true; } return false; }
@Override public boolean applies(GameEvent event, Ability source, Game game) { if (event.getType() == GameEvent.EventType.SEARCH_LIBRARY) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null && game.isOpponent(controller, event.getPlayerId())) { return true; } } return false; }
@Override public boolean checkTrigger(GameEvent event, Game game) { if (game.getOpponents(getControllerId()).contains(event.getPlayerId())) { for (Effect effect : getEffects()) { effect.setTargetPointer(new FixedTarget(event.getSourceId())); } return true; } return false; }
@Override public boolean applies(GameEvent event, Ability source, Game game) { if (!this.used && super.applies(event, source, game)) { if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(targetSource.getFirstTarget())) { return true; } } return false; }
@Override public boolean applies(GameEvent event, Ability source, Game game) { if (event.getType() == GameEvent.EventType.ZONE_CHANGE && event.getTargetId().equals(source.getFirstTarget()) && ((ZoneChangeEvent) event).getFromZone().equals(Zone.BATTLEFIELD) && !((ZoneChangeEvent) event).getToZone().equals(Zone.EXILED)) { return true; } return false; }
@Override public void watch(GameEvent event, Game game) { if (event.getType() == EventType.DAMAGED_CREATURE || event.getType() == EventType.DAMAGED_PLANESWALKER || event.getType() == EventType.DAMAGED_PLAYER) { if (!damageSources.contains(event.getSourceId())) { damageSources.add(event.getSourceId()); } } }
@Override public boolean checkTrigger(GameEvent event, Game game) { if (event.getType() == GameEvent.EventType.SPELL_CAST) { Spell spell = game.getStack().getSpell(event.getTargetId()); if (spell != null && spell.getColor().contains(ObjectColor.GREEN)) { return true; } } return false; }
@Override public boolean checkTrigger(GameEvent event, Game game) { if (event.getType() == GameEvent.EventType.TAPPED) { Permanent p = game.getPermanent(event.getTargetId()); if (p != null && p.getCardType().contains(CardType.CREATURE)) { if (game.getOpponents(this.controllerId).contains(p.getControllerId())) return true; } } return false; }
@Override public boolean applies(GameEvent event, Ability source, Game game) { if (event.getType() == EventType.ZONE_CHANGE && ((ZoneChangeEvent) event).isDiesEvent()) { DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId()); if (watcher != null) return watcher.damagedCreatures.contains(event.getTargetId()); } return false; }
@Override public boolean checkTrigger(GameEvent event, Game game) { Permanent target = game.getPermanent(this.getFirstTarget()); if (target != null && event.getSourceId().equals(target.getId())) { for (Effect effect : this.getEffects()) { effect.setValue("damage", event.getAmount()); } return true; } return false; }