use of mage.abilities.costs.Cost in project mage by magefree.
the class TapXTargetCost method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller == null || sourceObject == null) {
return false;
}
int xValue = source.getManaCostsToPay().getX();
for (Cost cost : source.getCosts()) {
if (cost instanceof TapXTargetCost) {
xValue = ((TapXTargetCost) cost).getAmount();
break;
}
}
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, xValue));
controller.lookAtCards(sourceObject.getIdName(), cards, game);
TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to put into your hand"));
target.setNotTarget(true);
if (controller.chooseTarget(Outcome.DrawCard, cards, target, source, game)) {
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.HAND, source, game);
cards.remove(card);
}
}
controller.putCardsOnBottomOfLibrary(cards, game, source, true);
return true;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class MomentousFallEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int power = 0;
int toughness = 0;
for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost && !((SacrificeTargetCost) cost).getPermanents().isEmpty()) {
power = ((SacrificeTargetCost) cost).getPermanents().get(0).getPower().getValue();
toughness = ((SacrificeTargetCost) cost).getPermanents().get(0).getToughness().getValue();
break;
}
}
if (power > 0) {
controller.drawCards(power, source, game);
}
if (toughness > 0) {
controller.gainLife(toughness, game, source);
}
return true;
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class MysticRemoraEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
MageObject sourceObject = source.getSourceObject(game);
if (controller != null && opponent != null && sourceObject != null) {
if (controller.chooseUse(Outcome.DrawCard, "Draw a card (" + sourceObject.getLogName() + ')', source, game)) {
Cost cost = ManaUtil.createManaCost(4, false);
if (opponent.chooseUse(Outcome.Benefit, "Pay {4}?", source, game) && cost.pay(source, game, source, opponent.getId(), false, null)) {
return true;
}
controller.drawCards(1, source, game);
}
return true;
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class OsgirTheReconstructorCreateArtifactTokensEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Card card = null;
for (Cost cost : source.getCosts()) {
if (!(cost instanceof ExileFromGraveCost)) {
continue;
}
card = ((ExileFromGraveCost) cost).getExiledCards().get(0);
}
if (player == null || card == null) {
return false;
}
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(player.getId(), null, false, 2);
effect.setTargetPointer(new FixedTarget(card.getId(), game.getState().getZoneChangeCounter(card.getId())));
effect.apply(game, source);
return true;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class ProwlingPangolinEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
boolean costPaid = false;
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Cost cost = new SacrificeTargetCost(new TargetControlledPermanent(2, 2, new FilterControlledCreaturePermanent("two creatures"), true));
Player player = game.getPlayer(playerId);
if (player != null && cost.canPay(source, source, playerId, game) && player.chooseUse(Outcome.Sacrifice, "Sacrifice two creatures?", source, game) && cost.pay(source, game, source, playerId, true, null)) {
costPaid = true;
}
}
if (costPaid) {
Permanent sourceObject = game.getPermanent(source.getSourceId());
if (sourceObject != null) {
sourceObject.sacrifice(source, game);
}
}
return true;
}
return false;
}
Aggregations