Search in sources :

Example 16 with StackObject

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

the class BecomesTargetAttachedTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Permanent enchantment = game.getPermanent(sourceId);
    StackObject sourceObject = game.getStack().getStackObject(event.getSourceId());
    if (enchantment != null && enchantment.getAttachedTo() != null) {
        if (event.getTargetId().equals(enchantment.getAttachedTo()) && filter.match(sourceObject, getSourceId(), getControllerId(), game)) {
            return true;
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) FilterStackObject(mage.filter.FilterStackObject) StackObject(mage.game.stack.StackObject)

Example 17 with StackObject

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

the class CounterUnlessPaysEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
    if (spell == null) {
        return false;
    }
    Player player = game.getPlayer(spell.getControllerId());
    if (player == null) {
        return false;
    }
    Cost costToPay;
    String costValueMessage;
    if (cost != null) {
        costToPay = cost.copy();
        costValueMessage = costToPay.getText();
    } else {
        costToPay = ManaUtil.createManaCost(genericMana, game, source, this);
        costValueMessage = "{" + genericMana.calculate(game, source, this) + "}";
    }
    String message = "";
    if (costToPay instanceof ManaCost) {
        message += "Pay ";
    }
    message += costValueMessage + '?';
    costToPay.clearPaid();
    if (!(player.chooseUse(Outcome.Benefit, message, source, game) && costToPay.pay(source, game, source, spell.getControllerId(), false, null))) {
        game.informPlayers(player.getLogName() + " chooses not to pay " + costValueMessage + " to prevent the counter effect");
        if (exile) {
            game.getStack().counter(spell.getId(), source, game, Zone.EXILED, false, ZoneDetail.NONE);
        } else {
            return game.getStack().counter(spell.getId(), source, game);
        }
    }
    game.informPlayers(player.getLogName() + " chooses to pay " + costValueMessage + " to prevent the counter effect");
    return true;
}
Also used : Player(mage.players.Player) ManaCost(mage.abilities.costs.mana.ManaCost) StackObject(mage.game.stack.StackObject) Cost(mage.abilities.costs.Cost) ManaCost(mage.abilities.costs.mana.ManaCost)

Example 18 with StackObject

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

the class CantBeTargetedTargetEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (getTargetPointer().getTargets(game, source).contains(event.getTargetId())) {
        if (targetController == TargetController.OPPONENT && !game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) {
            return false;
        }
        StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
        MageObject sourceObject;
        if (stackObject instanceof StackAbility) {
            sourceObject = ((StackAbility) stackObject).getSourceObject(game);
        } else {
            sourceObject = stackObject;
        }
        if (filterSource.match(sourceObject, game)) {
            return true;
        }
    }
    return false;
}
Also used : StackObject(mage.game.stack.StackObject) MageObject(mage.MageObject) StackAbility(mage.game.stack.StackAbility)

Example 19 with StackObject

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

the class SameControllerPredicate 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 : Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) StackObject(mage.game.stack.StackObject)

Example 20 with StackObject

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

the class BrowbeatDrawEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    StackObject spell = null;
    for (StackObject object : game.getStack()) {
        if (object instanceof Spell && object.getSourceId().equals(source.getSourceId())) {
            spell = object;
        }
    }
    if (spell != null) {
        boolean drawCards = true;
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null && player.chooseUse(Outcome.Detriment, "Have " + spell.getLogName() + " deal 5 damage to you?", source, game)) {
                drawCards = false;
                player.damage(5, source.getSourceId(), source, game);
                game.informPlayers(player.getLogName() + " has " + spell.getLogName() + " deal 5 to them");
            }
        }
        if (drawCards) {
            UUID targetPlayer = getTargetPointer().getFirst(game, source);
            if (targetPlayer != null) {
                Player player = game.getPlayer(targetPlayer);
                if (player != null) {
                    player.drawCards(3, source, game);
                }
            }
        }
        return drawCards;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) StackObject(mage.game.stack.StackObject) UUID(java.util.UUID) 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