Search in sources :

Example 11 with ManaCost

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

the class PermanentToken method copyFromToken.

private void copyFromToken(Token token, Game game, boolean reset) {
    // modify all attributes permanently (without game usage)
    this.name = token.getName();
    this.abilities.clear();
    if (reset) {
        this.abilities.addAll(token.getAbilities());
    } else {
        // so sourceId must be null (keep triggered abilities forever?)
        for (Ability ability : token.getAbilities()) {
            this.addAbility(ability, null, game);
        }
    }
    this.abilities.setControllerId(this.controllerId);
    this.manaCost.clear();
    for (ManaCost cost : token.getManaCost()) {
        this.getManaCost().add(cost.copy());
    }
    this.cardType.clear();
    this.cardType.addAll(token.getCardType(game));
    this.color = token.getColor(game).copy();
    this.frameColor = token.getFrameColor(game);
    this.frameStyle = token.getFrameStyle();
    this.supertype.clear();
    this.supertype.addAll(token.getSuperType());
    this.subtype.copyFrom(token.getSubtype(game));
    this.tokenDescriptor = token.getTokenDescriptor();
    this.startingLoyalty = token.getStartingLoyalty();
}
Also used : Ability(mage.abilities.Ability) ManaCost(mage.abilities.costs.mana.ManaCost)

Example 12 with ManaCost

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

