Search in sources :

Example 36 with StackObject

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

the class AegisOfHonorEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (event.getTargetId().equals(source.getControllerId())) {
        // Checks to see the damage is to Aegis of Honor's controller
        Spell spell = null;
        StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
        if (stackObject == null) {
            stackObject = (StackObject) game.getLastKnownInformation(event.getSourceId(), Zone.STACK);
        }
        if (stackObject instanceof Spell) {
            spell = (Spell) stackObject;
        }
        // Checks if damage is from a sorcery or instants
        if (spell != null && instantOrSorceryfilter.match(spell.getCard(), game)) {
            TargetPlayer target = new TargetPlayer();
            target.add(spell.getControllerId(), game);
            redirectTarget = target;
            return true;
        }
    }
    return false;
}
Also used : StackObject(mage.game.stack.StackObject) Spell(mage.game.stack.Spell) TargetPlayer(mage.target.TargetPlayer)

Example 37 with StackObject

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

the class ArcaneAdaptationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    SubType subType = ChooseCreatureTypeEffect.getChosenCreatureType(source.getSourceId(), game);
    if (controller == null || subType == null) {
        return false;
    }
    // in graveyard
    for (UUID cardId : controller.getGraveyard()) {
        Card card = game.getCard(cardId);
        if (card != null && card.isCreature(game) && !card.hasSubtype(subType, game)) {
            game.getState().getCreateMageObjectAttribute(card, game).getSubtype().add(subType);
        }
    }
    // on Hand
    for (UUID cardId : controller.getHand()) {
        Card card = game.getCard(cardId);
        if (card != null && card.isCreature(game) && !card.hasSubtype(subType, game)) {
            game.getState().getCreateMageObjectAttribute(card, game).getSubtype().add(subType);
        }
    }
    // in Exile
    for (Card card : game.getState().getExile().getAllCards(game)) {
        if (card.isCreature(game) && !card.hasSubtype(subType, game)) {
            game.getState().getCreateMageObjectAttribute(card, game).getSubtype().add(subType);
        }
    }
    // in Library (e.g. for Mystical Teachings)
    for (Card card : controller.getLibrary().getCards(game)) {
        if (card.isOwnedBy(controller.getId()) && card.isCreature(game) && !card.hasSubtype(subType, game)) {
            game.getState().getCreateMageObjectAttribute(card, game).getSubtype().add(subType);
        }
    }
    // commander in command zone
    for (CommandObject commandObject : game.getState().getCommand()) {
        if (commandObject instanceof Commander) {
            Card card = game.getCard(((Commander) commandObject).getId());
            if (card != null && card.isOwnedBy(controller.getId()) && card.isCreature(game) && !card.hasSubtype(subType, game)) {
                game.getState().getCreateMageObjectAttribute(card, game).getSubtype().add(subType);
            }
        }
    }
    // creature spells you control
    for (Iterator<StackObject> iterator = game.getStack().iterator(); iterator.hasNext(); ) {
        StackObject stackObject = iterator.next();
        if (stackObject instanceof Spell && stackObject.isControlledBy(source.getControllerId()) && stackObject.isCreature(game) && !stackObject.hasSubtype(subType, game)) {
            Card card = ((Spell) stackObject).getCard();
            game.getState().getCreateMageObjectAttribute(card, game).getSubtype().add(subType);
        }
    }
    // creatures you control
    List<Permanent> creatures = game.getBattlefield().getAllActivePermanents(new FilterControlledCreaturePermanent(), source.getControllerId(), game);
    for (Permanent creature : creatures) {
        if (creature != null) {
            creature.addSubType(game, subType);
        }
    }
    return true;
}
Also used : CommandObject(mage.game.command.CommandObject) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Commander(mage.game.command.Commander) StackObject(mage.game.stack.StackObject) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) UUID(java.util.UUID) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Example 38 with StackObject

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

the class SharesTypePredicate method apply.

@Override
public boolean apply(ObjectSourcePlayer<MageItem> input, Game game) {
    StackObject source = game.getStack().getStackObject(input.getSourceId());
    if (source != null) {
        if (source.getStackAbility().getTargets().isEmpty() || source.getStackAbility().getTargets().get(0).getTargets().isEmpty()) {
            return true;
        }
        Permanent firstPermanent = game.getPermanent(source.getStackAbility().getTargets().get(0).getTargets().get(0));
        Permanent secondPermanent = game.getPermanent(input.getObject().getId());
        if (firstPermanent != null && secondPermanent != null) {
            if (firstPermanent.isCreature(game) && secondPermanent.isCreature(game)) {
                return true;
            }
            if (firstPermanent.isArtifact(game) && secondPermanent.isArtifact(game)) {
                return true;
            }
        }
        return false;
    }
    return true;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) StackObject(mage.game.stack.StackObject)

Example 39 with StackObject

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

the class PowerSinkCounterUnlessPaysEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
    if (spell != null) {
        Player player = game.getPlayer(spell.getControllerId());
        Player controller = game.getPlayer(source.getControllerId());
        MageObject sourceObject = game.getObject(source.getSourceId());
        if (player != null && controller != null && sourceObject != null) {
            int amount = source.getManaCostsToPay().getX();
            if (amount > 0) {
                Cost cost = ManaUtil.createManaCost(amount, true);
                if (player.chooseUse(Outcome.Benefit, "Pay " + cost.getText() + " to prevent?", source, game)) {
                    if (cost.pay(source, game, source, player.getId(), false)) {
                        game.informPlayers(sourceObject.getName() + ": additional cost was paid");
                        return true;
                    }
                }
                game.informPlayers(sourceObject.getName() + ": additional cost wasn't paid - countering " + spell.getName());
                // Counter target spell unless its controller pays {X}
                game.getStack().counter(source.getFirstTarget(), source, game);
                // that player taps all lands with mana abilities they control...
                List<Permanent> lands = game.getBattlefield().getAllActivePermanents(new FilterLandPermanent(), player.getId(), game);
                for (Permanent land : lands) {
                    Abilities<Ability> landAbilities = land.getAbilities();
                    for (Ability ability : landAbilities) {
                        if (ability instanceof ActivatedManaAbilityImpl) {
                            land.tap(source, game);
                            break;
                        }
                    }
                }
                // ...and empties their mana pool
                player.getManaPool().emptyPool(game);
            }
            return true;
        }
    }
    return false;
}
Also used : Ability(mage.abilities.Ability) Player(mage.players.Player) FilterLandPermanent(mage.filter.common.FilterLandPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject) MageObject(mage.MageObject) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) Cost(mage.abilities.costs.Cost)

Example 40 with StackObject

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

the class ValkmiraProtectorsShieldTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
    if (stackObject == null || !game.getOpponents(getControllerId()).contains(stackObject.getControllerId())) {
        return false;
    }
    if (isControlledBy(event.getTargetId())) {
        this.getEffects().setTargetPointer(new FixedTarget(stackObject.getId(), game));
        return true;
    }
    Permanent permanent = game.getPermanent(event.getTargetId());
    if (permanent == null || !permanent.isControlledBy(getControllerId())) {
        return false;
    }
    this.getEffects().setTargetPointer(new FixedTarget(stackObject.getId(), game));
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) FilterPermanent(mage.filter.FilterPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject)

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