Search in sources :

Example 1 with Spell

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

the class BeamsplitterMageApplier method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!isControlledBy(event.getPlayerId())) {
        return false;
    }
    Spell spell = game.getSpellOrLKIStack(event.getTargetId());
    if (spell == null || !spell.isInstantOrSorcery(game)) {
        return false;
    }
    if (spell.getSpellAbilities().stream().map(AbilityImpl::getModes).flatMap(m -> m.getSelectedModes().stream().map(m::get)).filter(Objects::nonNull).map(Mode::getTargets).flatMap(Collection::stream).filter(t -> !t.isNotTarget()).map(Target::getTargets).flatMap(Collection::stream).anyMatch(uuid -> !getSourceId().equals(uuid) && uuid != null)) {
        return false;
    }
    this.getEffects().setValue("spellCast", spell);
    return true;
}
Also used : Target(mage.target.Target) java.util(java.util) Zone(mage.constants.Zone) Predicate(mage.filter.predicate.Predicate) MageObjectReference(mage.MageObjectReference) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) SubType(mage.constants.SubType) FilterPermanent(mage.filter.FilterPermanent) Mode(mage.abilities.Mode) Player(mage.players.Player) StackObjectCopyApplier(mage.util.functions.StackObjectCopyApplier) CardType(mage.constants.CardType) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) StackObject(mage.game.stack.StackObject) Spell(mage.game.stack.Spell) StaticFilters(mage.filter.StaticFilters) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) MageInt(mage.MageInt) CardSetInfo(mage.cards.CardSetInfo) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) Game(mage.game.Game) AbilityImpl(mage.abilities.AbilityImpl) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) AnotherPredicate(mage.filter.predicate.mageobject.AnotherPredicate) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) AbilityImpl(mage.abilities.AbilityImpl) Target(mage.target.Target) Spell(mage.game.stack.Spell)

Example 2 with Spell

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

the class BeamsplitterMageApplier method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Spell spell = (Spell) getValue("spellCast");
    if (player == null || spell == null) {
        return false;
    }
    FilterPermanent filter = new FilterControlledCreaturePermanent("a creature you control that can be targeted by " + spell.getName());
    filter.add(AnotherPredicate.instance);
    filter.add(new BeamsplitterMagePredicate(spell));
    TargetPermanent target = new TargetPermanent(filter);
    target.setNotTarget(true);
    player.choose(outcome, target, source.getSourceId(), game);
    Permanent permanent = game.getPermanent(target.getFirstTarget());
    if (permanent == null) {
        return false;
    }
    spell.createCopyOnStack(game, source, player.getId(), false, 1, new BeamsplitterMageApplier(permanent, game));
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) Spell(mage.game.stack.Spell)

Example 3 with Spell

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

the class BeaconOfDestinyEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    // check source
    MageObject object = game.getObject(event.getSourceId());
    if (object == null) {
        game.informPlayers("Couldn't find source of damage");
        return false;
    }
    if (!object.getId().equals(damageSource.getFirstTarget()) && (!(object instanceof Spell) || !((Spell) object).getSourceId().equals(damageSource.getFirstTarget()))) {
        return false;
    }
    TargetPermanent target = new TargetPermanent();
    target.add(source.getSourceId(), game);
    this.redirectTarget = target;
    // check player
    Player player = game.getPlayer(event.getTargetId());
    if (player != null) {
        if (player.getId().equals(source.getControllerId())) {
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) TargetPermanent(mage.target.TargetPermanent) Spell(mage.game.stack.Spell)

Example 4 with Spell

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

the class BoseijuWhoSheltersAllCantCounterEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    BoseijuWhoSheltersAllWatcher watcher = game.getState().getWatcher(BoseijuWhoSheltersAllWatcher.class, source.getSourceId());
    Spell spell = game.getStack().getSpell(event.getTargetId());
    return spell != null && watcher != null && watcher.spellCantBeCountered(new MageObjectReference(spell, game));
}
Also used : Spell(mage.game.stack.Spell) MageObjectReference(mage.MageObjectReference)

Example 5 with Spell

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

the class ChecksAndBalancesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
    if (spell != null) {
        for (UUID uuid : game.getOpponents(spell.getControllerId())) {
            Player player = game.getPlayer(uuid);
            if (player != null) {
                if (player.getHand().isEmpty()) {
                    game.informPlayers(player.getLogName() + " doesn't have a card in hand to discard to counter " + spell.getLogName() + ", effect aborted.");
                    return true;
                }
            }
        }
        for (UUID uuid : game.getOpponents(spell.getControllerId())) {
            Player player = game.getPlayer(uuid);
            if (player != null) {
                if (!player.chooseUse(outcome, "Discard a card to counter " + spell.getLogName() + '?', source, game)) {
                    game.informPlayers(player.getLogName() + " refuses to discard a card to counter " + spell.getLogName());
                    return true;
                } else {
                    game.informPlayers(player.getLogName() + " agrees to discard a card to counter " + spell.getLogName());
                }
            }
        }
        for (UUID uuid : game.getOpponents(spell.getControllerId())) {
            Player player = game.getPlayer(uuid);
            if (player != null && !player.getHand().isEmpty()) {
                TargetCardInHand target = new TargetCardInHand();
                if (player.choose(Outcome.Discard, target, source.getSourceId(), game)) {
                    Card card = game.getCard(target.getFirstTarget());
                    player.discard(card, false, source, game);
                }
            }
        }
        game.getStack().counter(spell.getId(), source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) FilterSpell(mage.filter.FilterSpell) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Aggregations

Spell (mage.game.stack.Spell)311 Player (mage.players.Player)155 Permanent (mage.game.permanent.Permanent)90 UUID (java.util.UUID)79 MageObject (mage.MageObject)69 Card (mage.cards.Card)51 TargetSpell (mage.target.TargetSpell)48 StackObject (mage.game.stack.StackObject)42 FilterCard (mage.filter.FilterCard)38 FilterSpell (mage.filter.FilterSpell)36 FixedTarget (mage.target.targetpointer.FixedTarget)33 MageObjectReference (mage.MageObjectReference)24 Effect (mage.abilities.effects.Effect)22 OneShotEffect (mage.abilities.effects.OneShotEffect)22 Target (mage.target.Target)22 Ability (mage.abilities.Ability)20 SpellAbility (mage.abilities.SpellAbility)16 FilterPermanent (mage.filter.FilterPermanent)15 TargetCard (mage.target.TargetCard)15 TargetPlayer (mage.target.TargetPlayer)14