Search in sources :

Example 71 with SpellAbility

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

the class MCTSPlayer method simulateVariableCosts.

protected void simulateVariableCosts(Ability ability, List<Ability> options, 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));
        options.add(newAbility);
    }
}
Also used : SpellAbility(mage.abilities.SpellAbility) PassAbility(mage.abilities.common.PassAbility) ActivatedAbility(mage.abilities.ActivatedAbility) Ability(mage.abilities.Ability) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) SpellAbility(mage.abilities.SpellAbility)

Example 72 with SpellAbility

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

the class ApocalypseHydraEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanentEntering(source.getSourceId());
    if (permanent == null) {
        return false;
    }
    SpellAbility spellAbility = (SpellAbility) getValue(EntersBattlefieldEffect.SOURCE_CAST_SPELL_ABILITY);
    if (spellAbility == null || !spellAbility.getSourceId().equals(source.getSourceId()) || permanent.getZoneChangeCounter(game) != spellAbility.getSourceObjectZoneChangeCounter()) {
        return false;
    }
    int amount = spellAbility.getManaCostsToPay().getX();
    if (amount > 0) {
        if (amount < 5) {
            permanent.addCounters(CounterType.P1P1.createInstance(amount), source.getControllerId(), source, game);
        } else {
            permanent.addCounters(CounterType.P1P1.createInstance(amount * 2), source.getControllerId(), source, game);
        }
    }
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) SpellAbility(mage.abilities.SpellAbility)

Example 73 with SpellAbility

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

the class DefenseGridCostModificationEffect method apply.

@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
    SpellAbility spellAbility = (SpellAbility) abilityToModify;
    spellAbility.getManaCostsToPay().add(new GenericManaCost(3));
    return true;
}
Also used : GenericManaCost(mage.abilities.costs.mana.GenericManaCost) SpellAbility(mage.abilities.SpellAbility)

Example 74 with SpellAbility

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

the class AnimarCostReductionEffect method apply.

@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
    Ability spellAbility = abilityToModify;
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (sourcePermanent != null && spellAbility != null) {
        int amount = sourcePermanent.getCounters(game).getCount(CounterType.P1P1);
        CardUtil.reduceCost(spellAbility, amount);
        return true;
    }
    return false;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) SpellCastControllerTriggeredAbility(mage.abilities.common.SpellCastControllerTriggeredAbility) SpellAbility(mage.abilities.SpellAbility) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent)

Example 75 with SpellAbility

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

the class CemeteryProwlerCostReductionEffect method apply.

@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
    if (abilityToModify instanceof SpellAbility) {
        // sourceObjectZoneChangeCounter is not working here.  Getting it from GameState works.
        UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), game.getState().getZoneChangeCounter(source.getSourceId()));
        ExileZone exileZone = game.getExile().getExileZone(exileId);
        Card castCard = ((SpellAbility) abilityToModify).getCharacteristics(game);
        if (exileZone != null && castCard != null) {
            HashSet<CardType> cardTypes = new HashSet<>();
            for (UUID cardId : exileZone) {
                Card card = game.getCard(cardId);
                if (card != null) {
                    cardTypes.addAll(card.getCardType(game));
                }
            }
            int sharedTypes = 0;
            for (CardType type : castCard.getCardType(game)) {
                if (cardTypes.contains(type)) {
                    sharedTypes++;
                }
            }
            if (sharedTypes > 0) {
                CardUtil.reduceCost(abilityToModify, sharedTypes);
                return true;
            }
        }
    }
    return false;
}
Also used : ExileZone(mage.game.ExileZone) SpellAbility(mage.abilities.SpellAbility) UUID(java.util.UUID) Card(mage.cards.Card) HashSet(java.util.HashSet)

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