the class FlashEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null || !controller.chooseUse(Outcome.PutCreatureInPlay, choiceText, source, game)) {
        return false;
    }
    TargetCardInHand target = new TargetCardInHand(StaticFilters.FILTER_CARD_CREATURE);
    if (controller.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card != null) {
            controller.moveCards(card, Zone.BATTLEFIELD, source, game);
            ManaCosts<ManaCost> reducedCost = ManaCosts.removeVariableManaCost(CardUtil.reduceCost(card.getManaCost(), 2));
            if (controller.chooseUse(Outcome.Benefit, String.valueOf("Pay " + reducedCost.getText()) + Character.toString('?'), source, game)) {
                reducedCost.clearPaid();
                if (reducedCost.pay(source, game, source, source.getControllerId(), false, null)) {
                    return true;
                }
            }
            Permanent permanent = game.getPermanent(card.getId());
            if (permanent != null) {
                permanent.sacrifice(source, game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) ManaCost(mage.abilities.costs.mana.ManaCost) Card(mage.cards.Card)

Example 13 with ManaCost

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

the class AlternativeCostSourceAbility method askToActivateAlternativeCosts.

@Override
public boolean askToActivateAlternativeCosts(Ability ability, Game game) {
    if (ability != null && AbilityType.SPELL == ability.getAbilityType()) {
        if (filter != null) {
            Card card = game.getCard(ability.getSourceId());
            if (!filter.match(card, ability.getSourceId(), ability.getControllerId(), game)) {
                return false;
            }
        }
        Player player = game.getPlayer(ability.getControllerId());
        if (player != null) {
            Costs<AlternativeCost2> alternativeCostsToCheck;
            if (dynamicCost != null) {
                alternativeCostsToCheck = new CostsImpl<>();
                alternativeCostsToCheck.add(convertToAlternativeCost(dynamicCost.getCost(ability, game)));
            } else {
                alternativeCostsToCheck = this.alternateCosts;
            }
            String costChoiceText;
            if (dynamicCost != null) {
                costChoiceText = dynamicCost.getText(ability, game);
            } else {
                costChoiceText = alternativeCostsToCheck.isEmpty() ? "Cast without paying its mana cost?" : "Pay alternative costs? (" + alternativeCostsToCheck.getText() + ')';
            }
            if (alternativeCostsToCheck.canPay(ability, ability, ability.getControllerId(), game) && player.chooseUse(Outcome.Benefit, costChoiceText, this, game)) {
                if (ability instanceof SpellAbility) {
                    ability.getManaCostsToPay().removeIf(manaCost -> manaCost instanceof VariableCost);
                    CardUtil.reduceCost((SpellAbility) ability, ability.getManaCosts());
                } else {
                    ability.getManaCostsToPay().clear();
                }
                if (!onlyMana) {
                    ability.getCosts().clear();
                }
                for (AlternativeCost2 alternateCost : alternativeCostsToCheck) {
                    alternateCost.activate();
                    for (Iterator it = ((Costs) alternateCost).iterator(); it.hasNext(); ) {
                        Cost costDetailed = (Cost) it.next();
                        if (costDetailed instanceof ManaCost) {
                            ability.getManaCostsToPay().add((ManaCost) costDetailed.copy());
                        } else if (costDetailed != null) {
                            ability.getCosts().add(costDetailed.copy());
                        }
                    }
                }
                // save activated status
                game.getState().setValue(getActivatedKey(ability), Boolean.TRUE);
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
    return isActivated(ability, game);
}
Also used : Player(mage.players.Player) ManaCost(mage.abilities.costs.mana.ManaCost) Iterator(java.util.Iterator) SpellAbility(mage.abilities.SpellAbility) ManaCost(mage.abilities.costs.mana.ManaCost) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 14 with ManaCost

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

the class SacrificeSourceUnlessPaysEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (player != null && sourcePermanent != null) {
        Cost costToPay;
        String costValueMessage;
        if (cost != null) {
            costToPay = cost.copy();
            costValueMessage = costToPay.getText();
        } else {
            costToPay = ManaUtil.createManaCost(genericMana, game, source, this);
            costValueMessage = "{" + genericMana.calculate(game, source, this) + "}";
        }
        String message = "";
        if (costToPay instanceof ManaCost) {
            message += "Pay ";
        }
        message += costValueMessage + '?';
        costToPay.clearPaid();
        if (costToPay.canPay(source, source, source.getControllerId(), game) && player.chooseUse(Outcome.Benefit, message, source, game) && costToPay.pay(source, game, source, source.getControllerId(), false, null)) {
            game.informPlayers(player.getLogName() + " chooses to pay " + costValueMessage + " to prevent sacrifice effect");
            return true;
        }
        game.informPlayers(player.getLogName() + " chooses not to pay " + costValueMessage + " to prevent sacrifice effect");
        if (source.getSourceObjectZoneChangeCounter() == game.getState().getZoneChangeCounter(source.getSourceId()) && game.getState().getZone(source.getSourceId()) == Zone.BATTLEFIELD) {
            sourcePermanent.sacrifice(source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ManaCost(mage.abilities.costs.mana.ManaCost) Cost(mage.abilities.costs.Cost) ManaCost(mage.abilities.costs.mana.ManaCost)

Example 15 with ManaCost

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

the class SacrificeOpponentsUnlessPayEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<UUID> permsToSacrifice = new ArrayList<>();
    filter.add(TargetController.YOU.getControllerPredicate());
    for (UUID playerId : game.getOpponents(source.getControllerId())) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            Cost costToPay;
            String costValueMessage;
            if (cost != null) {
                costToPay = cost.copy();
                costValueMessage = costToPay.getText();
            } else {
                costToPay = ManaUtil.createManaCost(genericMana, game, source, this);
                costValueMessage = "{" + genericMana.calculate(game, source, this) + "}";
            }
            String message = "";
            if (costToPay instanceof ManaCost) {
                message += "Pay ";
            }
            message += costValueMessage + '?';
            costToPay.clearPaid();
            if (!(player.chooseUse(Outcome.Benefit, message, source, game) && costToPay.pay(source, game, source, player.getId(), false, null))) {
                game.informPlayers(player.getLogName() + " chooses not to pay " + costValueMessage + " to prevent the sacrifice effect");
                int numTargets = Math.min(amount.calculate(game, source, this), game.getBattlefield().countAll(filter, player.getId(), game));
                if (numTargets > 0) {
                    TargetPermanent target = new TargetPermanent(numTargets, numTargets, filter, true);
                    if (target.canChoose(source.getSourceId(), player.getId(), game)) {
                        player.chooseTarget(Outcome.Sacrifice, target, source, game);
                        permsToSacrifice.addAll(target.getTargets());
                    }
                }
            } else {
                game.informPlayers(player.getLogName() + " chooses to pay " + costValueMessage + " to prevent the sacrifice effect");
            }
        }
    }
    for (UUID permID : permsToSacrifice) {
        Permanent permanent = game.getPermanent(permID);
        if (permanent != null) {
            permanent.sacrifice(source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) ManaCost(mage.abilities.costs.mana.ManaCost) ArrayList(java.util.ArrayList) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) ManaCost(mage.abilities.costs.mana.ManaCost)

Aggregations

ManaCost (mage.abilities.costs.mana.ManaCost)26 Player (mage.players.Player)16 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)11 Permanent (mage.game.permanent.Permanent)9 Card (mage.cards.Card)8 Cost (mage.abilities.costs.Cost)6 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)6 UUID (java.util.UUID)4 Ability (mage.abilities.Ability)4 VariableManaCost (mage.abilities.costs.mana.VariableManaCost)4 TargetPermanent (mage.target.TargetPermanent)4 ArrayList (java.util.ArrayList)3 ActivatedManaAbilityImpl (mage.abilities.mana.ActivatedManaAbilityImpl)3 FilterPermanent (mage.filter.FilterPermanent)3 Iterator (java.util.Iterator)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 ApprovingObject (mage.ApprovingObject)2 Mana (mage.Mana)2 ObjectColor (mage.ObjectColor)2