Search in sources :

Example 31 with Cost

use of mage.abilities.costs.Cost in project mage by magefree.

the class DralnusPetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null && source.getAbilityType() == AbilityType.STATIC) {
        permanent = game.getPermanentEntering(source.getSourceId());
    }
    if (controller != null && permanent != null) {
        SpellAbility spellAbility = (SpellAbility) getValue(EntersBattlefieldEffect.SOURCE_CAST_SPELL_ABILITY);
        if (spellAbility != null && spellAbility.getSourceId().equals(source.getSourceId()) && permanent.getZoneChangeCounter(game) == spellAbility.getSourceObjectZoneChangeCounter()) {
            int cmc = 0;
            for (Cost cost : spellAbility.getCosts()) {
                if (cost instanceof DiscardCardCost && !((DiscardCardCost) cost).getCards().isEmpty()) {
                    cmc = ((DiscardCardCost) cost).getCards().get(0).getManaValue();
                }
                if (cmc > 0) {
                    return new AddCountersSourceEffect(CounterType.P1P1.createInstance(cmc), true).apply(game, source);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : DiscardCardCost(mage.abilities.costs.common.DiscardCardCost) AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) SpellAbility(mage.abilities.SpellAbility) DiscardCardCost(mage.abilities.costs.common.DiscardCardCost) Cost(mage.abilities.costs.Cost)

Example 32 with Cost

use of mage.abilities.costs.Cost in project mage by magefree.

the class DragonsFireEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent targetedPermanent = game.getPermanent(targetPointer.getFirst(game, source));
    if (targetedPermanent == null) {
        return false;
    }
    DragonsFireCost.DragonZone dragonZone = DragonsFireCost.DragonZone.NONE;
    UUID selectedCardId = null;
    int damage = 3;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof DragonsFireCost) {
            DragonsFireCost dragonsFireCost = (DragonsFireCost) cost;
            dragonZone = dragonsFireCost.getDragonZone();
            selectedCardId = dragonsFireCost.getSelectedCardId();
            break;
        }
    }
    switch(dragonZone) {
        case HAND:
            Card card = game.getCard(selectedCardId);
            if (card != null) {
                damage = card.getPower().getValue();
            }
            break;
        case BATTLEFIELD:
            Permanent dragon = game.getPermanentOrLKIBattlefield(selectedCardId);
            if (dragon != null) {
                damage = dragon.getPower().getValue();
            }
            break;
    }
    targetedPermanent.damage(damage, source.getSourceId(), source, game);
    return true;
}
Also used : FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 33 with Cost

use of mage.abilities.costs.Cost in project mage by magefree.

the class LeylineTyrantDamageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int costX = player.announceXMana(0, Integer.MAX_VALUE, "Announce the value for {X}", game, source);
    String manaString;
    if (costX == 0) {
        manaString = "{0}";
    } else {
        manaString = "";
        for (int i = 0; i < costX; i++) {
            manaString += "{R}";
        }
    }
    Cost cost = new ManaCostsImpl<>(manaString);
    cost.clearPaid();
    if (!cost.pay(source, game, source, source.getControllerId(), false)) {
        return false;
    }
    ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new DamageTargetEffect(costX), false, "{this} deals " + costX + " damage to any target");
    ability.addTarget(new TargetAnyTarget());
    game.fireReflexiveTriggeredAbility(ability, source);
    return true;
}
Also used : Player(mage.players.Player) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) Cost(mage.abilities.costs.Cost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) TargetAnyTarget(mage.target.common.TargetAnyTarget)

Example 34 with Cost

use of mage.abilities.costs.Cost in project mage by magefree.

the class NashiMoonSagesScionPlayEffect method applies.

@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    if (!super.applies(objectId, source, affectedControllerId, game) || !NashiMoonSagesScionWatcher.checkCard(game, source, mor)) {
        return false;
    }
    Card cardToCheck = mor.getCard(game);
    if (cardToCheck.isLand(game)) {
        return true;
    }
    // allows to play/cast with alternative life cost
    Player controller = game.getPlayer(source.getControllerId());
    PayLifeCost lifeCost = new PayLifeCost(cardToCheck.getSpellAbility().getManaCosts().manaValue());
    Costs<Cost> newCosts = new CostsImpl<>();
    newCosts.add(lifeCost);
    newCosts.addAll(cardToCheck.getSpellAbility().getCosts());
    controller.setCastSourceIdWithAlternateMana(cardToCheck.getId(), null, newCosts);
    return true;
}
Also used : Player(mage.players.Player) CostsImpl(mage.abilities.costs.CostsImpl) PayLifeCost(mage.abilities.costs.common.PayLifeCost) PayLifeCost(mage.abilities.costs.common.PayLifeCost) Cost(mage.abilities.costs.Cost)

Example 35 with Cost

use of mage.abilities.costs.Cost in project mage by magefree.

the class SpellSyphonEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (sourceObject != null && spell != null) {
        Player player = game.getPlayer(spell.getControllerId());
        Player controller = game.getPlayer(source.getControllerId());
        if (player != null && controller != null) {
            int amount = controller.getHand().size();
            if (amount > 0) {
                Cost cost = ManaUtil.createManaCost(amount, false);
                if (!cost.pay(source, game, source, spell.getControllerId(), false)) {
                    game.informPlayers(sourceObject.getLogName() + ": cost wasn't payed - countering target spell.");
                    return game.getStack().counter(source.getFirstTarget(), source, game);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) StackObject(mage.game.stack.StackObject) MageObject(mage.MageObject) Cost(mage.abilities.costs.Cost)

Aggregations

Cost (mage.abilities.costs.Cost)174 Player (mage.players.Player)142 Permanent (mage.game.permanent.Permanent)86 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)41 Card (mage.cards.Card)32 UUID (java.util.UUID)30 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)29 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)26 TapSourceCost (mage.abilities.costs.common.TapSourceCost)23 FilterCard (mage.filter.FilterCard)22 MageObject (mage.MageObject)19 PayLifeCost (mage.abilities.costs.common.PayLifeCost)17 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)16 FixedTarget (mage.target.targetpointer.FixedTarget)16 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)14 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)14 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)13 ContinuousEffect (mage.abilities.effects.ContinuousEffect)12 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)11 OneShotEffect (mage.abilities.effects.OneShotEffect)9