1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-03-13 01:09:53 -09:00

changes to support tracking mana sources + some refactoring

This commit is contained in:
BetaSteward 2011-09-21 14:01:00 -04:00
parent b8fc0196b3
commit ee870a8970
15 changed files with 496 additions and 501 deletions

View file

@ -206,15 +206,15 @@ class CagedSunEffect extends ManaEffect<CagedSunEffect> {
if (player != null) {
ObjectColor color = (ObjectColor) game.getState().getValue(source.getSourceId() + "_color");
if (color.isBlack())
player.getManaPool().changeMana(Mana.BlackMana, game, source);
player.getManaPool().addMana(Mana.BlackMana, game, source);
else if (color.isBlue())
player.getManaPool().changeMana(Mana.BlueMana, game, source);
player.getManaPool().addMana(Mana.BlueMana, game, source);
else if (color.isRed())
player.getManaPool().changeMana(Mana.RedMana, game, source);
player.getManaPool().addMana(Mana.RedMana, game, source);
else if (color.isGreen())
player.getManaPool().changeMana(Mana.GreenMana, game, source);
player.getManaPool().addMana(Mana.GreenMana, game, source);
else if (color.isWhite())
player.getManaPool().changeMana(Mana.WhiteMana, game, source);
player.getManaPool().addMana(Mana.WhiteMana, game, source);
}
return true;
}

View file

@ -165,27 +165,27 @@ class VorinclexEffect extends ManaEffect<VorinclexEffect> {
else
player.choose(outcome, choice, game);
if (choice.getChoice().equals("Black")) {
player.getManaPool().changeMana(Mana.BlackMana, game, source);
player.getManaPool().addMana(Mana.BlackMana, game, source);
return true;
}
else if (choice.getChoice().equals("Blue")) {
player.getManaPool().changeMana(Mana.BlueMana, game, source);
player.getManaPool().addMana(Mana.BlueMana, game, source);
return true;
}
else if (choice.getChoice().equals("Red")) {
player.getManaPool().changeMana(Mana.RedMana, game, source);
player.getManaPool().addMana(Mana.RedMana, game, source);
return true;
}
else if (choice.getChoice().equals("Green")) {
player.getManaPool().changeMana(Mana.GreenMana, game, source);
player.getManaPool().addMana(Mana.GreenMana, game, source);
return true;
}
else if (choice.getChoice().equals("White")) {
player.getManaPool().changeMana(Mana.WhiteMana, game, source);
player.getManaPool().addMana(Mana.WhiteMana, game, source);
return true;
}
else if (choice.getChoice().equals("Colorless")) {
player.getManaPool().changeMana(Mana.ColorlessMana, game, source);
player.getManaPool().addMana(Mana.ColorlessMana, game, source);
return true;
}
}

View file

@ -27,9 +27,11 @@
*/
package mage;
import mage.Constants.ManaType;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.filter.Filter;
import mage.filter.FilterMana;
import mage.game.Game;
import java.io.Serializable;
@ -109,4 +111,17 @@ public class ConditionalMana extends Mana implements Serializable {
public String getDescription() {
return staticText;
}
public void removeAll(FilterMana filter) {
if (filter == null) {
return;
}
if (filter.isBlack()) black = 0;
if (filter.isBlue()) blue = 0;
if (filter.isWhite()) white = 0;
if (filter.isGreen()) green = 0;
if (filter.isRed()) red = 0;
if (filter.isColorless()) colorless = 0;
}
}

View file

@ -65,6 +65,10 @@ public final class Constants {
}
public enum ManaType {
BLACK, BLUE, GREEN, RED, WHITE, COLORLESS
}
public enum CardType {
ARTIFACT ("Artifact"),
CREATURE ("Creature"),

View file

@ -31,6 +31,7 @@ package mage;
import java.io.Serializable;
import mage.Constants.ColoredManaSymbol;
import mage.Constants.ManaType;
import mage.filter.FilterMana;
import mage.util.Copyable;
@ -40,13 +41,13 @@ import mage.util.Copyable;
*/
public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
private int red;
private int green;
private int blue;
private int white;
private int black;
private int colorless;
private int any;
protected int red;
protected int green;
protected int blue;
protected int white;
protected int black;
protected int colorless;
protected int any;
public static final Mana RedMana = RedMana(1);
public static final Mana GreenMana = GreenMana(1);
@ -418,4 +419,45 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
return 0;
}
public int get(ManaType manaType) {
switch(manaType) {
case BLACK:
return black;
case BLUE:
return blue;
case GREEN:
return green;
case RED:
return red;
case WHITE:
return white;
case COLORLESS:
return colorless;
}
return 0;
}
public void set(ManaType manaType, int amount) {
switch(manaType) {
case BLACK:
black = amount;
break;
case BLUE:
blue = amount;
break;
case GREEN:
green = amount;
break;
case RED:
red = amount;
break;
case WHITE:
white = amount;
break;
case COLORLESS:
colorless = amount;
break;
}
}
}

