@Override public String getIdName() { String idName; if (card != null) { idName = card.getId().toString().substring(0, 3); } else { idName = getId().toString().substring(0, 3); } return getName() + " [" + idName + ']'; }
@Override public void watch(GameEvent event, Game game) { if (event.getType() == GameEvent.EventType.SPELL_CAST) { Spell spell = game.getStack().getSpell(event.getSourceId()); if (spell != null && spell.getName().equals("Approach of the Second Sun")) { approachesCast.put(event.getPlayerId(), getApproachesCast(event.getPlayerId()) + 1); } } }
@Override public boolean checkTrigger(GameEvent event, Game game) { if (event.getPlayerId().equals(this.getControllerId())) { Spell spell = game.getStack().getSpell(event.getTargetId()); if (spell != null && spell.isArtifact()) { ((MishraArtificerProdigyEffect) this.getEffects().get(0)).setName(spell.getName()); return true; } } return false; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source)); if (controller != null && spell != null) { MageObject mageObject = game.getObject(source.getSourceId()); if (mageObject instanceof Permanent) { Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId()); if (permanent != null && game.getState().getValue(mageObject.getId() + "_letter") != null) { int lifegainValue = 0; String spellName = spell.getName(); for (int i = 0; i < spellName.length(); i++) { char letter = spellName.charAt(i); String chosenLetter = (String) game.getState().getValue(mageObject.getId() + "_letter"); if (Character.isLetter(letter) && Character.toUpperCase(letter) == chosenLetter.charAt(0)) { lifegainValue++; } } controller.gainLife(lifegainValue, game, source); return true; } } } return false; } }
@Override public boolean checkTrigger(GameEvent event, Game game) { if (super.checkTrigger(event, game)) { CastFromHandWatcher watcher = game.getState().getWatcher(CastFromHandWatcher.class); if (watcher != null && watcher.spellWasCastFromHand(event.getSourceId())) { Spell spell = game.getState().getStack().getSpell(event.getSourceId()); if (spell != null) { FilterCard filterCard = new FilterCard("a card named " + spell.getName() + " in your graveyard"); filterCard.add(new NamePredicate(spell.getName())); this.getTargets().clear(); this.getTargets().add(new TargetCardInYourGraveyard(filterCard)); return true; } } } return false; }
@Override public boolean checkInterveningIfClause(Game game) { Spell spell = game.getStack().getSpell(this.getEffects().get(0).getTargetPointer().getFirst(game, this)); if (spell != null) { String spellName = spell.getName(); Permanent sourcePermanent = game.getPermanent(this.getSourceId()); if (sourcePermanent != null) { for (UUID imprintId : sourcePermanent.getImprinted()) { Card card = game.getCard(imprintId); if (card != null && card.getName().equals(spellName)) { ((SpellweaverHelixCastEffect) this.getEffects().get(0)).setSpellName(spellName); return true; } } } } return false; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller == null) { return false; } Spell spell = game.getStack().getSpell(getTargetPointer().getFirst(game, source)); if (spell != null) { game.getStack().counter(spell.getId(), source.getSourceId(), game); if (SpellMasteryCondition.instance.apply(game, source) && controller.chooseUse(Outcome.PlayForFree, "Copy " + spell.getName() + " (you may choose new targets for the copy)?", source, game)) { StackObject newStackObject = spell.createCopyOnStack(game, source, source.getControllerId(), true); if (newStackObject instanceof Spell) { String activateMessage = ((Spell) newStackObject).getActivatedMessage(game); if (activateMessage.startsWith(" casts ")) { activateMessage = activateMessage.substring(6); } game.informPlayers(controller.getLogName() + activateMessage); } } return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { MageObjectReference spellRef = (MageObjectReference) this.getValue("GravestormSpellRef"); if (spellRef != null) { GravestormWatcher watcher = game.getState().getWatcher(GravestormWatcher.class); if(watcher != null) { int gravestormCount = watcher.getGravestormCount(); if (gravestormCount > 0) { Spell spell = (Spell) this.getValue("GravestormSpell"); if (spell != null) { if (!game.isSimulation()) { game.informPlayers("Gravestorm: " + spell.getName() + " will be copied " + gravestormCount + " time" + (gravestormCount > 1 ? "s" : "")); } for (int i = 0; i < gravestormCount; i++) { spell.createCopyOnStack(game, source, source.getControllerId(), true); } } } return true; } } return false; }
@Override public boolean checkTrigger(GameEvent event, Game game) { if (event.getPlayerId().equals(this.getControllerId())) { String cardName = ""; if (event.getType() == GameEvent.EventType.SPELL_CAST) { Spell spell = game.getStack().getSpell(event.getTargetId()); if (spell != null) { cardName = spell.getName(); } } if (event.getType() == GameEvent.EventType.LAND_PLAYED) { Card card = game.getCard(event.getTargetId()); if (card != null) { cardName = card.getName(); } } if (!cardName.isEmpty()) { ExileZone searchTheCityExileZone = game.getExile().getExileZone(this.getSourceId()); FilterCard filter = new FilterCard(); filter.add(new NamePredicate(cardName)); if (searchTheCityExileZone.count(filter, game) > 0) { this.getEffects().get(0).setValue("cardName", cardName); return true; } } } return false; }
@Override public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) { if (targets.choose(Outcome.Exile, controllerId, sourceId, game)) { Player player = game.getPlayer(controllerId); for (UUID targetId : targets.get(0).getTargets()) { Spell spellToExile = game.getStack().getSpell(targetId); if (spellToExile == null) { return false; } String spellName = spellToExile.getName(); if (spellToExile.isCopy()) { game.getStack().remove(spellToExile, game); } else { spellToExile.moveToExile(null, "", ability.getSourceId(), game); } paid = true; if (!game.isSimulation()) { game.informPlayers(player.getLogName() + " exiles " + spellName + " (as costs)"); } } } return paid; }
@Override public boolean apply(Game game, Ability source) { int count = 0; MageObject mageObject = game.getObject(source.getSourceId()); if(mageObject != null) { Spell spell = (Spell) game.getState().getValue("avenShrine" + mageObject); if (spell != null) { Player controller = game.getPlayer(spell.getControllerId()); if (controller != null) { String name = spell.getName(); FilterCard filterCardName = new FilterCard(); filterCardName.add(new NamePredicate(name)); for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Player player = game.getPlayer(playerId); if (player != null) { count += player.getGraveyard().count(filterCardName, game); } } controller.gainLife(count, game, source); return true; } } } return false; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { UUID targetId = source.getFirstTarget(); Player affectedPlayer = game.getPlayer(targetId); if (affectedPlayer != null) { Effect effect = new DiscardTargetEffect(2); effect.setTargetPointer(new FixedTarget(targetId)); effect.apply(game, source); if (affectedPlayer.chooseUse(Outcome.Copy, "Copy the spell?", source, game)) { Spell spell = game.getStack().getSpell(source.getSourceId()); if (spell != null) { spell.createCopyOnStack(game, source, affectedPlayer.getId(), true); game.informPlayers(affectedPlayer.getLogName() + " copies " + spell.getName() + '.'); } } return true; } } return false; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller == null || game.getPermanentOrLKIBattlefield(source.getSourceId()) == null) { return false; } Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source)); if (spell == null) { return false; } FilterCard filter = new FilterCard(); filter.add(new NamePredicate(spell.getName())); for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Player player = game.getPlayer(playerId); if (player != null) { player.moveCards(player.getGraveyard().getCards(filter, game), Zone.BATTLEFIELD, source, game); } } return true; }
@Override public boolean apply(Game game, Ability source) { Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source)); Player controller = game.getPlayer(source.getControllerId()); if (spell != null && controller != null) { Player spellCaster = game.getPlayer(spell.getControllerId()); // controller gets controll of spell spell.setControllerId(controller.getId()); // and chooses new targets spell.chooseNewTargets(game, controller.getId()); game.informPlayers(controller.getLogName() + " got control of " + spell.getName() + " spell."); // and spell controller get control of Perplexing Chimera if (spellCaster != null) { ContinuousEffect effect = new PerplexingChimeraControlEffect(); effect.setTargetPointer(new FixedTarget(spellCaster.getId())); game.addEffect(effect, source); } } return false; } }
@Override public boolean apply(Game game, Ability source) { int count = 0; MageObject mageObject = game.getObject(source.getSourceId()); if(mageObject != null) { Spell spell = (Spell) game.getState().getValue("cabalShrine" + mageObject); if (spell != null) { Player controller = game.getPlayer(spell.getControllerId()); if (controller != null) { String name = spell.getName(); FilterCard filterCardName = new FilterCard(); filterCardName.add(new NamePredicate(name)); for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Player player = game.getPlayer(playerId); if (player != null) { count += player.getGraveyard().count(filterCardName, game); } } controller.discard(count, false, source, game); return true; } } } return false; }
@Override public boolean apply(Game game, Ability source) { int count = 0; MageObject mageObject = game.getObject(source.getSourceId()); if(mageObject != null) { Spell spell = (Spell) game.getState().getValue("dwarvenShrine" + mageObject); if (spell != null) { Player controller = game.getPlayer(spell.getControllerId()); if (controller != null) { String name = spell.getName(); FilterCard filterCardName = new FilterCard(); filterCardName.add(new NamePredicate(name)); for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Player player = game.getPlayer(playerId); if (player != null) { count += player.getGraveyard().count(filterCardName, game); } } controller.damage(count * 2, mageObject.getId(), game, false, true); return true; } } } return false; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { UUID targetId = source.getFirstTarget(); Permanent permanent = game.getPermanent(targetId); if (permanent != null) { Player affectedPlayer = game.getPlayer(permanent.getControllerId()); if (affectedPlayer != null) { Effect effect = new DestroyTargetEffect(); effect.setTargetPointer(new FixedTarget(targetId)); effect.apply(game, source); if (affectedPlayer.chooseUse(Outcome.Copy, "Copy the spell?", source, game)) { Spell spell = game.getStack().getSpell(source.getSourceId()); if (spell != null) { spell.createCopyOnStack(game, source, affectedPlayer.getId(), true); game.informPlayers(affectedPlayer.getLogName() + " copies " + spell.getName() + '.'); } } return true; } } } return false; } }
@Override public boolean apply(Game game, Ability source) { Spell spell = game.getStack().getSpell(getTargetPointer().getFirst(game, source)); if (spell != null) { Player controller = game.getPlayer(spell.getControllerId()); if (controller != null) { int count = 0; String name = spell.getName(); FilterCard filterCardName = new FilterCard(); filterCardName.add(new NamePredicate(name)); for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Player player = game.getPlayer(playerId); if (player != null) { count += player.getGraveyard().count(filterCardName, game); } } if (count > 0) { new SquirrelToken().putOntoBattlefield(count, game, source.getSourceId(), spell.getControllerId()); } return true; } } return false; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Spell targetSpell = game.getStack().getSpell(source.getFirstTarget()); if (targetSpell != null) { Player controllerOfTargetedSpell = game.getPlayer(targetSpell.getControllerId()); if (controller != null && controllerOfTargetedSpell != null) { int numToDiscard = controller.getAmount(0, controller.getHand().size(), "How many cards do you want to discard?", game); Cards discardedCards = controller.discard(numToDiscard, false, source, game); int actualNumberDiscarded = discardedCards.size(); GenericManaCost cost = new GenericManaCost(actualNumberDiscarded * 3); if (controllerOfTargetedSpell.chooseUse(Outcome.AIDontUseIt, "Do you want to pay " + cost.convertedManaCost() + " to prevent " + targetSpell.getName() + " from gettting countered?", source, game) && cost.pay(source, game, source.getSourceId(), controllerOfTargetedSpell.getId(), false)) { return true; } else { targetSpell.counter(source.getSourceId(), game); return true; } } } return false; } }
if (spell != null) { spell.createCopyOnStack(game, source, affectedPlayer.getId(), true); game.informPlayers(affectedPlayer.getLogName() + " copies " + spell.getName() + '.');