Search in sources :

Example 51 with Effect

use of mage.abilities.effects.Effect in project mage by magefree.

the class DestroyPlaneswalkerWhenDamagedTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Permanent permanent = getSourcePermanentIfItStillExists(game);
    if (permanent == null) {
        return false;
    }
    boolean applies = filter != null ? permanent.isPlaneswalker(game) && filter.match(permanent, game) : event.getSourceId().equals(getSourceId());
    if (applies) {
        Effect effect = new DestroyTargetEffect();
        effect.setTargetPointer(new FixedTarget(event.getTargetId(), game));
        this.getEffects().clear();
        this.addEffect(effect);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent) DestroyTargetEffect(mage.abilities.effects.common.DestroyTargetEffect) DestroyTargetEffect(mage.abilities.effects.common.DestroyTargetEffect) Effect(mage.abilities.effects.Effect)

Example 52 with Effect

use of mage.abilities.effects.Effect in project mage by magefree.

the class LicidSpecialActionEffect method apply.

@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
    Permanent licid = (Permanent) source.getSourceObjectIfItStillExists(game);
    if (licid != null) {
        switch(layer) {
            case TypeChangingEffects_4:
                licid.removeAllCardTypes(game);
                licid.addCardType(game, CardType.ENCHANTMENT);
                licid.removeAllSubTypes(game);
                licid.addSubType(game, SubType.AURA);
                break;
            case AbilityAddingRemovingEffects_6:
                List<Ability> toRemove = new ArrayList<>();
                for (Ability ability : licid.getAbilities(game)) {
                    for (Effect effect : ability.getEffects()) {
                        if (effect instanceof LicidEffect) {
                            toRemove.add(ability);
                            break;
                        }
                    }
                }
                licid.removeAbilities(toRemove, source.getSourceId(), game);
                Ability ability = new EnchantAbility("creature");
                ability.setRuleAtTheTop(true);
                licid.addAbility(ability, source.getSourceId(), game);
                licid.getSpellAbility().getTargets().clear();
                Target target = new TargetCreaturePermanent();
                target.addTarget(this.getTargetPointer().getFirst(game, source), source, game);
                licid.getSpellAbility().getTargets().add(target);
        }
        return true;
    }
    discard();
    return false;
}
Also used : EnchantAbility(mage.abilities.keyword.EnchantAbility) Ability(mage.abilities.Ability) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ArrayList(java.util.ArrayList) OneShotEffect(mage.abilities.effects.OneShotEffect) RemoveSpecialActionEffect(mage.abilities.effects.common.RemoveSpecialActionEffect) Effect(mage.abilities.effects.Effect) CreateSpecialActionEffect(mage.abilities.effects.common.CreateSpecialActionEffect) AttachEffect(mage.abilities.effects.common.AttachEffect) EnchantAbility(mage.abilities.keyword.EnchantAbility)

Example 53 with Effect

use of mage.abilities.effects.Effect in project mage by magefree.

the class LeavesBattlefieldAllTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    if (zEvent.getFromZone() == Zone.BATTLEFIELD) {
        UUID targetId = event.getTargetId();
        Permanent permanent = game.getPermanentOrLKIBattlefield(targetId);
        if (filter.match(permanent, getSourceId(), getControllerId(), game)) {
            if (setTargetPointer != SetTargetPointer.NONE) {
                for (Effect effect : this.getEffects()) {
                    switch(setTargetPointer) {
                        case PERMANENT:
                            effect.setTargetPointer(new FixedTarget(permanent, game));
                            break;
                        case PLAYER:
                            effect.setTargetPointer(new FixedTarget(permanent.getControllerId()));
                            break;
                    }
                }
            }
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent) Effect(mage.abilities.effects.Effect) UUID(java.util.UUID)

Example 54 with Effect

use of mage.abilities.effects.Effect in project mage by magefree.

the class CreateTokenCopyTargetEffect method removeTokensCreatedAtEndOf.

private void removeTokensCreatedAtEndOf(Game game, Ability source, PhaseStep phaseStepToExileCards, boolean exile) {
    Effect effect;
    if (exile) {
        effect = new ExileTargetEffect(null, "", Zone.BATTLEFIELD).setText("exile the token copies");
    } else {
        effect = new SacrificeTargetEffect("sacrifice the token copies");
    }
    effect.setTargetPointer(new FixedTargets(addedTokenPermanents, game));
    DelayedTriggeredAbility exileAbility;
    switch(phaseStepToExileCards) {
        case END_TURN:
            exileAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect);
            break;
        case END_COMBAT:
            exileAbility = new AtTheEndOfCombatDelayedTriggeredAbility(effect);
            break;
        default:
            return;
    }
    game.addDelayedTriggeredAbility(exileAbility, source);
}
Also used : AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) FixedTargets(mage.target.targetpointer.FixedTargets) AtTheEndOfCombatDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) OneShotEffect(mage.abilities.effects.OneShotEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Effect(mage.abilities.effects.Effect) AtTheEndOfCombatDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility)

