mirror of
https://github.com/correl/mage.git
synced 2025-01-11 19:13:02 +00:00
* Norn's Annex - Fixed a bug with the payment of phyrexian mana (fixes #3178).
This commit is contained in:
parent
09e4435a89
commit
884a3af503
4 changed files with 34 additions and 46 deletions
|
@ -27,12 +27,17 @@
|
|||
*/
|
||||
package mage.abilities.costs.mana;
|
||||
|
||||
import java.util.*;
|
||||
import mage.Mana;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.abilities.costs.Costs;
|
||||
import mage.abilities.costs.CostsImpl;
|
||||
import mage.abilities.costs.VariableCost;
|
||||
import mage.abilities.costs.common.PayLifeCost;
|
||||
import mage.abilities.mana.ManaOptions;
|
||||
import mage.constants.ColoredManaSymbol;
|
||||
import mage.constants.Outcome;
|
||||
import mage.filter.Filter;
|
||||
import mage.game.Game;
|
||||
import mage.players.ManaPool;
|
||||
|
@ -40,8 +45,6 @@ import mage.players.Player;
|
|||
import mage.target.Targets;
|
||||
import mage.util.ManaUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
* @param <T>
|
||||
|
@ -158,6 +161,7 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
|
|||
@Override
|
||||
public boolean payOrRollback(Ability ability, Game game, UUID sourceId, UUID payingPlayerId) {
|
||||
int bookmark = game.bookmarkState();
|
||||
handlePhyrexianManaCosts(payingPlayerId, ability, game);
|
||||
if (pay(ability, game, sourceId, payingPlayerId, false, null)) {
|
||||
game.removeBookmark(bookmark);
|
||||
return true;
|
||||
|
@ -166,6 +170,30 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
|
|||
return false;
|
||||
}
|
||||
|
||||
private void handlePhyrexianManaCosts(UUID payingPlayerId, Ability source, Game game) {
|
||||
Player player = game.getPlayer(payingPlayerId);
|
||||
if (this == null || player == null) {
|
||||
return; // nothing to be done without any mana costs. prevents NRE from occurring here
|
||||
}
|
||||
Iterator<T> manaCostIterator = this.iterator();
|
||||
Costs<PayLifeCost> tempCosts = new CostsImpl<>();
|
||||
|
||||
while (manaCostIterator.hasNext()) {
|
||||
ManaCost manaCost = manaCostIterator.next();
|
||||
if (manaCost instanceof PhyrexianManaCost) {
|
||||
PhyrexianManaCost phyrexianManaCost = (PhyrexianManaCost) manaCost;
|
||||
PayLifeCost payLifeCost = new PayLifeCost(2);
|
||||
if (payLifeCost.canPay(source, source.getSourceId(), player.getId(), game)
|
||||
&& player.chooseUse(Outcome.LoseLife, "Pay 2 life instead of " + phyrexianManaCost.getBaseText() + '?', source, game)) {
|
||||
manaCostIterator.remove();
|
||||
tempCosts.add(payLifeCost);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tempCosts.pay(source, game, source.getSourceId(), player.getId(), false, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ManaCosts<T> getUnpaid() {
|
||||
ManaCosts<T> unpaid = new ManaCostsImpl<>();
|
||||
|
|
|
@ -27,13 +27,8 @@
|
|||
*/
|
||||
package mage.abilities.costs.mana;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.Mana;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.constants.ColoredManaSymbol;
|
||||
import mage.game.Game;
|
||||
import mage.players.ManaPool;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -64,7 +59,6 @@ public class PhyrexianManaCost extends ColoredManaCost {
|
|||
return new ColoredManaCost(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PhyrexianManaCost copy() {
|
||||
return new PhyrexianManaCost(this);
|
||||
|
|
|
@ -27,16 +27,10 @@
|
|||
*/
|
||||
package mage.abilities.effects;
|
||||
|
||||
import java.util.Iterator;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.abilities.costs.Costs;
|
||||
import mage.abilities.costs.CostsImpl;
|
||||
import mage.abilities.costs.common.PayLifeCost;
|
||||
import mage.abilities.costs.mana.ManaCost;
|
||||
import mage.abilities.costs.mana.ManaCosts;
|
||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
import mage.abilities.costs.mana.PhyrexianManaCost;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
|
@ -93,7 +87,7 @@ public abstract class PayCostToAttackBlockEffectImpl extends ReplacementEffectIm
|
|||
this.manaCosts = manaCosts;
|
||||
}
|
||||
|
||||
public PayCostToAttackBlockEffectImpl(PayCostToAttackBlockEffectImpl effect) {
|
||||
public PayCostToAttackBlockEffectImpl(final PayCostToAttackBlockEffectImpl effect) {
|
||||
super(effect);
|
||||
if (effect.cost != null) {
|
||||
this.cost = effect.cost.copy();
|
||||
|
@ -125,11 +119,11 @@ public abstract class PayCostToAttackBlockEffectImpl extends ReplacementEffectIm
|
|||
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
|
||||
ManaCosts attackBlockManaTax = getManaCostToPay(event, source, game);
|
||||
if (attackBlockManaTax != null) {
|
||||
return handleManaCosts(attackBlockManaTax, event, source, game);
|
||||
return handleManaCosts(attackBlockManaTax.copy(), event, source, game);
|
||||
}
|
||||
Cost attackBlockOtherTax = getOtherCostToPay(event, source, game);
|
||||
if (attackBlockOtherTax != null) {
|
||||
return handleOtherCosts(attackBlockOtherTax, event, source, game);
|
||||
return handleOtherCosts(attackBlockOtherTax.copy(), event, source, game);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -146,9 +140,6 @@ public abstract class PayCostToAttackBlockEffectImpl extends ReplacementEffectIm
|
|||
attackBlockManaTax.clearPaid();
|
||||
if (attackBlockManaTax.canPay(source, source.getSourceId(), player.getId(), game)
|
||||
&& player.chooseUse(Outcome.Neutral, chooseText, source, game)) {
|
||||
|
||||
handlePhyrexianManaCosts(getManaCostToPay(event, source, game), player, source, game);
|
||||
|
||||
if (attackBlockManaTax instanceof ManaCostsImpl) {
|
||||
if (attackBlockManaTax.payOrRollback(source, game, source.getSourceId(), event.getPlayerId())) {
|
||||
return false;
|
||||
|
@ -160,30 +151,6 @@ public abstract class PayCostToAttackBlockEffectImpl extends ReplacementEffectIm
|
|||
return false;
|
||||
}
|
||||
|
||||
private void handlePhyrexianManaCosts(ManaCosts<ManaCost> manaCosts, Player player, Ability source, Game game) {
|
||||
|
||||
if (manaCosts == null) return; // nothing to be done without any mana costs. prevents NRE from occurring here
|
||||
|
||||
Iterator<ManaCost> manaCostIterator = manaCosts.iterator();
|
||||
Costs<PayLifeCost> costs = new CostsImpl<>();
|
||||
|
||||
while(manaCostIterator.hasNext()) {
|
||||
ManaCost manaCost = manaCostIterator.next();
|
||||
if(manaCost instanceof PhyrexianManaCost) {
|
||||
PhyrexianManaCost phyrexianManaCost = (PhyrexianManaCost)manaCost;
|
||||
PayLifeCost payLifeCost = new PayLifeCost(2);
|
||||
if(payLifeCost.canPay(source, source.getSourceId(), player.getId(), game) &&
|
||||
player.chooseUse(Outcome.LoseLife, "Pay 2 life instead of " + phyrexianManaCost.getBaseText() + '?', source, game)) {
|
||||
manaCostIterator.remove();
|
||||
costs.add(payLifeCost);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
costs.pay(source, game, source.getSourceId(), player.getId(), false, null);
|
||||
}
|
||||
|
||||
|
||||
private boolean handleOtherCosts(Cost attackBlockOtherTax, GameEvent event, Ability source, Game game) {
|
||||
Player player = game.getPlayer(event.getPlayerId());
|
||||
if (player != null) {
|
||||
|
|
|
@ -30,7 +30,6 @@ package mage.abilities.effects.common.combat;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.mana.ManaCosts;
|
||||
import mage.abilities.effects.PayCostToAttackBlockEffectImpl;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
|
@ -67,7 +66,7 @@ public class CantAttackYouUnlessPayManaAllEffect extends PayCostToAttackBlockEff
|
|||
+ " for each creature he or she controls that's attacking you";
|
||||
}
|
||||
|
||||
public CantAttackYouUnlessPayManaAllEffect(CantAttackYouUnlessPayManaAllEffect effect) {
|
||||
public CantAttackYouUnlessPayManaAllEffect(final CantAttackYouUnlessPayManaAllEffect effect) {
|
||||
super(effect);
|
||||
this.payAlsoForAttackingPlaneswalker = effect.payAlsoForAttackingPlaneswalker;
|
||||
this.filterCreaturePermanent = effect.filterCreaturePermanent;
|
||||
|
|
Loading…
Reference in a new issue