Search in sources :

Example 6 with ManaCosts

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

the class TilonallisSummonerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        ManaCosts cost = new ManaCostsImpl("{X}{R}");
        if (controller.chooseUse(outcome, "Pay " + cost.getText() + "? If you do, you create X 1/1 red Elemental creature tokens that are tapped and attacking.", source, game)) {
            int costX = controller.announceXMana(0, Integer.MAX_VALUE, "Announce the value for {X}", game, source);
            cost.add(new GenericManaCost(costX));
            if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
                // otherwise you can undo the payment
                controller.resetStoredBookmark(game);
                CreateTokenEffect effect = new CreateTokenEffect(new TilonallisSummonerElementalToken(), costX, true, true);
                effect.apply(game, source);
                Effect exileEffect = new ExileTargetEffect(null, "", Zone.BATTLEFIELD).setText("exile those tokens unless you have the city's blessing");
                exileEffect.setTargetPointer(new FixedTargets(new CardsImpl(effect.getLastAddedTokenIds()), game));
                game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect, TargetController.ANY, new InvertCondition(CitysBlessingCondition.instance)), source);
            }
        }
        return true;
    }
    return false;
}
Also used : ManaCosts(mage.abilities.costs.mana.ManaCosts) Player(mage.players.Player) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) TilonallisSummonerElementalToken(mage.game.permanent.token.TilonallisSummonerElementalToken) FixedTargets(mage.target.targetpointer.FixedTargets) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) CitysBlessingHint(mage.abilities.hint.common.CitysBlessingHint) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) InvertCondition(mage.abilities.condition.InvertCondition) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) CardsImpl(mage.cards.CardsImpl) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Example 7 with ManaCosts

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

the class WelcomeToTheFoldEffect method init.

@Override
public void init(Ability source, Game game) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int maxToughness = 2;
        ManaCosts manaCosts = source.getManaCostsToPay();
        if (!manaCosts.getVariableCosts().isEmpty()) {
            maxToughness = source.getManaCostsToPay().getX();
        }
        Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
        if (permanent != null && permanent.getToughness().getValue() > maxToughness) {
            this.discard();
            return;
        }
    }
    super.init(source, game);
}
Also used : ManaCosts(mage.abilities.costs.mana.ManaCosts) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent)

Example 8 with ManaCosts

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

the class PayCostToAttackBlockEffectImpl method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    ManaCosts attackBlockManaTax = getManaCostToPay(event, source, game);
    if (attackBlockManaTax != null) {
        return handleManaCosts(attackBlockManaTax.copy(), event, source, game);
    }
    Cost attackBlockOtherTax = getOtherCostToPay(event, source, game);
    if (attackBlockOtherTax != null) {
        return handleOtherCosts(attackBlockOtherTax.copy(), event, source, game);
    }
    return false;
}
Also used : ManaCosts(mage.abilities.costs.mana.ManaCosts) Cost(mage.abilities.costs.Cost)

Example 9 with ManaCosts

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

the class PlayerImpl method cast.

/**
 * @param originalAbility
 * @param game
 * @param noMana          cast it without paying mana costs
 * @param approvingObject which object approved the cast
 * @return
 */
