Search in sources :

Example 11 with StackObject

use of mage.game.stack.StackObject in project mage by magefree.

the class SourceTargetsPermanentCondition method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject sourceSpell = game.getStack().getStackObject(source.getSourceId());
    if (sourceSpell == null) {
        return false;
    }
    Iterator<Target> targets = sourceSpell.getStackAbility().getTargets().iterator();
    while (targets.hasNext()) {
        Permanent permanent = game.getPermanentOrLKIBattlefield(targets.next().getFirstTarget());
        if (filter.match(permanent, source.getSourceId(), source.getControllerId(), game)) {
            return true;
        }
    }
    return false;
}
Also used : Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent) StackObject(mage.game.stack.StackObject)

Example 12 with StackObject

use of mage.game.stack.StackObject in project mage by magefree.

the class ReplicateCopyEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getSourceId().equals(this.sourceId)) {
        StackObject spell = game.getStack().getStackObject(this.sourceId);
        if (spell instanceof Spell) {
            Card card = ((Spell) spell).getCard();
            if (card != null) {
                for (Ability ability : card.getAbilities(game)) {
                    if (ability instanceof ReplicateAbility) {
                        if (ability.isActivated()) {
                            for (Effect effect : this.getEffects()) {
                                effect.setValue("ReplicateSpell", spell);
                                effect.setValue("ReplicateCount", ((ReplicateAbility) ability).getActivateCount());
                            }
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : StaticAbility(mage.abilities.StaticAbility) SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) StackObject(mage.game.stack.StackObject) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Example 13 with StackObject

use of mage.game.stack.StackObject in project mage by magefree.

the class DomriChaosBringerTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!event.getSourceId().equals(spellId)) {
        return false;
    }
    if (game.getTurnNum() != turnNumber) {
        return false;
    }
    MageObject mo = game.getObject(event.getTargetId());
    if (mo == null || !mo.isCreature(game)) {
        return false;
    }
    StackObject stackObject = game.getStack().getStackObject(event.getTargetId());
    if (stackObject == null) {
        return false;
    }
    this.getEffects().clear();
    FilterCard filter = new FilterCard();
    filter.add(new CardIdPredicate(stackObject.getSourceId()));
    this.addEffect(new GainAbilityControlledSpellsEffect(new RiotAbility(), filter));
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) RiotAbility(mage.abilities.keyword.RiotAbility) MageObject(mage.MageObject) StackObject(mage.game.stack.StackObject) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate) GainAbilityControlledSpellsEffect(mage.abilities.effects.common.continuous.GainAbilityControlledSpellsEffect)

Example 14 with StackObject

use of mage.game.stack.StackObject in project mage by magefree.

the class GripOfChaosEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject stackObject = game.getStack().getStackObject(this.getTargetPointer().getFirst(game, source));
    if (stackObject != null) {
        for (UUID modeId : stackObject.getStackAbility().getModes().getSelectedModes()) {
            Mode mode = stackObject.getStackAbility().getModes().get(modeId);
            for (Target target : mode.getTargets()) {
                UUID oldTargetId = target.getFirstTarget();
                Set<UUID> possibleTargets = target.possibleTargets(stackObject.getSourceId(), stackObject.getControllerId(), game);
                if (possibleTargets.contains(stackObject.getId())) {
                    // The stackObject can't target itself
                    possibleTargets.remove(stackObject.getId());
                }
                if (!possibleTargets.isEmpty()) {
                    int i = 0;
                    int rnd = RandomUtil.nextInt(possibleTargets.size());
                    Iterator<UUID> it = possibleTargets.iterator();
                    while (i < rnd) {
                        it.next();
                        i++;
                    }
                    UUID newTargetId = it.next();
                    target.remove(oldTargetId);
                    target.add(newTargetId, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) Mode(mage.abilities.Mode) StackObject(mage.game.stack.StackObject) UUID(java.util.UUID)

Example 15 with StackObject

use of mage.game.stack.StackObject in project mage by magefree.

the class MaelstromNexusGainCascadeFirstSpellEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        for (StackObject stackObject : game.getStack()) {
            // only spells cast, so no copies of spells
            if ((stackObject instanceof Spell) && !stackObject.isCopy() && stackObject.isControlledBy(source.getControllerId())) {
                Spell spell = (Spell) stackObject;
                FirstSpellCastThisTurnWatcher watcher = game.getState().getWatcher(FirstSpellCastThisTurnWatcher.class);
                if (watcher != null && spell.getId().equals(watcher.getIdOfFirstCastSpell(source.getControllerId()))) {
                    game.getState().addOtherAbility(spell.getCard(), cascadeAbility);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FirstSpellCastThisTurnWatcher(mage.watchers.common.FirstSpellCastThisTurnWatcher) Player(mage.players.Player) StackObject(mage.game.stack.StackObject) Spell(mage.game.stack.Spell)

Aggregations

StackObject (mage.game.stack.StackObject)130 Player (mage.players.Player)63 Permanent (mage.game.permanent.Permanent)57 Spell (mage.game.stack.Spell)41 MageObject (mage.MageObject)37 UUID (java.util.UUID)36 Card (mage.cards.Card)29 Target (mage.target.Target)17 TargetPermanent (mage.target.TargetPermanent)15 FilterCard (mage.filter.FilterCard)14 Ability (mage.abilities.Ability)13 FilterPermanent (mage.filter.FilterPermanent)13 StackAbility (mage.game.stack.StackAbility)13 FixedTarget (mage.target.targetpointer.FixedTarget)12 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)11 HashSet (java.util.HashSet)10 Effect (mage.abilities.effects.Effect)9 Game (mage.game.Game)9 MageObjectReference (mage.MageObjectReference)8 Cost (mage.abilities.costs.Cost)8