[minor] formatting

This commit is contained in:
LevelX2 2013-04-02 13:46:43 +02:00
parent 7beb02a5c1
commit de20fcb5cc
5 changed files with 96 additions and 70 deletions

View file

@ -34,15 +34,6 @@
package mage.client.game; package mage.client.game;
import mage.client.MageFrame;
import mage.client.chat.ChatPanel;
import mage.client.components.MageTextArea;
import mage.client.dialog.MageDialog;
import mage.client.util.AudioManager;
import mage.client.util.gui.ArrowBuilder;
import mage.remote.Session;
import org.apache.log4j.Logger;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.io.Serializable; import java.io.Serializable;
@ -51,6 +42,14 @@ import java.util.UUID;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import mage.client.MageFrame;
import mage.client.chat.ChatPanel;
import mage.client.components.MageTextArea;
import mage.client.dialog.MageDialog;
import mage.client.util.AudioManager;
import mage.client.util.gui.ArrowBuilder;
import mage.remote.Session;
import org.apache.log4j.Logger;
/** /**
@ -136,6 +135,7 @@ public class FeedbackPanel extends javax.swing.JPanel {
this.btnSpecial.setVisible(special); this.btnSpecial.setVisible(special);
this.btnSpecial.setText("Special"); this.btnSpecial.setText("Special");
this.helper.setSpecial("Special", special); this.helper.setSpecial("Special", special);
// Handling Phyrexian mana
if (message.contains("P}")) { if (message.contains("P}")) {
this.btnSpecial.setVisible(true); this.btnSpecial.setVisible(true);
this.btnSpecial.setText("Pay 2 life"); this.btnSpecial.setText("Pay 2 life");
@ -289,7 +289,7 @@ public class FeedbackPanel extends javax.swing.JPanel {
session.sendPlayerString(gameId, "special"); session.sendPlayerString(gameId, "special");
}//GEN-LAST:event_btnSpecialActionPerformed }//GEN-LAST:event_btnSpecialActionPerformed
private void btnUndoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSpecialActionPerformed private void btnUndoActionPerformed(java.awt.event.ActionEvent evt) {
session.undo(gameId); session.undo(gameId);
} }

View file

@ -28,6 +28,8 @@
package mage.player.human; package mage.player.human;
import java.io.Serializable;
import java.util.*;
import mage.Constants.Outcome; import mage.Constants.Outcome;
import mage.Constants.RangeOfInfluence; import mage.Constants.RangeOfInfluence;
import mage.Constants.Zone; import mage.Constants.Zone;
@ -65,8 +67,6 @@ import mage.target.common.TargetDefender;
import mage.util.ManaUtil; import mage.util.ManaUtil;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import java.io.Serializable;
import java.util.*;
/** /**
* *
@ -140,8 +140,9 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
updateGameStatePriority("chooseMulligan", game); updateGameStatePriority("chooseMulligan", game);
game.fireAskPlayerEvent(playerId, "Do you want to take a mulligan?"); game.fireAskPlayerEvent(playerId, "Do you want to take a mulligan?");
waitForBooleanResponse(); waitForBooleanResponse();
if (!abort) if (!abort) {
return response.getBoolean(); return response.getBoolean();
}
return false; return false;
} }
@ -150,8 +151,9 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
updateGameStatePriority("chooseUse", game); updateGameStatePriority("chooseUse", game);
game.fireAskPlayerEvent(playerId, message); game.fireAskPlayerEvent(playerId, message);
waitForBooleanResponse(); waitForBooleanResponse();
if (!abort) if (!abort) {
return response.getBoolean(); return response.getBoolean();
}
return false; return false;
} }
@ -164,8 +166,9 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
replacementEffectChoice.getChoices().add(count + ". " + effectText); replacementEffectChoice.getChoices().add(count + ". " + effectText);
count++; count++;
} }
if (replacementEffectChoice.getChoices().size() == 1) if (replacementEffectChoice.getChoices().size() == 1) {
return 0; return 0;
}
while (!abort) { while (!abort) {
game.fireChooseEvent(playerId, replacementEffectChoice); game.fireChooseEvent(playerId, replacementEffectChoice);
waitForResponse(); waitForResponse();
@ -174,8 +177,9 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
replacementEffectChoice.setChoice(response.getString()); replacementEffectChoice.setChoice(response.getString());
count = 1; count = 1;
for (int i = 0; i < rEffects.size(); i++) { for (int i = 0; i < rEffects.size(); i++) {
if (replacementEffectChoice.getChoice().equals(count + ". " + rEffects.get(i))) if (replacementEffectChoice.getChoice().equals(count + ". " + rEffects.get(i))) {
return i; return i;
}
count++; count++;
} }
} }
@ -302,7 +306,9 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
required = false; required = false;
} else { } else {
int count = cards.count(target.getFilter(), game); int count = cards.count(target.getFilter(), game);
if (count == 0) required = false; if (count == 0) {
required = false;
}
} }
Map<String, Serializable> options = getOptions(target); Map<String, Serializable> options = getOptions(target);
if (target.getTargets().size() > 0) { if (target.getTargets().size() > 0) {
@ -343,7 +349,9 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
required = false; required = false;
} else { } else {
int count = cards.count(target.getFilter(), game); int count = cards.count(target.getFilter(), game);
if (count == 0) required = false; if (count == 0) {
required = false;
}
} }
game.fireSelectTargetEvent(playerId, target.getMessage(), cards, target.isRequired(), null); game.fireSelectTargetEvent(playerId, target.getMessage(), cards, target.isRequired(), null);
waitForResponse(); waitForResponse();
@ -438,8 +446,9 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
waitForResponse(); waitForResponse();
if (response.getUUID() != null) { if (response.getUUID() != null) {
for (TriggeredAbility ability: abilities) { for (TriggeredAbility ability: abilities) {
if (ability.getId().equals(response.getUUID())) if (ability.getId().equals(response.getUUID())) {
return ability; return ability;
}
} }
} }
} }
@ -608,8 +617,9 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
waitForResponse(); waitForResponse();
if (response.getUUID() != null) { if (response.getUUID() != null) {
for (Permanent perm: attackers) { for (Permanent perm: attackers) {
if (perm.getId().equals(response.getUUID())) if (perm.getId().equals(response.getUUID())) {
return perm.getId(); return perm.getId();
}
} }
} }
} }
@ -625,8 +635,9 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
waitForResponse(); waitForResponse();
if (response.getUUID() != null) { if (response.getUUID() != null) {
for (Permanent perm: blockers) { for (Permanent perm: blockers) {
if (perm.getId().equals(response.getUUID())) if (perm.getId().equals(response.getUUID())) {
return perm.getId(); return perm.getId();
}
} }
} }
} }
@ -651,7 +662,9 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
int remainingDamage = damage; int remainingDamage = damage;
while (remainingDamage > 0) { while (remainingDamage > 0) {
Target target = new TargetCreatureOrPlayer(); Target target = new TargetCreatureOrPlayer();
if (singleTargetName != null) target.setTargetName(singleTargetName); if (singleTargetName != null) {
target.setTargetName(singleTargetName);
}
choose(Outcome.Damage, target, sourceId, game); choose(Outcome.Damage, target, sourceId, game);
if (targets.isEmpty() || targets.contains(target.getFirstTarget())) { if (targets.isEmpty() || targets.contains(target.getFirstTarget())) {
int damageAmount = getAmount(0, remainingDamage, "Select amount", game); int damageAmount = getAmount(0, remainingDamage, "Select amount", game);
@ -700,8 +713,9 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
game.fireGetChoiceEvent(playerId, name, new ArrayList<SpecialAction>(specialActions.values())); game.fireGetChoiceEvent(playerId, name, new ArrayList<SpecialAction>(specialActions.values()));
waitForResponse(); waitForResponse();
if (response.getUUID() != null) { if (response.getUUID() != null) {
if (specialActions.containsKey(response.getUUID())) if (specialActions.containsKey(response.getUUID())) {
activateAbility(specialActions.get(response.getUUID()), game); activateAbility(specialActions.get(response.getUUID()), game);
}
} }
} }
@ -717,8 +731,9 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
game.fireGetChoiceEvent(playerId, name, new ArrayList<ActivatedAbility>(abilities.values())); game.fireGetChoiceEvent(playerId, name, new ArrayList<ActivatedAbility>(abilities.values()));
waitForResponse(); waitForResponse();
if (response.getUUID() != null) { if (response.getUUID() != null) {
if (abilities.containsKey(response.getUUID())) if (abilities.containsKey(response.getUUID())) {
activateAbility(abilities.get(response.getUUID()), game); activateAbility(abilities.get(response.getUUID()), game);
}
} }
} }
@ -730,16 +745,18 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
Map<UUID, String> modeMap = new LinkedHashMap<UUID, String>(); Map<UUID, String> modeMap = new LinkedHashMap<UUID, String>();
for (Mode mode: modes.values()) { for (Mode mode: modes.values()) {
String modeText = mode.getEffects().getText(mode); String modeText = mode.getEffects().getText(mode);
if (obj != null) if (obj != null) {
modeText = modeText.replace("{source}", obj.getName()); modeText = modeText.replace("{source}", obj.getName());
}
modeMap.put(mode.getId(), modeText); modeMap.put(mode.getId(), modeText);
} }
game.fireGetModeEvent(playerId, "Choose Mode", modeMap); game.fireGetModeEvent(playerId, "Choose Mode", modeMap);
waitForResponse(); waitForResponse();
if (response.getUUID() != null) { if (response.getUUID() != null) {
for (Mode mode: modes.values()) { for (Mode mode: modes.values()) {
if (mode.getId().equals(response.getUUID())) if (mode.getId().equals(response.getUUID())) {
return mode; return mode;
}
} }
} }
return null; return null;
@ -752,8 +769,9 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
updateGameStatePriority("choosePile", game); updateGameStatePriority("choosePile", game);
game.fireChoosePileEvent(playerId, message, pile1, pile2); game.fireChoosePileEvent(playerId, message, pile1, pile2);
waitForBooleanResponse(); waitForBooleanResponse();
if (!abort) if (!abort) {
return response.getBoolean(); return response.getBoolean();
}
return false; return false;
} }

View file

@ -28,6 +28,7 @@
package mage.abilities.costs.mana; package mage.abilities.costs.mana;
import java.util.UUID;
import mage.Constants.ColoredManaSymbol; import mage.Constants.ColoredManaSymbol;
import mage.Constants.ManaType; import mage.Constants.ManaType;
import mage.Mana; import mage.Mana;
@ -39,7 +40,6 @@ import mage.game.Game;
import mage.players.ManaPool; import mage.players.ManaPool;
import mage.players.Player; import mage.players.Player;
import java.util.UUID;
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 {
@ -61,8 +61,9 @@ public abstract class ManaCostImpl<T extends ManaCostImpl<T>> extends CostImpl<T
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();
if (manaCost.sourceFilter != null) if (manaCost.sourceFilter != null) {
this.sourceFilter = manaCost.sourceFilter.copy(); this.sourceFilter = manaCost.sourceFilter.copy();
}
} }
@Override @Override
@ -168,27 +169,33 @@ public abstract class ManaCostImpl<T extends ManaCostImpl<T>> extends CostImpl<T
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;
} }
@ -206,10 +213,12 @@ public abstract class ManaCostImpl<T extends ManaCostImpl<T>> extends CostImpl<T
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;
} }

View file

@ -28,6 +28,7 @@
package mage.abilities.costs.mana; package mage.abilities.costs.mana;
import java.util.*;
import mage.Constants.ColoredManaSymbol; import mage.Constants.ColoredManaSymbol;
import mage.Mana; import mage.Mana;
import mage.abilities.Ability; import mage.abilities.Ability;
@ -39,7 +40,7 @@ import mage.players.ManaPool;
import mage.players.Player; import mage.players.Player;
import mage.target.Targets; import mage.target.Targets;
import java.util.*;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -115,21 +116,13 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
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.getUnpaid(), game)) if (player.playMana(this.getUnpaid(), game)) {
assignPayment(game, ability, player.getManaPool()); assignPayment(game, ability, player.getManaPool());
else }
else {
return false; return false;
}
} }
// no more needed because X costs are added to the cost during announcing of the X costs
// 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; return true;
} }
@ -156,8 +149,9 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
public ManaCosts<T> getUnpaid() { public ManaCosts<T> getUnpaid() {
ManaCosts<T> unpaid = new ManaCostsImpl<T>(); ManaCosts<T> unpaid = new ManaCostsImpl<T>();
for (T 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;
} }
@ -166,8 +160,9 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
public ManaCosts<T> getUnpaidVariableCosts() { public ManaCosts<T> getUnpaidVariableCosts() {
ManaCosts<T> unpaid = new ManaCostsImpl<T>(); ManaCosts<T> unpaid = new ManaCostsImpl<T>();
for (ManaCost cost : this) { for (ManaCost 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;
} }
@ -177,13 +172,10 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
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) {
// // add empty cost (#Issue 210)
// variableCosts.add(new VariableManaCost());
// }
return variableCosts; return variableCosts;
} }
@ -191,16 +183,18 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
public int getX() { public int getX() {
int amount = 0; int amount = 0;
List<VariableCost> variableCosts = getVariableCosts(); List<VariableCost> variableCosts = getVariableCosts();
if (!variableCosts.isEmpty()) if (!variableCosts.isEmpty()) {
amount = variableCosts.get(0).getAmount(); amount = variableCosts.get(0).getAmount();
}
return amount; return amount;
} }
@Override @Override
public void setX(int x) { public void setX(int x) {
List<VariableCost> variableCosts = getVariableCosts(); List<VariableCost> variableCosts = getVariableCosts();
if (!variableCosts.isEmpty()) if (!variableCosts.isEmpty()) {
variableCosts.get(0).setAmount(x); variableCosts.get(0).setAmount(x);
}
} }
@Override @Override
@ -251,8 +245,9 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
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("^\\{|\\}\\{|\\}$");
int modifierForX = 0; int modifierForX = 0;
for (String symbol : symbols) { for (String symbol : symbols) {
@ -261,8 +256,9 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
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 {
// check X wasn't added before // check X wasn't added before
if (modifierForX == 0) { if (modifierForX == 0) {
@ -317,8 +313,9 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
@Override @Override
public String getText() { public String getText() {
if (this.size() == 0) if (this.size() == 0) {
return ""; return "";
}
StringBuilder sbText = new StringBuilder(); StringBuilder sbText = new StringBuilder();
for (ManaCost cost : this) { for (ManaCost cost : this) {
@ -346,8 +343,9 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
@Override @Override
public boolean testPay(Mana testMana) { public boolean testPay(Mana testMana) {
for (ManaCost cost : this) { for (ManaCost cost : this) {
if (cost.testPay(testMana)) if (cost.testPay(testMana)) {
return true; return true;
}
} }
return false; return false;
} }
@ -355,8 +353,9 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
@Override @Override
public boolean canPay(UUID sourceId, UUID controllerId, Game game) { public boolean canPay(UUID sourceId, UUID controllerId, Game game) {
for (T cost : this) { for (T cost : this) {
if (!cost.canPay(sourceId, controllerId, game)) if (!cost.canPay(sourceId, controllerId, game)) {
return false; return false;
}
} }
return true; return true;
} }
@ -364,8 +363,9 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
@Override @Override
public boolean isPaid() { public boolean isPaid() {
for (T cost : this) { for (T cost : this) {
if (!((T) cost instanceof VariableManaCost) && !cost.isPaid()) if (!((T) cost instanceof VariableManaCost) && !cost.isPaid()) {
return false; return false;
}
} }
return true; return true;
} }

View file

@ -28,13 +28,14 @@
package mage.abilities.costs.mana; package mage.abilities.costs.mana;
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;
import mage.game.Game; import mage.game.Game;
import mage.players.ManaPool; import mage.players.ManaPool;
import java.util.UUID;
/** /**
* *
@ -53,13 +54,12 @@ public class PhyrexianManaCost extends ColoredManaCost {
@Override @Override
public void assignPayment(Game game, Ability ability, ManaPool pool) { public void assignPayment(Game game, Ability ability, ManaPool pool) {
if (assignColored(ability, game, pool, this.mana)) assignColored(ability, game, pool, this.mana);
return;
} }
@Override @Override
public String getText() { public String getText() {
return "{" + mana.toString() + "P}"; return new StringBuilder("{").append(mana.toString()).append("P}").toString();
} }
@Override @Override
@ -86,4 +86,3 @@ public class PhyrexianManaCost extends ColoredManaCost {
return new PhyrexianManaCost(this); return new PhyrexianManaCost(this);
} }
} }