use of mage.abilities.costs.Cost in project mage by magefree.
the class ConfiscationCoupEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
new GetEnergyCountersControllerEffect(4).apply(game, source);
Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (targetPermanent != null) {
Cost cost = new PayEnergyCost(targetPermanent.getManaCost().manaValue());
if (cost.canPay(source, source, source.getControllerId(), game)) {
int manaValue = targetPermanent.getManaCost().manaValue();
StringBuilder energy = new StringBuilder(manaValue);
for (int i = 0; i < manaValue; i++) {
energy.append("{E}");
}
if (controller.chooseUse(outcome, "Pay " + energy + " to get control of " + targetPermanent.getLogName() + '?', source, game)) {
if (cost.pay(source, game, source, source.getControllerId(), true)) {
ContinuousEffect controllEffect = new GainControlTargetEffect(Duration.Custom);
controllEffect.setTargetPointer(new FixedTarget(targetPermanent, game));
game.addEffect(controllEffect, source);
}
}
}
}
return true;
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class DivertEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(source.getFirstTarget());
Cost cost = ManaUtil.createManaCost(2, false);
if (spell != null) {
Player player = game.getPlayer(spell.getControllerId());
if (player != null) {
if (!cost.pay(source, game, source, spell.getControllerId(), false, null)) {
return spell.chooseNewTargets(game, source.getControllerId(), true, true, null);
}
}
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class DisruptionAuraEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (player != null && permanent != null) {
String message = CardUtil.replaceSourceName("Pay {this} mana cost ?", permanent.getLogName());
Cost cost = permanent.getManaCost().copy();
if (player.chooseUse(Outcome.Benefit, message, source, game)) {
cost.clearPaid();
if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
return true;
}
}
permanent.sacrifice(source, game);
return true;
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class DreamTidesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (player != null && sourcePermanent != null) {
int countBattlefield = game.getBattlefield().getAllActivePermanents(filter, game.getActivePlayerId(), game).size();
while (player.canRespond() && countBattlefield > 0 && player.chooseUse(Outcome.AIDontUseIt, "Pay {2} and untap a tapped nongreen creature under your control?", source, game)) {
Target tappedCreatureTarget = new TargetControlledCreaturePermanent(1, 1, filter, true);
if (player.choose(Outcome.Detriment, tappedCreatureTarget, source.getSourceId(), game)) {
Cost cost = ManaUtil.createManaCost(2, false);
Permanent tappedCreature = game.getPermanent(tappedCreatureTarget.getFirstTarget());
if (cost.pay(source, game, source, player.getId(), false)) {
tappedCreature.untap(game);
}
}
countBattlefield = game.getBattlefield().getAllActivePermanents(filter, game.getActivePlayerId(), game).size();
}
return true;
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class IceCaveEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
Spell spell = (Spell) game.getStack().getStackObject(targetPointer.getFirst(game, source));
if (sourcePermanent != null && spell != null && controller != null) {
Player spellController = game.getPlayer(spell.getControllerId());
Cost cost = new ManaCostsImpl(spell.getSpellAbility().getManaCosts().getText());
if (spellController != null) {
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null && !player.equals(spellController)) {
cost.clearPaid();
if (cost.canPay(source, source, player.getId(), game) && player.chooseUse(outcome, "Pay " + cost.getText() + " to counter " + spell.getIdName() + '?', source, game)) {
if (cost.pay(source, game, source, playerId, false, null)) {
game.informPlayers(player.getLogName() + " pays" + cost.getText() + " to counter " + spell.getIdName() + '.');
game.getStack().counter(spell.getId(), source, game);
break;
}
}
}
}
}
}
return true;
}
Aggregations