Search in sources :

Example 96 with StackObject

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

the class LeylineOfCombustionTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    StackObject sourceObject = game.getStack().getStackObject(event.getSourceId());
    if (sourceObject == null) {
        return false;
    }
    Player targetter = game.getPlayer(event.getPlayerId());
    if (targetter == null || !targetter.hasOpponent(this.controllerId, game)) {
        return false;
    }
    if (!event.getTargetId().equals(this.controllerId)) {
        Permanent permanent = game.getPermanentOrLKIBattlefield(event.getTargetId());
        if (permanent == null || !permanent.isControlledBy(this.controllerId)) {
            return false;
        }
    }
    // If a spell targets you and/or a permanent you control multiple times,
    // or if a spell targets you and one or more permanents you control,
    // Leyline of Combustion’s triggered ability triggers once.
    Set<UUID> sourceObjects = (Set<UUID>) game.getState().getValue("sourceObjects" + this.id);
    if (sourceObjects == null) {
        sourceObjects = new HashSet<>();
    }
    if (!sourceObjects.add(sourceObject.getId())) {
        return false;
    }
    game.getState().setValue("sourceObjects" + this.id, sourceObjects);
    this.getEffects().clear();
    Effect effect = new DamageTargetEffect(2);
    effect.setTargetPointer(new FixedTarget(event.getPlayerId(), game));
    this.addEffect(effect);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Set(java.util.Set) HashSet(java.util.HashSet) Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject) Effect(mage.abilities.effects.Effect) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) UUID(java.util.UUID) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect)

Example 97 with StackObject

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

the class OverrideEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (sourceObject != null && spell != null) {
        Player player = game.getPlayer(spell.getControllerId());
        Player controller = game.getPlayer(source.getControllerId());
        if (player != null && controller != null) {
            int amount = ArtifactYouControlCount.instance.calculate(game, source, this);
            if (amount > 0) {
                Cost cost = ManaUtil.createManaCost(amount, false);
                if (!cost.pay(source, game, source, spell.getControllerId(), false)) {
                    game.informPlayers(sourceObject.getLogName() + ": cost wasn't payed - countering target spell.");
                    return game.getStack().counter(source.getFirstTarget(), source, game);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) StackObject(mage.game.stack.StackObject) MageObject(mage.MageObject) Cost(mage.abilities.costs.Cost)

Example 98 with StackObject

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

the class SameCastingCostPredicate 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.getManaValue() == inputPermanent.getManaValue();
        }
    }
    return true;
}
Also used : TargetArtifactPermanent(mage.target.common.TargetArtifactPermanent) Permanent(mage.game.permanent.Permanent) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) StackObject(mage.game.stack.StackObject)

Example 99 with StackObject

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

the class SkullscorchDiscardEffect 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 discardCards = true;
        Player player = game.getPlayer(targetPointer.getFirst(game, source));
        if (player != null) {
            if (player.chooseUse(Outcome.Detriment, "Have " + spell.getLogName() + " deal 4 damage to you?", source, game)) {
                discardCards = false;
                player.damage(4, source.getSourceId(), source, game);
                game.informPlayers(player.getLogName() + " has " + spell.getLogName() + " deal 4 to them");
            }
            if (discardCards) {
                player.discard(2, true, false, source, game);
            }
        }
        return discardCards;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) StackObject(mage.game.stack.StackObject) Spell(mage.game.stack.Spell)

Example 100 with StackObject

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

the class SkophosMazeWardenTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
    if (stackObject == null) {
        return false;
    }
    Permanent permanent = game.getPermanent(stackObject.getSourceId());
    if (permanent == null || !permanent.isControlledBy(getControllerId()) || !permanent.isLand(game) || !permanent.getName().equals("Labyrinth of Skophos")) {
        return false;
    }
    Permanent creature = game.getPermanent(event.getTargetId());
    if (creature == null || !creature.isCreature(game) || creature.getId().equals(getSourceId())) {
        return false;
    }
    this.getEffects().clear();
    this.addEffect(new FightTargetSourceEffect().setTargetPointer(new FixedTarget(creature, game)));
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject) FightTargetSourceEffect(mage.abilities.effects.common.FightTargetSourceEffect)

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