Search in sources :

Example 1 with BeginningOfUpkeepTriggeredAbility

use of mage.abilities.common.BeginningOfUpkeepTriggeredAbility in project mage by magefree.

the class GlyphOfDelusionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    if (source.getTargets().get(1) != null) {
        Permanent targetPermanent = game.getPermanent(source.getTargets().get(1).getFirstTarget());
        if (targetPermanent != null) {
            targetPermanent.addCounters(CounterType.GLYPH.createInstance(targetPermanent.getPower().getValue()), source.getControllerId(), source, game);
            SimpleStaticAbility ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new ConditionalContinuousRuleModifyingEffect(new DontUntapInControllersUntapStepSourceEffect(), new SourceHasCounterCondition(CounterType.GLYPH)).setText("This creature doesn't untap during your untap step if it has a glyph counter on it"));
            GainAbilityTargetEffect effect = new GainAbilityTargetEffect(ability, Duration.Custom);
            effect.setTargetPointer(new FixedTarget(targetPermanent.getId(), game));
            game.addEffect(effect, source);
            BeginningOfUpkeepTriggeredAbility ability2 = new BeginningOfUpkeepTriggeredAbility(new RemoveCounterSourceEffect(CounterType.GLYPH.createInstance()), TargetController.YOU, false);
            GainAbilityTargetEffect effect2 = new GainAbilityTargetEffect(ability2, Duration.Custom);
            effect2.setTargetPointer(new FixedTarget(targetPermanent.getId(), game));
            game.addEffect(effect2, source);
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) DontUntapInControllersUntapStepSourceEffect(mage.abilities.effects.common.DontUntapInControllersUntapStepSourceEffect) SourceHasCounterCondition(mage.abilities.condition.common.SourceHasCounterCondition) ConditionalContinuousRuleModifyingEffect(mage.abilities.decorator.ConditionalContinuousRuleModifyingEffect) RemoveCounterSourceEffect(mage.abilities.effects.common.counter.RemoveCounterSourceEffect)

Example 2 with BeginningOfUpkeepTriggeredAbility

use of mage.abilities.common.BeginningOfUpkeepTriggeredAbility in project mage by magefree.

the class VesuvanDoppelgangerCopyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null) {
        permanent = game.getPermanentEntering(source.getSourceId());
    }
    final Permanent sourcePermanent = permanent;
    if (controller != null && sourcePermanent != null) {
        Target target = new TargetPermanent(new FilterCreaturePermanent("target creature (you copy from)"));
        target.setRequired(true);
        if (source instanceof SimpleStaticAbility) {
            target = new TargetPermanent(new FilterCreaturePermanent("creature (you copy from)"));
            target.setRequired(false);
            target.setNotTarget(true);
        }
        if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
            controller.choose(Outcome.Copy, target, source.getSourceId(), game);
            Permanent copyFromPermanent = game.getPermanent(target.getFirstTarget());
            if (copyFromPermanent != null) {
                game.copyPermanent(copyFromPermanent, sourcePermanent.getId(), source, new CopyApplier() {

                    @Override
                    public boolean apply(Game game, MageObject blueprint, Ability source, UUID copyToObjectId) {
                        blueprint.getColor().setColor(sourcePermanent.getColor(game));
                        blueprint.getAbilities().add(new BeginningOfUpkeepTriggeredAbility(Zone.BATTLEFIELD, new VesuvanDoppelgangerCopyEffect(), TargetController.YOU, true, false, rule2));
                        return true;
                    }
                });
                return true;
            }
        }
    }
    return false;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) MageObject(mage.MageObject) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Game(mage.game.Game) CopyApplier(mage.util.functions.CopyApplier) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID)

Example 3 with BeginningOfUpkeepTriggeredAbility

use of mage.abilities.common.BeginningOfUpkeepTriggeredAbility in project mage by magefree.

the class CryptoplasmEffect method apply.

