use of mage.abilities.costs.Cost in project mage by magefree.
the class UnnaturalHungerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent aura = game.getPermanent(source.getSourceId());
if (aura != null) {
Permanent attachedTo = game.getPermanent(aura.getAttachedTo());
if (attachedTo != null) {
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
// not attached permanent
filter.add(Predicates.not(new PermanentIdPredicate(aura.getAttachedTo())));
Cost cost = new SacrificeTargetCost(new TargetControlledCreaturePermanent(filter));
Player enchantedCreatureController = game.getPlayer(attachedTo.getControllerId());
if (enchantedCreatureController != null && cost.canPay(source, source, enchantedCreatureController.getId(), game) && enchantedCreatureController.chooseUse(outcome, "Sacrifice another creature to prevent " + attachedTo.getPower().getValue() + " damage?", source, game) && cost.pay(source, game, source, enchantedCreatureController.getId(), true)) {
}
if (enchantedCreatureController != null && !cost.isPaid()) {
enchantedCreatureController.damage(attachedTo.getPower().getValue(), source.getSourceId(), source, game);
}
return true;
}
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class BirthingPodEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sacrificedPermanent = null;
for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost) {
SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
if (!sacrificeCost.getPermanents().isEmpty()) {
sacrificedPermanent = sacrificeCost.getPermanents().get(0);
}
break;
}
}
Player controller = game.getPlayer(source.getControllerId());
if (sacrificedPermanent == null || controller == null) {
return false;
}
int newConvertedCost = sacrificedPermanent.getManaValue() + 1;
FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost);
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, newConvertedCost));
filter.add(CardType.CREATURE.getPredicate());
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
controller.shuffleLibrary(source, game);
return true;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class ChainOfPlasmaEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
UUID targetId = source.getFirstTarget();
Player affectedPlayer = null;
Player player = game.getPlayer(targetId);
if (player != null) {
player.damage(3, source.getSourceId(), source, game);
affectedPlayer = player;
} else {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null) {
permanent.damage(3, source.getSourceId(), source, game, false, true);
affectedPlayer = game.getPlayer(permanent.getControllerId());
}
}
if (affectedPlayer != null) {
if (affectedPlayer.chooseUse(Outcome.Copy, "Discard a card to copy the spell?", source, game)) {
Cost cost = new DiscardCardCost();
if (cost.pay(source, game, source, affectedPlayer.getId(), false, null)) {
Spell spell = game.getStack().getSpell(source.getSourceId());
if (spell != null) {
spell.createCopyOnStack(game, source, affectedPlayer.getId(), true);
}
}
}
return true;
}
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class CorpseweftEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int amount = 0;
for (Cost cost : source.getCosts()) {
if (cost instanceof ExileFromGraveCost) {
amount = ((ExileFromGraveCost) cost).getExiledCards().size() * 2;
new CreateTokenEffect(new CorpseweftZombieToken(amount, amount), 1, true, false).apply(game, source);
}
}
if (amount > 0) {
}
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class EsperSentinelEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && opponent != null && permanent != null) {
Cost cost = ManaUtil.createManaCost(permanent.getPower().getValue(), false);
if (!opponent.chooseUse(Outcome.Benefit, "Pay " + cost.getText() + "?", source, game) || !cost.pay(source, game, source, opponent.getId(), false)) {
controller.drawCards(1, source, game);
}
return true;
}
return false;
}
Aggregations