Added UUID to costs (required for optional costs for kicker)

This commit is contained in:
magenoxx 2011-09-14 00:35:02 +04:00
parent f72a04f175
commit a07c210ac0
6 changed files with 526 additions and 495 deletions

View file

@ -23,6 +23,11 @@ public class CompositeCost implements Cost {
this.description = cost.description; this.description = cost.description;
} }
@Override
public UUID getId() {
throw new RuntimeException("Not supported method");
}
@Override @Override
public String getText() { public String getText() {
return description; return description;

View file

@ -37,6 +37,7 @@ import mage.target.Targets;
public interface Cost extends Serializable { public interface Cost extends Serializable {
public UUID getId();
public String getText(); public String getText();
public boolean canPay(UUID sourceId, UUID controllerId, Game game); public boolean canPay(UUID sourceId, UUID controllerId, Game game);
public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana); public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana);

View file

@ -31,8 +31,11 @@ package mage.abilities.costs;
import mage.target.Target; import mage.target.Target;
import mage.target.Targets; import mage.target.Targets;
import java.util.UUID;
public abstract class CostImpl<T extends CostImpl<T>> implements Cost { public abstract class CostImpl<T extends CostImpl<T>> implements Cost {
protected UUID id;
protected String text; protected String text;
protected boolean paid; protected boolean paid;
protected Targets targets; protected Targets targets;
@ -41,11 +44,13 @@ public abstract class CostImpl<T extends CostImpl<T>> implements Cost {
public abstract T copy(); public abstract T copy();
public CostImpl() { public CostImpl() {
id = UUID.randomUUID();
paid = false; paid = false;
targets = new Targets(); targets = new Targets();
} }
public CostImpl(final CostImpl cost) { public CostImpl(final CostImpl cost) {
this.id = cost.id;
this.text = cost.text; this.text = cost.text;
this.paid = cost.paid; this.paid = cost.paid;
this.targets = cost.targets.copy(); this.targets = cost.targets.copy();
@ -82,4 +87,9 @@ public abstract class CostImpl<T extends CostImpl<T>> implements Cost {
paid = true; paid = true;
} }
@Override
public UUID getId() {
return this.id;
}
} }

View file

@ -51,7 +51,12 @@ public class CostsImpl<T extends Cost> extends ArrayList<T> implements Costs<T>
} }
} }
@Override @Override
public UUID getId() {
throw new RuntimeException("Not supported method");
}
@Override
public String getText() { public String getText() {
if (this.size() == 0) if (this.size() == 0)
return ""; return "";

View file

@ -29,6 +29,7 @@
package mage.abilities.costs.mana; package mage.abilities.costs.mana;
import java.util.UUID; import java.util.UUID;
import mage.Constants.ColoredManaSymbol; import mage.Constants.ColoredManaSymbol;
import mage.Mana; import mage.Mana;
import mage.abilities.Ability; import mage.abilities.Ability;
@ -40,269 +41,269 @@ import mage.players.Player;
public abstract class ManaCostImpl<T extends ManaCostImpl<T>> extends CostImpl<T> implements ManaCost { public abstract class ManaCostImpl<T extends ManaCostImpl<T>> extends CostImpl<T> implements ManaCost {
protected Mana payment; protected Mana payment;
protected Mana cost; protected Mana cost;
protected ManaOptions options; protected ManaOptions options;
@Override @Override
public abstract T copy(); public abstract T copy();
public ManaCostImpl() { public ManaCostImpl() {
payment = new Mana(); payment = new Mana();
options = new ManaOptions(); options = new ManaOptions();
} }
public ManaCostImpl(final ManaCostImpl manaCost) { public ManaCostImpl(final ManaCostImpl manaCost) {
super(manaCost); super(manaCost);
this.payment = manaCost.payment.copy(); this.payment = manaCost.payment.copy();
this.cost = manaCost.cost.copy(); this.cost = manaCost.cost.copy();
this.options = manaCost.options.copy(); this.options = manaCost.options.copy();
} }
@Override @Override
public Mana getPayment() { public Mana getPayment() {
return payment; return payment;
} }
@Override @Override
public Mana getMana() { public Mana getMana() {
return cost; return cost;
} }
@Override @Override
public ManaOptions getOptions() { public ManaOptions getOptions() {
return options; return options;
} }
@Override @Override
public void clearPaid() { public void clearPaid() {
payment.clear(); payment.clear();
super.clearPaid(); super.clearPaid();
} }
protected boolean assignColored(Ability ability, Game game, ManaPool pool, ColoredManaSymbol mana) { protected boolean assignColored(Ability ability, Game game, ManaPool pool, ColoredManaSymbol mana) {
// first check special mana // first check special mana
switch (mana) { switch (mana) {
case B: case B:
if (payConditionalBlack(ability, game, pool)) return true; if (payConditionalBlack(ability, game, pool)) return true;
if (pool.getBlack() > 0) { if (pool.getBlack() > 0) {
this.payment.addBlack(); this.payment.addBlack();
pool.removeBlack(); pool.removeBlack();
return true; return true;
} }
break; break;
case U: case U:
if (payConditionalBlue(ability, game, pool)) return true; if (payConditionalBlue(ability, game, pool)) return true;
if (pool.getBlue() > 0) { if (pool.getBlue() > 0) {
this.payment.addBlue(); this.payment.addBlue();
pool.removeBlue(); pool.removeBlue();
return true; return true;
} }
break; break;
case W: case W:
if (payConditionalWhite(ability, game, pool)) return true; if (payConditionalWhite(ability, game, pool)) return true;
if (pool.getWhite() > 0) { if (pool.getWhite() > 0) {
this.payment.addWhite(); this.payment.addWhite();
pool.removeWhite(); pool.removeWhite();
return true; return true;
} }
break; break;
case G: case G:
if (payConditionalGreen(ability, game, pool)) return true; if (payConditionalGreen(ability, game, pool)) return true;
if (pool.getGreen() > 0) { if (pool.getGreen() > 0) {
this.payment.addGreen(); this.payment.addGreen();
pool.removeGreen(); pool.removeGreen();
return true; return true;
} }
break; break;
case R: case R:
if (payConditionalRed(ability, game, pool)) return true; if (payConditionalRed(ability, game, pool)) return true;
if (pool.getRed() > 0) { if (pool.getRed() > 0) {
this.payment.addRed(); this.payment.addRed();
pool.removeRed(); pool.removeRed();
return true; return true;
} }
break; break;
} }
return false; return false;
} }
private boolean payConditionalRed(Ability ability, Game game, ManaPool pool) { private boolean payConditionalRed(Ability ability, Game game, ManaPool pool) {
if (pool.getConditionalRed(ability, game) > 0) { if (pool.getConditionalRed(ability, game) > 0) {
this.payment.addRed(); this.payment.addRed();
pool.removeConditionalRed(ability, game); pool.removeConditionalRed(ability, game);
return true; return true;
} }
return false; return false;
} }
private boolean payConditionalGreen(Ability ability, Game game, ManaPool pool) { private boolean payConditionalGreen(Ability ability, Game game, ManaPool pool) {
if (pool.getConditionalGreen(ability, game) > 0) { if (pool.getConditionalGreen(ability, game) > 0) {
this.payment.addGreen(); this.payment.addGreen();
pool.removeConditionalGreen(ability, game); pool.removeConditionalGreen(ability, game);
return true; return true;
} }
return false; return false;
} }
private boolean payConditionalWhite(Ability ability, Game game, ManaPool pool) { private boolean payConditionalWhite(Ability ability, Game game, ManaPool pool) {
if (pool.getConditionalWhite(ability, game) > 0) { if (pool.getConditionalWhite(ability, game) > 0) {
this.payment.addWhite(); this.payment.addWhite();
pool.removeConditionalWhite(ability, game); pool.removeConditionalWhite(ability, game);
return true; return true;
} }
return false; return false;
} }
private boolean payConditionalBlue(Ability ability, Game game, ManaPool pool) { private boolean payConditionalBlue(Ability ability, Game game, ManaPool pool) {
if (pool.getConditionalBlue(ability, game) > 0) { if (pool.getConditionalBlue(ability, game) > 0) {
this.payment.addBlue(); this.payment.addBlue();
pool.removeConditionalBlue(ability, game); pool.removeConditionalBlue(ability, game);
return true; return true;
} }
return false; return false;
} }
private boolean payConditionalBlack(Ability ability, Game game, ManaPool pool) { private boolean payConditionalBlack(Ability ability, Game game, ManaPool pool) {
if (pool.getConditionalBlack(ability, game) > 0) { if (pool.getConditionalBlack(ability, game) > 0) {
this.payment.addBlack(); this.payment.addBlack();
pool.removeConditionalBlack(ability, game); pool.removeConditionalBlack(ability, game);
return true; return true;
} }
return false; return false;
} }
private boolean payConditionalColorless(Ability ability, Game game, ManaPool pool) { private boolean payConditionalColorless(Ability ability, Game game, ManaPool pool) {
if (pool.getConditionalColorless(ability, game) > 0) { if (pool.getConditionalColorless(ability, game) > 0) {
this.payment.addColorless(); this.payment.addColorless();
pool.removeConditionalColorless(ability, game); pool.removeConditionalColorless(ability, game);
return true; return true;
} }
return false; return false;
} }
protected boolean assignColorless(Ability ability, Game game, ManaPool pool, int mana) { protected boolean assignColorless(Ability ability, Game game, ManaPool pool, int mana) {
int conditionalCount = pool.getConditionalCount(ability, game, null); int conditionalCount = pool.getConditionalCount(ability, game, null);
while (mana > payment.count() && (pool.count() > 0 || conditionalCount > 0)) { while (mana > payment.count() && (pool.count() > 0 || conditionalCount > 0)) {
if (payConditionalColorless(ability, game, pool)) continue; if (payConditionalColorless(ability, game, pool)) continue;
if (payConditionalBlack(ability, game, pool)) continue; if (payConditionalBlack(ability, game, pool)) continue;
if (payConditionalBlue(ability, game, pool)) continue; if (payConditionalBlue(ability, game, pool)) continue;
if (payConditionalWhite(ability, game, pool)) continue; if (payConditionalWhite(ability, game, pool)) continue;
if (payConditionalGreen(ability, game, pool)) continue; if (payConditionalGreen(ability, game, pool)) continue;
if (payConditionalRed(ability, game, pool)) continue; if (payConditionalRed(ability, game, pool)) continue;
if (pool.getColorless() > 0) { if (pool.getColorless() > 0) {
this.payment.addColorless(); this.payment.addColorless();
pool.removeColorless(); pool.removeColorless();
continue; continue;
} }
if (pool.getBlack() > 0) { if (pool.getBlack() > 0) {
this.payment.addBlack(); this.payment.addBlack();
pool.removeBlack(); pool.removeBlack();
continue; continue;
} }
if (pool.getBlue() > 0) { if (pool.getBlue() > 0) {
this.payment.addBlue(); this.payment.addBlue();
pool.removeBlue(); pool.removeBlue();
continue; continue;
} }
if (pool.getWhite() > 0) { if (pool.getWhite() > 0) {
this.payment.addWhite(); this.payment.addWhite();
pool.removeWhite(); pool.removeWhite();
continue; continue;
} }
if (pool.getGreen() > 0) { if (pool.getGreen() > 0) {
this.payment.addGreen(); this.payment.addGreen();
pool.removeGreen(); pool.removeGreen();
continue; continue;
} }
if (pool.getRed() > 0) { if (pool.getRed() > 0) {
this.payment.addRed(); this.payment.addRed();
pool.removeRed(); pool.removeRed();
continue; continue;
} }
break; break;
} }
return mana > payment.count(); return mana > payment.count();
} }
protected boolean isColoredPaid(ColoredManaSymbol mana) { protected boolean isColoredPaid(ColoredManaSymbol mana) {
switch (mana) { switch (mana) {
case B: case B:
if (this.payment.getBlack() > 0) if (this.payment.getBlack() > 0)
return true; return true;
case U: case U:
if (this.payment.getBlue() > 0) if (this.payment.getBlue() > 0)
return true; return true;
case W: case W:
if (this.payment.getWhite() > 0) if (this.payment.getWhite() > 0)
return true; return true;
case G: case G:
if (this.payment.getGreen() > 0) if (this.payment.getGreen() > 0)
return true; return true;
case R: case R:
if (this.payment.getRed() > 0) if (this.payment.getRed() > 0)
return true; return true;
} }
return false; return false;
} }
protected boolean isColorlessPaid(int mana) { protected boolean isColorlessPaid(int mana) {
if (this.payment.count() >= mana) if (this.payment.count() >= mana)
return true; return true;
return false; return false;
} }
@Override @Override
public boolean canPay(UUID sourceId, UUID controllerId, Game game) { public boolean canPay(UUID sourceId, UUID controllerId, Game game) {
return true; return true;
} }
@Override @Override
public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana) { public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana) {
if (noMana) { if (noMana) {
setPaid(); setPaid();
return true; return true;
} }
Player player = game.getPlayer(controllerId); Player player = game.getPlayer(controllerId);
assignPayment(game, ability, player.getManaPool()); assignPayment(game, ability, player.getManaPool());
while (!isPaid()) { while (!isPaid()) {
if (player.playMana(this, game)) if (player.playMana(this, game))
assignPayment(game, ability, player.getManaPool()); assignPayment(game, ability, player.getManaPool());
else else
return false; return false;
} }
return true; return true;
} }
@Override @Override
public void setPaid() { public void setPaid() {
this.paid = true; this.paid = true;
} }
@Override @Override
public void setPayment(Mana mana) { public void setPayment(Mana mana) {
this.payment.add(mana); this.payment.add(mana);
} }
protected void addColoredOption(ColoredManaSymbol symbol) { protected void addColoredOption(ColoredManaSymbol symbol) {
switch (symbol) { switch (symbol) {
case B: case B:
this.options.add(Mana.BlackMana); this.options.add(Mana.BlackMana);
break; break;
case U: case U:
this.options.add(Mana.BlueMana); this.options.add(Mana.BlueMana);
break; break;
case W: case W:
this.options.add(Mana.WhiteMana); this.options.add(Mana.WhiteMana);
break; break;
case R: case R:
this.options.add(Mana.RedMana); this.options.add(Mana.RedMana);
break; break;
case G: case G:
this.options.add(Mana.GreenMana); this.options.add(Mana.GreenMana);
break; break;
} }
} }
} }

