Search in sources :

Example 66 with StackObject

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

the class ShannaSisaysLegacyEffect 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 instanceof Ability) {
            if (!stackObject.isControlledBy(source.getControllerId())) {
                return true;
            }
        }
    }
    return false;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Ability(mage.abilities.Ability) StackObject(mage.game.stack.StackObject) Card(mage.cards.Card)

Example 67 with StackObject

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

the class MoveAuraEffect 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 firstTarget = game.getPermanent(source.getStackAbility().getTargets().get(0).getTargets().get(0));
        Permanent inputPermanent = game.getPermanent(input.getObject().getId());
        if (firstTarget != null && inputPermanent != null) {
            return firstTarget.isControlledBy(inputPermanent.getControllerId());
        }
    }
    return true;
}
Also used : FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterEnchantmentPermanent(mage.filter.common.FilterEnchantmentPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) StackObject(mage.game.stack.StackObject)

Example 68 with StackObject

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

the class GreatestPowerCountCreatureYouControl 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 maxPower = new GreatestPowerCountCreatureYouControl().calculate(game, source, this);
            Cost cost = ManaUtil.createManaCost(maxPower, true);
            if (player.chooseUse(Outcome.Benefit, "Pay " + cost.getText() + "? (otherwise " + spell.getName() + " will be countered)", source, game) && cost.pay(source, game, source, player.getId(), false)) {
                return true;
            }
            game.informPlayers(sourceObject.getName() + ": cost wasn't payed - countering " + spell.getName());
            return game.getStack().counter(source.getFirstTarget(), source, game);
        }
    }
    return false;
}
Also used : Player(mage.players.Player) StackObject(mage.game.stack.StackObject) MageObject(mage.MageObject) Cost(mage.abilities.costs.Cost) ValueHint(mage.abilities.hint.ValueHint)

Example 69 with StackObject

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

the class SpelljackEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        UUID targetId = targetPointer.getFirst(game, source);
        StackObject stackObject = game.getStack().getStackObject(targetId);
        if (stackObject != null && game.getStack().counter(targetId, source, game, Zone.EXILED, false, ZoneDetail.NONE)) {
            Card card = ((Spell) stackObject).getCard();
            if (card != null) {
                ContinuousEffect effect = new PlayFromNotOwnHandZoneTargetEffect(Zone.EXILED, TargetController.YOU, Duration.Custom, true);
                effect.setTargetPointer(new FixedTarget(card.getId(), game.getState().getZoneChangeCounter(card.getId())));
                game.addEffect(effect, source);
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) PlayFromNotOwnHandZoneTargetEffect(mage.abilities.effects.common.asthought.PlayFromNotOwnHandZoneTargetEffect) StackObject(mage.game.stack.StackObject) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) Card(mage.cards.Card)

Example 70 with StackObject

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

the class ToshiroUmezawaReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    UUID eventObject = event.getTargetId();
    StackObject stackObject = game.getStack().getStackObject(eventObject);
    Player controller = game.getPlayer(source.getControllerId());
    if (stackObject != null && controller != null) {
        if (stackObject instanceof Spell) {
            game.rememberLKI(stackObject.getId(), Zone.STACK, stackObject);
        }
        if (stackObject instanceof Card && eventObject.equals(cardId)) {
            return controller.moveCards((Card) stackObject, Zone.EXILED, source, game);
        }
    }
    return false;
}
Also used : Player(mage.players.Player) StackObject(mage.game.stack.StackObject) UUID(java.util.UUID) Spell(mage.game.stack.Spell) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

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