Search in sources :

Example 1 with AlternateManaPaymentAbility

use of mage.abilities.costs.mana.AlternateManaPaymentAbility in project mage by magefree.

the class PlayerImpl method findActivatedAbilityFromPlayable.

protected ActivatedAbility findActivatedAbilityFromPlayable(MageObject object, ManaOptions availableMana, Ability ability, Game game) {
    // special mana to pay spell cost
    ManaOptions manaFull = availableMana.copy();
    if (ability instanceof SpellAbility) {
        for (AlternateManaPaymentAbility altAbility : CardUtil.getAbilities(object, game).stream().filter(a -> a instanceof AlternateManaPaymentAbility).map(a -> (AlternateManaPaymentAbility) a).collect(Collectors.toList())) {
            ManaOptions manaSpecial = altAbility.getManaOptions(ability, game, ability.getManaCostsToPay());
            manaFull.addMana(manaSpecial);
        }
    }
    // replace alternative abilities by real play abilities (e.g. morph/facedown static ability by play land)
    if (ability instanceof ActivatedManaAbilityImpl) {
        // mana ability
        if (((ActivatedManaAbilityImpl) ability).canActivate(this.getId(), game).canActivate()) {
            return (ActivatedManaAbilityImpl) ability;
        }
    } else if (ability instanceof AlternativeSourceCosts) {
        // alternative cost must be replaced by real play ability
        return findActivatedAbilityFromAlternativeSourceCost(object, manaFull, ability, game);
    } else if (ability instanceof ActivatedAbility) {
        // all other activated ability
        if (canPlay((ActivatedAbility) ability, manaFull, object, game)) {
            return (ActivatedAbility) ability;
        }
    }
    // non playable abilities like static
    return null;
}
Also used : MatchPlayer(mage.game.match.MatchPlayer) PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) UserData(mage.players.net.UserData) Counters(mage.counters.Counters) mage.abilities.costs(mage.abilities.costs) Logger(org.apache.log4j.Logger) ManaCost(mage.abilities.costs.mana.ManaCost) StackObject(mage.game.stack.StackObject) mage.constants(mage.constants) mage.abilities(mage.abilities) Choice(mage.choices.Choice) FilterMana(mage.filter.FilterMana) FilterCard(mage.filter.FilterCard) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) StaticFilters(mage.filter.StaticFilters) GameLog(mage.util.GameLog) AlternateManaPaymentAbility(mage.abilities.costs.mana.AlternateManaPaymentAbility) RestrictionUntapNotMoreThanEffect(mage.abilities.effects.RestrictionUntapNotMoreThanEffect) ImmutableMap(com.google.common.collect.ImmutableMap) mage.abilities.keyword(mage.abilities.keyword) mage.cards(mage.cards) FilterCreatureForCombatBlock(mage.filter.common.FilterCreatureForCombatBlock) TargetDiscard(mage.target.common.TargetDiscard) StackAbility(mage.game.stack.StackAbility) CardUtil(mage.util.CardUtil) Collectors(java.util.stream.Collectors) CommandObject(mage.game.command.CommandObject) Serializable(java.io.Serializable) FilterCreatureForCombat(mage.filter.common.FilterCreatureForCombat) Permanent(mage.game.permanent.Permanent) Entry(java.util.Map.Entry) TargetAmount(mage.target.TargetAmount) WhileSearchingPlayFromLibraryAbility(mage.abilities.common.WhileSearchingPlayFromLibraryAbility) CounterType(mage.counters.CounterType) Target(mage.target.Target) mage(mage) java.util(java.util) RestrictionEffect(mage.abilities.effects.RestrictionEffect) mage.game(mage.game) LoseControlOnOtherPlayersControllerEffect(mage.abilities.effects.common.LoseControlOnOtherPlayersControllerEffect) DesignationType(mage.designations.DesignationType) mage.game.events(mage.game.events) AtTheEndOfTurnStepPostDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheEndOfTurnStepPostDelayedTriggeredAbility) Predicates(mage.filter.predicate.Predicates) FilterPermanent(mage.filter.FilterPermanent) ManaOptions(mage.abilities.mana.ManaOptions) Step(mage.game.turn.Step) Designation(mage.designations.Designation) PermanentToken(mage.game.permanent.PermanentToken) TargetCard(mage.target.TargetCard) Counter(mage.counters.Counter) CombatGroup(mage.game.combat.CombatGroup) Spell(mage.game.stack.Spell) MageDrawAction(mage.actions.MageDrawAction) RandomUtil(mage.util.RandomUtil) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) ManaCosts(mage.abilities.costs.mana.ManaCosts) PassAbility(mage.abilities.common.PassAbility) SquirrelToken(mage.game.permanent.token.SquirrelToken) Deck(mage.cards.decks.Deck) PlayLandAsCommanderAbility(mage.abilities.common.PlayLandAsCommanderAbility) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) ChoiceImpl(mage.choices.ChoiceImpl) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) ActivationStatus(mage.abilities.ActivatedAbility.ActivationStatus) PermanentCard(mage.game.permanent.PermanentCard) TargetPermanent(mage.target.TargetPermanent) ManaOptions(mage.abilities.mana.ManaOptions) AlternateManaPaymentAbility(mage.abilities.costs.mana.AlternateManaPaymentAbility) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 Serializable (java.io.Serializable)1 java.util (java.util)1 Entry (java.util.Map.Entry)1 Collectors (java.util.stream.Collectors)1 mage (mage)1 mage.abilities (mage.abilities)1 ActivationStatus (mage.abilities.ActivatedAbility.ActivationStatus)1 PassAbility (mage.abilities.common.PassAbility)1 PlayLandAsCommanderAbility (mage.abilities.common.PlayLandAsCommanderAbility)1 WhileSearchingPlayFromLibraryAbility (mage.abilities.common.WhileSearchingPlayFromLibraryAbility)1 AtTheEndOfTurnStepPostDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheEndOfTurnStepPostDelayedTriggeredAbility)1 mage.abilities.costs (mage.abilities.costs)1 AlternateManaPaymentAbility (mage.abilities.costs.mana.AlternateManaPaymentAbility)1 ManaCost (mage.abilities.costs.mana.ManaCost)1 ManaCosts (mage.abilities.costs.mana.ManaCosts)1 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)1 RestrictionEffect (mage.abilities.effects.RestrictionEffect)1 RestrictionUntapNotMoreThanEffect (mage.abilities.effects.RestrictionUntapNotMoreThanEffect)1 LoseControlOnOtherPlayersControllerEffect (mage.abilities.effects.common.LoseControlOnOtherPlayersControllerEffect)1