use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.
the class OgreMarauderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
UUID defendingPlayerId = game.getCombat().getDefendingPlayerId(source.getSourceId(), game);
MageObject sourceObject = game.getObject(source.getSourceId());
Player defender = game.getPlayer(defendingPlayerId);
if (defender != null && sourceObject != null) {
Cost cost = new SacrificeTargetCost(new TargetControlledCreaturePermanent(FILTER_CONTROLLED_CREATURE_SHORT_TEXT));
if (cost.canPay(source, source, defendingPlayerId, game) && defender.chooseUse(Outcome.LoseAbility, "Sacrifice a creature to prevent that " + sourceObject.getLogName() + " can't be blocked?", source, game)) {
if (!cost.pay(source, game, source, defendingPlayerId, false, null)) {
// cost was not payed - so source can't be blocked
ContinuousEffect effect = new CantBeBlockedSourceEffect(Duration.EndOfTurn);
game.addEffect(effect, source);
}
}
return true;
}
return false;
}
use of mage.abilities.costs.common.SacrificeTargetCost in project mage by magefree.
the class ScrapWelderCost method getFixedCostsFromAnnouncedValue.
@Override
public Cost getFixedCostsFromAnnouncedValue(int xValue) {
FilterControlledArtifactPermanent filter = new FilterControlledArtifactPermanent("an artifact with mana value " + xValue);
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, xValue));
return new SacrificeTargetCost(filter);
}
use of mage.abilities.costs.common.SacrificeTargetCost 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.common.SacrificeTargetCost 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.common.SacrificeTargetCost in project mage by magefree.
the class BushmeatPoacherEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
SacrificeTargetCost cost = source.getCosts().stream().filter(SacrificeTargetCost.class::isInstance).map(SacrificeTargetCost.class::cast).findFirst().orElse(null);
if (cost == null) {
return false;
}
Permanent permanent = cost.getPermanents().get(0);
if (permanent == null) {
return false;
}
int amount = permanent.getToughness().getValue();
if (amount > 0) {
player.gainLife(amount, game, source);
}
return player.drawCards(1, source, game) > 0;
}
Aggregations