use of mage.abilities.effects.common.CreateTokenCopyTargetEffect in project mage by magefree.
the class MirrorMockeryEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
if (enchantment == null) {
return false;
}
Permanent enchanted = game.getPermanentOrLKIBattlefield(enchantment.getAttachedTo());
if (enchanted != null) {
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect();
effect.setTargetPointer(new FixedTarget(enchanted, game));
effect.apply(game, source);
for (Permanent addedToken : effect.getAddedPermanents()) {
if (addedToken != null) {
ExileTargetEffect exileEffect = new ExileTargetEffect();
exileEffect.setTargetPointer(new FixedTarget(addedToken, game));
game.addDelayedTriggeredAbility(new AtTheEndOfCombatDelayedTriggeredAbility(exileEffect), source);
}
}
return true;
}
return false;
}
use of mage.abilities.effects.common.CreateTokenCopyTargetEffect 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.abilities.effects.common.CreateTokenCopyTargetEffect in project mage by magefree.
the class MiragePhalanxEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = source.getSourcePermanentOrLKI(game);
if (permanent == null) {
return false;
}
// It has haste
CreateTokenCopyTargetEffect tokenCopyEffect = new CreateTokenCopyTargetEffect(source.getControllerId(), null, true);
tokenCopyEffect.setTargetPointer(new FixedTarget(permanent, game));
// It loses soulbond
tokenCopyEffect.addAbilityClassesToRemoveFromTokens(SoulbondAbility.class);
// Create the token(s)
tokenCopyEffect.apply(game, source);
// Exile it at the end of combat
tokenCopyEffect.exileTokensCreatedAtEndOfCombat(game, source);
return !tokenCopyEffect.getAddedPermanents().isEmpty();
}
use of mage.abilities.effects.common.CreateTokenCopyTargetEffect 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.abilities.effects.common.CreateTokenCopyTargetEffect in project mage by magefree.
the class SecondHarvestEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
FilterControlledPermanent filter = new FilterControlledPermanent("each token you control");
filter.add(TokenPredicate.TRUE);
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, controller.getId(), game)) {
if (permanent != null) {
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect();
effect.setTargetPointer(new FixedTarget(permanent, game));
effect.apply(game, source);
}
}
return true;
}
return false;
}
Aggregations