use of mage.abilities.costs.mana.ManaCosts in project mage by magefree.
the class TilonallisSummonerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
ManaCosts cost = new ManaCostsImpl("{X}{R}");
if (controller.chooseUse(outcome, "Pay " + cost.getText() + "? If you do, you create X 1/1 red Elemental creature tokens that are tapped and attacking.", source, game)) {
int costX = controller.announceXMana(0, Integer.MAX_VALUE, "Announce the value for {X}", game, source);
cost.add(new GenericManaCost(costX));
if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
// otherwise you can undo the payment
controller.resetStoredBookmark(game);
CreateTokenEffect effect = new CreateTokenEffect(new TilonallisSummonerElementalToken(), costX, true, true);
effect.apply(game, source);
Effect exileEffect = new ExileTargetEffect(null, "", Zone.BATTLEFIELD).setText("exile those tokens unless you have the city's blessing");
exileEffect.setTargetPointer(new FixedTargets(new CardsImpl(effect.getLastAddedTokenIds()), game));
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect, TargetController.ANY, new InvertCondition(CitysBlessingCondition.instance)), source);
}
}
return true;
}
return false;
}
use of mage.abilities.costs.mana.ManaCosts in project mage by magefree.
the class WelcomeToTheFoldEffect method init.
@Override
public void init(Ability source, Game game) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int maxToughness = 2;
ManaCosts manaCosts = source.getManaCostsToPay();
if (!manaCosts.getVariableCosts().isEmpty()) {
maxToughness = source.getManaCostsToPay().getX();
}
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (permanent != null && permanent.getToughness().getValue() > maxToughness) {
this.discard();
return;
}
}
super.init(source, game);
}
use of mage.abilities.costs.mana.ManaCosts in project mage by magefree.
the class PayCostToAttackBlockEffectImpl method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
ManaCosts attackBlockManaTax = getManaCostToPay(event, source, game);
if (attackBlockManaTax != null) {
return handleManaCosts(attackBlockManaTax.copy(), event, source, game);
}
Cost attackBlockOtherTax = getOtherCostToPay(event, source, game);
if (attackBlockOtherTax != null) {
return handleOtherCosts(attackBlockOtherTax.copy(), event, source, game);
}
return false;
}
use of mage.abilities.costs.mana.ManaCosts in project mage by magefree.
the class PlayerImpl method cast.
/**
* @param originalAbility
* @param game
* @param noMana cast it without paying mana costs
* @param approvingObject which object approved the cast
* @return
*/
@Override
public boolean cast(SpellAbility originalAbility, Game game, boolean noMana, ApprovingObject approvingObject) {
if (game == null || originalAbility == null) {
return false;
}
// Use ability copy to avoid problems with targets and costs on recast (issue https://github.com/magefree/mage/issues/5189).
SpellAbility ability = originalAbility.copy();
ability.setControllerId(getId());
ability.setSourceObjectZoneChangeCounter(game.getState().getZoneChangeCounter(ability.getSourceId()));
// 20091005 - 601.2a
if (ability.getSourceId() == null) {
logger.error("Ability without sourceId turn " + game.getTurnNum() + ". Ability: " + ability.getRule());
return false;
}
Card card = game.getCard(ability.getSourceId());
if (card != null) {
Zone fromZone = game.getState().getZone(card.getMainCard().getId());
GameEvent castEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, ability.getId(), ability, playerId, approvingObject);
castEvent.setZone(fromZone);
if (!game.replaceEvent(castEvent, ability)) {
int bookmark = game.bookmarkState();
// move global bookmark to current state (if you activated mana before then you can't rollback it)
setStoredBookmark(bookmark);
card.cast(game, fromZone, ability, playerId);
Spell spell = game.getStack().getSpell(ability.getId());
if (spell == null) {
logger.error("Got no spell from stack. ability: " + ability.getRule());
return false;
}
if (card.isCopy()) {
spell.setCopy(true, null);
}
// Update the zcc to the stack
ability.setSourceObjectZoneChangeCounter(game.getState().getZoneChangeCounter(ability.getSourceId()));
// some effects set sourceId to cast without paying mana costs or other costs
if (getCastSourceIdWithAlternateMana().contains(ability.getSourceId())) {
Ability spellAbility = spell.getSpellAbility();
ManaCosts alternateCosts = getCastSourceIdManaCosts().get(ability.getSourceId());
Costs<Cost> costs = getCastSourceIdCosts().get(ability.getSourceId());
if (alternateCosts == null) {
noMana = true;
} else {
spellAbility.getManaCosts().clear();
spellAbility.getManaCostsToPay().clear();
spellAbility.getManaCosts().add(alternateCosts.copy());
spellAbility.getManaCostsToPay().add(alternateCosts.copy());
}
spellAbility.getCosts().clear();
if (costs != null) {
spellAbility.getCosts().addAll(costs);
}
}
// TODO: test multiple alternative cost for different cards as same time
clearCastSourceIdManaCosts();
castEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, spell.getSpellAbility().getId(), spell.getSpellAbility(), playerId, approvingObject);
castEvent.setZone(fromZone);
game.fireEvent(castEvent);
if (spell.activate(game, noMana)) {
GameEvent castedEvent = GameEvent.getEvent(GameEvent.EventType.SPELL_CAST, spell.getSpellAbility().getId(), spell.getSpellAbility(), playerId, approvingObject);
castedEvent.setZone(fromZone);
game.fireEvent(castedEvent);
if (!game.isSimulation()) {
game.informPlayers(getLogName() + spell.getActivatedMessage(game));
}
game.removeBookmark(bookmark);
resetStoredBookmark(game);
return true;
}
restoreState(bookmark, ability.getRule(), game);
}
}
return false;
}
use of mage.abilities.costs.mana.ManaCosts in project mage by magefree.
the class PlayerImpl method canPlay.
/**
* @param ability
* @param availableMana if null, it won't be checked if enough mana is
* available
* @param sourceObject
* @param game
* @return
*/
protected boolean canPlay(ActivatedAbility ability, ManaOptions availableMana, MageObject sourceObject, Game game) {
if (!(ability instanceof ActivatedManaAbilityImpl)) {
// Copy is needed because cost reduction effects modify e.g. the mana to activate/cast the ability
ActivatedAbility copy = ability.copy();
if (!copy.canActivate(playerId, game).canActivate()) {
return false;
}
if (availableMana != null) {
sourceObject.adjustCosts(copy, game);
game.getContinuousEffects().costModification(copy, game);
}
boolean canBeCastRegularly = true;
if (copy instanceof SpellAbility && copy.getManaCosts().isEmpty() && copy.getCosts().isEmpty()) {
// 117.6. Some mana costs contain no mana symbols. This represents an unpayable cost...
// 117.6a (...) If an alternative cost is applied to an unpayable cost,
// including an effect that allows a player to cast a spell without paying its mana cost, the alternative cost may be paid.
canBeCastRegularly = false;
}
if (canBeCastRegularly) {
if (canPayMinimumManaCost(copy, availableMana, game)) {
return true;
}
}
// ALTERNATIVE COST FROM dynamic effects
if (getCastSourceIdWithAlternateMana().contains(copy.getSourceId())) {
ManaCosts alternateCosts = getCastSourceIdManaCosts().get(copy.getSourceId());
Costs<Cost> costs = getCastSourceIdCosts().get(copy.getSourceId());
boolean canPutToPlay = true;
if (alternateCosts != null && !alternateCosts.canPay(copy, copy, playerId, game)) {
canPutToPlay = false;
}
if (costs != null && !costs.canPay(copy, copy, playerId, game)) {
canPutToPlay = false;
}
if (canPutToPlay) {
return true;
}
}
// ALTERNATIVE COST from source card (any AlternativeSourceCosts)
if (AbilityType.SPELL.equals(ability.getAbilityType())) {
return canPlayCardByAlternateCost(game.getCard(ability.getSourceId()), availableMana, copy, game);
}
}
return false;
}
Aggregations