use of mage.target.targetpointer.FixedTargets in project mage by magefree.
the class MirrorMatchEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (UUID attackerId : game.getCombat().getAttackers()) {
Permanent attacker = game.getPermanent(attackerId);
if (attacker != null && source.isControlledBy(game.getCombat().getDefendingPlayerId(attackerId, game))) {
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(source.getControllerId(), null, false);
effect.setTargetPointer(new FixedTarget(attacker, game));
effect.apply(game, source);
CombatGroup group = game.getCombat().findGroup(attacker.getId());
boolean isCreature = false;
if (group != null) {
for (Permanent addedToken : effect.getAddedPermanents()) {
if (addedToken.isCreature(game)) {
group.addBlockerToGroup(addedToken.getId(), attackerId, game);
isCreature = true;
}
}
ExileTargetEffect exileEffect = new ExileTargetEffect("Exile those tokens at end of combat");
exileEffect.setTargetPointer(new FixedTargets(effect.getAddedPermanents(), game));
game.addDelayedTriggeredAbility(new AtTheEndOfCombatDelayedTriggeredAbility(exileEffect), source);
if (isCreature) {
group.pickBlockerOrder(attacker.getControllerId(), game);
}
}
}
}
return true;
}
return false;
}
use of mage.target.targetpointer.FixedTargets in project mage by magefree.
the class SeanceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Card card = game.getCard(source.getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && card != null) {
// Also if the move to exile is replaced, the copy takes place
controller.moveCards(card, Zone.EXILED, source, game);
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(source.getControllerId(), null, false);
effect.setTargetPointer(new FixedTarget(card, game));
effect.setAdditionalSubType(SubType.SPIRIT);
effect.apply(game, source);
ExileTargetEffect exileEffect = new ExileTargetEffect();
exileEffect.setTargetPointer(new FixedTargets(effect.getAddedPermanents(), game));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
game.addDelayedTriggeredAbility(delayedAbility, source);
return true;
}
return false;
}
use of mage.target.targetpointer.FixedTargets in project mage by magefree.
the class TilonallisSummonerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
ManaCosts cost = new ManaCostsImpl("{X}{R}");
if (controller.chooseUse(outcome, "Pay " + cost.getText() + "? If you do, you create X 1/1 red Elemental creature tokens that are tapped and attacking.", source, game)) {
int costX = controller.announceXMana(0, Integer.MAX_VALUE, "Announce the value for {X}", game, source);
cost.add(new GenericManaCost(costX));
if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
// otherwise you can undo the payment
controller.resetStoredBookmark(game);
CreateTokenEffect effect = new CreateTokenEffect(new TilonallisSummonerElementalToken(), costX, true, true);
effect.apply(game, source);
Effect exileEffect = new ExileTargetEffect(null, "", Zone.BATTLEFIELD).setText("exile those tokens unless you have the city's blessing");
exileEffect.setTargetPointer(new FixedTargets(new CardsImpl(effect.getLastAddedTokenIds()), game));
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect, TargetController.ANY, new InvertCondition(CitysBlessingCondition.instance)), source);
}
}
return true;
}
return false;
}
use of mage.target.targetpointer.FixedTargets in project mage by magefree.
the class PlayFromNotOwnHandZoneTargetEffect method exileAndPlayFromExile.
/**
* Exiles the cards and let the allowed player play them from exile for the given duration
* Supports:
* - cards (use any side)
* - permanents (use permanent, not permanent's card)
*
* @param game
* @param source
* @param cards
* @param allowedCaster
* @param duration
* @param withoutMana
* @param anyColor
* @param onlyCastAllowed true for rule "cast that card" and false for rule "play that card"
* @return
*/
public static boolean exileAndPlayFromExile(Game game, Ability source, Set<Card> cards, TargetController allowedCaster, Duration duration, boolean withoutMana, boolean anyColor, boolean onlyCastAllowed) {
if (cards == null || cards.isEmpty()) {
return true;
}
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller == null || sourceObject == null) {
return false;
}
UUID exileId = CardUtil.getExileZoneId(controller.getId().toString() + "-" + game.getState().getTurnNum() + "-" + sourceObject.getIdName(), game);
String exileName = sourceObject.getIdName() + " free play" + (Duration.EndOfTurn.equals(duration) ? " on turn " + game.getState().getTurnNum() : "") + " for " + controller.getName();
if (Duration.EndOfTurn.equals(duration)) {
game.getExile().createZone(exileId, exileName).setCleanupOnEndTurn(true);
}
if (!controller.moveCardsToExile(cards, source, game, true, exileId, exileName)) {
return false;
}
// get real cards (if it was called on permanent instead card, example: Release to the Wind)
Set<Card> cardsToPlay = cards.stream().map(Card::getMainCard).filter(card -> Zone.EXILED.equals(game.getState().getZone(card.getId()))).collect(Collectors.toSet());
ContinuousEffect effect = new PlayFromNotOwnHandZoneTargetEffect(Zone.EXILED, allowedCaster, duration, withoutMana, onlyCastAllowed);
effect.setTargetPointer(new FixedTargets(cardsToPlay, game));
game.addEffect(effect, source);
if (anyColor) {
for (Card card : cardsToPlay) {
game.addEffect(new YouMaySpendManaAsAnyColorToCastTargetEffect(duration).setTargetPointer(new FixedTarget(card, game)), source);
}
}
return true;
}
use of mage.target.targetpointer.FixedTargets in project mage by magefree.
the class FlamesOfRemembranceMayPlayExiledEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, amount.calculate(game, source, this)));
if (!cards.isEmpty()) {
controller.moveCardsToExile(cards.getCards(game), source, game, true, source.getSourceId(), CardUtil.createObjectRealtedWindowTitle(source, game, ""));
ContinuousEffect effect = new FlamesOfRemembranceMayPlayExiledEffect();
effect.setTargetPointer(new FixedTargets(cards, game));
game.addEffect(effect, source);
}
return true;
}
return false;
}
Aggregations