Search in sources :

Example 21 with Spell

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

the class PsychicRebuttalPredicate method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Spell spell = game.getStack().getSpell(getTargetPointer().getFirst(game, source));
    if (spell != null) {
        game.getStack().counter(spell.getId(), source, game);
        if (SpellMasteryCondition.instance.apply(game, source) && controller.chooseUse(Outcome.PlayForFree, "Copy " + spell.getName() + " (you may choose new targets for the copy)?", source, game)) {
            spell.createCopyOnStack(game, source, source.getControllerId(), true);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ObjectSourcePlayer(mage.filter.predicate.ObjectSourcePlayer) FilterSpell(mage.filter.FilterSpell) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell)

Example 22 with Spell

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

the class RemKarolusStalwartSlayerReplacementEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    UUID targetId = event.getTargetId();
    if (targetId.equals(source.getSourceId())) {
        return false;
    }
    UUID controllerId = source.getControllerId();
    if (!targetId.equals(controllerId)) {
        Permanent permanent = game.getPermanent(targetId);
        if (permanent == null || !permanent.isControlledBy(controllerId)) {
            return false;
        }
    }
    StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
    if (stackObject == null) {
        stackObject = (StackObject) game.getLastKnownInformation(event.getSourceId(), Zone.STACK);
    }
    if (stackObject instanceof Spell) {
        return super.applies(event, source, game);
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 23 with Spell

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

the class SenTripletsPlayFromOpponentsHandEffect method applies.

@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    Card card = game.getCard(objectId);
    Zone zone;
    if (card instanceof Spell) {
        zone = ((Spell) card).getFromZone();
    } else if (card != null) {
        zone = game.getState().getZone(card.getMainCard().getId());
    } else {
        return false;
    }
    return card.isOwnedBy(getTargetPointer().getFirst(game, source)) && zone == Zone.HAND && source.isControlledBy(affectedControllerId);
}
Also used : Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Example 24 with Spell

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

the class SiftThroughSandsWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (condition) {
        // no need to check - condition has already occured
        return;
    }
    if (event.getType() == GameEvent.EventType.SPELL_CAST && controllerId.equals(event.getPlayerId())) {
        Spell spell = game.getStack().getSpell(event.getTargetId());
        if (spell.getCard().getName().equals("Peer Through Depths")) {
            castPeerThroughDepths = true;
        } else if (spell.getCard().getName().equals("Reach Through Mists")) {
            castReachThroughMists = true;
        }
        condition = castPeerThroughDepths && castReachThroughMists;
    }
}
Also used : Spell(mage.game.stack.Spell)

Example 25 with Spell

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

the class SplitDecisionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getStack().getSpell(getTargetPointer().getFirst(game, source));
    if (spell == null) {
        return false;
    }
    // Outcome.Benefit - AI will use counter all the time (Denial choice)
    // TODO: add AI hint logic in the choice method, see Tyrant's Choice as example
    TwoChoiceVote vote = new TwoChoiceVote("Denial (counter " + spell.getIdName() + ")", "Duplication (copy " + spell.getIdName() + ")", Outcome.Benefit);
    vote.doVotes(source, game);
    int denialCount = vote.getVoteCount(true);
    int duplicationCount = vote.getVoteCount(false);
    if (denialCount > duplicationCount) {
        return game.getStack().counter(spell.getId(), source, game);
    } else {
        return new CopyTargetSpellEffect().apply(game, source);
    }
}
Also used : CopyTargetSpellEffect(mage.abilities.effects.common.CopyTargetSpellEffect) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) TwoChoiceVote(mage.choices.TwoChoiceVote)

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