Search in sources :

Example 26 with ActivatedManaAbilityImpl

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

the class ComputerPlayer method getSortedProducers.

/**
 * returns a list of Permanents that produce mana sorted by the number of
 * mana the Permanent produces that match the unpaid costs in ascending
 * order
 * <p>
 * the idea is that we should pay costs first from mana producers that
 * produce only one type of mana and save the multi-mana producers for those
 * costs that can't be paid by any other producers
 *
 * @param unpaid - the amount of unpaid mana costs
 * @param game
 * @return List<Permanent>
 */
private List<MageObject> getSortedProducers(ManaCosts<ManaCost> unpaid, Game game) {
    List<MageObject> unsorted = this.getAvailableManaProducers(game);
    unsorted.addAll(this.getAvailableManaProducersWithCost(game));
    Map<MageObject, Integer> scored = new HashMap<>();
    for (MageObject mageObject : unsorted) {
        int score = 0;
        for (ManaCost cost : unpaid) {
            Abilities: for (ActivatedManaAbilityImpl ability : mageObject.getAbilities().getAvailableActivatedManaAbilities(Zone.BATTLEFIELD, playerId, game)) {
                for (Mana netMana : ability.getNetMana(game)) {
                    if (cost.testPay(netMana)) {
                        score++;
                        break Abilities;
                    }
                }
            }
        }
        if (score > 0) {
            // score mana producers that produce other mana types and have other uses higher
            score += mageObject.getAbilities().getAvailableActivatedManaAbilities(Zone.BATTLEFIELD, playerId, game).size();
            score += mageObject.getAbilities().getActivatedAbilities(Zone.BATTLEFIELD).size();
            if (!mageObject.getCardType(game).contains(CardType.LAND)) {
                score += 2;
            } else if (mageObject.getCardType(game).contains(CardType.CREATURE)) {
                score += 2;
            }
        }
        scored.put(mageObject, score);
    }
    return sortByValue(scored);
}
Also used : ConditionalMana(mage.ConditionalMana) Mana(mage.Mana) MageObject(mage.MageObject) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl)

Example 27 with ActivatedManaAbilityImpl

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

the class BenthicExplorersManaEffect method getManaTypes.

private Set<ManaType> getManaTypes(Game game, Ability source) {
    Set<ManaType> types = EnumSet.noneOf(ManaType.class);
    if (game == null || game.getPhase() == null) {
        return types;
    }
    Permanent land = (Permanent) game.getState().getValue("UntapTargetCost" + source.getSourceId().toString());
    if (land != null) {
        Abilities<ActivatedManaAbilityImpl> mana = land.getAbilities().getActivatedManaAbilities(Zone.BATTLEFIELD);
        for (ActivatedManaAbilityImpl ability : mana) {
            if (ability.definesMana(game)) {
                types.addAll(ability.getProducableManaTypes(game));
            }
        }
    }
    return types;
}
Also used : FilterLandPermanent(mage.filter.common.FilterLandPermanent) TargetLandPermanent(mage.target.common.TargetLandPermanent) Permanent(mage.game.permanent.Permanent) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl)

Example 28 with ActivatedManaAbilityImpl

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

the class BattlemagesBracersTriggeredAbility method checkTrigger.

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

Example 29 with ActivatedManaAbilityImpl

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

the class HumanPlayer method playManaAbilities.

protected void playManaAbilities(UUID objectId, Ability abilityToCast, ManaCost unpaid, Game game) {
    updateGameStatePriority("playManaAbilities", game);
    MageObject object = game.getObject(objectId);
    if (object == null) {
        return;
    }
    // can't see lands as playable and must know the reason (if they click on land then they get that message)
    if (abilityToCast.getAbilityType() == AbilityType.SPELL) {
        Spell spell = game.getStack().getSpell(abilityToCast.getSourceId());
        boolean haveManaAbilities = object.getAbilities().stream().anyMatch(a -> a instanceof ManaAbility);
        if (spell != null && !spell.isResolving() && haveManaAbilities) {
            switch(spell.getCurrentActivatingManaAbilitiesStep()) {
                // if you used special mana ability like convoke then normal mana abilities will be restricted to use, see Convoke for details
                case BEFORE:
                case NORMAL:
                    break;
                case AFTER:
                    game.informPlayer(this, "You can no longer use activated mana abilities to pay for the current spell (special mana pay already used). Cancel and recast the spell to activate mana abilities first.");
                    return;
            }
        }
    }
    Zone zone = game.getState().getZone(object.getId());
    if (zone != null) {
        LinkedHashMap<UUID, ActivatedManaAbilityImpl> useableAbilities = getUseableManaAbilities(object, zone, game);
        if (!useableAbilities.isEmpty()) {
            // eliminates other abilities if one fits perfectly
            useableAbilities = ManaUtil.tryToAutoPay(unpaid, useableAbilities);
            currentlyUnpaidMana = unpaid;
            activateAbility(useableAbilities, object, game);
            currentlyUnpaidMana = null;
        }
    }
}
Also used : ManaAbility(mage.abilities.mana.ManaAbility) MageObject(mage.MageObject) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) Spell(mage.game.stack.Spell)

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