use of mage.abilities.costs.mana.ManaCost in project mage by magefree.
the class PermanentToken method copyFromToken.
private void copyFromToken(Token token, Game game, boolean reset) {
// modify all attributes permanently (without game usage)
this.name = token.getName();
this.abilities.clear();
if (reset) {
this.abilities.addAll(token.getAbilities());
} else {
// so sourceId must be null (keep triggered abilities forever?)
for (Ability ability : token.getAbilities()) {
this.addAbility(ability, null, game);
}
}
this.abilities.setControllerId(this.controllerId);
this.manaCost.clear();
for (ManaCost cost : token.getManaCost()) {
this.getManaCost().add(cost.copy());
}
this.cardType.clear();
this.cardType.addAll(token.getCardType(game));
this.color = token.getColor(game).copy();
this.frameColor = token.getFrameColor(game);
this.frameStyle = token.getFrameStyle();
this.supertype.clear();
this.supertype.addAll(token.getSuperType());
this.subtype.copyFrom(token.getSubtype(game));
this.tokenDescriptor = token.getTokenDescriptor();
this.startingLoyalty = token.getStartingLoyalty();
}
use of mage.abilities.costs.mana.ManaCost in project mage by magefree.
the class FlashEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null || !controller.chooseUse(Outcome.PutCreatureInPlay, choiceText, source, game)) {
return false;
}
TargetCardInHand target = new TargetCardInHand(StaticFilters.FILTER_CARD_CREATURE);
if (controller.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
ManaCosts<ManaCost> reducedCost = ManaCosts.removeVariableManaCost(CardUtil.reduceCost(card.getManaCost(), 2));
if (controller.chooseUse(Outcome.Benefit, String.valueOf("Pay " + reducedCost.getText()) + Character.toString('?'), source, game)) {
reducedCost.clearPaid();
if (reducedCost.pay(source, game, source, source.getControllerId(), false, null)) {
return true;
}
}
Permanent permanent = game.getPermanent(card.getId());
if (permanent != null) {
permanent.sacrifice(source, game);
}
return true;
}
}
return false;
}
use of mage.abilities.costs.mana.ManaCost in project mage by magefree.
the class AlternativeCostSourceAbility method askToActivateAlternativeCosts.
@Override
public boolean askToActivateAlternativeCosts(Ability ability, Game game) {
if (ability != null && AbilityType.SPELL == ability.getAbilityType()) {
if (filter != null) {
Card card = game.getCard(ability.getSourceId());
if (!filter.match(card, ability.getSourceId(), ability.getControllerId(), game)) {
return false;
}
}
Player player = game.getPlayer(ability.getControllerId());
if (player != null) {
Costs<AlternativeCost2> alternativeCostsToCheck;
if (dynamicCost != null) {
alternativeCostsToCheck = new CostsImpl<>();
alternativeCostsToCheck.add(convertToAlternativeCost(dynamicCost.getCost(ability, game)));
} else {
alternativeCostsToCheck = this.alternateCosts;
}
String costChoiceText;
if (dynamicCost != null) {
costChoiceText = dynamicCost.getText(ability, game);
} else {
costChoiceText = alternativeCostsToCheck.isEmpty() ? "Cast without paying its mana cost?" : "Pay alternative costs? (" + alternativeCostsToCheck.getText() + ')';
}
if (alternativeCostsToCheck.canPay(ability, ability, ability.getControllerId(), game) && player.chooseUse(Outcome.Benefit, costChoiceText, this, game)) {
if (ability instanceof SpellAbility) {
ability.getManaCostsToPay().removeIf(manaCost -> manaCost instanceof VariableCost);
CardUtil.reduceCost((SpellAbility) ability, ability.getManaCosts());
} else {
ability.getManaCostsToPay().clear();
}
if (!onlyMana) {
ability.getCosts().clear();
}
for (AlternativeCost2 alternateCost : alternativeCostsToCheck) {
alternateCost.activate();
for (Iterator it = ((Costs) alternateCost).iterator(); it.hasNext(); ) {
Cost costDetailed = (Cost) it.next();
if (costDetailed instanceof ManaCost) {
ability.getManaCostsToPay().add((ManaCost) costDetailed.copy());
} else if (costDetailed != null) {
ability.getCosts().add(costDetailed.copy());
}
}
}
// save activated status
game.getState().setValue(getActivatedKey(ability), Boolean.TRUE);
} else {
return false;
}
} else {
return false;
}
}
return isActivated(ability, game);
}
use of mage.abilities.costs.mana.ManaCost in project mage by magefree.
the class SacrificeSourceUnlessPaysEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (player != null && sourcePermanent != null) {
Cost costToPay;
String costValueMessage;
if (cost != null) {
costToPay = cost.copy();
costValueMessage = costToPay.getText();
} else {
costToPay = ManaUtil.createManaCost(genericMana, game, source, this);
costValueMessage = "{" + genericMana.calculate(game, source, this) + "}";
}
String message = "";
if (costToPay instanceof ManaCost) {
message += "Pay ";
}
message += costValueMessage + '?';
costToPay.clearPaid();
if (costToPay.canPay(source, source, source.getControllerId(), game) && player.chooseUse(Outcome.Benefit, message, source, game) && costToPay.pay(source, game, source, source.getControllerId(), false, null)) {
game.informPlayers(player.getLogName() + " chooses to pay " + costValueMessage + " to prevent sacrifice effect");
return true;
}
game.informPlayers(player.getLogName() + " chooses not to pay " + costValueMessage + " to prevent sacrifice effect");
if (source.getSourceObjectZoneChangeCounter() == game.getState().getZoneChangeCounter(source.getSourceId()) && game.getState().getZone(source.getSourceId()) == Zone.BATTLEFIELD) {
sourcePermanent.sacrifice(source, game);
}
return true;
}
return false;
}
use of mage.abilities.costs.mana.ManaCost in project mage by magefree.
the class SacrificeOpponentsUnlessPayEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<UUID> permsToSacrifice = new ArrayList<>();
filter.add(TargetController.YOU.getControllerPredicate());
for (UUID playerId : game.getOpponents(source.getControllerId())) {
Player player = game.getPlayer(playerId);
if (player != null) {
Cost costToPay;
String costValueMessage;
if (cost != null) {
costToPay = cost.copy();
costValueMessage = costToPay.getText();
} else {
costToPay = ManaUtil.createManaCost(genericMana, game, source, this);
costValueMessage = "{" + genericMana.calculate(game, source, this) + "}";
}
String message = "";
if (costToPay instanceof ManaCost) {
message += "Pay ";
}
message += costValueMessage + '?';
costToPay.clearPaid();
if (!(player.chooseUse(Outcome.Benefit, message, source, game) && costToPay.pay(source, game, source, player.getId(), false, null))) {
game.informPlayers(player.getLogName() + " chooses not to pay " + costValueMessage + " to prevent the sacrifice effect");
int numTargets = Math.min(amount.calculate(game, source, this), game.getBattlefield().countAll(filter, player.getId(), game));
if (numTargets > 0) {
TargetPermanent target = new TargetPermanent(numTargets, numTargets, filter, true);
if (target.canChoose(source.getSourceId(), player.getId(), game)) {
player.chooseTarget(Outcome.Sacrifice, target, source, game);
permsToSacrifice.addAll(target.getTargets());
}
}
} else {
game.informPlayers(player.getLogName() + " chooses to pay " + costValueMessage + " to prevent the sacrifice effect");
}
}
}
for (UUID permID : permsToSacrifice) {
Permanent permanent = game.getPermanent(permID);
if (permanent != null) {
permanent.sacrifice(source, game);
}
}
return true;
}
Aggregations