Search in sources :

Example 51 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class VolatileClawsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    for (Iterator<MageObjectReference> it = affectedObjectList.iterator(); it.hasNext(); ) {
        Permanent permanent = it.next().getPermanent(game);
        if (permanent == null) {
            // no longer on the battlefield, remove reference to object
            it.remove();
            continue;
        }
        permanent.setIsAllCreatureTypes(game, true);
    }
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) MageObjectReference(mage.MageObjectReference)

Example 52 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class VodalianWarMachineWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() == GameEvent.EventType.ACTIVATED_ABILITY) {
        if (event.getSourceId() != null) {
            Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
            if (sourcePermanent != null) {
                StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
                if (stackAbility != null) {
                    Ability ability = stackAbility.getStackAbility();
                    if (ability != null) {
                        for (Cost cost : ability.getCosts()) {
                            if (cost instanceof TapTargetCost && cost.isPaid()) {
                                TapTargetCost tapCost = (TapTargetCost) cost;
                                if (tapCost.getTarget().isChosen()) {
                                    MageObjectReference mor = new MageObjectReference(sourcePermanent.getId(), sourcePermanent.getZoneChangeCounter(game), game);
                                    Set<MageObjectReference> toAdd;
                                    if (tappedMerfolkIds.get(mor) == null) {
                                        toAdd = new HashSet<>();
                                    } else {
                                        toAdd = tappedMerfolkIds.get(mor);
                                    }
                                    for (UUID targetId : tapCost.getTarget().getTargets()) {
                                        toAdd.add(new MageObjectReference(targetId, game));
                                    }
                                    tappedMerfolkIds.put(mor, toAdd);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) DiesSourceTriggeredAbility(mage.abilities.common.DiesSourceTriggeredAbility) StackAbility(mage.game.stack.StackAbility) DefenderAbility(mage.abilities.keyword.DefenderAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TapTargetCost(mage.abilities.costs.common.TapTargetCost) TapTargetCost(mage.abilities.costs.common.TapTargetCost) Cost(mage.abilities.costs.Cost) StackAbility(mage.game.stack.StackAbility) MageObjectReference(mage.MageObjectReference)

Example 53 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class WishWatcher method applies.

@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    if (source.getControllerId().equals(affectedControllerId)) {
        Player controller = game.getPlayer(source.getControllerId());
        MageObject sourceObject = source.getSourceObject(game);
        UUID mainCardId = CardUtil.getMainCardId(game, objectId);
        if (controller != null && sourceObject != null && controller.getSideboard().contains(mainCardId)) {
            WishWatcher watcher = game.getState().getWatcher(WishWatcher.class);
            return watcher != null && !watcher.isAbilityUsed(new MageObjectReference(sourceObject, game));
        }
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) UUID(java.util.UUID) MageObjectReference(mage.MageObjectReference)

Example 54 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class ManifestTargetPlayerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (targetPlayer != null) {
        Ability newSource = source.copy();
        newSource.setWorksFaceDown(true);
        Set<Card> cards = targetPlayer.getLibrary().getTopCards(game, amount);
        for (Card card : cards) {
            ManaCosts manaCosts = null;
            if (card.isCreature(game)) {
                manaCosts = card.getSpellAbility().getManaCosts();
                if (manaCosts == null) {
                    manaCosts = new ManaCostsImpl("{0}");
                }
            }
            MageObjectReference objectReference = new MageObjectReference(card.getId(), card.getZoneChangeCounter(game) + 1, game);
            game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference, Duration.Custom, FaceDownType.MANIFESTED), newSource);
        }
        targetPlayer.moveCards(cards, Zone.BATTLEFIELD, source, game, false, true, false, null);
        for (Card card : cards) {
            Permanent permanent = game.getPermanent(card.getId());
            if (permanent != null) {
                permanent.setManifested(true);
            }
        }
        return true;
    }
    return false;
}
Also used : Ability(mage.abilities.Ability) ManaCosts(mage.abilities.costs.mana.ManaCosts) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card) BecomesFaceDownCreatureEffect(mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect)

Example 55 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class CaromEffect method init.

@Override
public void init(Ability source, Game game) {
    super.init(source, game);
    redirectToObject = new MageObjectReference(source.getTargets().get(1).getFirstTarget(), game);
}
Also used : 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