/** * Damages attacking creatures by a creature that blocked several ones Damages only attackers as * blocker was damage in either {@link #singleBlockerDamage} or {@link #multiBlockerDamage}. * * <p>Handles abilities like "{this} an block any number of creatures.". * * @param first * @param game */ private void multiAttackerDamage(boolean first, Game game) { Permanent blocker = game.getPermanent(blockers.get(0)); if (blocker == null) { return; } Player player = game.getPlayer(blocker.getControllerId()); int damage = getDamageValueFromPermanent(blocker, game); if (canDamage(blocker, first)) { Map<UUID, Integer> assigned = new HashMap<>(); for (UUID attackerId : attackerOrder) { Permanent attacker = game.getPermanent(attackerId); int lethalDamage; if (blocker.getAbilities().containsKey(DeathtouchAbility.getInstance().getId())) { lethalDamage = 1; } else { lethalDamage = attacker.getToughness().getValue() - attacker.getDamage(); } if (lethalDamage >= damage) { assigned.put(attackerId, damage); break; } int damageAssigned = player.getAmount( lethalDamage, damage, "Assign damage to " + attacker.getLogName(), game); assigned.put(attackerId, damageAssigned); damage -= damageAssigned; } for (Map.Entry<UUID, Integer> entry : assigned.entrySet()) { Permanent attacker = game.getPermanent(entry.getKey()); attacker.markDamage(entry.getValue(), blocker.getId(), game, true, true); } } }
@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 apply(Game game, Ability source) { Permanent sourcePermanent = game.getPermanent(source.getSourceId()); if (sourcePermanent == null) { sourcePermanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD); } if (sourcePermanent == null) { return false; } int damage = sourcePermanent.getPower().getValue(); Permanent permanent = game.getPermanent(source.getFirstTarget()); if (permanent != null) { permanent.damage(damage, sourcePermanent.getId(), game, false, true); return true; } Player player = game.getPlayer(source.getFirstTarget()); if (player != null) { player.damage(damage, sourcePermanent.getId(), game, false, true); return true; } return false; }
/** * Damages attacking creatures by a creature that blocked several ones Damages only attackers as * blocker was damage in {@link #singleBlockerDamage}. * * <p>Handles abilities like "{this} an block any number of creatures.". * * @param first * @param game */ private void singleAttackerDamage(boolean first, Game game) { Permanent blocker = game.getPermanent(blockers.get(0)); Permanent attacker = game.getPermanent(attackers.get(0)); if (blocker != null && attacker != null) { if (canDamage(blocker, first)) { int damage = getDamageValueFromPermanent(blocker, game); attacker.markDamage(damage, blocker.getId(), game, true, true); } } }
@Override public boolean canPay(Ability ability, UUID sourceId, UUID controllerId, Game game) { Permanent permanent = game.getPermanent(sourceId); if (permanent != null) { Permanent attachment = game.getPermanent(attachmentid); if (attachment != null && permanent.getAttachments().contains(attachmentid)) { return true; } } return false; }
@Override public boolean apply(Game game, Ability source) { Permanent permanent = game.getPermanent(source.getFirstTarget()); if (targetPointer != null) { permanent = game.getPermanent(targetPointer.getFirst(game, source)); } if (permanent != null) { return permanent.changeControllerId(source.getControllerId(), game); } return false; }
@Override public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana) { Permanent permanent = game.getPermanent(sourceId); if (permanent != null) { Permanent attachment = game.getPermanent(attachmentid); if (attachment != null) { permanent.removeAttachment(attachmentid, game); this.paid = true; } } return paid; }
@Override public boolean apply(Game game, Ability source) { Permanent sourcePermanent = game.getPermanent(source.getSourceId()); if (sourcePermanent != null && sourcePermanent.getCounters().getCount(CounterType.P1P1) > 0) { Permanent targetPermanent = game.getPermanent(targetPointer.getFirst(game, source)); if (targetPermanent != null) { sourcePermanent.getCounters().removeCounter(CounterType.P1P1, 1); targetPermanent.addCounters(CounterType.P1P1.createInstance(), game); return true; } } return false; }
@Override public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana) { Permanent attachment = game.getPermanent(sourceId); Permanent permanent = game.getPermanent(attachment.getAttachedTo()); if (permanent != null) { paid = permanent.removeAttachment(attachment.getId(), game); if (paid) { game.fireEvent( GameEvent.getEvent(GameEvent.EventType.UNATTACHED, sourceId, sourceId, controllerId)); } } return paid; }
@Override public boolean checkTrigger(GameEvent event, Game game) { if (event.getType() == GameEvent.EventType.CREATURE_BLOCKED) { Permanent equipment = game.getPermanent(sourceId); if (equipment != null && equipment.getAttachedTo() != null) { Permanent equipped = game.getPermanent(equipment.getAttachedTo()); if (equipped.getId().equals(event.getTargetId())) { return true; } } } return false; }
@Override public boolean apply(Game game, Ability source) { Permanent creature1 = game.getPermanent(source.getSourceId()); Permanent creature2 = game.getPermanent(source.getFirstTarget()); // 20110930 - 701.10 if (creature1 != null && creature2 != null) { if (creature1.getCardType().contains(CardType.CREATURE) && creature2.getCardType().contains(CardType.CREATURE)) { return creature1.fight(creature2, source, game); } } return false; }
@Override public boolean apply(Game game, Ability source) { Permanent enchantment = game.getPermanent(source.getSourceId()); if (enchantment != null) { Permanent creature = game.getPermanent(enchantment.getAttachedTo()); if (creature != null) { if (filter.match(creature, source.getSourceId(), enchantment.getControllerId(), game)) { return true; } } } return false; }
public void applyDamage(Game game) { for (UUID uuid : attackers) { Permanent permanent = game.getPermanent(uuid); if (permanent != null) { permanent.applyDamage(game); } } for (UUID uuid : blockers) { Permanent permanent = game.getPermanent(uuid); if (permanent != null) { permanent.applyDamage(game); } } }
@Override public boolean apply(Game game, Ability source) { boolean result = false; Permanent permanent = game.getPermanent(source.getFirstTarget()); if (permanent != null) { result |= permanent.moveToZone(Zone.HAND, source.getId(), game, false); } permanent = game.getPermanent(source.getTargets().get(1).getFirstTarget()); if (permanent != null) { result |= permanent.moveToZone(Zone.HAND, source.getId(), game, false); } return result; }
@Override public boolean applies(GameEvent event, Ability source, Game game) { if (super.applies(event, source, game)) { if (event.getTargetId().equals(source.getControllerId())) { Permanent sourcePermanent = game.getPermanent(source.getSourceId()); if (sourcePermanent != null && !sourcePermanent.isTapped()) { Permanent damageSource = game.getPermanent(event.getSourceId()); if (damageSource != null && filter.match(damageSource, game)) { return true; } } } } return false; }
@Override public boolean apply(Game game, Ability source) { Permanent permanent = game.getPermanent(source.getFirstTarget()); if (permanent != null) { LinkedList<UUID> attachments = new LinkedList(); attachments.addAll(permanent.getAttachments()); for (UUID uuid : attachments) { Permanent aura = game.getPermanent(uuid); if (aura != null && aura.getSubtype().contains("Aura")) { aura.destroy(source.getId(), game, false); } } } return false; }
public boolean hasFirstOrDoubleStrike(Game game) { for (UUID permId : attackers) { Permanent attacker = game.getPermanent(permId); if (attacker != null && hasFirstOrDoubleStrike(attacker)) { return true; } } for (UUID permId : blockers) { Permanent blocker = game.getPermanent(permId); if (blocker != null && hasFirstOrDoubleStrike(blocker)) { return true; } } return false; }
@Override public boolean apply(Game game, Ability source) { Permanent creature1 = game.getPermanent(source.getSourceId()); Permanent creature2 = game.getPermanent(source.getFirstTarget()); // 20110930 - 701.10 if (creature1 != null && creature2 != null) { if (creature1.getCardType().contains(CardType.CREATURE) && creature2.getCardType().contains(CardType.CREATURE)) { creature1.damage(creature2.getPower().getValue(), creature2.getId(), game, true, false); creature2.damage(creature1.getPower().getValue(), creature1.getId(), game, true, false); return true; } } return false; }
@Override public boolean checkTrigger(GameEvent event, Game game) { if (event.getType() == GameEvent.EventType.DRAW_STEP_PRE) { switch (targetController) { case YOU: boolean yours = event.getPlayerId().equals(this.controllerId); if (yours) { if (getTargets().size() == 0) { for (Effect effect : this.getEffects()) { effect.setTargetPointer(new FixedTarget(event.getPlayerId())); } } } return yours; case OPPONENT: if (game.getOpponents(this.controllerId).contains(event.getPlayerId())) { if (getTargets().size() == 0) { for (Effect effect : this.getEffects()) { effect.setTargetPointer(new FixedTarget(event.getPlayerId())); } } return true; } case CONTROLLER_ATTACHED_TO: Permanent attachment = game.getPermanent(sourceId); if (attachment != null && attachment.getAttachedTo() != null) { Permanent attachedTo = game.getPermanent(attachment.getAttachedTo()); if (attachedTo != null && attachedTo.getControllerId().equals(event.getPlayerId())) { if (getTargets().size() == 0) { for (Effect effect : this.getEffects()) { effect.setTargetPointer(new FixedTarget(event.getPlayerId())); } } return true; } } break; case ANY: if (getTargets().size() == 0) { for (Effect effect : this.getEffects()) { effect.setTargetPointer(new FixedTarget(event.getPlayerId())); } } return true; } } return false; }
@Override public boolean applies(GameEvent event, Ability source, Game game) { boolean isCombat = false; switch (event.getType()) { case DAMAGE_CREATURE: case DAMAGE_PLAYER: case DAMAGE_PLANESWALKER: if (event instanceof DamageCreatureEvent) { isCombat = ((DamageCreatureEvent) event).isCombatDamage(); } else if (event instanceof DamageEvent) { isCombat = ((DamageEvent) event).isCombatDamage(); } if (isCombat) { Permanent equipment = game.getPermanent(source.getSourceId()); if (equipment != null && equipment.getAttachedTo() != null) { UUID attachedTo = equipment.getAttachedTo(); if (event.getSourceId().equals(attachedTo)) { event.setAmount(event.getAmount() * 2); } else if (event.getTargetId().equals(attachedTo)) { event.setAmount(event.getAmount() * 2); } } } } return false; }
@Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); if (player == null) { return false; } Card card = player.getLibrary().getFromTop(game); if (card != null) { Cards cards = new CardsImpl(); cards.add(card); player.lookAtCards("Explorer's Scope", cards, game); if (card.getCardType().contains(CardType.LAND)) { String message = "Put " + card.getName() + " onto the battlefield tapped?"; if (player.chooseUse(Outcome.PutLandInPlay, message, game)) { if (card.putOntoBattlefield( game, Zone.LIBRARY, source.getId(), source.getControllerId())) { Permanent permanent = game.getPermanent(card.getId()); if (permanent != null) { permanent.setTapped(true); } } } } } return true; }
@Override public void assignDamage( int damage, List<UUID> targets, String singleTargetName, UUID sourceId, Game game) { int remainingDamage = damage; UUID targetId; int amount; while (remainingDamage > 0) { if (targets.size() == 1) { targetId = targets.get(0); amount = remainingDamage; } else { targetId = targets.get(rnd.nextInt(targets.size())); amount = rnd.nextInt(damage + 1); } Permanent permanent = game.getPermanent(targetId); if (permanent != null) { permanent.damage(amount, sourceId, game, true, false); remainingDamage -= amount; } else { Player player = game.getPlayer(targetId); if (player != null) { player.damage(amount, sourceId, game, false, true); remainingDamage -= amount; } } targets.remove(targetId); } }
@Override public boolean apply(Game game, Ability source) { Permanent permanent = game.getPermanent(source.getSourceId()); Permanent targetCreature = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source)); if (targetCreature != null && permanent != null) { Permanent blueprintPermanent = game.copyPermanent( Duration.Custom, targetCreature, permanent.getId(), source, new EmptyApplyToPermanent()); blueprintPermanent.addAbility( new EntersBattlefieldAllTriggeredAbility( Zone.BATTLEFIELD, new UnstableShapeshifterEffect(), filterAnotherCreature, false, SetTargetPointer.PERMANENT, ""), game); return true; } return false; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { MageObject mageObject = source.getSourceObject(game); Permanent permanent = game.getPermanent(source.getSourceId()); if (permanent != null && mageObject != null && new MageObjectReference(permanent, game).refersTo(mageObject, game)) { if (permanent.sacrifice(source.getSourceId(), game)) { UUID exileId = CardUtil.getExileZoneId( game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()); if (exileId != null) { ExileZone exileZone = game.getExile().getExileZone(exileId); Card exiledCard = null; if (exileZone != null) { for (Card card : exileZone.getCards(game)) { exiledCard = card; break; } } if (exiledCard != null) { if (exiledCard.getSpellAbility().canChooseTarget(game)) { controller.cast(exiledCard.getSpellAbility(), game, true); } } } } } return true; } return false; }
@Override public boolean apply(Game game, Ability source) { MageObject mageObject = source.getSourceObject(game); Permanent permanent = game.getPermanent(source.getSourceId()); if (permanent != null && mageObject == null && new MageObjectReference(permanent, game).refersTo(mageObject, game)) { discard(); return false; } UUID exileId = CardUtil.getExileZoneId( game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()); if (exileId != null) { ExileZone exileZone = game.getExile().getExileZone(exileId); if (exileZone == null) { return false; } Card exiledCard = null; for (Card card : exileZone.getCards(game)) { exiledCard = card; break; } if (exiledCard != null) { int value = exiledCard.getManaCost().convertedManaCost(); permanent.getPower().setValue(value); permanent.getToughness().setValue(value); } } return true; }
@Override public boolean apply(Game game, Ability source) { Permanent permanent = game.getPermanent(source.getSourceId()); if (permanent == null) { return false; } if (permanent.isCopy()) { // copies can't transform return true; } if (!permanent.isTransformed()) { // keep original card return true; } Card card = permanent.getSecondCardFace(); if (card == null) { return false; } TransformAbility.transform(permanent, card, game); return true; }
@java.lang.Override public boolean apply(Game game, Ability source) { Permanent sourceObject = game.getPermanentOrLKIBattlefield(source.getSourceId()); if (sourceObject != null) { // create cost for sacrificing an artifact Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true); // if they can pay the cost, then they must pay if (target.canChoose(source.getSourceId(), controller.getId(), game)) { controller.choose(Outcome.Sacrifice, target, source.getSourceId(), game); Permanent artifactSacrifice = game.getPermanent(target.getFirstTarget()); if (artifactSacrifice != null) { // sacrifice the chosen artifact artifactSacrifice.sacrifice(source.getSourceId(), game); } } else { sourceObject.tap(game); controller.damage(4, source.getSourceId(), game, false, true); } } return true; } return false; }
@Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(targetPointer.getFirst(game, source)); if (player == null) { return false; } if (player.getLife() > 2 && player.chooseUse( Outcome.Neutral, "Pay 2 life? If you don't, return a permanent you control to its owner's hand.", game)) { player.loseLife(2, game); game.informPlayers( player.getName() + " pays 2 life. He will not return a permanent he or she controls."); return true; } else { Target target = new TargetControlledPermanent(); if (target.canChoose(source.getSourceId(), player.getId(), game) && player.chooseTarget(outcome, target, source, game)) { Permanent permanent = game.getPermanent(target.getFirstTarget()); if (permanent != null) { game.informPlayers(player.getName() + " returns " + permanent.getName() + " to hand."); return permanent.moveToZone(Zone.HAND, source.getSourceId(), game, false); } } } 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 apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); // If no controller, exit out here and do not vote. if (controller == null) return false; this.vote("feather", "quill", controller, game, source); Permanent permanent = game.getPermanent(source.getSourceId()); // Feathers Votes // If feathers received zero votes or the permanent is no longer on the battlefield, do not // attempt to put P1P1 counter on it. if (voteOneCount > 0 && permanent != null) permanent.addCounters(CounterType.P1P1.createInstance(voteOneCount), game); // Quill Votes // Only let the controller loot the appropriate amount of cards if it was voted for. if (voteTwoCount > 0) { Effect lootCardsEffect = new DrawDiscardControllerEffect(voteTwoCount, voteTwoCount); lootCardsEffect.apply(game, source); } return true; }