Search in sources :

Example 1 with StackObject

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

the class CounterlashEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    if (stackObject != null && controller != null) {
        game.getStack().counter(source.getFirstTarget(), source, game);
        if (controller.chooseUse(Outcome.PlayForFree, "Cast a nonland card in your hand that " + "shares a card type with that spell without paying its mana cost?", source, game)) {
            FilterCard filter = new FilterCard();
            List<Predicate<MageObject>> types = new ArrayList<>();
            for (CardType type : stackObject.getCardType(game)) {
                if (type != CardType.LAND) {
                    types.add(type.getPredicate());
                }
            }
            filter.add(Predicates.or(types));
            TargetCardInHand target = new TargetCardInHand(filter);
            if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
                Card card = controller.getHand().get(target.getFirstTarget(), game);
                if (card != null) {
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                    controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) CardType(mage.constants.CardType) StackObject(mage.game.stack.StackObject) ArrayList(java.util.ArrayList) Predicate(mage.filter.predicate.Predicate) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 2 with StackObject

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

the class CountermandEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean countered = false;
    StackObject stackObject = game.getStack().getStackObject(targetPointer.getFirst(game, source));
    if (game.getStack().counter(source.getFirstTarget(), source, game)) {
        countered = true;
    }
    if (stackObject != null) {
        Player controller = game.getPlayer(stackObject.getControllerId());
        if (controller != null) {
            controller.millCards(4, source, game);
        }
    }
    return countered;
}
Also used : Player(mage.players.Player) StackObject(mage.game.stack.StackObject)

Example 3 with StackObject

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

the class FiendslayerPaladinEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    Card targetCard = game.getCard(event.getTargetId());
    StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
    if (targetCard != null && stackObject != null && targetCard.getId().equals(source.getSourceId())) {
        if (stackObject.getColor(game).isBlack() || stackObject.getColor(game).isRed()) {
            if (!stackObject.isControlledBy(source.getControllerId()) && stackObject.isInstant(game) || stackObject.isSorcery(game)) {
                return true;
            }
        }
    }
    return false;
}
Also used : StackObject(mage.game.stack.StackObject) Card(mage.cards.Card)

Example 4 with StackObject

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

the class FrightfulDelusionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
    Cost cost = ManaUtil.createManaCost(1, false);
    if (spell != null) {
        Player player = game.getPlayer(spell.getControllerId());
        if (player != null) {
            cost.clearPaid();
            game.getPlayer(spell.getControllerId()).discard(1, false, false, source, game);
            if (!cost.pay(source, game, source, spell.getControllerId(), false, null)) {
                return game.getStack().counter(source.getFirstTarget(), source, game);
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) StackObject(mage.game.stack.StackObject) Cost(mage.abilities.costs.Cost)

Example 5 with StackObject

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

the class PsychicBattleEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
    if (stackObject != null) {
        if (!stackObject.isTargetChanged() && !stackObject.getName().equals("Psychic Battle")) {
            this.getEffects().get(0).setTargetPointer(new FixedTarget(event.getSourceId()));
            // resets the targetChanged flag
            stackObject.setTargetChanged(false);
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) 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