Search in sources :

Example 66 with SpellAbility

use of mage.abilities.SpellAbility in project mage by magefree.

the class MiracleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    // use target pointer here, so it's the same card that triggered the event (not gone back to library e.g.)
    Card card = game.getCard(getTargetPointer().getFirst(game, source));
    if (controller != null && card != null) {
        SpellAbility abilityToCast = card.getSpellAbility().copy();
        ManaCosts<ManaCost> costRef = abilityToCast.getManaCostsToPay();
        // replace with the new cost
        costRef.clear();
        costRef.add(miracleCosts);
        controller.cast(abilityToCast, game, false, new ApprovingObject(source, game));
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) ManaCost(mage.abilities.costs.mana.ManaCost) SpellAbility(mage.abilities.SpellAbility) Card(mage.cards.Card)

Example 67 with SpellAbility

use of mage.abilities.SpellAbility in project mage by magefree.

the class SpliceOntoArcaneEffect method apply.

@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
    Player controller = game.getPlayer(source.getControllerId());
    Card spliceCard = game.getCard(source.getSourceId());
    if (spliceCard != null && controller != null) {
        Spell spell = game.getStack().getSpell(abilityToModify.getId());
        if (spell != null) {
            SpellAbility splicedAbility = spliceCard.getSpellAbility().copy();
            splicedAbility.setSpellAbilityType(SpellAbilityType.SPLICE);
            splicedAbility.setSourceId(abilityToModify.getSourceId());
            spell.addSpellAbility(splicedAbility);
            for (Iterator it = ((SpliceOntoArcaneAbility) source).getSpliceCosts().iterator(); it.hasNext(); ) {
                spell.getSpellAbility().getCosts().add(((Cost) it.next()).copy());
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Iterator(java.util.Iterator) SpellAbility(mage.abilities.SpellAbility) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Example 68 with SpellAbility

use of mage.abilities.SpellAbility in project mage by magefree.

the class TurriIslandEffect method applies.

@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
    if (abilityToModify instanceof SpellAbility) {
        Plane cPlane = game.getState().getCurrentPlane();
        if (cPlane == null) {
            return false;
        }
        if (!cPlane.getPlaneType().equals(Planes.PLANE_TURRI_ISLAND)) {
            return false;
        }
        Card spellCard = ((SpellAbility) abilityToModify).getCharacteristics(game);
        if (spellCard != null) {
            return filter.match(spellCard, game) && selectedByRuntimeData(spellCard, source, game);
        }
    }
    return false;
}
Also used : Plane(mage.game.command.Plane) SpellAbility(mage.abilities.SpellAbility) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

Example 69 with SpellAbility

use of mage.abilities.SpellAbility in project mage by magefree.

the class PlayableObjectRecord method load.

public void load(List<ActivatedAbility> activatedAbilities) {
    this.basicManaAbilities.clear();
    this.basicPlayAbilities.clear();
    this.basicCastAbilities.clear();
    this.other.clear();
    // split abilities to types (it allows to enable or disable playable icon)
    for (ActivatedAbility ability : activatedAbilities) {
        List<PlayableObjectRecord> dest;
        if (ability instanceof BasicManaAbility) {
            dest = this.basicManaAbilities;
        } else if (ability instanceof PlayLandAbility) {
            dest = this.basicPlayAbilities;
        } else if (ability instanceof SpellAbility && (((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.BASE)) {
            dest = this.basicCastAbilities;
        } else {
            dest = this.other;
        }
        // collect info about abilities for card icons popup, must be simple online text (html symbols are possible)
        // some long html tags can be miss (example: ability extra hint) -- that's ok
        String shortInfo = ability.toString();
        if (shortInfo.length() > 50) {
            shortInfo = shortInfo.substring(0, 50 - 1) + "...";
        }
        shortInfo = shortInfo.replace("<br>", " ");
        shortInfo = shortInfo.replace("\n", " ");
        dest.add(new PlayableObjectRecord(ability.getId(), shortInfo));
    }
}
Also used : PlayLandAbility(mage.abilities.PlayLandAbility) BasicManaAbility(mage.abilities.mana.BasicManaAbility) ActivatedAbility(mage.abilities.ActivatedAbility) SpellAbility(mage.abilities.SpellAbility)

Example 70 with SpellAbility

use of mage.abilities.SpellAbility in project mage by magefree.

the class SimulatedPlayer method simulateVariableCosts.

// protected void simulateAction(Game game, SimulatedAction previousActions, Ability action) {
// List<Ability> actions = new ArrayList<Ability>(previousActions.getAbilities());
// actions.add(action);
// Game sim = game.copy();
// if (sim.getPlayer(playerId).activateAbility((ActivatedAbility) action.copy(), sim)) {
// sim.applyEffects();
// sim.getPlayers().resetPassed();
// allActions.add(new SimulatedAction(sim, actions));
// }
// }
// add a generic mana cost for each amount possible
protected void simulateVariableCosts(Ability ability, Game game) {
    int numAvailable = getAvailableManaProducers(game).size() - ability.getManaCosts().manaValue();
    int start = 0;
    if (!(ability instanceof SpellAbility)) {
        // only use x=0 on spell abilities
        if (numAvailable == 0)
            return;
        else
            start = 1;
    }
    for (int i = start; i < numAvailable; i++) {
        Ability newAbility = ability.copy();
        newAbility.getManaCostsToPay().add(new GenericManaCost(i));
        allActions.add(newAbility);
    }
}
Also used : PassAbility(mage.abilities.common.PassAbility) StackAbility(mage.game.stack.StackAbility) TriggeredAbility(mage.abilities.TriggeredAbility) SpellAbility(mage.abilities.SpellAbility) ActivatedAbility(mage.abilities.ActivatedAbility) Ability(mage.abilities.Ability) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) SpellAbility(mage.abilities.SpellAbility)

Aggregations

SpellAbility (mage.abilities.SpellAbility)75 Player (mage.players.Player)32 UUID (java.util.UUID)22 Card (mage.cards.Card)21 Permanent (mage.game.permanent.Permanent)21 Ability (mage.abilities.Ability)16 Spell (mage.game.stack.Spell)12 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)10 FilterCard (mage.filter.FilterCard)9 Iterator (java.util.Iterator)8 MageObject (mage.MageObject)7 Target (mage.target.Target)7 ArrayList (java.util.ArrayList)6 ApprovingObject (mage.ApprovingObject)4 ActivatedAbility (mage.abilities.ActivatedAbility)4 Cost (mage.abilities.costs.Cost)4 Effect (mage.abilities.effects.Effect)4 Outcome (mage.constants.Outcome)4 FilterPermanent (mage.filter.FilterPermanent)4 PassAbility (mage.abilities.common.PassAbility)3