use of mage.abilities.effects.common.CreateTokenCopyTargetEffect in project mage by magefree.
the class CreateTokenCopySourceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (permanent == null) {
return false;
}
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(source.getControllerId(), null, false, number, tapped, false);
effect.setTargetPointer(new FixedTarget(source.getSourceId(), game));
return effect.apply(game, source);
}
use of mage.abilities.effects.common.CreateTokenCopyTargetEffect in project mage by magefree.
the class FaerieArtisansEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanentToCopy = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && permanentToCopy != null) {
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(null, CardType.ARTIFACT, false);
effect.setTargetPointer(new FixedTarget(permanentToCopy, game));
if (effect.apply(game, source)) {
String oldTokens = (String) game.getState().getValue(source.getSourceId().toString() + source.getSourceObjectZoneChangeCounter());
StringBuilder sb = new StringBuilder();
for (Permanent permanent : effect.getAddedPermanents()) {
if (sb.length() > 0) {
sb.append(';');
}
sb.append(permanent.getId());
}
game.getState().setValue(source.getSourceId().toString() + source.getSourceObjectZoneChangeCounter(), sb.toString());
if (oldTokens != null) {
Cards cards = new CardsImpl();
StringTokenizer tokenizer = new StringTokenizer(oldTokens, ";");
while (tokenizer.hasMoreTokens()) {
String tokenId = tokenizer.nextToken();
cards.add(UUID.fromString(tokenId));
}
controller.moveCards(cards, Zone.EXILED, source, game);
}
return true;
}
}
return false;
}
use of mage.abilities.effects.common.CreateTokenCopyTargetEffect in project mage by magefree.
the class FlamerushRiderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (controller != null && permanent != null) {
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(source.getControllerId(), null, true, 1, true, true);
effect.setTargetPointer(new FixedTarget(permanent, game));
effect.apply(game, source);
for (Permanent addedToken : effect.getAddedPermanents()) {
Effect exileEffect = new ExileTargetEffect();
exileEffect.setTargetPointer(new FixedTarget(addedToken, game));
new CreateDelayedTriggeredAbilityEffect(new AtTheEndOfCombatDelayedTriggeredAbility(exileEffect), false).apply(game, source);
}
return true;
}
return false;
}
use of mage.abilities.effects.common.CreateTokenCopyTargetEffect in project mage by magefree.
the class FlameshadowConjuringEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (permanent != null) {
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(null, null, true);
effect.setTargetPointer(getTargetPointer());
if (effect.apply(game, source)) {
for (Permanent tokenPermanent : effect.getAddedPermanents()) {
ExileTargetEffect exileEffect = new ExileTargetEffect();
exileEffect.setTargetPointer(new FixedTarget(tokenPermanent, 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 HauntingImitationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Cards cards = new CardsImpl();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
Card card = player.getLibrary().getFromTop(game);
if (card == null) {
continue;
}
player.revealCards(source, new CardsImpl(cards), game);
if (card.isCreature(game)) {
cards.add(card);
}
}
if (cards.isEmpty()) {
Player player = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObjectIfItStillExists(game);
if (player != null && sourceObject instanceof Card) {
player.moveCards((Card) sourceObject, Zone.HAND, source, game);
}
return true;
}
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(source.getControllerId(), null, false, 1, false, false, null, 1, 1, true);
effect.setAdditionalSubType(SubType.SPIRIT);
for (Card card : cards.getCards(game)) {
effect.setSavedPermanent(new PermanentCard(card, source.getControllerId(), game));
effect.apply(game, source);
}
return true;
}
Aggregations