Search in sources :

Example 1 with ManaPool

use of mage.players.ManaPool in project mage by magefree.

the class GlissaSunseekerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (controller == null || permanent == null) {
        return false;
    }
    ManaPool pool = controller.getManaPool();
    int blackMana = pool.getBlack();
    int whiteMana = pool.getWhite();
    int blueMana = pool.getBlue();
    int greenMana = pool.getGreen();
    int redMana = pool.getRed();
    int colorlessMana = pool.getColorless();
    int manaPoolTotal = blackMana + whiteMana + blueMana + greenMana + redMana + colorlessMana;
    if (permanent.getManaValue() == manaPoolTotal) {
        return permanent.destroy(source, game, false);
    }
    return false;
}
Also used : Player(mage.players.Player) TargetArtifactPermanent(mage.target.common.TargetArtifactPermanent) Permanent(mage.game.permanent.Permanent) ManaPool(mage.players.ManaPool)

Example 2 with ManaPool

use of mage.players.ManaPool in project mage by magefree.

the class ImproviseEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Spell spell = game.getStack().getSpell(source.getSourceId());
    if (controller != null && spell != null) {
        for (UUID artifactId : this.getTargetPointer().getTargets(game, source)) {
            Permanent perm = game.getPermanent(artifactId);
            if (perm == null) {
                continue;
            }
            if (!perm.isTapped() && perm.tap(source, game)) {
                ManaPool manaPool = controller.getManaPool();
                manaPool.addMana(Mana.ColorlessMana(1), game, source);
                manaPool.unlockManaType(ManaType.COLORLESS);
                if (!game.isSimulation()) {
                    game.informPlayers("Improvise: " + controller.getLogName() + " taps " + perm.getLogName() + " to pay {1}");
                }
                // can't use mana abilities after that (improvise cost must be payed after mana abilities only)
                spell.setCurrentActivatingManaAbilitiesStep(ActivationManaAbilityStep.AFTER);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) ManaPool(mage.players.ManaPool) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 3 with ManaPool

use of mage.players.ManaPool in project mage by magefree.

the class ConvokeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Spell spell = game.getStack().getSpell(source.getSourceId());
    if (controller != null && spell != null) {
        for (UUID creatureId : this.getTargetPointer().getTargets(game, source)) {
            Permanent perm = game.getPermanent(creatureId);
            if (perm == null) {
                continue;
            }
            String manaName;
            if (!perm.isTapped() && perm.tap(source, game)) {
                ManaPool manaPool = controller.getManaPool();
                Choice chooseManaType = buildChoice(perm.getColor(game), unpaid.getMana());
                if (!chooseManaType.getChoices().isEmpty()) {
                    if (chooseManaType.getChoices().size() > 1) {
                        chooseManaType.getChoices().add("Colorless");
                        chooseManaType.setMessage("Choose mana color to reduce from " + perm.getName());
                        if (!controller.choose(Outcome.Benefit, chooseManaType, game)) {
                            return false;
                        }
                    } else {
                        chooseManaType.setChoice(chooseManaType.getChoices().iterator().next());
                    }
                    if (chooseManaType.getChoice().equals("Black")) {
                        manaPool.addMana(Mana.BlackMana(1), game, source);
                        manaPool.unlockManaType(ManaType.BLACK);
                    }
                    if (chooseManaType.getChoice().equals("Blue")) {
                        manaPool.addMana(Mana.BlueMana(1), game, source);
                        manaPool.unlockManaType(ManaType.BLUE);
                    }
                    if (chooseManaType.getChoice().equals("Green")) {
                        manaPool.addMana(Mana.GreenMana(1), game, source);
                        manaPool.unlockManaType(ManaType.GREEN);
                    }
                    if (chooseManaType.getChoice().equals("White")) {
                        manaPool.addMana(Mana.WhiteMana(1), game, source);
                        manaPool.unlockManaType(ManaType.WHITE);
                    }
                    if (chooseManaType.getChoice().equals("Red")) {
                        manaPool.addMana(Mana.RedMana(1), game, source);
                        manaPool.unlockManaType(ManaType.RED);
                    }
                    if (chooseManaType.getChoice().equals("Colorless")) {
                        manaPool.addMana(Mana.ColorlessMana(1), game, source);
                        manaPool.unlockManaType(ManaType.COLORLESS);
                    }
                    manaName = chooseManaType.getChoice().toLowerCase(Locale.ENGLISH);
                } else {
                    manaPool.addMana(Mana.ColorlessMana(1), game, source);
                    manaPool.unlockManaType(ManaType.COLORLESS);
                    manaName = "colorless";
                }
                game.fireEvent(GameEvent.getEvent(GameEvent.EventType.CONVOKED, perm.getId(), source, source.getControllerId()));
                game.informPlayers("Convoke: " + controller.getLogName() + " taps " + perm.getLogName() + " to pay one " + manaName + " mana");
                // can't use mana abilities after that (convoke cost must be payed after mana abilities only)
                spell.setCurrentActivatingManaAbilitiesStep(ActivationManaAbilityStep.AFTER);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ManaPool(mage.players.ManaPool) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 4 with ManaPool

use of mage.players.ManaPool in project mage by magefree.

the class DelveEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Spell spell = game.getStack().getSpell(source.getSourceId());
    if (controller != null && spell != null) {
        ExileFromGraveCost exileFromGraveCost = (ExileFromGraveCost) source.getCosts().get(0);
        List<Card> exiledCards = exileFromGraveCost.getExiledCards();
        if (!exiledCards.isEmpty()) {
            Cards toDelve = new CardsImpl();
            for (Card card : exiledCards) {
                toDelve.add(card);
            }
            ManaPool manaPool = controller.getManaPool();
            manaPool.addMana(Mana.ColorlessMana(toDelve.size()), game, source);
            manaPool.unlockManaType(ManaType.COLORLESS);
            String keyString = CardUtil.getCardZoneString("delvedCards", source.getSourceId(), game);
            @SuppressWarnings("unchecked") Cards delvedCards = (Cards) game.getState().getValue(keyString);
            if (delvedCards == null) {
                game.getState().setValue(keyString, toDelve);
            } else {
                delvedCards.addAll(toDelve);
            }
            // can't use mana abilities after that (delve cost must be payed after mana abilities only)
            spell.setCurrentActivatingManaAbilitiesStep(ActivationManaAbilityStep.AFTER);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ExileFromGraveCost(mage.abilities.costs.common.ExileFromGraveCost) ManaPool(mage.players.ManaPool) Spell(mage.game.stack.Spell) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 5 with ManaPool

use of mage.players.ManaPool in project mage by magefree.

the class DoublingCubeEffect method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    if (game != null) {
        Player controller = game.getPlayer(source.getControllerId());
        if (controller != null) {
            ManaPool pool = controller.getManaPool();
            int blackMana = pool.getBlack();
            int whiteMana = pool.getWhite();
            int blueMana = pool.getBlue();
            int greenMana = pool.getGreen();
            int redMana = pool.getRed();
            int colorlessMana = pool.getColorless();
            for (ConditionalMana conditionalMana : pool.getConditionalMana()) {
                blackMana += conditionalMana.getBlack();
                whiteMana += conditionalMana.getWhite();
                blueMana += conditionalMana.getBlue();
                greenMana += conditionalMana.getGreen();
                redMana += conditionalMana.getRed();
                colorlessMana += conditionalMana.getColorless();
            }
            return new Mana(whiteMana, blueMana, blackMana, redMana, greenMana, 0, 0, colorlessMana);
        }
    }
    return new Mana();
}
Also used : Player(mage.players.Player) ConditionalMana(mage.ConditionalMana) Mana(mage.Mana) ConditionalMana(mage.ConditionalMana) ManaPool(mage.players.ManaPool)

Aggregations

ManaPool (mage.players.ManaPool)8 Player (mage.players.Player)8 Spell (mage.game.stack.Spell)5 UUID (java.util.UUID)3 Permanent (mage.game.permanent.Permanent)3 Card (mage.cards.Card)2 FilterCard (mage.filter.FilterCard)2 ApprovingObject (mage.ApprovingObject)1 ConditionalMana (mage.ConditionalMana)1 MageObject (mage.MageObject)1 Mana (mage.Mana)1 SpellAbility (mage.abilities.SpellAbility)1 Cost (mage.abilities.costs.Cost)1 ExileFromGraveCost (mage.abilities.costs.common.ExileFromGraveCost)1 ManaCost (mage.abilities.costs.mana.ManaCost)1 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)1 RestrictionEffect (mage.abilities.effects.RestrictionEffect)1 Cards (mage.cards.Cards)1 CardsImpl (mage.cards.CardsImpl)1 Choice (mage.choices.Choice)1