Search in sources :

Example 46 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class ShamanEnKorRedirectFromTargetEffect method init.

@Override
public void init(Ability source, Game game) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        TargetSource target = new TargetSource();
        target.choose(Outcome.PreventDamage, player.getId(), source.getSourceId(), game);
        this.sourceObject = new MageObjectReference(target.getFirstTarget(), game);
    } else {
        discard();
    }
}
Also used : TargetSource(mage.target.TargetSource) Player(mage.players.Player) MageObjectReference(mage.MageObjectReference)

Example 47 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class TeferisTimeTwistReturnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    Player player = game.getPlayer(source.getControllerId());
    if (permanent == null || player == null) {
        return false;
    }
    Effect effect = new TeferisTimeTwistReturnEffect(new MageObjectReference(permanent.getId(), permanent.getZoneChangeCounter(game) + 1, game));
    if (!player.moveCards(permanent, Zone.EXILED, source, game)) {
        return false;
    }
    game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect), source);
    return true;
}
Also used : Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) MageObjectReference(mage.MageObjectReference)

Example 48 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class ToralfsHammerEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    DamagedEvent dEvent = (DamagedEvent) event;
    if (dEvent.getExcess() < 1 || dEvent.isCombatDamage() || !game.getOpponents(getControllerId()).contains(game.getControllerId(event.getTargetId()))) {
        return false;
    }
    this.getEffects().clear();
    this.getTargets().clear();
    this.addEffect(new DamageTargetEffect(dEvent.getExcess()));
    FilterCreaturePlayerOrPlaneswalker filter = new FilterCreaturePlayerOrPlaneswalker();
    filter.getPermanentFilter().add(Predicates.not(new MageObjectReferencePredicate(new MageObjectReference(event.getTargetId(), game))));
    this.addTarget(new TargetAnyTarget(filter));
    return true;
}
Also used : DamagedEvent(mage.game.events.DamagedEvent) FilterCreaturePlayerOrPlaneswalker(mage.filter.common.FilterCreaturePlayerOrPlaneswalker) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) MageObjectReference(mage.MageObjectReference) TargetAnyTarget(mage.target.common.TargetAnyTarget)

Example 49 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class TotalWarDestroyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player activePlayer = game.getPlayer(game.getActivePlayerId());
    if (activePlayer != null) {
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(activePlayer.getId())) {
            // Noncreature cards are safe.
            if (!permanent.isCreature(game)) {
                continue;
            }
            // Tapped cards are safe.
            if (permanent.isTapped()) {
                continue;
            }
            // Walls are safe.
            if (permanent.hasSubtype(SubType.WALL, game)) {
                continue;
            }
            // Creatures that attacked are safe.
            AttackedOrBlockedThisCombatWatcher watcher = game.getState().getWatcher(AttackedOrBlockedThisCombatWatcher.class);
            if (watcher != null && watcher.getAttackedThisTurnCreatures().contains(new MageObjectReference(permanent, game))) {
                continue;
            }
            // Creatures that weren't controlled since the beginning of turn are safe.
            if (!permanent.wasControlledFromStartOfControllerTurn()) {
                continue;
            }
            // Destroy the rest.
            permanent.destroy(source, game, false);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) AttackedOrBlockedThisCombatWatcher(mage.watchers.common.AttackedOrBlockedThisCombatWatcher) MageObjectReference(mage.MageObjectReference)

Example 50 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class UnscytheEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (((ZoneChangeEvent) event).isDiesEvent()) {
        ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
        if (zEvent.getTarget().isCreature(game)) {
            // target token can't create Zombie
            Permanent equipment = game.getPermanent(getSourceId());
            // the currently equiped creature must have done damage to the dying creature
            if (equipment != null && equipment.getAttachedTo() != null) {
                boolean damageDealt = false;
                for (MageObjectReference mor : zEvent.getTarget().getDealtDamageByThisTurn()) {
                    if (mor.refersTo(equipment.getAttachedTo(), game)) {
                        damageDealt = true;
                        break;
                    }
                }
                if (damageDealt) {
                    Effect effect = this.getEffects().get(0);
                    effect.setTargetPointer(new FixedTarget(event.getTargetId()));
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) BoostEquippedEffect(mage.abilities.effects.common.continuous.BoostEquippedEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) GainAbilityAttachedEffect(mage.abilities.effects.common.continuous.GainAbilityAttachedEffect) 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