Search in sources :

Example 6 with ManaEvent

use of mage.game.events.ManaEvent in project mage by magefree.

the class CumulativeUpkeepEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (player != null && permanent != null) {
        int ageCounter = permanent.getCounters(game).getCount(CounterType.AGE);
        if (cumulativeCost instanceof ManaCost) {
            ManaCostsImpl totalCost = new ManaCostsImpl<>();
            for (int i = 0; i < ageCounter; i++) {
                totalCost.add((ManaCost) cumulativeCost.copy());
            }
            if (player.chooseUse(Outcome.Benefit, "Pay " + totalCost.getText() + '?', source, game)) {
                totalCost.clearPaid();
                if (totalCost.payOrRollback(source, game, source, source.getControllerId())) {
                    game.fireEvent(new ManaEvent(EventType.PAID_CUMULATIVE_UPKEEP, permanent.getId(), source, player.getId(), totalCost.getUsedManaToPay()));
                    return true;
                }
            }
            game.fireEvent(new GameEvent(GameEvent.EventType.DIDNT_PAY_CUMULATIVE_UPKEEP, permanent.getId(), source, player.getId(), ageCounter, false));
            if (source.getControllerId().equals(permanent.getControllerId())) {
                // Permanent can only be sacrificed if you still control it
                permanent.sacrifice(source, game);
            }
            return true;
        } else {
            CostsImpl<Cost> totalCost = new CostsImpl<>();
            for (int i = 0; i < ageCounter; i++) {
                totalCost.add(cumulativeCost.copy());
            }
            if (player.chooseUse(Outcome.Benefit, totalCost.getText() + '?', source, game)) {
                totalCost.clearPaid();
                int bookmark = game.bookmarkState();
                if (totalCost.pay(source, game, source, source.getControllerId(), false, null)) {
                    game.fireEvent(new GameEvent(GameEvent.EventType.PAID_CUMULATIVE_UPKEEP, permanent.getId(), source, player.getId(), ageCounter, false));
                    return true;
                } else {
                    player.restoreState(bookmark, source.getRule(), game);
                }
            }
            game.fireEvent(new GameEvent(GameEvent.EventType.DIDNT_PAY_CUMULATIVE_UPKEEP, permanent.getId(), source, player.getId(), ageCounter, false));
            permanent.sacrifice(source, game);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ManaCost(mage.abilities.costs.mana.ManaCost) CostsImpl(mage.abilities.costs.CostsImpl) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) GameEvent(mage.game.events.GameEvent) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) ManaEvent(mage.game.events.ManaEvent) Cost(mage.abilities.costs.Cost) ManaCost(mage.abilities.costs.mana.ManaCost) OrCost(mage.abilities.costs.OrCost)

Example 7 with ManaEvent

use of mage.game.events.ManaEvent in project mage by magefree.

the class ContaminationReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    ManaEvent manaEvent = (ManaEvent) event;
    Mana mana = manaEvent.getMana();
    mana.setToMana(Mana.BlackMana(1));
    return false;
}
Also used : Mana(mage.Mana) ManaEvent(mage.game.events.ManaEvent) TappedForManaEvent(mage.game.events.TappedForManaEvent)

Example 8 with ManaEvent

use of mage.game.events.ManaEvent in project mage by magefree.

the class DeepWaterReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    ManaEvent manaEvent = (ManaEvent) event;
    Mana mana = manaEvent.getMana();
    mana.setToMana(Mana.BlueMana(mana.count()));
    return false;
}
Also used : Mana(mage.Mana) ManaEvent(mage.game.events.ManaEvent) TappedForManaEvent(mage.game.events.TappedForManaEvent)

Example 9 with ManaEvent

use of mage.game.events.ManaEvent in project mage by magefree.

the class InfernalDarknessReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    ManaEvent manaEvent = (ManaEvent) event;
    Mana mana = manaEvent.getMana();
    mana.setToMana(Mana.BlackMana(mana.count()));
    return false;
}
Also used : Mana(mage.Mana) ManaEvent(mage.game.events.ManaEvent) TappedForManaEvent(mage.game.events.TappedForManaEvent)

Example 10 with ManaEvent

use of mage.game.events.ManaEvent in project mage by magefree.

the class ManaPool method addMana.

public void addMana(Mana manaToAdd, Game game, Ability source, boolean dontLoseUntilEOT) {
    if (manaToAdd != null) {
        Mana mana = manaToAdd.copy();
        if (!game.replaceEvent(new ManaEvent(EventType.ADD_MANA, source.getId(), source, playerId, mana))) {
            if (mana instanceof ConditionalMana) {
                ConditionalMana conditionalMana = (ConditionalMana) mana;
                ManaPoolItem item = new ManaPoolItem(conditionalMana, source.getSourceObject(game), conditionalMana.getManaProducerOriginalId() != null ? conditionalMana.getManaProducerOriginalId() : source.getOriginalId());
                if (dontLoseUntilEOT) {
                    item.setDuration(Duration.EndOfTurn);
                }
                this.manaItems.add(item);
            } else {
                ManaPoolItem item = new ManaPoolItem(mana.getRed(), mana.getGreen(), mana.getBlue(), mana.getWhite(), mana.getBlack(), mana.getGeneric() + mana.getColorless(), source.getSourceObject(game), source.getOriginalId(), mana.getFlag());
                if (dontLoseUntilEOT) {
                    item.setDuration(Duration.EndOfTurn);
                }
                this.manaItems.add(item);
            }
            ManaEvent manaEvent = new ManaEvent(EventType.MANA_ADDED, source.getId(), source, playerId, mana);
            manaEvent.setData(mana.toString());
            game.fireEvent(manaEvent);
        }
    }
}
Also used : ConditionalMana(mage.ConditionalMana) Mana(mage.Mana) FilterMana(mage.filter.FilterMana) ConditionalMana(mage.ConditionalMana) ManaEvent(mage.game.events.ManaEvent)

Aggregations

ManaEvent (mage.game.events.ManaEvent)15 TappedForManaEvent (mage.game.events.TappedForManaEvent)12 Mana (mage.Mana)11 AddManaOfAnyColorEffect (mage.abilities.effects.mana.AddManaOfAnyColorEffect)2 Permanent (mage.game.permanent.Permanent)2 ConditionalMana (mage.ConditionalMana)1 ObjectColor (mage.ObjectColor)1 Cost (mage.abilities.costs.Cost)1 CostsImpl (mage.abilities.costs.CostsImpl)1 OrCost (mage.abilities.costs.OrCost)1 ManaCost (mage.abilities.costs.mana.ManaCost)1 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)1 Effect (mage.abilities.effects.Effect)1 OneShotEffect (mage.abilities.effects.OneShotEffect)1 BoostSourceEffect (mage.abilities.effects.common.continuous.BoostSourceEffect)1 AddManaOfAnyTypeProducedEffect (mage.abilities.effects.mana.AddManaOfAnyTypeProducedEffect)1 Card (mage.cards.Card)1 FilterMana (mage.filter.FilterMana)1 FilterLandPermanent (mage.filter.common.FilterLandPermanent)1 GameEvent (mage.game.events.GameEvent)1