mirror of
https://github.com/correl/mage.git
synced 2025-01-12 19:25:44 +00:00
Fixed a bug that x spells that need black mana to pay for x (e.g. Consume Spirit) could be paid with all kind of mana.
This commit is contained in:
parent
726a0b8a94
commit
5c479eb919
12 changed files with 184 additions and 22 deletions
|
@ -129,10 +129,23 @@ class BurnAtTheStakeCost extends CostImpl<BurnAtTheStakeCost> implements Variabl
|
|||
return this.amountPaid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not Supported
|
||||
* @param filter
|
||||
*/
|
||||
@Override
|
||||
public void setFilter(FilterMana filter) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Not supported
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FilterMana getFilter() {
|
||||
return new FilterMana();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAmount(int amount) {
|
||||
this.amountPaid = amount;
|
||||
|
|
|
@ -120,10 +120,23 @@ class HarvestPyreCost extends CostImpl<HarvestPyreCost> implements VariableCost
|
|||
return amountPaid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not Supported
|
||||
* @param filter
|
||||
*/
|
||||
@Override
|
||||
public void setFilter(FilterMana filter) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Not supported
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FilterMana getFilter() {
|
||||
return new FilterMana();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HarvestPyreCost copy() {
|
||||
return new HarvestPyreCost(this);
|
||||
|
|
|
@ -121,10 +121,23 @@ class ExileXFromGraveyardCost extends CostImpl<ExileXFromGraveyardCost> implemen
|
|||
return amountPaid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not Supported
|
||||
* @param filter
|
||||
*/
|
||||
@Override
|
||||
public void setFilter(FilterMana filter) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Not supported
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FilterMana getFilter() {
|
||||
return new FilterMana();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExileXFromGraveyardCost copy() {
|
||||
return new ExileXFromGraveyardCost(this);
|
||||
|
|
|
@ -117,10 +117,23 @@ class DevastatingSummonsCost extends CostImpl<DevastatingSummonsCost> implements
|
|||
return amountPaid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not Supported
|
||||
* @param filter
|
||||
*/
|
||||
@Override
|
||||
public void setFilter(FilterMana filter) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Not supported
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FilterMana getFilter() {
|
||||
return new FilterMana();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DevastatingSummonsCost copy() {
|
||||
return new DevastatingSummonsCost(this);
|
||||
|
|
|
@ -166,10 +166,23 @@ class FirestormCost extends CostImpl<FirestormCost> implements VariableCost {
|
|||
return amountPaid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not Supported
|
||||
* @param filter
|
||||
*/
|
||||
@Override
|
||||
public void setFilter(FilterMana filter) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Not supported
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FilterMana getFilter() {
|
||||
return new FilterMana();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FirestormCost copy() {
|
||||
return new FirestormCost(this);
|
||||
|
|
|
@ -196,28 +196,7 @@ public abstract class AbilityImpl<T extends AbilityImpl<T>> implements Ability {
|
|||
// 20121001 - 601.2b
|
||||
// If the spell has a variable cost that will be paid as it's being cast (such as an {X} in
|
||||
// its mana cost; see rule 107.3), the player announces the value of that variable.
|
||||
// TODO: Handle announcing other variable costs here like: RemoveVariableCountersSourceCost
|
||||
VariableManaCost variableManaCost = null;
|
||||
for (ManaCost cost: manaCostsToPay) {
|
||||
if (cost instanceof VariableManaCost) {
|
||||
variableManaCost = (VariableManaCost) cost;
|
||||
break; // only one VariableManCost per spell (or is it possible to have more?)
|
||||
}
|
||||
}
|
||||
if (variableManaCost != null) {
|
||||
int xValue;
|
||||
if (!variableManaCost.isPaid()) { // should only happen for human players
|
||||
if (!noMana) {
|
||||
xValue = game.getPlayer(this.controllerId).announceXMana(variableManaCost.getMinX(), Integer.MAX_VALUE, "Announce the value for " + variableManaCost.getText(), game, this);
|
||||
int amountMana = xValue * variableManaCost.getMultiplier();
|
||||
manaCostsToPay.add(new ManaCostsImpl(new StringBuilder("{").append(amountMana).append("}").toString()));
|
||||
manaCostsToPay.setX(amountMana);
|
||||
}
|
||||
variableManaCost.setPaid();
|
||||
}
|
||||
xValue = getManaCostsToPay().getX();
|
||||
game.informPlayers(new StringBuilder(game.getPlayer(this.controllerId).getName()).append(" announced a value of ").append(xValue).append(" for ").append(variableManaCost.getText()).toString());
|
||||
}
|
||||
VariableManaCost variableManaCost = handleXCosts(game, noMana);
|
||||
|
||||
//20121001 - 601.2c
|
||||
// 601.2c The player announces his or her choice of an appropriate player, object, or zone for
|
||||
|
@ -298,6 +277,66 @@ public abstract class AbilityImpl<T extends AbilityImpl<T>> implements Ability {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the announcement of X mana costs and sets manaCostsToPay.
|
||||
*
|
||||
* @param game
|
||||
* @param noMana
|
||||
* @return variableManaCost for late check
|
||||
*/
|
||||
protected VariableManaCost handleXCosts(Game game, boolean noMana) {
|
||||
// 20121001 - 601.2b
|
||||
// If the spell has a variable cost that will be paid as it's being cast (such as an {X} in
|
||||
// its mana cost; see rule 107.3), the player announces the value of that variable.
|
||||
// TODO: Handle announcing other variable costs here like: RemoveVariableCountersSourceCost
|
||||
VariableManaCost variableManaCost = null;
|
||||
for (ManaCost cost: manaCostsToPay) {
|
||||
if (cost instanceof VariableManaCost) {
|
||||
variableManaCost = (VariableManaCost) cost;
|
||||
break; // only one VariableManCost per spell (or is it possible to have more?)
|
||||
}
|
||||
}
|
||||
if (variableManaCost != null) {
|
||||
int xValue;
|
||||
if (!variableManaCost.isPaid()) { // should only happen for human players
|
||||
if (!noMana) {
|
||||
xValue = game.getPlayer(this.controllerId).announceXMana(variableManaCost.getMinX(), Integer.MAX_VALUE, "Announce the value for " + variableManaCost.getText(), game, this);
|
||||
int amountMana = xValue * variableManaCost.getMultiplier();
|
||||
StringBuilder manaString = new StringBuilder();
|
||||
if (variableManaCost.getFilter() == null || variableManaCost.getFilter().isColorless()) {
|
||||
manaString.append("{").append(amountMana).append("}");
|
||||
} else {
|
||||
String manaSymbol = null;
|
||||
if (variableManaCost.getFilter().isBlack()) {
|
||||
manaSymbol = "B";
|
||||
} else if (variableManaCost.getFilter().isRed()) {
|
||||
manaSymbol = "R";
|
||||
} else if (variableManaCost.getFilter().isBlue()) {
|
||||
manaSymbol = "U";
|
||||
} else if (variableManaCost.getFilter().isGreen()) {
|
||||
manaSymbol = "G";
|
||||
} else if (variableManaCost.getFilter().isWhite()) {
|
||||
manaSymbol = "W";
|
||||
}
|
||||
if (manaSymbol == null) {
|
||||
throw new UnsupportedOperationException("ManaFilter is not supported: " +this.toString() );
|
||||
}
|
||||
for (int i = 0; i < amountMana; i++) {
|
||||
manaString.append("{").append(manaSymbol).append("}");
|
||||
}
|
||||
}
|
||||
manaCostsToPay.add(new ManaCostsImpl(manaString.toString()));
|
||||
manaCostsToPay.setX(amountMana);
|
||||
}
|
||||
variableManaCost.setPaid();
|
||||
}
|
||||
xValue = getManaCostsToPay().getX();
|
||||
game.informPlayers(new StringBuilder(game.getPlayer(this.controllerId).getName()).append(" announced a value of ").append(xValue).append(" for ").append(variableManaCost.getText()).toString());
|
||||
}
|
||||
|
||||
return variableManaCost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset(Game game) {}
|
||||
|
||||
|
|
|
@ -39,4 +39,5 @@ public interface VariableCost {
|
|||
int getAmount();
|
||||
void setAmount(int amount);
|
||||
void setFilter(FilterMana filter);
|
||||
FilterMana getFilter();
|
||||
}
|
||||
|
|
|
@ -93,10 +93,23 @@ public class PayVariableLoyaltyCost extends CostImpl<PayVariableLoyaltyCost> imp
|
|||
amountPaid = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not Supported
|
||||
* @param filter
|
||||
*/
|
||||
@Override
|
||||
public void setFilter(FilterMana filter) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Not supported
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FilterMana getFilter() {
|
||||
return new FilterMana();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PayVariableLoyaltyCost copy() {
|
||||
return new PayVariableLoyaltyCost(this);
|
||||
|
|
|
@ -103,10 +103,23 @@ public class RemoveVariableCountersSourceCost extends CostImpl<RemoveVariableCou
|
|||
amountPaid = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not Supported
|
||||
* @param filter
|
||||
*/
|
||||
@Override
|
||||
public void setFilter(FilterMana filter) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Not supported
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FilterMana getFilter() {
|
||||
return new FilterMana();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RemoveVariableCountersSourceCost copy() {
|
||||
return new RemoveVariableCountersSourceCost(this);
|
||||
|
|
|
@ -137,10 +137,23 @@ public class RemoveVariableCountersTargetCost extends CostImpl<RemoveVariableCou
|
|||
amountPaid = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not Supported
|
||||
* @param filter
|
||||
*/
|
||||
@Override
|
||||
public void setFilter(FilterMana filter) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Not supported
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FilterMana getFilter() {
|
||||
return new FilterMana();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPay(UUID sourceId, UUID controllerId, Game game) {
|
||||
return target.canChoose(controllerId, game);
|
||||
|
|
|
@ -97,10 +97,23 @@ public class TapVariableTargetCost extends CostImpl<TapVariableTargetCost> imple
|
|||
amountPaid = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not Supported
|
||||
* @param filter
|
||||
*/
|
||||
@Override
|
||||
public void setFilter(FilterMana filter) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Not supported
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FilterMana getFilter() {
|
||||
return new FilterMana();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TapVariableTargetCost copy() {
|
||||
return new TapVariableTargetCost(this);
|
||||
|
|
|
@ -115,6 +115,11 @@ public class VariableManaCost extends ManaCostImpl<VariableManaCost> implements
|
|||
this.filter = filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FilterMana getFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VariableManaCost copy() {
|
||||
return new VariableManaCost(this);
|
||||
|
|
Loading…
Reference in a new issue