View file

@ -45,122 +45,126 @@ import java.util.*;
*/ */
public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements ManaCosts<T> { public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements ManaCosts<T> {
private static Map<String, ManaCosts> costs = new HashMap<String, ManaCosts>(); protected UUID id;
public ManaCostsImpl() { private static Map<String, ManaCosts> costs = new HashMap<String, ManaCosts>();
}
public ManaCostsImpl(String mana) { public ManaCostsImpl() {
load(mana); this.id = UUID.randomUUID();
} }
public ManaCostsImpl(final ManaCostsImpl<T> costs) { public ManaCostsImpl(String mana) {
for (T cost : costs) { this.id = UUID.randomUUID();
this.add((T) cost.copy()); load(mana);
} }
}
@Override public ManaCostsImpl(final ManaCostsImpl<T> costs) {
public boolean add(ManaCost cost) { this.id = costs.id;
if (cost instanceof ManaCosts) { for (T cost : costs) {
for (ManaCost manaCost : (ManaCosts<T>) cost) { this.add((T) cost.copy());
super.add((T) manaCost); }
} }
return true;
} else {
return super.add((T) cost);
}
}
@Override @Override
public int convertedManaCost() { public boolean add(ManaCost cost) {
int total = 0; if (cost instanceof ManaCosts) {
for (ManaCost cost : this) { for (ManaCost manaCost : (ManaCosts<T>) cost) {
total += cost.convertedManaCost(); super.add((T) manaCost);
} }
return total; return true;
} } else {
return super.add((T) cost);
}
}
@Override @Override
public Mana getMana() { public int convertedManaCost() {
Mana mana = new Mana(); int total = 0;
for (ManaCost cost : this) { for (ManaCost cost : this) {
mana.add(cost.getMana()); total += cost.convertedManaCost();
} }
return mana; return total;
} }
@Override @Override
public Mana getPayment() { public Mana getMana() {
Mana manaTotal = new Mana(); Mana mana = new Mana();
for (ManaCost cost : this) { for (ManaCost cost : this) {
manaTotal.add(cost.getPayment()); mana.add(cost.getMana());
} }
return manaTotal; return mana;
} }
@Override @Override
public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana) { public Mana getPayment() {
if (this.size() == 0 || noMana) { Mana manaTotal = new Mana();
setPaid(); for (ManaCost cost : this) {
return true; manaTotal.add(cost.getPayment());
} }
return manaTotal;
}
Player player = game.getPlayer(controllerId); @Override
assignPayment(game, ability, player.getManaPool()); public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana) {
while (!isPaid()) { if (this.size() == 0 || noMana) {
if (player.playMana(this.getUnpaid(), game)) setPaid();
assignPayment(game, ability, player.getManaPool()); return true;
else }
return false;
}
for (ManaCost cost : this.getUnpaidVariableCosts()) {
VariableManaCost vCost = (VariableManaCost) cost;
while (!vCost.isPaid()) {
if (player.playXMana(vCost, (ManaCosts<ManaCost>) this, game))
vCost.assignPayment(game, ability, player.getManaPool());
else
return false;
}
}
return true;
}
@Override Player player = game.getPlayer(controllerId);
public ManaCosts<T> getUnpaid() { assignPayment(game, ability, player.getManaPool());
ManaCosts<T> unpaid = new ManaCostsImpl<T>(); while (!isPaid()) {
for (T cost : this) { if (player.playMana(this.getUnpaid(), game))
if (!(cost instanceof VariableManaCost) && !cost.isPaid()) assignPayment(game, ability, player.getManaPool());
unpaid.add((T) cost.getUnpaid()); else
} return false;
return unpaid; }
} for (ManaCost cost : this.getUnpaidVariableCosts()) {
VariableManaCost vCost = (VariableManaCost) cost;
while (!vCost.isPaid()) {
if (player.playXMana(vCost, (ManaCosts<ManaCost>) this, game))
vCost.assignPayment(game, ability, player.getManaPool());
else
return false;
}
}
return true;
}
@Override @Override
public ManaCosts<T> getUnpaidVariableCosts() { public ManaCosts<T> getUnpaid() {
ManaCosts<T> unpaid = new ManaCostsImpl<T>(); ManaCosts<T> unpaid = new ManaCostsImpl<T>();
for (ManaCost cost : this) { for (T cost : this) {
if (cost instanceof VariableManaCost && !cost.isPaid()) if (!(cost instanceof VariableManaCost) && !cost.isPaid())
unpaid.add((T) cost.getUnpaid()); unpaid.add((T) cost.getUnpaid());
} }
return unpaid; return unpaid;
} }
@Override
public ManaCosts<T> getUnpaidVariableCosts() {
ManaCosts<T> unpaid = new ManaCostsImpl<T>();
for (ManaCost cost : this) {
if (cost instanceof VariableManaCost && !cost.isPaid())
unpaid.add((T) cost.getUnpaid());
}
return unpaid;
}
@Override
@Override public List<VariableCost> getVariableCosts() {
public List<VariableCost> getVariableCosts() { List<VariableCost> variableCosts = new ArrayList<VariableCost>();
List<VariableCost> variableCosts = new ArrayList<VariableCost>(); for (ManaCost cost : this) {
for (ManaCost cost : this) { if (cost instanceof VariableCost)
if (cost instanceof VariableCost) variableCosts.add((VariableCost) cost);
variableCosts.add((VariableCost) cost); }
}
// if (variableCosts.size() == 0) { // if (variableCosts.size() == 0) {
// // add empty cost (#Issue 210) // // add empty cost (#Issue 210)
// variableCosts.add(new VariableManaCost()); // variableCosts.add(new VariableManaCost());
// } // }
return variableCosts; return variableCosts;
} }
@Override @Override
public int getX() { public int getX() {
@ -171,176 +175,181 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
return amount; return amount;
} }
@Override @Override
public void setPayment(Mana mana) { public void setPayment(Mana mana) {
} }
@Override @Override
public void assignPayment(Game game, Ability ability, ManaPool pool) { public void assignPayment(Game game, Ability ability, ManaPool pool) {
//attempt to pay colored costs first //attempt to pay colored costs first
for (ManaCost cost : this) { for (ManaCost cost : this) {
if (!cost.isPaid() && cost instanceof ColoredManaCost) { if (!cost.isPaid() && cost instanceof ColoredManaCost) {
cost.assignPayment(game, ability, pool); cost.assignPayment(game, ability, pool);
} }
} }
for (ManaCost cost : this) { for (ManaCost cost : this) {
if (!cost.isPaid() && cost instanceof HybridManaCost) { if (!cost.isPaid() && cost instanceof HybridManaCost) {
cost.assignPayment(game, ability, pool); cost.assignPayment(game, ability, pool);
} }
} }
for (ManaCost cost : this) { for (ManaCost cost : this) {
if (!cost.isPaid() && cost instanceof MonoHybridManaCost) { if (!cost.isPaid() && cost instanceof MonoHybridManaCost) {
cost.assignPayment(game, ability, pool); cost.assignPayment(game, ability, pool);
} }
} }
for (ManaCost cost : this) { for (ManaCost cost : this) {
if (!cost.isPaid() && cost instanceof GenericManaCost) { if (!cost.isPaid() && cost instanceof GenericManaCost) {
cost.assignPayment(game, ability, pool); cost.assignPayment(game, ability, pool);
} }
} }
for (ManaCost cost : this) { for (ManaCost cost : this) {
if (!cost.isPaid() && cost instanceof VariableManaCost) { if (!cost.isPaid() && cost instanceof VariableManaCost) {
cost.assignPayment(game, ability, pool); cost.assignPayment(game, ability, pool);
} }
} }
} }
@Override @Override
public void load(String mana) { public void load(String mana) {
this.clear(); this.clear();
if (costs.containsKey(mana)) { if (costs.containsKey(mana)) {
ManaCosts<T> savedCosts = costs.get(mana); ManaCosts<T> savedCosts = costs.get(mana);
for (ManaCost cost : savedCosts) { for (ManaCost cost : savedCosts) {
this.add((T) cost.copy()); this.add((T) cost.copy());
} }
} else { } else {
if (mana == null || mana.length() == 0) if (mana == null || mana.length() == 0)
return; return;
String[] symbols = mana.split("^\\{|\\}\\{|\\}$"); String[] symbols = mana.split("^\\{|\\}\\{|\\}$");
for (String symbol : symbols) { for (String symbol : symbols) {
if (symbol.length() > 0) { if (symbol.length() > 0) {
if (symbol.length() == 1 || isNumeric(symbol)) { if (symbol.length() == 1 || isNumeric(symbol)) {
if (Character.isDigit(symbol.charAt(0))) { if (Character.isDigit(symbol.charAt(0))) {
this.add((T) new GenericManaCost(Integer.valueOf(symbol))); this.add((T) new GenericManaCost(Integer.valueOf(symbol)));
} else { } else {
if (!symbol.equals("X")) if (!symbol.equals("X"))
this.add((T) new ColoredManaCost(ColoredManaSymbol.lookup(symbol.charAt(0)))); this.add((T) new ColoredManaCost(ColoredManaSymbol.lookup(symbol.charAt(0))));
else else
this.add((T) new VariableManaCost()); this.add((T) new VariableManaCost());
//TODO: handle multiple {X} and/or {Y} symbols //TODO: handle multiple {X} and/or {Y} symbols
} }
} else { } else {
if (Character.isDigit(symbol.charAt(0))) { if (Character.isDigit(symbol.charAt(0))) {
this.add((T) new MonoHybridManaCost(ColoredManaSymbol.lookup(symbol.charAt(2)))); this.add((T) new MonoHybridManaCost(ColoredManaSymbol.lookup(symbol.charAt(2))));
} else if (symbol.contains("P")) { } else if (symbol.contains("P")) {
this.add((T) new PhyrexianManaCost(ColoredManaSymbol.lookup(symbol.charAt(0)))); this.add((T) new PhyrexianManaCost(ColoredManaSymbol.lookup(symbol.charAt(0))));
} else { } else {
this.add((T) new HybridManaCost(ColoredManaSymbol.lookup(symbol.charAt(0)), ColoredManaSymbol.lookup(symbol.charAt(2)))); this.add((T) new HybridManaCost(ColoredManaSymbol.lookup(symbol.charAt(0)), ColoredManaSymbol.lookup(symbol.charAt(2))));
} }
} }
} }
} }
costs.put(mana, this.copy()); costs.put(mana, this.copy());
} }
} }
private boolean isNumeric(String symbol) { private boolean isNumeric(String symbol) {
try { try {
Integer.parseInt(symbol); Integer.parseInt(symbol);
return true; return true;
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
return false; return false;
} }
} }
@Override @Override
public List<String> getSymbols() { public List<String> getSymbols() {
List<String> symbols = new ArrayList<String>(); List<String> symbols = new ArrayList<String>();
for (ManaCost cost : this) { for (ManaCost cost : this) {
symbols.add(cost.getText()); symbols.add(cost.getText());
} }
return symbols; return symbols;
} }
@Override @Override
public String getText() { public UUID getId() {
if (this.size() == 0) return this.id;
return ""; }
StringBuilder sbText = new StringBuilder(); @Override
for (ManaCost cost : this) { public String getText() {
sbText.append(cost.getText()); if (this.size() == 0)
} return "";
return sbText.toString();
}
@Override StringBuilder sbText = new StringBuilder();
public ManaOptions getOptions() { for (ManaCost cost : this) {
ManaOptions options = new ManaOptions(); sbText.append(cost.getText());
for (ManaCost cost : this) { }
options.addMana(cost.getOptions()); return sbText.toString();
} }
return options;
}
@Override @Override
public boolean testPay(Mana testMana) { public ManaOptions getOptions() {
for (ManaCost cost : this) { ManaOptions options = new ManaOptions();
if (cost.testPay(testMana)) for (ManaCost cost : this) {
return true; options.addMana(cost.getOptions());
} }
return false; return options;
} }
@Override @Override
public boolean canPay(UUID sourceId, UUID controllerId, Game game) { public boolean testPay(Mana testMana) {
for (T cost : this) { for (ManaCost cost : this) {
if (!cost.canPay(sourceId, controllerId, game)) if (cost.testPay(testMana))
return false; return true;
} }
return true; return false;
} }
@Override @Override
public boolean isPaid() { public boolean canPay(UUID sourceId, UUID controllerId, Game game) {
for (T cost : this) { for (T cost : this) {
if (!((T) cost instanceof VariableManaCost) && !cost.isPaid()) if (!cost.canPay(sourceId, controllerId, game))
return false; return false;
} }
return true; return true;
} }
@Override @Override
public void clearPaid() { public boolean isPaid() {
for (T cost : this) { for (T cost : this) {
cost.clearPaid(); if (!((T) cost instanceof VariableManaCost) && !cost.isPaid())
} return false;
} }
return true;
}
@Override @Override
public void setPaid() { public void clearPaid() {
for (T cost : this) { for (T cost : this) {
cost.setPaid(); cost.clearPaid();
} }
} }
@Override @Override
public Targets getTargets() { public void setPaid() {
Targets targets = new Targets(); for (T cost : this) {
for (T cost : this) { cost.setPaid();
targets.addAll(cost.getTargets()); }
} }
return targets;
}
@Override @Override
public ManaCosts<T> copy() { public Targets getTargets() {
return new ManaCostsImpl(this); Targets targets = new Targets();
} for (T cost : this) {
targets.addAll(cost.getTargets());
}
return targets;
}
@Override
public ManaCosts<T> copy() {
return new ManaCostsImpl(this);
}
} }