use of mage.abilities.effects.Effect in project mage by magefree.
the class StormHeraldAttachableToPredicate method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
FilterCard filter = new FilterCard("aura cards to attach to creatures you control");
filter.add(SubType.AURA.getPredicate());
filter.add(new StormHeraldAttachablePredicate(controller.getId()));
Set<Card> possibleTargets = controller.getGraveyard().getCards(filter, source.getSourceId(), controller.getId(), game);
if (!possibleTargets.isEmpty()) {
TargetCard targetAuras = new TargetCard(0, Integer.MAX_VALUE, Zone.GRAVEYARD, filter);
targetAuras.setNotTarget(true);
controller.chooseTarget(outcome, new CardsImpl(possibleTargets), targetAuras, source, game);
// Move the cards to the battlefield to a creature you control
List<Permanent> toExile = new ArrayList<>();
for (UUID auraId : targetAuras.getTargets()) {
Card auraCard = game.getCard(auraId);
if (auraCard != null) {
FilterPermanent filterAttachTo = new FilterControlledCreaturePermanent("creature you control to attach " + auraCard.getIdName() + " to");
filterAttachTo.add(new StormHeraldAttachableToPredicate(auraCard));
TargetPermanent targetCreature = new TargetPermanent(filterAttachTo);
targetCreature.setNotTarget(true);
if (controller.choose(Outcome.PutCardInPlay, targetCreature, source.getSourceId(), game)) {
Permanent targetPermanent = game.getPermanent(targetCreature.getFirstTarget());
if (!targetPermanent.cantBeAttachedBy(auraCard, source, game, true)) {
game.getState().setValue("attachTo:" + auraCard.getId(), targetPermanent);
controller.moveCards(auraCard, Zone.BATTLEFIELD, source, game);
targetPermanent.addAttachment(auraCard.getId(), source, game);
Permanent permanent = game.getPermanent(auraId);
if (permanent != null) {
toExile.add(permanent);
}
}
}
}
}
ContinuousEffect continuousEffect = new StormHeraldReplacementEffect();
continuousEffect.setTargetPointer(new FixedTargets(toExile, game));
game.addEffect(continuousEffect, source);
Effect exileEffect = new ExileTargetEffect("exile those Auras");
exileEffect.setTargetPointer(new FixedTargets(toExile, game));
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect), source);
}
return true;
}
return false;
}
use of mage.abilities.effects.Effect in project mage by magefree.
the class TearsOfRageEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Effect effect = new SacrificeTargetEffect("Sacrifice those creatures at the beginning of the next end step", source.getControllerId());
effect.setTargetPointer(new FixedTargets(game.getBattlefield().getAllActivePermanents(new FilterAttackingCreature(), controller.getId(), game), game));
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect), source);
return true;
}
return false;
}
use of mage.abilities.effects.Effect in project mage by magefree.
the class TeferisTimeTwistReturnEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
Player player = game.getPlayer(source.getControllerId());
if (permanent == null || player == null) {
return false;
}
Effect effect = new TeferisTimeTwistReturnEffect(new MageObjectReference(permanent.getId(), permanent.getZoneChangeCounter(game) + 1, game));
if (!player.moveCards(permanent, Zone.EXILED, source, game)) {
return false;
}
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect), source);
return true;
}
use of mage.abilities.effects.Effect in project mage by magefree.
the class UnscytheEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (((ZoneChangeEvent) event).isDiesEvent()) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (zEvent.getTarget().isCreature(game)) {
// target token can't create Zombie
Permanent equipment = game.getPermanent(getSourceId());
// the currently equiped creature must have done damage to the dying creature
if (equipment != null && equipment.getAttachedTo() != null) {
boolean damageDealt = false;
for (MageObjectReference mor : zEvent.getTarget().getDealtDamageByThisTurn()) {
if (mor.refersTo(equipment.getAttachedTo(), game)) {
damageDealt = true;
break;
}
}
if (damageDealt) {
Effect effect = this.getEffects().get(0);
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
return true;
}
}
}
}
return false;
}
use of mage.abilities.effects.Effect in project mage by magefree.
the class VoidwalkEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller != null && permanent != null && sourceObject != null) {
if (controller.moveCardToExileWithInfo(permanent, source.getSourceId(), sourceObject.getIdName(), source, game, Zone.BATTLEFIELD, true)) {
// create delayed triggered ability
Effect effect = new ReturnToBattlefieldUnderOwnerControlTargetEffect(false, false);
effect.setText("Return that card to the battlefield under its owner's control at the beginning of the next end step");
effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game));
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect), source);
return true;
}
}
return false;
}
Aggregations