use of mage.target.targetpointer.FixedTargets in project mage by magefree.
the class GhoulsNightOutTypeChangingEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
UUID controllerId = source.getControllerId();
Player controller = game.getPlayer(controllerId);
if (controller != null) {
Set<Card> cardsToBattlefield = new HashSet<>();
for (UUID playerId : game.getState().getPlayersInRange(controllerId, game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
boolean creatureInGraveyard = false;
for (UUID cardId : player.getGraveyard()) {
Card card = game.getCard(cardId);
if (card != null && card.isCreature(game)) {
creatureInGraveyard = true;
break;
}
}
if (creatureInGraveyard) {
FilterCreatureCard filter = new FilterCreatureCard("creature card in " + player.getName() + "'s graveyard");
TargetCard target = new TargetCard(Zone.GRAVEYARD, filter);
target.setNotTarget(true);
controller.chooseTarget(controllerId.equals(playerId) ? Outcome.Benefit : Outcome.Detriment, player.getGraveyard(), target, source, game);
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
cardsToBattlefield.add(card);
}
}
}
}
if (!cardsToBattlefield.isEmpty()) {
controller.moveCards(cardsToBattlefield, Zone.BATTLEFIELD, source, game);
cardsToBattlefield.removeIf(card -> game.getState().getZone(card.getId()) != Zone.BATTLEFIELD);
if (!cardsToBattlefield.isEmpty()) {
game.addEffect(new GhoulsNightOutTypeChangingEffect().setTargetPointer(new FixedTargets(cardsToBattlefield, game)), source);
game.addEffect(new GainAbilityTargetEffect(new DecayedAbility(), Duration.Custom).setTargetPointer(new FixedTargets(cardsToBattlefield, game)), source);
return true;
}
}
}
return false;
}
use of mage.target.targetpointer.FixedTargets in project mage by magefree.
the class NacatlWarPrideEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent origNactalWarPride = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (origNactalWarPride == null) {
return false;
}
CreatureAttackedWhichPlayerWatcher PlayerAttackedWatcher = game.getState().getWatcher(CreatureAttackedWhichPlayerWatcher.class);
// Count the number of creatures attacked opponent controls
UUID defenderId = PlayerAttackedWatcher.getPlayerAttackedThisTurnByCreature(source.getSourceId());
int count = 0;
if (defenderId != null) {
count = game.getBattlefield().countAll(new FilterControlledCreaturePermanent(), defenderId, game);
}
if (count == 0) {
return false;
}
List<Permanent> copies = new ArrayList<>();
Player controller = game.getPlayer(source.getControllerId());
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(controller.getId(), null, false, count, true, true);
effect.setTargetPointer(new FixedTarget(origNactalWarPride, game));
effect.apply(game, source);
copies.addAll(effect.getAddedPermanents());
if (!copies.isEmpty()) {
FixedTargets fixedTargets = new FixedTargets(copies, game);
ExileTargetEffect exileEffect = new ExileTargetEffect();
exileEffect.setTargetPointer(fixedTargets).setText("exile the tokens");
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect), source);
return true;
}
return false;
}
use of mage.target.targetpointer.FixedTargets in project mage by magefree.
the class SokenzanCrucibleOfDefianceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Token token = new SpiritToken();
token.putOntoBattlefield(2, game, source);
game.addEffect(new GainAbilityTargetEffect(HasteAbility.getInstance()).setTargetPointer(new FixedTargets(token, game)), source);
return true;
}
use of mage.target.targetpointer.FixedTargets in project mage by magefree.
the class ChandraHeartOfFireUltimateEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Set<Card> exiledCards = new HashSet<>();
// from graveyard
Target target = new TargetCardInYourGraveyard(0, Integer.MAX_VALUE, filter, true).withChooseHint("from graveyard");
if (target.canChoose(source.getSourceId(), controller.getId(), game) && target.choose(Outcome.AIDontUseIt, controller.getId(), source.getSourceId(), game)) {
Set<Card> cards = new CardsImpl(target.getTargets()).getCards(game);
exiledCards.addAll(cards);
}
// from library
target = new TargetCardInLibrary(0, Integer.MAX_VALUE, filter).withChooseHint("from library");
if (target.canChoose(source.getSourceId(), controller.getId(), game) && target.choose(Outcome.AIDontUseIt, controller.getId(), source.getSourceId(), game)) {
Set<Card> cards = new CardsImpl(target.getTargets()).getCards(game);
exiledCards.addAll(cards);
}
// exile cards all at once and set the exile name to the source card
controller.moveCardsToExile(exiledCards, source, game, true, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source));
controller.shuffleLibrary(source, game);
exiledCards.removeIf(card -> !Zone.EXILED.equals(game.getState().getZone(card.getId())));
if (!exiledCards.isEmpty()) {
ContinuousEffect effect = new PlayFromNotOwnHandZoneTargetEffect(Zone.EXILED, Duration.EndOfTurn);
effect.setTargetPointer(new FixedTargets(exiledCards, game));
game.addEffect(effect, source);
}
return true;
}
return false;
}
use of mage.target.targetpointer.FixedTargets in project mage by magefree.
the class MisstepEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getFirstTarget());
if (player != null) {
List<Permanent> doNotUntapNextUntapStep = new ArrayList<>();
for (Permanent creature : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, player.getId(), game)) {
doNotUntapNextUntapStep.add(creature);
}
if (!doNotUntapNextUntapStep.isEmpty()) {
ContinuousEffect effect = new DontUntapInControllersNextUntapStepTargetEffect("", player.getId());
effect.setText("those creatures don't untap during that player's next untap step");
effect.setTargetPointer(new FixedTargets(doNotUntapNextUntapStep, game));
game.addEffect(effect, source);
}
return true;
}
return false;
}
Aggregations