Search in sources :

Example 36 with Cost

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

the class OozeFluxCreateTokenEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int xValue = 0;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof RemoveVariableCountersTargetCost) {
            xValue = ((RemoveVariableCountersTargetCost) cost).getAmount();
            break;
        }
    }
    Token tokenCopy = token.copy();
    tokenCopy.getAbilities().newId();
    tokenCopy.getPower().modifyBaseValue(xValue);
    tokenCopy.getToughness().modifyBaseValue(xValue);
    tokenCopy.putOntoBattlefield(1, game, source, source.getControllerId());
    return true;
}
Also used : RemoveVariableCountersTargetCost(mage.abilities.costs.common.RemoveVariableCountersTargetCost) Token(mage.game.permanent.token.Token) OozeToken(mage.game.permanent.token.OozeToken) Cost(mage.abilities.costs.Cost) RemoveVariableCountersTargetCost(mage.abilities.costs.common.RemoveVariableCountersTargetCost)

Example 37 with Cost

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

the class OozeToken method apply.

@Override
public boolean apply(Game game, Ability source) {
    int value = 0;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost) {
            value = ((SacrificeTargetCost) cost).getPermanents().get(0).getPower().getValue();
        }
    }
    Token token = new OozeToken(value);
    // neccessary if token has ability like DevourAbility()
    token.getAbilities().newId();
    token.putOntoBattlefield(1, game, source, source.getControllerId());
    return true;
}
Also used : SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Token(mage.game.permanent.token.Token) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost)

Example 38 with Cost

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

the class RohgahhOfKherKeepEffect 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) {
        return false;
    }
    Cost cost = new ManaCostsImpl("{R}{R}{R}");
    if (!cost.canPay(source, source, player.getId(), game) || !player.chooseUse(Outcome.Benefit, "Pay {R}{R}{R}?", source, game) || !cost.pay(source, game, source, player.getId(), false)) {
        TargetOpponent target = new TargetOpponent();
        Player opponent = null;
        if (target.choose(Outcome.Detriment, player.getId(), source.getSourceId(), game)) {
            opponent = game.getPlayer(target.getFirstTarget());
        }
        new TapAllEffect(filter).apply(game, source);
        if (permanent != null) {
            permanent.tap(source, game);
        }
        if (opponent != null) {
            new GainControlAllEffect(Duration.Custom, filter, opponent.getId()).apply(game, source);
            if (permanent != null) {
                ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, opponent.getId());
                effect.setTargetPointer(new FixedTarget(permanent, game));
                game.addEffect(effect, source);
            }
        }
        return true;
    }
    return false;
}
Also used : TapAllEffect(mage.abilities.effects.common.TapAllEffect) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) GainControlAllEffect(mage.abilities.effects.common.continuous.GainControlAllEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Cost(mage.abilities.costs.Cost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 39 with Cost

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

the class VodalianWarMachineWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() == GameEvent.EventType.ACTIVATED_ABILITY) {
        if (event.getSourceId() != null) {
            Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
            if (sourcePermanent != null) {
                StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
                if (stackAbility != null) {
                    Ability ability = stackAbility.getStackAbility();
                    if (ability != null) {
                        for (Cost cost : ability.getCosts()) {
                            if (cost instanceof TapTargetCost && cost.isPaid()) {
                                TapTargetCost tapCost = (TapTargetCost) cost;
                                if (tapCost.getTarget().isChosen()) {
                                    MageObjectReference mor = new MageObjectReference(sourcePermanent.getId(), sourcePermanent.getZoneChangeCounter(game), game);
                                    Set<MageObjectReference> toAdd;
                                    if (tappedMerfolkIds.get(mor) == null) {
                                        toAdd = new HashSet<>();
                                    } else {
                                        toAdd = tappedMerfolkIds.get(mor);
                                    }
                                    for (UUID targetId : tapCost.getTarget().getTargets()) {
                                        toAdd.add(new MageObjectReference(targetId, game));
                                    }
                                    tappedMerfolkIds.put(mor, toAdd);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) DiesSourceTriggeredAbility(mage.abilities.common.DiesSourceTriggeredAbility) StackAbility(mage.game.stack.StackAbility) DefenderAbility(mage.abilities.keyword.DefenderAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TapTargetCost(mage.abilities.costs.common.TapTargetCost) TapTargetCost(mage.abilities.costs.common.TapTargetCost) Cost(mage.abilities.costs.Cost) StackAbility(mage.game.stack.StackAbility) MageObjectReference(mage.MageObjectReference)

Example 40 with Cost

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

the class WithdrawEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Effect effect = new ReturnToHandTargetEffect();
    effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game));
    effect.apply(game, source);
    Permanent secondCreature = game.getPermanent(source.getTargets().get(1).getFirstTarget());
    if (secondCreature != null) {
        Player creatureController = game.getPlayer(secondCreature.getControllerId());
        if (creatureController != null) {
            Cost cost = ManaUtil.createManaCost(1, false);
            if (creatureController.chooseUse(Outcome.Benefit, "Pay {1}? (Otherwise " + secondCreature.getName() + " will be returned to its owner's hand)", source, game)) {
                cost.pay(source, game, source, creatureController.getId(), false);
            }
            if (!cost.isPaid()) {
                creatureController.moveCards(secondCreature, Zone.HAND, source, game);
            }
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) 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