Search in sources :

Example 6 with Condition

use of mage.abilities.condition.Condition in project mage by magefree.

the class DreadWightCounterCondition method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
    if (permanent != null) {
        // add paralyzation counter
        Effect effect = new AddCountersTargetEffect(CounterType.PARALYZATION.createInstance());
        effect.setTargetPointer(new FixedTarget(permanent, game));
        effect.apply(game, source);
        // tap permanent
        permanent.tap(source, game);
        // does not untap while paralyzation counter is on it
        ContinuousRuleModifyingEffect effect2 = new DreadWightDoNotUntapEffect(Duration.WhileOnBattlefield, permanent.getId());
        effect2.setText("This creature doesn't untap during its controller's untap step for as long as it has a paralyzation counter on it");
        Condition condition = new DreadWightCounterCondition(permanent.getId());
        ConditionalContinuousRuleModifyingEffect conditionalEffect = new ConditionalContinuousRuleModifyingEffect(effect2, condition);
        Ability ability = new SimpleStaticAbility(Zone.BATTLEFIELD, conditionalEffect);
        ContinuousEffect effect3 = new GainAbilityTargetEffect(ability, Duration.WhileOnBattlefield);
        ability.setRuleVisible(true);
        effect3.setTargetPointer(new FixedTarget(permanent, game));
        game.addEffect(effect3, source);
        // each gains 4: remove paralyzation counter
        Ability activatedAbility = new SimpleActivatedAbility(Zone.BATTLEFIELD, new RemoveCounterSourceEffect(CounterType.PARALYZATION.createInstance()), new ManaCostsImpl("{4}"));
        ContinuousEffect effect4 = new GainAbilityTargetEffect(activatedAbility, Duration.WhileOnBattlefield);
        effect4.setTargetPointer(new FixedTarget(permanent, game));
        game.addEffect(effect4, source);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Condition(mage.abilities.condition.Condition) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) AtTheEndOfCombatDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) ConditionalContinuousRuleModifyingEffect(mage.abilities.decorator.ConditionalContinuousRuleModifyingEffect) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ConditionalContinuousRuleModifyingEffect(mage.abilities.decorator.ConditionalContinuousRuleModifyingEffect) ContinuousRuleModifyingEffect(mage.abilities.effects.ContinuousRuleModifyingEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) CreateDelayedTriggeredAbilityEffect(mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect) ConditionalContinuousRuleModifyingEffect(mage.abilities.decorator.ConditionalContinuousRuleModifyingEffect) ContinuousRuleModifyingEffect(mage.abilities.effects.ContinuousRuleModifyingEffect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) RemoveCounterSourceEffect(mage.abilities.effects.common.counter.RemoveCounterSourceEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) RemoveCounterSourceEffect(mage.abilities.effects.common.counter.RemoveCounterSourceEffect)

Example 7 with Condition

use of mage.abilities.condition.Condition in project mage by magefree.

the class PlaneswalkersMischiefCondition method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(source.getFirstTarget());
    if (opponent != null && opponent.getHand().size() > 0) {
        Card revealedCard = opponent.getHand().getRandom(game);
        if (revealedCard == null) {
            return false;
        }
        Cards cards = new CardsImpl(revealedCard);
        opponent.revealCards(source, cards, game);
        if (revealedCard.isInstant(game) || revealedCard.isSorcery(game)) {
            opponent.moveCardToExileWithInfo(revealedCard, source.getSourceId(), "Planeswalker's Mischief", source, game, Zone.HAND, true);
            AsThoughEffect effect = new PlaneswalkersMischiefCastFromExileEffect();
            effect.setTargetPointer(new FixedTarget(revealedCard.getId()));
            game.addEffect(effect, source);
            OneShotEffect effect2 = new ReturnFromExileEffect(Zone.HAND);
            Condition condition = new PlaneswalkersMischiefCondition(source.getSourceId(), revealedCard.getId());
            ConditionalOneShotEffect effect3 = new ConditionalOneShotEffect(effect2, condition, "if you haven't cast it, return it to its owner's hand.");
            DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect3);
            delayedAbility.addWatcher(new SpellsCastWatcher());
            game.addDelayedTriggeredAbility(delayedAbility, source);
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Condition(mage.abilities.condition.Condition) Player(mage.players.Player) ReturnFromExileEffect(mage.abilities.effects.common.ReturnFromExileEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) ConditionalOneShotEffect(mage.abilities.decorator.ConditionalOneShotEffect) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) AsThoughEffect(mage.abilities.effects.AsThoughEffect) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) SpellsCastWatcher(mage.watchers.common.SpellsCastWatcher) ConditionalOneShotEffect(mage.abilities.decorator.ConditionalOneShotEffect)