@Override
public boolean cast(SpellAbility originalAbility, Game game, boolean noMana, ApprovingObject approvingObject) {
    if (game == null || originalAbility == null) {
        return false;
    }
    // Use ability copy to avoid problems with targets and costs on recast (issue https://github.com/magefree/mage/issues/5189).
    SpellAbility ability = originalAbility.copy();
    ability.setControllerId(getId());
    ability.setSourceObjectZoneChangeCounter(game.getState().getZoneChangeCounter(ability.getSourceId()));
    // 20091005 - 601.2a
    if (ability.getSourceId() == null) {
        logger.error("Ability without sourceId turn " + game.getTurnNum() + ". Ability: " + ability.getRule());
        return false;
    }
    Card card = game.getCard(ability.getSourceId());
    if (card != null) {
        Zone fromZone = game.getState().getZone(card.getMainCard().getId());
        GameEvent castEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, ability.getId(), ability, playerId, approvingObject);
        castEvent.setZone(fromZone);
        if (!game.replaceEvent(castEvent, ability)) {
            int bookmark = game.bookmarkState();
            // move global bookmark to current state (if you activated mana before then you can't rollback it)
            setStoredBookmark(bookmark);
            card.cast(game, fromZone, ability, playerId);
            Spell spell = game.getStack().getSpell(ability.getId());
            if (spell == null) {
                logger.error("Got no spell from stack. ability: " + ability.getRule());
                return false;
            }
            if (card.isCopy()) {
                spell.setCopy(true, null);
            }
            // Update the zcc to the stack
            ability.setSourceObjectZoneChangeCounter(game.getState().getZoneChangeCounter(ability.getSourceId()));
            // some effects set sourceId to cast without paying mana costs or other costs
            if (getCastSourceIdWithAlternateMana().contains(ability.getSourceId())) {
                Ability spellAbility = spell.getSpellAbility();
                ManaCosts alternateCosts = getCastSourceIdManaCosts().get(ability.getSourceId());
                Costs<Cost> costs = getCastSourceIdCosts().get(ability.getSourceId());
                if (alternateCosts == null) {
                    noMana = true;
                } else {
                    spellAbility.getManaCosts().clear();
                    spellAbility.getManaCostsToPay().clear();
                    spellAbility.getManaCosts().add(alternateCosts.copy());
                    spellAbility.getManaCostsToPay().add(alternateCosts.copy());
                }
                spellAbility.getCosts().clear();
                if (costs != null) {
                    spellAbility.getCosts().addAll(costs);
                }
            }
            // TODO: test multiple alternative cost for different cards as same time
            clearCastSourceIdManaCosts();
            castEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, spell.getSpellAbility().getId(), spell.getSpellAbility(), playerId, approvingObject);
            castEvent.setZone(fromZone);
            game.fireEvent(castEvent);
            if (spell.activate(game, noMana)) {
                GameEvent castedEvent = GameEvent.getEvent(GameEvent.EventType.SPELL_CAST, spell.getSpellAbility().getId(), spell.getSpellAbility(), playerId, approvingObject);
                castedEvent.setZone(fromZone);
                game.fireEvent(castedEvent);
                if (!game.isSimulation()) {
                    game.informPlayers(getLogName() + spell.getActivatedMessage(game));
                }
                game.removeBookmark(bookmark);
                resetStoredBookmark(game);
                return true;
            }
            restoreState(bookmark, ability.getRule(), game);
        }
    }
    return false;
}
Also used : AlternateManaPaymentAbility(mage.abilities.costs.mana.AlternateManaPaymentAbility) StackAbility(mage.game.stack.StackAbility) WhileSearchingPlayFromLibraryAbility(mage.abilities.common.WhileSearchingPlayFromLibraryAbility) AtTheEndOfTurnStepPostDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheEndOfTurnStepPostDelayedTriggeredAbility) PassAbility(mage.abilities.common.PassAbility) PlayLandAsCommanderAbility(mage.abilities.common.PlayLandAsCommanderAbility) ManaCosts(mage.abilities.costs.mana.ManaCosts) ManaCost(mage.abilities.costs.mana.ManaCost) Spell(mage.game.stack.Spell) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) PermanentCard(mage.game.permanent.PermanentCard)

Example 10 with ManaCosts

use of mage.abilities.costs.mana.ManaCosts 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)

Aggregations

ManaCosts (mage.abilities.costs.mana.ManaCosts)21 Player (mage.players.Player)16 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)15 Permanent (mage.game.permanent.Permanent)8 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)7 MageObjectReference (mage.MageObjectReference)6 Ability (mage.abilities.Ability)6 BecomesFaceDownCreatureEffect (mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect)6 Card (mage.cards.Card)6 UUID (java.util.UUID)4 OneShotEffect (mage.abilities.effects.OneShotEffect)3 Set (java.util.Set)2 ReflexiveTriggeredAbility (mage.abilities.common.delayed.ReflexiveTriggeredAbility)2 ManaCost (mage.abilities.costs.mana.ManaCost)2 Effect (mage.abilities.effects.Effect)2 AddCountersSourceEffect (mage.abilities.effects.common.counter.AddCountersSourceEffect)2 CardImpl (mage.cards.CardImpl)2 CardSetInfo (mage.cards.CardSetInfo)2 FilterPermanent (mage.filter.FilterPermanent)2 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)2