Search in sources :

Example 11 with ActivatedManaAbilityImpl

use of mage.abilities.mana.ActivatedManaAbilityImpl in project mage by magefree.

the class PlayerImpl method canPlay.

/**
 * @param ability
 * @param availableMana if null, it won't be checked if enough mana is
 *                      available
 * @param sourceObject
 * @param game
 * @return
 */
protected boolean canPlay(ActivatedAbility ability, ManaOptions availableMana, MageObject sourceObject, Game game) {
    if (!(ability instanceof ActivatedManaAbilityImpl)) {
        // Copy is needed because cost reduction effects modify e.g. the mana to activate/cast the ability
        ActivatedAbility copy = ability.copy();
        if (!copy.canActivate(playerId, game).canActivate()) {
            return false;
        }
        if (availableMana != null) {
            sourceObject.adjustCosts(copy, game);
            game.getContinuousEffects().costModification(copy, game);
        }
        boolean canBeCastRegularly = true;
        if (copy instanceof SpellAbility && copy.getManaCosts().isEmpty() && copy.getCosts().isEmpty()) {
            // 117.6. Some mana costs contain no mana symbols. This represents an unpayable cost...
            // 117.6a (...) If an alternative cost is applied to an unpayable cost,
            // including an effect that allows a player to cast a spell without paying its mana cost, the alternative cost may be paid.
            canBeCastRegularly = false;
        }
        if (canBeCastRegularly) {
            if (canPayMinimumManaCost(copy, availableMana, game)) {
                return true;
            }
        }
        // ALTERNATIVE COST FROM dynamic effects
        if (getCastSourceIdWithAlternateMana().contains(copy.getSourceId())) {
            ManaCosts alternateCosts = getCastSourceIdManaCosts().get(copy.getSourceId());
            Costs<Cost> costs = getCastSourceIdCosts().get(copy.getSourceId());
            boolean canPutToPlay = true;
            if (alternateCosts != null && !alternateCosts.canPay(copy, copy, playerId, game)) {
                canPutToPlay = false;
            }
            if (costs != null && !costs.canPay(copy, copy, playerId, game)) {
                canPutToPlay = false;
            }
            if (canPutToPlay) {
                return true;
            }
        }
        // ALTERNATIVE COST from source card (any AlternativeSourceCosts)
        if (AbilityType.SPELL.equals(ability.getAbilityType())) {
            return canPlayCardByAlternateCost(game.getCard(ability.getSourceId()), availableMana, copy, game);
        }
    }
    return false;
}
Also used : ManaCosts(mage.abilities.costs.mana.ManaCosts) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) ManaCost(mage.abilities.costs.mana.ManaCost)

Example 12 with ActivatedManaAbilityImpl

use of mage.abilities.mana.ActivatedManaAbilityImpl in project mage by magefree.

the class RowanKenrithEmblemTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!event.getPlayerId().equals(getControllerId())) {
        return false;
    }
    StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
    if (stackAbility == null || stackAbility.getStackAbility() instanceof ActivatedManaAbilityImpl) {
        return false;
    }
    this.getEffects().setValue("stackAbility", stackAbility);
    return true;
}
Also used : ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) StackAbility(mage.game.stack.StackAbility)

Example 13 with ActivatedManaAbilityImpl

use of mage.abilities.mana.ActivatedManaAbilityImpl in project mage by magefree.

the class RevelInSilenceEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!game.getOpponents(event.getPlayerId()).contains(getControllerId())) {
        return false;
    }
    StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
    if (stackAbility.getStackAbility() instanceof ActivatedManaAbilityImpl) {
        return false;
    }
    getEffects().setTargetPointer(new FixedTarget(event.getPlayerId()));
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) StackAbility(mage.game.stack.StackAbility)

Example 14 with ActivatedManaAbilityImpl

use of mage.abilities.mana.ActivatedManaAbilityImpl in project mage by magefree.

the class AnyColorLandsProduceManaEffect method getManaTypes.

private Mana getManaTypes(Game game, Ability source) {
    Mana types = new Mana();
    if (game == null || game.getPhase() == null) {
        return types;
    }
    if (inManaTypeCalculation) {
        return types;
    }
    inManaTypeCalculation = true;
    List<Permanent> lands = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CONTROLLED_PERMANENT_LAND, source.getControllerId(), source.getSourceId(), game);
    for (Permanent land : lands) {
        Abilities<ActivatedManaAbilityImpl> mana = land.getAbilities().getActivatedManaAbilities(Zone.BATTLEFIELD);
        for (ActivatedManaAbilityImpl ability : mana) {
            if (!ability.equals(source) && ability.definesMana(game)) {
                for (Mana netMana : ability.getNetMana(game)) {
                    types.add(netMana);
                }
            }
        }
    }
    inManaTypeCalculation = false;
    return types;
}
Also used : Mana(mage.Mana) Permanent(mage.game.permanent.Permanent) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl)

Example 15 with ActivatedManaAbilityImpl

use of mage.abilities.mana.ActivatedManaAbilityImpl in project mage by magefree.

the class PlayerImpl method getUseableManaAbilities.

protected LinkedHashMap<UUID, ActivatedManaAbilityImpl> getUseableManaAbilities(MageObject object, Zone zone, Game game) {
    LinkedHashMap<UUID, ActivatedManaAbilityImpl> useable = new LinkedHashMap<>();
    boolean canUse = !(object instanceof Permanent) || ((Permanent) object).canUseActivatedAbilities(game);
    for (ActivatedManaAbilityImpl ability : object.getAbilities().getActivatedManaAbilities(zone)) {
        if (canUse || ability.getAbilityType() == AbilityType.SPECIAL_ACTION) {
            if (ability.canActivate(playerId, game).canActivate()) {
                useable.put(ability.getId(), ability);
            }
        }
    }
    return useable;
}
Also used : Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) TargetPermanent(mage.target.TargetPermanent) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl)

Aggregations

ActivatedManaAbilityImpl (mage.abilities.mana.ActivatedManaAbilityImpl)29 Permanent (mage.game.permanent.Permanent)12 StackAbility (mage.game.stack.StackAbility)7 MageObject (mage.MageObject)6 Mana (mage.Mana)5 Ability (mage.abilities.Ability)5 ManaCost (mage.abilities.costs.mana.ManaCost)5 Card (mage.cards.Card)5 FilterCard (mage.filter.FilterCard)5 FilterPermanent (mage.filter.FilterPermanent)5 TargetPermanent (mage.target.TargetPermanent)5 UUID (java.util.UUID)4 ConditionalMana (mage.ConditionalMana)4 ManaOptions (mage.abilities.mana.ManaOptions)4 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)4 PermanentCard (mage.game.permanent.PermanentCard)4 LinkedHashMap (java.util.LinkedHashMap)3 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)3 Counter (mage.counters.Counter)3 Player (mage.players.Player)3