Search in sources :

Example 1 with ActivatedManaAbilityImpl

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

the class GameStateEvaluator method evaluatePermanent.

public static int evaluatePermanent(Permanent permanent, Game game, boolean ignoreTapped) {
    int value = 0;
    if (ignoreTapped) {
        value = 5;
    } else {
        value = permanent.isTapped() ? 4 : 5;
    }
    if (permanent.getCardType(game).contains(CardType.CREATURE)) {
        value += evaluateCreature(permanent, game) * CREATURE_FACTOR;
    }
    value += permanent.getAbilities().getActivatedManaAbilities(Zone.BATTLEFIELD).size();
    for (ActivatedAbility ability : permanent.getAbilities().getActivatedAbilities(Zone.BATTLEFIELD)) {
        if (!(ability instanceof ActivatedManaAbilityImpl) && ability.canActivate(ability.getControllerId(), game).canActivate()) {
            value += ability.getEffects().size();
        }
    }
    for (Counter counter : permanent.getCounters(game).values()) {
        if (!(counter instanceof BoostCounter)) {
            value += counter.getCount();
        }
    }
    value += permanent.getAbilities().getStaticAbilities(Zone.BATTLEFIELD).size();
    value += permanent.getAbilities().getTriggeredAbilities(Zone.BATTLEFIELD).size();
    value += permanent.getManaCost().manaValue();
    // TODO: add a difficulty to calculation to ManaCost - sort permanents by difficulty for casting when evaluating game states
    return value;
}
Also used : BoostCounter(mage.counters.BoostCounter) Counter(mage.counters.Counter) ActivatedAbility(mage.abilities.ActivatedAbility) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) BoostCounter(mage.counters.BoostCounter)

Example 2 with ActivatedManaAbilityImpl

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

the class AbilityImpl method activate.

@Override
public boolean activate(Game game, boolean noMana) {
    Player controller = game.getPlayer(this.getControllerId());
    if (controller == null) {
        return false;
    }
    game.applyEffects();
    MageObject sourceObject = getSourceObject(game);
    if (getSourceObjectZoneChangeCounter() == 0) {
        setSourceObjectZoneChangeCounter(game.getState().getZoneChangeCounter(getSourceId()));
    }
    setSourcePermanentTransformCount(game);
    /* 20130201 - 601.2b
         * If the player wishes to splice any cards onto the spell (see rule 702.45), he
         * or she reveals those cards in their hand.
         */
    if (this.abilityType == AbilityType.SPELL) {
        game.getContinuousEffects().applySpliceEffects(this, game);
    }
    // For Flashback ability can be set X before, so the X costs have to be restored for the flashbacked ability
    if (noMana) {
        if (!this.getManaCostsToPay().getVariableCosts().isEmpty()) {
            int xValue = this.getManaCostsToPay().getX();
            this.getManaCostsToPay().clear();
            VariableManaCost xCosts = new VariableManaCost(VariableCostType.ADDITIONAL);
            // no x events - rules from Unbound Flourishing:
            // - Spells with additional costs that include X won't be affected by Unbound Flourishing. X must be in the spell's mana cost.
            xCosts.setAmount(xValue, xValue, false);
            this.getManaCostsToPay().add(xCosts);
        } else {
            this.getManaCostsToPay().clear();
        }
    }
    // A player can't apply two alternative methods of casting or two alternative costs to a single spell.
    if (!activateAlternateOrAdditionalCosts(sourceObject, noMana, controller, game)) {
        if (getAbilityType() == AbilityType.SPELL && ((SpellAbility) this).getSpellAbilityType() == SpellAbilityType.FACE_DOWN_CREATURE) {
            return false;
        }
    }
    // }
    if (getAbilityType() == AbilityType.SPELL && (getManaCostsToPay().isEmpty() && getCosts().isEmpty()) && !noMana) {
        return false;
    }
    // 20121001 - 601.2b
    // If the spell has a variable cost that will be paid as it's being cast (such as an {X} in
    // its mana cost; see rule 107.3), the player announces the value of that variable.
    VariableManaCost variableManaCost = handleManaXCosts(game, noMana, controller);
    String announceString = handleOtherXCosts(game, controller);
    // For effects from cards like Void Winnower x costs have to be set
    if (this.getAbilityType() == AbilityType.SPELL) {
        GameEvent castEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL_LATE, this.getId(), this, getControllerId());
        castEvent.setZone(game.getState().getZone(CardUtil.getMainCardId(game, sourceId)));
        if (game.replaceEvent(castEvent, this)) {
            return false;
        }
    }
    handlePhyrexianManaCosts(game, controller);
    // Kicking a spell is always optional.
    if (!getModes().choose(game, this)) {
        return false;
    }
    // 2. From single addTarget/setChoice, it's a preffered method for tests (process it in normal choose dialogs like human player)
    if (controller.isTestsMode()) {
        if (!controller.addTargets(this, game)) {
            return false;
        }
    }
    for (UUID modeId : this.getModes().getSelectedModes()) {
        this.getModes().setActiveMode(modeId);
        if (sourceObject != null && this.getAbilityType() != AbilityType.TRIGGERED) {
            // triggered abilities check this already in playerImpl.triggerAbility
            sourceObject.adjustTargets(this, game);
        }
        if (!getTargets().isEmpty()) {
            Outcome outcome = getEffects().getOutcome(this);
            // only activated abilities can be canceled by human user (not triggered)
            boolean canCancel = this instanceof ActivatedAbility && controller.isHuman();
            if (!getTargets().chooseTargets(outcome, this.controllerId, this, noMana, game, canCancel)) {
                // was canceled during targer selection
                return false;
            }
        }
    }
    // this is a hack to prevent mana abilities with mana costs from causing endless loops - pay other costs first
    if (this instanceof ActivatedManaAbilityImpl && !costs.pay(this, game, this, controllerId, noMana, null)) {
        logger.debug("activate mana ability failed - non mana costs");
        return false;
    }
    // fused spell contains 3 abilities (fused, left, right)
    // fused cost added to fused ability, so no need cost modification for other parts
    boolean needCostModification = !CardUtil.isFusedPartAbility(this, game);
    // 20101001 - 601.2e
    if (needCostModification && sourceObject != null) {
        // still needed for CostAdjuster objects (to handle some types of dynamic costs)
        sourceObject.adjustCosts(this, game);
        game.getContinuousEffects().costModification(this, game);
    }
    UUID activatorId = controllerId;
    if ((this instanceof ActivatedAbilityImpl) && ((ActivatedAbilityImpl) this).getActivatorId() != null) {
        activatorId = ((ActivatedAbilityImpl) this).getActivatorId();
    }
    // 20100716 - 601.2f  (noMana is not used here, because mana costs were cleared for this ability before adding additional costs and applying cost modification effects)
    if (!manaCostsToPay.pay(this, game, this, activatorId, false, null)) {
        // cancel during mana payment
        return false;
    }
    // 20100716 - 601.2g
    if (!costs.pay(this, game, this, activatorId, noMana, null)) {
        logger.debug("activate failed - non mana costs");
        return false;
    }
    // inform about x costs now, so canceled announcements are not shown in the log
    if ((announceString != null) && (!announceString.equals(""))) {
        game.informPlayers(announceString);
    }
    if (variableManaCost != null) {
        int xValue = getManaCostsToPay().getX();
        game.informPlayers(controller.getLogName() + " announces a value of " + xValue + " for " + variableManaCost.getText());
    }
    activated = true;
    return true;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) Hint(mage.abilities.hint.Hint) VariableManaCost(mage.abilities.costs.mana.VariableManaCost) GameEvent(mage.game.events.GameEvent) UUID(java.util.UUID)