View file

@ -32,6 +32,7 @@ import mage.abilities.Ability;
import mage.abilities.costs.*;
import mage.Mana;
import mage.abilities.mana.ManaOptions;
import mage.filter.Filter;
import mage.game.Game;
import mage.players.ManaPool;
@ -47,6 +48,8 @@ public interface ManaCost extends Cost {
public ManaCost getUnpaid();
public ManaOptions getOptions();
public boolean testPay(Mana testMana);
public Filter getSourceFilter();
public void setSourceFilter(Filter filter);
@Override
public ManaCost copy();

View file

@ -31,10 +31,12 @@ package mage.abilities.costs.mana;
import java.util.UUID;
import mage.Constants.ColoredManaSymbol;
import mage.Constants.ManaType;
import mage.Mana;
import mage.abilities.Ability;
import mage.abilities.costs.CostImpl;
import mage.abilities.mana.ManaOptions;
import mage.filter.Filter;
import mage.game.Game;
import mage.players.ManaPool;
import mage.players.Player;
@ -44,6 +46,7 @@ public abstract class ManaCostImpl<T extends ManaCostImpl<T>> extends CostImpl<T
protected Mana payment;
protected Mana cost;
protected ManaOptions options;
protected Filter sourceFilter;
@Override
public abstract T copy();
@ -58,6 +61,8 @@ public abstract class ManaCostImpl<T extends ManaCostImpl<T>> extends CostImpl<T
this.payment = manaCost.payment.copy();
this.cost = manaCost.cost.copy();
this.options = manaCost.options.copy();
if (manaCost.sourceFilter != null)
this.sourceFilter = manaCost.sourceFilter.copy();
}
@Override
@ -81,46 +86,45 @@ public abstract class ManaCostImpl<T extends ManaCostImpl<T>> extends CostImpl<T
super.clearPaid();
}
@Override
public Filter getSourceFilter() {
return this.sourceFilter;
}
@Override
public void setSourceFilter(Filter filter) {
this.sourceFilter = filter;
}
protected boolean assignColored(Ability ability, Game game, ManaPool pool, ColoredManaSymbol mana) {
// first check special mana
switch (mana) {
case B:
if (payConditionalBlack(ability, game, pool)) return true;
if (pool.getBlack() > 0) {
if (pool.pay(ManaType.BLACK, ability, sourceFilter, game)) {
this.payment.addBlack();
pool.removeBlack();
return true;
}
break;
case U:
if (payConditionalBlue(ability, game, pool)) return true;
if (pool.getBlue() > 0) {
if (pool.pay(ManaType.BLUE, ability, sourceFilter, game)) {
this.payment.addBlue();
pool.removeBlue();
return true;
}
break;
case W:
if (payConditionalWhite(ability, game, pool)) return true;
if (pool.getWhite() > 0) {
if (pool.pay(ManaType.WHITE, ability, sourceFilter, game)) {
this.payment.addWhite();
pool.removeWhite();
return true;
}
break;
case G:
if (payConditionalGreen(ability, game, pool)) return true;
if (pool.getGreen() > 0) {
if (pool.pay(ManaType.GREEN, ability, sourceFilter, game)) {
this.payment.addGreen();
pool.removeGreen();
return true;
}
break;
case R:
if (payConditionalRed(ability, game, pool)) return true;
if (pool.getRed() > 0) {
if (pool.pay(ManaType.RED, ability, sourceFilter, game)) {
this.payment.addRed();
pool.removeRed();
return true;
}
break;
@ -128,98 +132,31 @@ public abstract class ManaCostImpl<T extends ManaCostImpl<T>> extends CostImpl<T
return false;
}
private boolean payConditionalRed(Ability ability, Game game, ManaPool pool) {
if (pool.getConditionalRed(ability, game) > 0) {
this.payment.addRed();
pool.removeConditionalRed(ability, game);
return true;
}
return false;
}
private boolean payConditionalGreen(Ability ability, Game game, ManaPool pool) {
if (pool.getConditionalGreen(ability, game) > 0) {
this.payment.addGreen();
pool.removeConditionalGreen(ability, game);
return true;
}
return false;
}
private boolean payConditionalWhite(Ability ability, Game game, ManaPool pool) {
if (pool.getConditionalWhite(ability, game) > 0) {
this.payment.addWhite();
pool.removeConditionalWhite(ability, game);
return true;
}
return false;
}
private boolean payConditionalBlue(Ability ability, Game game, ManaPool pool) {
if (pool.getConditionalBlue(ability, game) > 0) {
this.payment.addBlue();
pool.removeConditionalBlue(ability, game);
return true;
}
return false;
}
private boolean payConditionalBlack(Ability ability, Game game, ManaPool pool) {
if (pool.getConditionalBlack(ability, game) > 0) {
this.payment.addBlack();
pool.removeConditionalBlack(ability, game);
return true;
}
return false;
}
private boolean payConditionalColorless(Ability ability, Game game, ManaPool pool) {
if (pool.getConditionalColorless(ability, game) > 0) {
this.payment.addColorless();
pool.removeConditionalColorless(ability, game);
return true;
}
return false;
}
protected boolean assignColorless(Ability ability, Game game, ManaPool pool, int mana) {
int conditionalCount = pool.getConditionalCount(ability, game, null);
while (mana > payment.count() && (pool.count() > 0 || conditionalCount > 0)) {
if (payConditionalColorless(ability, game, pool)) continue;
if (payConditionalBlack(ability, game, pool)) continue;
if (payConditionalBlue(ability, game, pool)) continue;
if (payConditionalWhite(ability, game, pool)) continue;
if (payConditionalGreen(ability, game, pool)) continue;
if (payConditionalRed(ability, game, pool)) continue;
if (pool.getColorless() > 0) {
if (pool.pay(ManaType.COLORLESS, ability, sourceFilter, game)) {
this.payment.addColorless();
pool.removeColorless();
continue;
}
if (pool.getBlack() > 0) {
if (pool.pay(ManaType.BLACK, ability, sourceFilter, game)) {
this.payment.addBlack();
pool.removeBlack();
continue;
}
if (pool.getBlue() > 0) {
if (pool.pay(ManaType.BLUE, ability, sourceFilter, game)) {
this.payment.addBlue();
pool.removeBlue();
continue;
}
if (pool.getWhite() > 0) {
if (pool.pay(ManaType.WHITE, ability, sourceFilter, game)) {
this.payment.addWhite();
pool.removeWhite();
continue;
}
if (pool.getGreen() > 0) {
if (pool.pay(ManaType.GREEN, ability, sourceFilter, game)) {
this.payment.addGreen();
pool.removeGreen();
continue;
}
if (pool.getRed() > 0) {
if (pool.pay(ManaType.RED, ability, sourceFilter, game)) {
this.payment.addRed();
pool.removeRed();
continue;
}
break;

View file

@ -33,6 +33,7 @@ import mage.Mana;
import mage.abilities.Ability;
import mage.abilities.costs.VariableCost;
import mage.abilities.mana.ManaOptions;
import mage.filter.Filter;
import mage.game.Game;
import mage.players.ManaPool;
import mage.players.Player;
@ -352,4 +353,16 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
return new ManaCostsImpl(this);
}
@Override
public Filter getSourceFilter() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setSourceFilter(Filter filter) {
for (T cost : this) {
cost.setSourceFilter(filter);
}
}
}

View file

@ -69,7 +69,7 @@ public class VariableManaCost extends ManaCostImpl<VariableManaCost> implements
public void assignPayment(Game game, Ability ability, ManaPool pool) {
payment.add(pool.getMana(filter));
payment.add(pool.getAllConditionalMana(ability, game, filter));
pool.emptyPoolConditional(ability, game, filter);
pool.payX(ability, game, filter);
}
@Override

View file

@ -59,23 +59,23 @@ public class AddManaOfAnyColorEffect extends ManaEffect<AddManaOfAnyColorEffect>
ChoiceColor choice = (ChoiceColor) source.getChoices().get(0);
Player player = game.getPlayer(source.getControllerId());
if (choice.getColor().isBlack()) {
player.getManaPool().changeMana(Mana.BlackMana, game, source);
player.getManaPool().addMana(Mana.BlackMana, game, source);
return true;
}
else if (choice.getColor().isBlue()) {
player.getManaPool().changeMana(Mana.BlueMana, game, source);
player.getManaPool().addMana(Mana.BlueMana, game, source);
return true;
}
else if (choice.getColor().isRed()) {
player.getManaPool().changeMana(Mana.RedMana, game, source);
player.getManaPool().addMana(Mana.RedMana, game, source);
return true;
}
else if (choice.getColor().isGreen()) {
player.getManaPool().changeMana(Mana.GreenMana, game, source);
player.getManaPool().addMana(Mana.GreenMana, game, source);
return true;
}
else if (choice.getColor().isWhite()) {
player.getManaPool().changeMana(Mana.WhiteMana, game, source);
player.getManaPool().addMana(Mana.WhiteMana, game, source);
return true;
}
return false;

View file

@ -33,7 +33,7 @@ public class BasicManaEffect extends ManaEffect<BasicManaEffect> {
@Override
public boolean apply(Game game, Ability source) {
game.getPlayer(source.getControllerId()).getManaPool().changeMana(mana, game, source);
game.getPlayer(source.getControllerId()).getManaPool().addMana(mana, game, source);
return true;
}

View file

@ -63,7 +63,7 @@ public class DynamicManaEffect extends BasicManaEffect {
@Override
public boolean apply(Game game, Ability source) {
computeMana(game, source);
game.getPlayer(source.getControllerId()).getManaPool().changeMana(computedMana, game, source);
game.getPlayer(source.getControllerId()).getManaPool().addMana(computedMana, game, source);
return true;
}

View file

@ -34,6 +34,7 @@ import java.util.Iterator;
import java.util.List;
import mage.ConditionalMana;
import mage.Constants.ManaType;
import mage.Mana;
import mage.abilities.Ability;
import mage.filter.Filter;
@ -47,236 +48,75 @@ import mage.game.events.GameEvent;
*/
public class ManaPool implements Serializable {
private int red = 0;
private int green = 0;
private int blue = 0;
private int white = 0;
private int black = 0;
private int colorless = 0;
private List<ConditionalMana> conditionalMana = new ArrayList<ConditionalMana>();
private List<ManaPoolItem> manaItems = new ArrayList<ManaPoolItem>();
public ManaPool() {}
public ManaPool(final ManaPool pool) {
this.red = pool.red;
this.green = pool.green;
this.blue = pool.blue;
this.white = pool.white;
this.black = pool.black;
this.colorless = pool.colorless;
for (ConditionalMana mana : pool.conditionalMana) {
conditionalMana.add(mana.copy());
for (ManaPoolItem item: pool.manaItems) {
manaItems.add(item.copy());
}
}
public void setRed(int red) {
this.red = red;
}
public void removeRed() {
red--;
}
public void addRed() {
red++;
}
public int getRed() {
return red;
}
public int getConditionalRed(Ability ability, Game game) {
if (ability == null || conditionalMana.size() == 0) {
return 0;
}
boolean hasRed = false;
for (ConditionalMana mana : conditionalMana) {
if (mana.getRed() > 0) {
hasRed = true;
break;
}
}
if (!hasRed) return 0;
for (ConditionalMana mana : conditionalMana) {
if (mana.getRed() > 0 && mana.apply(ability, game)) {
return mana.getRed();
}
}
return 0;
}
public void setGreen(int green) {
this.green = green;
}
public void removeGreen() {
green--;
}
public void addGreen() {
green++;
return get(ManaType.RED);
}
public int getGreen() {
return green;
}
public int getConditionalGreen(Ability ability, Game game) {
if (ability == null || conditionalMana.size() == 0) {
return 0;
}
boolean hasGreen = false;
for (ConditionalMana mana : conditionalMana) {
if (mana.getGreen() > 0) {
hasGreen = true;
break;
}
}
if (!hasGreen) return 0;
for (ConditionalMana mana : conditionalMana) {
if (mana.getGreen() > 0 && mana.apply(ability, game)) {
return mana.getGreen();
}
}
return 0;
}
public void setBlue(int blue) {
this.blue = blue;
}
public void removeBlue() {
blue--;
}
public void addBlue() {
blue++;
return get(ManaType.GREEN);
}
public int getBlue() {
return blue;
}
public int getConditionalBlue(Ability ability, Game game) {
if (ability == null || conditionalMana.size() == 0) {
return 0;
}
boolean hasBlue = false;
for (ConditionalMana mana : conditionalMana) {
if (mana.getBlue() > 0) {
hasBlue = true;
break;
}
}
if (!hasBlue) return 0;
for (ConditionalMana mana : conditionalMana) {
if (mana.getBlue() > 0 && mana.apply(ability, game)) {
return mana.getBlue();
}
}
return 0;
}
public void setWhite(int white) {
this.white = white;
}
public void removeWhite() {
white--;
}
public void addWhite() {
white++;
return get(ManaType.BLUE);
}
public int getWhite() {
return white;
}
public int getConditionalWhite(Ability ability, Game game) {
if (ability == null || conditionalMana.size() == 0) {
return 0;
}
boolean hasWhite = false;
for (ConditionalMana mana : conditionalMana) {
if (mana.getWhite() > 0) {
hasWhite = true;
break;
}
}
if (!hasWhite) return 0;
for (ConditionalMana mana : conditionalMana) {
if (mana.getWhite() > 0 && mana.apply(ability, game)) {
return mana.getWhite();
}
}
return 0;
}
public void setBlack(int black) {
this.black = black;
}
public void removeBlack() {
black--;
}
public void addBlack() {
black++;
return get(ManaType.WHITE);
}
public int getBlack() {
return black;
return get(ManaType.BLACK);
}
public int getConditionalBlack(Ability ability, Game game) {
if (ability == null || conditionalMana.size() == 0) {
return 0;
public boolean pay(ManaType manaType, Ability ability, Filter filter, Game game) {
if (getConditional(manaType, ability, filter, game) > 0) {
removeConditional(manaType, ability, game);
return true;
}
boolean hasBlack = false;
for (ConditionalMana mana : conditionalMana) {
if (mana.getBlack() > 0) {
hasBlack = true;
break;
for (ManaPoolItem mana : manaItems) {
if (filter == null || filter.match(game.getObject(mana.getSourceId()))) {
if (mana.get(manaType) > 0) {
mana.remove(manaType);
return true;
}
}
if (!hasBlack) return 0;
for (ConditionalMana mana : conditionalMana) {
if (mana.getBlack() > 0 && mana.apply(ability, game)) {
return mana.getBlack();
}
}
return 0;
return false;
}
public int getConditionalColorless(Ability ability, Game game) {
if (ability == null || conditionalMana.size() == 0) {
return 0;
}
boolean hasColorless = false;
for (ConditionalMana mana : conditionalMana) {
if (mana.getColorless() > 0) {
hasColorless = true;
break;
}
}
if (!hasColorless) return 0;
for (ConditionalMana mana : conditionalMana) {
if (mana.getColorless() > 0 && mana.apply(ability, game)) {
return mana.getColorless();
}
}
return 0;
public int get(ManaType manaType) {
return getMana().get(manaType);
}
private int getConditional(ManaType manaType, Ability ability, Filter filter, Game game) {
if (ability == null || getConditionalMana().isEmpty()) {
return 0;
}
for (ManaPoolItem mana : manaItems) {
if (mana.isConditional() && mana.getConditionalMana().get(manaType) > 0 && mana.getConditionalMana().apply(ability, game)) {
if (filter == null || filter.match(game.getObject(mana.getSourceId())))
return mana.getConditionalMana().get(manaType);
}
}
return 0;
}
public int getConditionalCount(Ability ability, Game game, FilterMana filter) {
if (ability == null || conditionalMana.size() == 0) {
if (ability == null || getConditionalMana().isEmpty()) {
return 0;
}
int count = 0;
for (ConditionalMana mana : conditionalMana) {
for (ConditionalMana mana : getConditionalMana()) {
if (mana.apply(ability, game)) {
count += mana.count(filter);
}
@ -284,126 +124,128 @@ public class ManaPool implements Serializable {
return count;
}
public void setColorless(int colorless) {
this.colorless = colorless;
}
public void removeColorless() {
colorless--;
}
public void addColorless() {
colorless++;
}
public int getColorless() {
return colorless;
return get(ManaType.COLORLESS);
}
public int emptyPool() {
int total = count();
black = 0;
blue = 0;
white = 0;
red = 0;
green = 0;
colorless = 0;
conditionalMana.clear();
manaItems.clear();
return total;
}
public int emptyPoolConditional(Ability ability, Game game) {
int total = count();
black = 0;
blue = 0;
white = 0;
red = 0;
green = 0;
colorless = 0;
// remove only those mana that can be spent for ability
Iterator<ConditionalMana> it = conditionalMana.iterator();
private int payX(Ability ability, Game game) {
int total = 0;
Iterator<ManaPoolItem> it = manaItems.iterator();
while (it.hasNext()) {
ConditionalMana mana = it.next();
if (mana.apply(ability, game)) {
total += mana.count();
ManaPoolItem item = it.next();
if (item.isConditional()) {
if (item.getConditionalMana().apply(ability, game)) {
total += item.count();
it.remove();
}
}
else {
total += item.count();
it.remove();
}
}
return total;
}
public int emptyPoolConditional(Ability ability, Game game, FilterMana filter) {
/**
* remove all mana from pool that applies and that matches filter
* @param ability
* @param game
* @param filter
* @return
*/
public int payX(Ability ability, Game game, FilterMana filter) {
if (filter == null) {
return emptyPoolConditional(ability, game);
return payX(ability, game);
}
int total = count(filter);
if (filter.isBlack()) black = 0;
if (filter.isBlue()) blue = 0;
if (filter.isWhite()) white = 0;
if (filter.isRed()) red = 0;
if (filter.isGreen()) green = 0;
if (filter.isColorless()) colorless = 0;
// remove only those mana that can be spent for ability
Iterator<ConditionalMana> it = conditionalMana.iterator();
int total = 0;
Iterator<ManaPoolItem> it = manaItems.iterator();
while (it.hasNext()) {
ConditionalMana mana = it.next();
if (mana.apply(ability, game)) {
if (mana.count(filter) > 0) {
total += mana.count();
ManaPoolItem item = it.next();
if (item.isConditional()) {
ConditionalMana c = item.getConditionalMana();
if (c.apply(ability, game)) {
int count = c.count(filter);
if (count > 0) {
total += count;
c.removeAll(filter);
if (c.count() == 0)
it.remove();
}
}
}
else {
if (filter.isBlack()) {
total += item.getBlack();
item.removeBlack();
}
if (filter.isBlue()) {
total += item.getBlue();
item.removeBlue();
}
if (filter.isWhite()) {
total += item.getWhite();
item.removeWhite();
}
if (filter.isRed()) {
total += item.getRed();
item.removeRed();
}
if (filter.isGreen()) {
total += item.getGreen();
item.removeGreen();
}
if (filter.isColorless()) {
total += item.getColorless();
item.removeColorless();
}
if (item.count() == 0)
it.remove();
}
}
return total;
}
public Mana getMana() {
Mana mana = new Mana();
mana.setBlack(black);
mana.setBlue(blue);
mana.setColorless(colorless);
mana.setGreen(green);
mana.setRed(red);
mana.setWhite(white);
return mana;
Mana m = new Mana();
for (ManaPoolItem item: manaItems) {
m.add(item.getMana());
}
return m;
}
public Mana getMana(FilterMana filter) {
if (filter == null) {
return getMana();
}
Mana mana = new Mana();
if (filter.isBlack()) mana.setBlack(black);
if (filter.isBlue()) mana.setBlue(blue);
if (filter.isColorless()) mana.setColorless(colorless);
if (filter.isGreen()) mana.setGreen(green);
if (filter.isRed()) mana.setRed(red);
if (filter.isWhite()) mana.setWhite(white);
return mana;
}
public Mana getAllConditionalMana(Ability ability, Game game) {
Mana mana = new Mana();
mana.setColorless(getConditionalCount(ability, game, null));
return mana;
Mana test = getMana();
Mana m = new Mana();
if (filter.isBlack()) m.setBlack(test.getBlack());
if (filter.isBlue()) m.setBlue(test.getBlue());
if (filter.isColorless()) m.setColorless(test.getColorless());
if (filter.isGreen()) m.setGreen(test.getGreen());
if (filter.isRed()) m.setRed(test.getRed());
if (filter.isWhite()) m.setWhite(test.getWhite());
return m;
}
public Mana getAllConditionalMana(Ability ability, Game game, FilterMana filter) {
Mana mana = new Mana();
mana.setColorless(getConditionalCount(ability, game, filter));
return mana;
Mana m = new Mana();
m.setColorless(getConditionalCount(ability, game, filter));
return m;
}
public void changeMana(Mana mana, Game game, Ability source) {
public void addMana(Mana mana, Game game, Ability source) {
if (mana instanceof ConditionalMana) {
this.conditionalMana.add((ConditionalMana)mana);
this.manaItems.add(new ManaPoolItem((ConditionalMana)mana, source.getSourceId()));
} else {
this.black += mana.getBlack();
this.blue += mana.getBlue();
this.white += mana.getWhite();
this.red += mana.getRed();
this.green += mana.getGreen();
this.colorless += mana.getColorless();
this.manaItems.add(new ManaPoolItem(mana.getRed(), mana.getGreen(), mana.getBlue(), mana.getWhite(), mana.getBlack(), mana.getColorless(), source.getSourceId()));
GameEvent event = GameEvent.getEvent(GameEvent.EventType.MANA_ADDED, source.getSourceId(), source.getId(), source.getControllerId());
event.setData(mana.toString());
game.fireEvent(event);
@ -411,101 +253,33 @@ public class ManaPool implements Serializable {
}
public List<ConditionalMana> getConditionalMana() {
List<ConditionalMana> conditionalMana = new ArrayList<ConditionalMana>();
for (ManaPoolItem item: manaItems) {
if (item.isConditional()) {
conditionalMana.add(item.getConditionalMana());
}
}
return conditionalMana;
}
public boolean checkMana(Mana mana) {
if (this.black < mana.getBlack())
return false;
if (this.blue < mana.getBlue())
return false;
if (this.white < mana.getWhite())
return false;
if (this.red < mana.getRed())
return false;
if (this.green < mana.getGreen())
return false;
if (this.colorless < mana.getColorless())
return false;
return true;
}
public int count() {
return red + green + blue + white + black + colorless;
int x = 0;
for (ManaPoolItem item: manaItems) {
x += item.count();
}
public int count(FilterMana filter) {
if (filter == null) {
return count();
}
int count = 0;
if (filter.isBlack()) count += black;
if (filter.isBlue()) count += blue;
if (filter.isWhite()) count += white;
if (filter.isGreen()) count += green;
if (filter.isRed()) count += red;
if (filter.isColorless()) count += colorless;
return count;
return x;
}
public ManaPool copy() {
return new ManaPool(this);
}
public void removeConditionalBlack(Ability ability, Game game) {
for (ConditionalMana mana : conditionalMana) {
if (mana.getBlack() > 0 && mana.apply(ability, game)) {
mana.setBlack(mana.getBlack() - 1);
private void removeConditional(ManaType manaType, Ability ability, Game game) {
for (ConditionalMana mana : getConditionalMana()) {
if (mana.get(manaType) > 0 && mana.apply(ability, game)) {
mana.set(manaType, mana.get(manaType) - 1);
break;
}
}
}
public void removeConditionalBlue(Ability ability, Game game) {
for (ConditionalMana mana : conditionalMana) {
if (mana.getBlue() > 0 && mana.apply(ability, game)) {
mana.setBlue(mana.getBlue() - 1);
break;
}
}
}
public void removeConditionalWhite(Ability ability, Game game) {
for (ConditionalMana mana : conditionalMana) {
if (mana.getWhite() > 0 && mana.apply(ability, game)) {
mana.setWhite(mana.getWhite() - 1);
break;
}
}
}
public void removeConditionalGreen(Ability ability, Game game) {
for (ConditionalMana mana : conditionalMana) {
if (mana.getGreen() > 0 && mana.apply(ability, game)) {
mana.setGreen(mana.getGreen() - 1);
break;
}
}
}
public void removeConditionalRed(Ability ability, Game game) {
for (ConditionalMana mana : conditionalMana) {
if (mana.getRed() > 0 && mana.apply(ability, game)) {
mana.setRed(mana.getRed() - 1);
break;
}
}
}
public void removeConditionalColorless(Ability ability, Game game) {
for (ConditionalMana mana : conditionalMana) {
if (mana.getColorless() > 0 && mana.apply(ability, game)) {
mana.setColorless(mana.getColorless() - 1);
break;
}
}
}
}

View file

@ -0,0 +1,206 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.players;
import java.io.Serializable;
import java.util.UUID;
import mage.ConditionalMana;
import mage.Constants.ManaType;
import mage.Mana;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class ManaPoolItem implements Serializable {
private int red = 0;
private int green = 0;
private int blue = 0;
private int white = 0;
private int black = 0;
private int colorless = 0;
private ConditionalMana conditionalMana;
private UUID sourceId;
public ManaPoolItem() {}
public ManaPoolItem(int red, int green, int blue, int white, int black, int colorless, UUID sourceId) {
this.red = red;
this.green = green;
this.blue = blue;
this.white = white;
this.black = black;
this.colorless = colorless;
this.sourceId = sourceId;
}
public ManaPoolItem(ConditionalMana conditionalMana, UUID sourceId) {
this.conditionalMana = conditionalMana;
this.sourceId = sourceId;
}
public ManaPoolItem(final ManaPoolItem item) {
this.red = item.red;
this.green = item.green;
this.blue = item.blue;
this.white = item.white;
this.black = item.black;
this.colorless = item.colorless;
if (item.conditionalMana != null)
this.conditionalMana = item.conditionalMana.copy();
this.sourceId = item.sourceId;
}
public ManaPoolItem copy() {
return new ManaPoolItem(this);
}
public UUID getSourceId() {
return sourceId;
}
public int getRed() {
return red;
}
public void removeRed() {
if (red > 0)
red--;
}
public int getGreen() {
return green;
}
public void removeGreen() {
if (green > 0)
green--;
}
public int getBlue() {
return blue;
}
public void removeBlue() {
if (blue > 0)
blue--;
}
public int getBlack() {
return black;
}
public void removeBlack() {
if (black > 0)
black--;
}
public int getWhite() {
return white;
}
public void removeWhite() {
if (white > 0)
white--;
}
public int getColorless() {
return colorless;
}
public void removeColorless() {
if (colorless > 0)
colorless--;
}
public boolean isConditional() {
return conditionalMana != null;
}
public ConditionalMana getConditionalMana() {
return conditionalMana;
}
public Mana getMana() {
return new Mana(red, green, blue, white, black, colorless, 0);
}
public int count() {
if (conditionalMana == null)
return red + green + blue + white + black + colorless;
return conditionalMana.count();
}
public int get(ManaType manaType) {
switch(manaType) {
case BLACK:
return black;
case BLUE:
return blue;
case GREEN:
return green;
case RED:
return red;
case WHITE:
return white;
case COLORLESS:
return colorless;
}
return 0;
}
public void remove(ManaType manaType) {
switch(manaType) {
case BLACK:
if (black > 0)
black--;
break;
case BLUE:
if (blue > 0)
blue--;
break;
case GREEN:
if (green > 0)
green--;
break;
case RED:
if (red > 0)
red--;
break;
case WHITE:
if (white > 0)
white--;
break;
case COLORLESS:
if (colorless > 0)
colorless--;
break;
}
}
}

View file

@ -30,6 +30,7 @@ package mage.players;
import java.util.LinkedHashMap;
import java.util.UUID;
import java.util.Map.Entry;
/**
*
@ -40,8 +41,8 @@ public class Players extends LinkedHashMap<UUID, Player> {
public Players() {}
public Players(final Players players) {
for (UUID id: players.keySet()) {
this.put(id, players.get(id).copy());
for (Entry<UUID, Player> entry: players.entrySet()) {
this.put(entry.getKey(), entry.getValue().copy());
}
}