@Override
public boolean apply(Game game, final Ability source) {
    Permanent creatureToCopy = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (creatureToCopy != null) {
        CopyApplier applier = new CopyApplier() {

            @Override
            public boolean apply(Game game, MageObject blueprint, Ability source, UUID copyToObjectId) {
                Ability upkeepAbility = new BeginningOfUpkeepTriggeredAbility(new CryptoplasmEffect(), TargetController.YOU, true);
                upkeepAbility.addTarget(new TargetCreaturePermanent());
                blueprint.getAbilities().add(upkeepAbility);
                return true;
            }
        };
        game.copyPermanent(creatureToCopy, source.getSourceId(), source, applier);
    }
    return true;
}
Also used : BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) Ability(mage.abilities.Ability) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Game(mage.game.Game) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) CopyApplier(mage.util.functions.CopyApplier) MageObject(mage.MageObject) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) UUID(java.util.UUID)

Example 4 with BeginningOfUpkeepTriggeredAbility

use of mage.abilities.common.BeginningOfUpkeepTriggeredAbility in project mage by magefree.

the class ShiftingShadowEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent aura = source.getSourcePermanentIfItStillExists(game);
    if (aura == null) {
        return false;
    }
    Permanent permanent = game.getPermanent(aura.getAttachedTo());
    if (permanent == null) {
        return false;
    }
    permanent.addAbility(HasteAbility.getInstance(), source.getSourceId(), game);
    permanent.addAbility(new BeginningOfUpkeepTriggeredAbility(new ShiftingShadowEffect(aura, game), TargetController.YOU, false), source.getSourceId(), game);
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility)

Example 5 with BeginningOfUpkeepTriggeredAbility

use of mage.abilities.common.BeginningOfUpkeepTriggeredAbility in project mage by magefree.

the class ObsidianFireheartGainAbilityEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    // If the owner/controller of this card leaves the game, the blaze counters
    // presence on the targeted land will continue to deal 1 damage every upkeep
    // to the lands controller.
    Permanent targetLand = game.getPermanent(source.getFirstTarget());
    if (targetLand != null && source.getTargets().get(0) != null) {
        ContinuousEffect effect = new ObsidianFireheartGainAbilityEffect(new BeginningOfUpkeepTriggeredAbility(new DamageControllerEffect(1), TargetController.YOU, false), Duration.Custom, "");
        // add a new independent ability that is not reliant on the source ability
        SimpleStaticAbility gainAbility = new SimpleStaticAbility(Zone.BATTLEFIELD, effect);
        // set sourcecard of the independent ability to the targeted permanent of the source ability
        gainAbility.setSourceId(targetLand.getId());
        // the target of the source ability is added to the new independent ability
        gainAbility.getTargets().add(source.getTargets().get(0));
        // add the continuous effect to the game with the independent ability
        game.addEffect(effect, gainAbility);
        return true;
    }
    return false;
}
Also used : DamageControllerEffect(mage.abilities.effects.common.DamageControllerEffect) FilterLandPermanent(mage.filter.common.FilterLandPermanent) TargetLandPermanent(mage.target.common.TargetLandPermanent) Permanent(mage.game.permanent.Permanent) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

Aggregations

BeginningOfUpkeepTriggeredAbility (mage.abilities.common.BeginningOfUpkeepTriggeredAbility)5 Permanent (mage.game.permanent.Permanent)5 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)3 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)3 TargetPermanent (mage.target.TargetPermanent)3 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)3 UUID (java.util.UUID)2 MageObject (mage.MageObject)2 Ability (mage.abilities.Ability)2 Game (mage.game.Game)2 CopyApplier (mage.util.functions.CopyApplier)2 SourceHasCounterCondition (mage.abilities.condition.common.SourceHasCounterCondition)1 ConditionalContinuousRuleModifyingEffect (mage.abilities.decorator.ConditionalContinuousRuleModifyingEffect)1 ContinuousEffect (mage.abilities.effects.ContinuousEffect)1 DamageControllerEffect (mage.abilities.effects.common.DamageControllerEffect)1 DontUntapInControllersUntapStepSourceEffect (mage.abilities.effects.common.DontUntapInControllersUntapStepSourceEffect)1 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)1 RemoveCounterSourceEffect (mage.abilities.effects.common.counter.RemoveCounterSourceEffect)1 FilterLandPermanent (mage.filter.common.FilterLandPermanent)1 Player (mage.players.Player)1