Example 55 with Effect

use of mage.abilities.effects.Effect in project mage by magefree.

the class CopyPermanentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourcePermanent = game.getPermanentEntering(source.getSourceId());
    if (sourcePermanent == null) {
        sourcePermanent = game.getObject(source.getSourceId());
    }
    if (controller == null || sourcePermanent == null) {
        return false;
    }
    Permanent copyFromPermanent = null;
    if (useTargetOfAbility) {
        copyFromPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    } else {
        Target target = new TargetPermanent(filter);
        target.setNotTarget(true);
        if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
            controller.choose(Outcome.Copy, target, source.getSourceId(), game);
            copyFromPermanent = game.getPermanent(target.getFirstTarget());
        }
    }
    if (copyFromPermanent == null) {
        return true;
    }
    bluePrintPermanent = game.copyPermanent(duration, copyFromPermanent, sourcePermanent.getId(), source, applier);
    if (bluePrintPermanent == null) {
        return false;
    }
    // if object is a copy of an aura, it needs to attach again for new target
    if (!bluePrintPermanent.hasSubtype(SubType.AURA, game)) {
        return true;
    }
    // copied from mage.cards.c.CopyEnchantment.java
    // permanent can be attached (Estrid's Mask) or enchant (Utopia Sprawl)
    // TODO: fix Animate Dead -- it's can't be copied (can't retarget)
    Outcome auraOutcome = Outcome.BoostCreature;
    Target auraTarget = null;
    // attach - search effect in spell ability (example: cast Utopia Sprawl, cast Estrid's Invocation on it)
    for (Ability ability : bluePrintPermanent.getAbilities()) {
        if (!(ability instanceof SpellAbility)) {
            continue;
        }
        auraOutcome = ability.getEffects().getOutcome(ability);
        for (Effect effect : ability.getEffects()) {
            if (!(effect instanceof AttachEffect)) {
                continue;
            }
            if (bluePrintPermanent.getSpellAbility().getTargets().size() > 0) {
                auraTarget = bluePrintPermanent.getSpellAbility().getTargets().get(0);
            }
        }
    }
    // enchant - search in all abilities (example: cast Estrid's Invocation on enchanted creature by Estrid, the Masked second ability, cast Estrid's Invocation on it)
    if (auraTarget == null) {
        for (Ability ability : bluePrintPermanent.getAbilities()) {
            if (!(ability instanceof EnchantAbility)) {
                continue;
            }
            auraOutcome = ability.getEffects().getOutcome(ability);
            if (ability.getTargets().size() > 0) {
                // Animate Dead don't have targets
                auraTarget = ability.getTargets().get(0);
            }
        }
    }
    /* if this is a copy of a copy, the copy's target has been
         * copied and needs to be cleared
         */
    if (auraTarget == null) {
        return true;
    }
    // clear selected target
    if (auraTarget.getFirstTarget() != null) {
        auraTarget.remove(auraTarget.getFirstTarget());
    }
    // select new target
    auraTarget.setNotTarget(true);
    if (!controller.choose(auraOutcome, auraTarget, source.getSourceId(), game)) {
        return true;
    }
    UUID targetId = auraTarget.getFirstTarget();
    Permanent targetPermanent = game.getPermanent(targetId);
    Player targetPlayer = game.getPlayer(targetId);
    if (targetPermanent != null) {
        targetPermanent.addAttachment(sourcePermanent.getId(), source, game);
    } else if (targetPlayer != null) {
        targetPlayer.addAttachment(sourcePermanent.getId(), source, game);
    } else {
        return false;
    }
    return true;
}
Also used : EnchantAbility(mage.abilities.keyword.EnchantAbility) SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) Outcome(mage.constants.Outcome) MageObject(mage.MageObject) SpellAbility(mage.abilities.SpellAbility) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) TargetPermanent(mage.target.TargetPermanent) EnchantAbility(mage.abilities.keyword.EnchantAbility) UUID(java.util.UUID)

Aggregations

Effect (mage.abilities.effects.Effect)328 OneShotEffect (mage.abilities.effects.OneShotEffect)254 FixedTarget (mage.target.targetpointer.FixedTarget)224 Permanent (mage.game.permanent.Permanent)180 Player (mage.players.Player)167 UUID (java.util.UUID)75 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)60 Card (mage.cards.Card)57 MageObject (mage.MageObject)41 ContinuousEffect (mage.abilities.effects.ContinuousEffect)40 TargetPermanent (mage.target.TargetPermanent)39 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)38 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)38 FilterPermanent (mage.filter.FilterPermanent)29 ReturnToBattlefieldUnderOwnerControlTargetEffect (mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect)28 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)27 AddCountersTargetEffect (mage.abilities.effects.common.counter.AddCountersTargetEffect)25 DamageTargetEffect (mage.abilities.effects.common.DamageTargetEffect)24 AttachEffect (mage.abilities.effects.common.AttachEffect)23 Target (mage.target.Target)22