use of mage.abilities.costs.Cost in project mage by magefree.
the class RescueFromTheUnderworldReturnEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
DelayedTriggeredAbility delayedAbility = ability.copy();
delayedAbility.getTargets().addAll(source.getTargets());
for (Effect effect : delayedAbility.getEffects()) {
effect.getTargetPointer().init(game, source);
}
// add the sacrificed creature as target
for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost) {
SacrificeTargetCost sacCost = (SacrificeTargetCost) cost;
TargetCardInGraveyard target = new TargetCardInGraveyard();
for (Permanent permanent : sacCost.getPermanents()) {
target.add(permanent.getId(), game);
delayedAbility.getTargets().add(target);
}
}
}
game.addDelayedTriggeredAbility(delayedAbility, source);
return true;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class TezzeretTheSeekerEffect3 method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
int cmc = 0;
for (Cost cost : source.getCosts()) {
if (cost instanceof PayVariableLoyaltyCost) {
cmc = ((PayVariableLoyaltyCost) cost).getAmount();
}
}
FilterArtifactCard filter = new FilterArtifactCard("artifact card with mana value " + cmc + " or less");
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, cmc + 1));
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
controller.shuffleLibrary(source, game);
return true;
}
controller.shuffleLibrary(source, game);
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class TetravusPredicate method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
if (player == null || permanent == null) {
return false;
}
int countersToRemove = permanent.getCounters(game).getCount(CounterType.P1P1);
if (countersToRemove == 0) {
return false;
}
countersToRemove = player.getAmount(0, countersToRemove, "Choose an amount of counters to remove", game);
Cost cost = new RemoveCountersSourceCost(CounterType.P1P1.createInstance(countersToRemove));
if (cost.pay(source, game, source, source.getControllerId(), true)) {
CreateTokenEffect effect = new CreateTokenEffect(new TetraviteToken(), countersToRemove);
effect.apply(game, source);
Object object = game.getState().getValue(CardUtil.getObjectZoneString("_tokensCreated", permanent, game));
Set<UUID> tokensCreated;
if (object != null) {
tokensCreated = (Set<UUID>) object;
} else {
tokensCreated = new HashSet<>();
}
for (UUID tokenId : effect.getLastAddedTokenIds()) {
if (tokenId != null) {
tokensCreated.add(tokenId);
}
}
game.getState().setValue(CardUtil.getCardZoneString("_tokensCreated", source.getSourceId(), game), tokensCreated);
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class TransmuteArtifactEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
// Sacrifice an artifact.
int manaValue = 0;
boolean sacrifice = false;
TargetControlledPermanent targetArtifact = new TargetControlledPermanent(new FilterControlledArtifactPermanent());
if (controller.chooseTarget(Outcome.Sacrifice, targetArtifact, source, game)) {
Permanent permanent = game.getPermanent(targetArtifact.getFirstTarget());
if (permanent != null) {
manaValue = permanent.getManaValue();
sacrifice = permanent.sacrifice(source, game);
}
} else {
return true;
}
// If you do, search your library for an artifact card.
if (sacrifice && controller.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
for (UUID cardId : target.getTargets()) {
Card card = controller.getLibrary().getCard(cardId, game);
if (card != null) {
// If that card's converted mana cost is less than or equal to the sacrificed artifact's converted mana cost, put it onto the battlefield.
if (card.getManaValue() <= manaValue) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
} else {
// If it's greater, you may pay {X}, where X is the difference. If you do, put it onto the battlefield.
Cost cost = ManaUtil.createManaCost(card.getManaValue() - manaValue, true);
boolean payed = false;
if (controller.chooseUse(Outcome.Benefit, "Do you want to pay " + cost.getText() + " to put it onto the battlefield?", source, game) && cost.pay(source, game, source, source.getControllerId(), false)) {
payed = true;
}
if (payed) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
} else {
// If you don't, put it into its owner's graveyard. Then shuffle your library
controller.moveCards(card, Zone.GRAVEYARD, source, game);
}
}
}
}
}
controller.shuffleLibrary(source, game);
return true;
}
controller.shuffleLibrary(source, game);
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class UrzasTomeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
new DrawCardSourceControllerEffect(1).apply(game, source);
if (controller != null && controller.chooseUse(Outcome.Exile, "Exile a historic card from your graveyard?", source, game)) {
Cost cost = new ExileFromGraveCost(new TargetCardInYourGraveyard(new FilterHistoricCard()));
if (cost.canPay(source, source, controller.getId(), game)) {
if (cost.pay(source, game, source, controller.getId(), false, null)) {
return true;
}
}
}
if (controller != null) {
controller.discard(1, false, false, source, game);
return true;
}
return false;
}
Aggregations