Example 8 with Condition

use of mage.abilities.condition.Condition in project mage by magefree.

the class LevelerCardBuilder method build.

/**
 * Main method constructing ability.
 *
 * @return
 */
public List<Ability> build() {
    List<Ability> constructed = new ArrayList<>();
    Condition condition = new SourceHasCounterCondition(CounterType.LEVEL, level1, level2);
    for (Ability ability : abilities) {
        ContinuousEffect effect = new GainAbilitySourceEffect(ability);
        ConditionalContinuousEffect abEffect = new ConditionalContinuousEffect(effect, condition, "");
        Ability staticAbility = new SimpleStaticAbility(Zone.BATTLEFIELD, abEffect);
        staticAbility.setRuleVisible(false);
        constructed.add(staticAbility);
    }
    ContinuousEffect effect = new SetPowerToughnessSourceEffect(power, toughness, Duration.WhileOnBattlefield, SubLayer.SetPT_7b);
    ConditionalContinuousEffect ptEffect = new ConditionalContinuousEffect(effect, condition, rule);
    constructed.add(new SimpleStaticAbility(Zone.BATTLEFIELD, ptEffect));
    return constructed;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Ability(mage.abilities.Ability) SourceHasCounterCondition(mage.abilities.condition.common.SourceHasCounterCondition) Condition(mage.abilities.condition.Condition) SetPowerToughnessSourceEffect(mage.abilities.effects.common.continuous.SetPowerToughnessSourceEffect) GainAbilitySourceEffect(mage.abilities.effects.common.continuous.GainAbilitySourceEffect) ArrayList(java.util.ArrayList) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) ConditionalContinuousEffect(mage.abilities.decorator.ConditionalContinuousEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) SourceHasCounterCondition(mage.abilities.condition.common.SourceHasCounterCondition) ConditionalContinuousEffect(mage.abilities.decorator.ConditionalContinuousEffect)

Example 9 with Condition

use of mage.abilities.condition.Condition in project mage by magefree.

the class BarrinsUnmakingEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (permanent != null) {
        Condition condition = new MostCommonColorCondition(permanent.getColor(game));
        if (condition.apply(game, source)) {
            Effect effect = new ReturnToHandTargetEffect();
            effect.setTargetPointer(new FixedTarget(permanent, game));
            return effect.apply(game, source);
        }
    }
    return false;
}
Also used : MostCommonColorCondition(mage.abilities.condition.common.MostCommonColorCondition) Condition(mage.abilities.condition.Condition) FixedTarget(mage.target.targetpointer.FixedTarget) MostCommonColorCondition(mage.abilities.condition.common.MostCommonColorCondition) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect)

Aggregations

Condition (mage.abilities.condition.Condition)9 Permanent (mage.game.permanent.Permanent)5 MostCommonColorCondition (mage.abilities.condition.common.MostCommonColorCondition)4 Effect (mage.abilities.effects.Effect)4 OneShotEffect (mage.abilities.effects.OneShotEffect)4 Player (mage.players.Player)4 FixedTarget (mage.target.targetpointer.FixedTarget)4 UUID (java.util.UUID)2 ObjectColor (mage.ObjectColor)2 Ability (mage.abilities.Ability)2 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)2 ContinuousEffect (mage.abilities.effects.ContinuousEffect)2 FilterPermanent (mage.filter.FilterPermanent)2 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)2 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)2 ArrayList (java.util.ArrayList)1 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)1 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)1 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)1 AtTheEndOfCombatDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility)1