Search in sources :

Example 56 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class CodespellClericWatcher method checkSpell.

boolean checkSpell(Ability source, Game game) {
    Permanent permanent = (Permanent) source.getEffects().get(0).getValue("permanentEnteredBattlefield");
    if (permanent == null) {
        return false;
    }
    int index = 0;
    for (MageObjectReference mor : spellMap.getOrDefault(source.getControllerId(), emptyList)) {
        index++;
        if (mor.getSourceId() == permanent.getId() && mor.getZoneChangeCounter() + 1 == permanent.getZoneChangeCounter(game)) {
            return index == 2;
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) MageObjectReference(mage.MageObjectReference)

Example 57 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class CyclopeanTombCounterWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObjectReference mor = new MageObjectReference(source.getSourceId(), source.getSourceObjectZoneChangeCounter(), game);
    CyclopeanTombCounterWatcher watcher = game.getState().getWatcher(CyclopeanTombCounterWatcher.class);
    if (controller != null && watcher != null) {
        Set<MageObjectReference> landRef = watcher.landMiredByCyclopeanTombInstance(mor, game);
        if (landRef == null || landRef.isEmpty()) {
            // no lands got mire counter from that instance
            return true;
        }
        FilterLandPermanent filter = new FilterLandPermanent("a land with a mire counter added from the Cyclopean Tomb instance (" + landRef.size() + " left)");
        Set<PermanentIdPredicate> idPref = new HashSet<>();
        for (MageObjectReference ref : landRef) {
            Permanent land = ref.getPermanent(game);
            if (land != null) {
                idPref.add(new PermanentIdPredicate(land.getId()));
            }
        }
        filter.add(Predicates.or(idPref));
        TargetLandPermanent target = new TargetLandPermanent(1, 1, filter, true);
        /*Player must choose a land each upkeep. Using the message are above the player hand where frequent interactions
             * take place is the most logical way to prompt for this scenario. A new constructor added to provide a not optional
             * option for any cards like this where the player must choose a target in such the way this card requires.
             */
        if (controller.chooseTarget(Outcome.Neutral, target, source, game)) {
            Permanent chosenLand = game.getPermanent(target.getFirstTarget());
            if (chosenLand != null) {
                Effect effect = new RemoveAllCountersTargetEffect(CounterType.MIRE);
                effect.setTargetPointer(new FixedTarget(chosenLand, game));
                effect.apply(game, source);
                landRef.remove(new MageObjectReference(chosenLand, game));
            }
        }
        return true;
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterLandPermanent(mage.filter.common.FilterLandPermanent) TargetLandPermanent(mage.target.common.TargetLandPermanent) Permanent(mage.game.permanent.Permanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) RemoveAllCountersTargetEffect(mage.abilities.effects.common.counter.RemoveAllCountersTargetEffect) BecomesBasicLandTargetEffect(mage.abilities.effects.common.continuous.BecomesBasicLandTargetEffect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) TargetLandPermanent(mage.target.common.TargetLandPermanent) RemoveAllCountersTargetEffect(mage.abilities.effects.common.counter.RemoveAllCountersTargetEffect) MageObjectReference(mage.MageObjectReference)

Example 58 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class ExhilaratingElocutionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (permanent == null) {
        return false;
    }
    permanent.addCounters(CounterType.P1P1.createInstance(2), source.getControllerId(), source, game);
    FilterCreaturePermanent filterPermanent = new FilterCreaturePermanent();
    filterPermanent.add(Predicates.not(new MageObjectReferencePredicate(new MageObjectReference(permanent, game))));
    game.addEffect(new BoostControlledEffect(1, 1, Duration.EndOfTurn, filterPermanent), source);
    return true;
}
Also used : FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) BoostControlledEffect(mage.abilities.effects.common.continuous.BoostControlledEffect) MageObjectReference(mage.MageObjectReference)

Example 59 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class GazeOfTheGorgonEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    if (!source.getTargets().isEmpty() && source.getFirstTarget() != null) {
        MageObjectReference mor = new MageObjectReference(source.getFirstTarget(), game);
        AtTheEndOfCombatDelayedTriggeredAbility delayedAbility = new AtTheEndOfCombatDelayedTriggeredAbility(new GazeOfTheGorgonEffect(mor));
        game.addDelayedTriggeredAbility(delayedAbility, source);
        return true;
    }
    return false;
}
Also used : AtTheEndOfCombatDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility) MageObjectReference(mage.MageObjectReference)

Example 60 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class HuntersInsightTriggeredAbility method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (permanent == null) {
        return false;
    }
    game.addDelayedTriggeredAbility(new HuntersInsightTriggeredAbility(new MageObjectReference(permanent, game)), source);
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) MageObjectReference(mage.MageObjectReference)

Aggregations

MageObjectReference (mage.MageObjectReference)250 Permanent (mage.game.permanent.Permanent)147 Player (mage.players.Player)76 UUID (java.util.UUID)47 Card (mage.cards.Card)45 Ability (mage.abilities.Ability)34 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)33 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)26 OneShotEffect (mage.abilities.effects.OneShotEffect)24 FilterPermanent (mage.filter.FilterPermanent)23 Game (mage.game.Game)22 Spell (mage.game.stack.Spell)21 TargetPermanent (mage.target.TargetPermanent)20 CardImpl (mage.cards.CardImpl)18 CardSetInfo (mage.cards.CardSetInfo)18 MageObject (mage.MageObject)17 Effect (mage.abilities.effects.Effect)16 HashSet (java.util.HashSet)15 mage.constants (mage.constants)14 GameEvent (mage.game.events.GameEvent)13