Search in sources :

Example 46 with Effect

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

the class TrostaniSelesnyasVoiceEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Permanent permanent = game.getPermanent(event.getTargetId());
    if (permanent != null && permanent.isCreature(game) && permanent.isControlledBy(this.controllerId) && !Objects.equals(event.getTargetId(), this.getSourceId())) {
        Effect effect = this.getEffects().get(0);
        // life is determined during resolution so it has to be retrieved there (e.g. Giant Growth before resolution)
        effect.setValue("lifeSource", event.getTargetId());
        effect.setValue("zoneChangeCounter", permanent.getZoneChangeCounter(game));
        return true;
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) OneShotEffect(mage.abilities.effects.OneShotEffect) PopulateEffect(mage.abilities.effects.common.PopulateEffect) Effect(mage.abilities.effects.Effect)

Example 47 with Effect

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

the class WaylayEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Token token = new WaylayToken();
    token.putOntoBattlefield(3, game, source, source.getControllerId());
    List<Permanent> toExile = new ArrayList<>();
    for (UUID tokenId : token.getLastAddedTokenIds()) {
        Permanent tokenPermanent = game.getPermanent(tokenId);
        if (tokenPermanent != null) {
            toExile.add(tokenPermanent);
        }
    }
    Effect effect = new ExileTargetEffect();
    effect.setTargetPointer(new FixedTargets(toExile, game));
    game.addDelayedTriggeredAbility(new AtTheBeginOfNextCleanupDelayedTriggeredAbility(effect), source);
    return true;
}
Also used : AtTheBeginOfNextCleanupDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextCleanupDelayedTriggeredAbility) Permanent(mage.game.permanent.Permanent) FixedTargets(mage.target.targetpointer.FixedTargets) ArrayList(java.util.ArrayList) WaylayToken(mage.game.permanent.token.WaylayToken) Token(mage.game.permanent.token.Token) WaylayToken(mage.game.permanent.token.WaylayToken) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) UUID(java.util.UUID) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Example 48 with Effect

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

the class WolfOfDevilsBreachDiscardCostCardConvertedManaCount method calculate.

@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
    for (Effect sourceEffect : sourceAbility.getEffects()) {
        if (sourceEffect instanceof DoIfCostPaid) {
            Cost doCosts = ((DoIfCostPaid) sourceEffect).getCost();
            if (doCosts instanceof Costs) {
                Costs costs = (Costs) doCosts;
                for (Object cost : costs) {
                    if (cost instanceof DiscardCardCost) {
                        DiscardCardCost discardCost = (DiscardCardCost) cost;
                        int cmc = 0;
                        for (Card card : discardCost.getCards()) {
                            cmc += card.getManaValue();
                        }
                        return cmc;
                    }
                }
            }
        }
    }
    return 0;
}
Also used : DiscardCardCost(mage.abilities.costs.common.DiscardCardCost) Costs(mage.abilities.costs.Costs) DoIfCostPaid(mage.abilities.effects.common.DoIfCostPaid) Effect(mage.abilities.effects.Effect) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) DiscardCardCost(mage.abilities.costs.common.DiscardCardCost) Cost(mage.abilities.costs.Cost) Card(mage.cards.Card)

Example 49 with Effect

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

the class DealsDamageToACreatureAllTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Permanent permanent = game.getPermanent(event.getTargetId());
    if (permanent == null || !permanent.isCreature(game)) {
        return false;
    }
    if (combatDamageOnly && !((DamagedEvent) event).isCombatDamage()) {
        return false;
    }
    permanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
    if (!filterPermanent.match(permanent, getSourceId(), getControllerId(), game)) {
        return false;
    }
    for (Effect effect : this.getEffects()) {
        effect.setValue("damage", event.getAmount());
        effect.setValue("sourceId", event.getSourceId());
        switch(setTargetPointer) {
            case PLAYER:
                effect.setTargetPointer(new FixedTarget(permanent.getControllerId()));
                break;
            case PERMANENT:
                effect.setTargetPointer(new FixedTarget(permanent, game));
                break;
            case PERMANENT_TARGET:
                Permanent permanent_target = game.getPermanentOrLKIBattlefield(event.getTargetId());
                if (permanent_target != null) {
                    effect.setTargetPointer(new FixedTarget(permanent_target, game));
                }
                break;
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent) DamagedEvent(mage.game.events.DamagedEvent) Effect(mage.abilities.effects.Effect)

Example 50 with Effect

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

the class DealsDamageToOpponentTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getSourceId().equals(this.sourceId) && game.getOpponents(this.getControllerId()).contains(event.getTargetId())) {
        if (onlyCombat && event instanceof DamagedPlayerEvent) {
            DamagedPlayerEvent damageEvent = (DamagedPlayerEvent) event;
            if (!damageEvent.isCombatDamage()) {
                return false;
            }
        }
        if (setTargetPointer) {
            for (Effect effect : getEffects()) {
                effect.setTargetPointer(new FixedTarget(event.getTargetId(), game));
                effect.setValue("damage", event.getAmount());
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Effect(mage.abilities.effects.Effect) DamagedPlayerEvent(mage.game.events.DamagedPlayerEvent)

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