Search in sources :

Example 91 with StackObject

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

the class GoblinArtisansTarget method canTarget.

@Override
public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) {
    if (!super.canTarget(controllerId, id, source, game)) {
        return false;
    }
    MageObjectReference sourceRef = new MageObjectReference(source.getSourceObject(game), game);
    Spell spell = game.getSpell(id);
    if (spell == null) {
        return false;
    }
    for (StackObject stackObject : game.getStack()) {
        if (!(stackObject instanceof StackAbility)) {
            continue;
        }
        Permanent permanent = ((StackAbility) stackObject).getSourcePermanentOrLKI(game);
        if (permanent != null && !sourceRef.refersTo(permanent, game) && permanent.isCreature(game) && "Goblin Artisans".equals(permanent.getName()) && stackObject.getStackAbility().getTargets().stream().map(Target::getTargets).flatMap(Collection::stream).anyMatch(id::equals)) {
            return false;
        }
    }
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject) Collection(java.util.Collection) MageObjectReference(mage.MageObjectReference) FilterArtifactSpell(mage.filter.common.FilterArtifactSpell) FilterSpell(mage.filter.FilterSpell) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) StackAbility(mage.game.stack.StackAbility)

Example 92 with StackObject

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

the class GrimoireThiefCounterspellEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Cards cards = new CardsImpl();
    MageObject sourceObject = game.getObject(source.getSourceId());
    Set<UUID> exileZones = (Set<UUID>) game.getState().getValue(GrimoireThief.VALUE_PREFIX + source.getSourceId().toString());
    if (exileZones != null && sourceObject != null) {
        for (ExileZone exileZone : game.getExile().getExileZones()) {
            if (!exileZone.isEmpty()) {
                cards.addAll(exileZone.getCards(game));
            }
        }
        // set face up first
        for (Card card : cards.getCards(game)) {
            card.setFaceDown(false, game);
        }
        // then counter any with the same name as the card exiled with Grimoire Thief
        for (Card card : cards.getCards(game)) {
            for (Iterator<StackObject> iterator = game.getStack().iterator(); iterator.hasNext(); ) {
                StackObject stackObject = iterator.next();
                MageObject mageObject = game.getObject(card.getId());
                String name1;
                String name2;
                if (mageObject instanceof SplitCard) {
                    name1 = ((SplitCard) mageObject).getLeftHalfCard().getName();
                    name2 = ((SplitCard) mageObject).getRightHalfCard().getName();
                } else {
                    // modal double faces cards, adventure cards -- all have one name in non stack/battlefield zone
                    name1 = mageObject.getName();
                    name2 = name1;
                }
                if (CardUtil.haveSameNames(stackObject, name1, game) || CardUtil.haveSameNames(stackObject, name2, game)) {
                    Spell spell = (Spell) stackObject;
                    game.getStack().counter(stackObject.getId(), source, game);
                    game.informPlayers(sourceObject.getLogName() + ": spell " + spell.getIdName() + " was countered.");
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) MageObject(mage.MageObject) StackObject(mage.game.stack.StackObject) ExileZone(mage.game.ExileZone) Spell(mage.game.stack.Spell) UUID(java.util.UUID)

Example 93 with StackObject

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

the class JelevaNephaliasWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    // Watcher saves all casts becaus of possible Clone cards that copy Jeleva
    if (event.getType() == GameEvent.EventType.SPELL_CAST) {
        if (!game.getStack().isEmpty()) {
            for (StackObject stackObject : game.getStack()) {
                if (stackObject instanceof Spell) {
                    Spell spell = (Spell) stackObject;
                    manaSpendToCast.putIfAbsent(spell.getSourceId().toString() + spell.getCard().getZoneChangeCounter(game), spell.getSpellAbility().getManaCostsToPay().manaValue());
                }
            }
        }
    }
}
Also used : StackObject(mage.game.stack.StackObject) Spell(mage.game.stack.Spell)

Example 94 with StackObject

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

the class JadedResponseEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
    if (stackObject == null) {
        return false;
    }
    boolean matches = game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game).stream().map(permanent -> permanent.getColor(game)).anyMatch(stackObject.getColor(game)::shares);
    return matches && game.getStack().counter(stackObject.getId(), source, game);
}
Also used : CardSetInfo(mage.cards.CardSetInfo) StaticFilters(mage.filter.StaticFilters) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) StackObject(mage.game.stack.StackObject) UUID(java.util.UUID) Ability(mage.abilities.Ability) TargetSpell(mage.target.TargetSpell) StackObject(mage.game.stack.StackObject)

Example 95 with StackObject

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

the class KozilekDiscardCost method canPay.

@Override
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
    if (game.getStack().isEmpty()) {
        return false;
    }
    Set<Integer> stackCMC = new HashSet<>();
    for (StackObject stackObject : game.getStack()) {
        if (stackObject instanceof Spell) {
            stackCMC.add(stackObject.getManaValue());
        }
    }
    Player controller = game.getPlayer(ability.getControllerId());
    if (controller != null) {
        for (Card card : controller.getHand().getCards(game)) {
            if (stackCMC.contains(card.getManaValue())) {
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) StackObject(mage.game.stack.StackObject) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) FilterSpell(mage.filter.FilterSpell) HashSet(java.util.HashSet) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

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