Example 3 with ActivatedManaAbilityImpl

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

the class ManaUtilTest method testManaToPayVsLand.

/**
 * Another way to test ManaUtil.tryToAutoPay Here we also check what ability
 * was auto chosen
 *
 * N.B. This method can be used ONLY if we have one ability left that auto
 * choose mode! That's why we assert the following: Assert.assertEquals(1,
 * useableAbilities.size());
 *
 * We get all mana abilities, then try to auto pay and compare to expected1
 * and expected2 params.
 *
 * @param manaToPay Mana that should be paid using land.
 * @param landName Land to use as mana producer.
 * @param expected1 The amount of mana abilities the land should have.
 * @param expectedChosen
 */
private void testManaToPayVsLand(String manaToPay, String landName, int expected1, Class<? extends BasicManaAbility> expectedChosen) {
    ManaCost unpaid = new ManaCostsImpl(manaToPay);
    Card card = CardRepository.instance.findCard(landName).getCard();
    Assert.assertNotNull(card);
    Map<UUID, ActivatedManaAbilityImpl> useableAbilities = getManaAbilities(card);
    Assert.assertEquals(expected1, useableAbilities.size());
    useableAbilities = ManaUtil.tryToAutoPay(unpaid, (LinkedHashMap<UUID, ActivatedManaAbilityImpl>) useableAbilities);
    Assert.assertEquals(1, useableAbilities.size());
    ActivatedManaAbilityImpl ability = useableAbilities.values().iterator().next();
    Assert.assertTrue("Wrong mana ability has been chosen", expectedChosen.isInstance(ability));
}
Also used : ManaCost(mage.abilities.costs.mana.ManaCost) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) UUID(java.util.UUID) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Card(mage.cards.Card) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with ActivatedManaAbilityImpl

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

the class ManaUtilTest method getManaAbilities.

/**
 * Extracts mana abilities from the card.
 *
 * @param card Card to extract mana abilities from.
 * @return
 */
private Map<UUID, ActivatedManaAbilityImpl> getManaAbilities(Card card) {
    Map<UUID, ActivatedManaAbilityImpl> useableAbilities = new LinkedHashMap<>();
    for (Ability ability : card.getAbilities()) {
        if (ability instanceof ActivatedManaAbilityImpl) {
            // we need to assign id manually as we are not in game
            ability.newId();
            useableAbilities.put(ability.getId(), (ActivatedManaAbilityImpl) ability);
        }
    }
    return useableAbilities;
}
Also used : BasicManaAbility(mage.abilities.mana.BasicManaAbility) BlackManaAbility(mage.abilities.mana.BlackManaAbility) RedManaAbility(mage.abilities.mana.RedManaAbility) SpellAbility(mage.abilities.SpellAbility) WhiteManaAbility(mage.abilities.mana.WhiteManaAbility) Ability(mage.abilities.Ability) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) UUID(java.util.UUID) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with ActivatedManaAbilityImpl

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

the class IllusionistsBracersTriggeredAbility 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;
    }
    this.getEffects().setValue("stackAbility", stackAbility);
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) StackAbility(mage.game.stack.StackAbility)

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