use of mage.abilities.costs.Cost in project mage by magefree.
the class PrimeSpeakerVannifarEffect 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 RhysticScryingEffect 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) {
boolean result = true;
boolean doEffect = false;
Cost cost = ManaUtil.createManaCost(2, false);
// check if any player is willing to pay
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null && player.canRespond() && cost.canPay(source, source, player.getId(), game) && player.chooseUse(Outcome.Benefit, "Pay " + cost.getText() + " for " + sourceObject.getLogName() + "?", source, game)) {
cost.clearPaid();
if (cost.pay(source, game, source, player.getId(), false, null)) {
if (!game.isSimulation()) {
game.informPlayers(player.getLogName() + " pays the cost for " + sourceObject.getLogName());
}
doEffect = true;
break;
}
}
}
// do the effects if anybody paid
if (doEffect) {
controller.discard(3, false, false, source, game);
}
return result;
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class RhysticStudyDrawEffect 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(1, false);
if (opponent.chooseUse(Outcome.Benefit, "Pay {1}?", 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 ScourgeOfNelTothPlayEffect method applies.
@Override
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
if (sourceId.equals(source.getSourceId()) && source.isControlledBy(affectedControllerId)) {
if (game.getState().getZone(source.getSourceId()) == Zone.GRAVEYARD) {
Player player = game.getPlayer(affectedControllerId);
if (player != null) {
// can sometimes be cast with base mana cost from grave????
Costs<Cost> costs = new CostsImpl<>();
costs.add(new SacrificeTargetCost(new TargetControlledCreaturePermanent(2)));
player.setCastSourceIdWithAlternateMana(sourceId, new ManaCostsImpl<>("{B}{B}"), costs);
return true;
}
}
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class ScourgeOfSkolaValeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost) {
int amount = ((SacrificeTargetCost) cost).getPermanents().get(0).getToughness().getValue();
Player player = game.getPlayer(source.getControllerId());
if (amount > 0 && player != null) {
return new AddCountersSourceEffect(CounterType.P1P1.createInstance(amount), true).apply(game, source);
}
}
}
return false;
}
Aggregations