use of mage.abilities.effects.common.CopyEffect in project mage by magefree.
the class BodyDoubleCopyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
Target target = new TargetCardInGraveyard(new FilterCreatureCard("creature card in a graveyard"));
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
player.choose(outcome, target, source.getSourceId(), game);
Card copyFromCard = game.getCard(target.getFirstTarget());
if (copyFromCard != null) {
CopyEffect copyEffect = new CopyEffect(Duration.Custom, copyFromCard, source.getSourceId());
game.addEffect(copyEffect, source);
}
}
return true;
}
return false;
}
use of mage.abilities.effects.common.CopyEffect in project mage by magefree.
the class OlagLudevicsHubrisCopyApplier method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Cards cards = new CardsImpl(game.getExile().getExileZone(CardUtil.getExileZoneId(game, source)));
cards.removeIf(uuid -> !game.getCard(uuid).isCreature(game));
if (cards.isEmpty()) {
return false;
}
Card copyFromCard = getCard(cards, source, game);
if (copyFromCard == null) {
return false;
}
Permanent newBluePrint = new PermanentCard(copyFromCard, source.getControllerId(), game);
newBluePrint.assignNewId();
CopyApplier applier = new OlagLudevicsHubrisCopyApplier();
applier.apply(game, newBluePrint, source, source.getSourceId());
CopyEffect copyEffect = new CopyEffect(Duration.Custom, newBluePrint, source.getSourceId());
copyEffect.newId();
copyEffect.setApplier(applier);
Ability newAbility = source.copy();
copyEffect.init(newAbility, game);
game.addEffect(copyEffect, newAbility);
return false;
}
use of mage.abilities.effects.common.CopyEffect in project mage by magefree.
the class LazavDimirMastermindCopyApplier method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent lazavDimirMastermind = game.getPermanent(source.getSourceId());
Permanent newBluePrint = null;
if (controller != null && lazavDimirMastermind != null) {
Card copyFromCard = game.getCard(((FixedTarget) getTargetPointer()).getTarget());
if (copyFromCard != null) {
newBluePrint = new PermanentCard(copyFromCard, source.getControllerId(), game);
newBluePrint.assignNewId();
CopyApplier applier = new LazavDimirMastermindCopyApplier();
applier.apply(game, newBluePrint, source, lazavDimirMastermind.getId());
CopyEffect copyEffect = new CopyEffect(Duration.Custom, newBluePrint, lazavDimirMastermind.getId());
copyEffect.newId();
copyEffect.setApplier(applier);
Ability newAbility = source.copy();
copyEffect.init(newAbility, game);
game.addEffect(copyEffect, newAbility);
}
return true;
}
return false;
}
use of mage.abilities.effects.common.CopyEffect in project mage by magefree.
the class ZamWesselEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
if (targetPlayer != null) {
TargetCard targetCard = new TargetCard(0, 1, Zone.HAND, StaticFilters.FILTER_CARD_CREATURE);
controller.choose(outcome, targetPlayer.getHand(), targetCard, game);
Card copyFromCard = game.getCard(targetCard.getFirstTarget());
if (copyFromCard != null) {
game.informPlayers(controller.getLogName() + " chooses to copy " + copyFromCard.getName());
CopyEffect copyEffect = new CopyEffect(Duration.Custom, copyFromCard, source.getSourceId());
game.addEffect(copyEffect, source);
}
}
return true;
}
return false;
}
use of mage.abilities.effects.common.CopyEffect in project mage by magefree.
the class GameImpl method copyPermanent.
@Override
public Permanent copyPermanent(Duration duration, Permanent copyFromPermanent, UUID copyToPermanentId, Ability source, CopyApplier applier) {
Permanent newBluePrint = null;
// handle copies of copies
for (Effect effect : getState().getContinuousEffects().getLayeredEffects(this)) {
if (effect instanceof CopyEffect) {
CopyEffect copyEffect = (CopyEffect) effect;
// there is another copy effect that our targetPermanent copies stats from
if (copyEffect.getSourceId().equals(copyFromPermanent.getId())) {
MageObject oldBluePrint = ((CopyEffect) effect).getTarget();
if (oldBluePrint instanceof Permanent) {
// copy it and apply the applier if any
newBluePrint = ((Permanent) oldBluePrint).copy();
}
}
}
}
// if it was no copy of copy take the target itself
if (newBluePrint == null) {
newBluePrint = copyFromPermanent.copy();
newBluePrint.reset(this);
// getState().addCard(permanent);
if (copyFromPermanent.isMorphed() || copyFromPermanent.isManifested() || copyFromPermanent.isFaceDown(this)) {
MorphAbility.setPermanentToFaceDownCreature(newBluePrint, this);
}
newBluePrint.assignNewId();
if (copyFromPermanent.isTransformed()) {
TransformAbility.transformPermanent(newBluePrint, newBluePrint.getSecondCardFace(), this, source);
}
}
if (applier != null) {
applier.apply(this, newBluePrint, source, copyToPermanentId);
}
// save original copy link (handle copy of copies too)
newBluePrint.setCopy(true, (copyFromPermanent.getCopyFrom() != null ? copyFromPermanent.getCopyFrom() : copyFromPermanent));
CopyEffect newEffect = new CopyEffect(duration, newBluePrint, copyToPermanentId);
newEffect.newId();
newEffect.setApplier(applier);
Ability newAbility = source.copy();
newEffect.init(newAbility, this);
// If there are already copy effects with duration = Custom to the same object, remove the existing effects because they no longer have any effect
if (duration == Duration.Custom) {
for (Effect effect : getState().getContinuousEffects().getLayeredEffects(this)) {
if (effect instanceof CopyEffect) {
CopyEffect copyEffect = (CopyEffect) effect;
// there is another copy effect that copies to the same permanent
if (copyEffect.getSourceId().equals(copyToPermanentId) && copyEffect.getDuration() == Duration.Custom) {
copyEffect.discard();
}
}
}
}
state.addEffect(newEffect, newAbility);
return newBluePrint;
}
Aggregations