mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
fixed possible NPEs
This commit is contained in:
parent
c0f837c2e0
commit
a327668660
7 changed files with 57 additions and 43 deletions
|
@ -250,12 +250,13 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showTables(UUID roomId) {
|
public void showTables(UUID roomId) {
|
||||||
|
|
||||||
this.roomId = roomId;
|
this.roomId = roomId;
|
||||||
session = MageFrame.getSession();
|
session = MageFrame.getSession();
|
||||||
|
UUID chatRoomId = null;
|
||||||
if (session != null) {
|
if (session != null) {
|
||||||
btnQuickStart.setVisible(session.isTestMode());
|
btnQuickStart.setVisible(session.isTestMode());
|
||||||
gameChooser.init(session);
|
gameChooser.init(session);
|
||||||
|
chatRoomId = session.getRoomChatId(roomId);
|
||||||
}
|
}
|
||||||
if (newTableDialog == null) {
|
if (newTableDialog == null) {
|
||||||
newTableDialog = new NewTableDialog();
|
newTableDialog = new NewTableDialog();
|
||||||
|
@ -269,14 +270,12 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
joinTableDialog = new JoinTableDialog();
|
joinTableDialog = new JoinTableDialog();
|
||||||
MageFrame.getDesktop().add(joinTableDialog, JLayeredPane.MODAL_LAYER);
|
MageFrame.getDesktop().add(joinTableDialog, JLayeredPane.MODAL_LAYER);
|
||||||
}
|
}
|
||||||
UUID chatRoomId = session.getRoomChatId(roomId);
|
|
||||||
if (chatRoomId != null) {
|
if (chatRoomId != null) {
|
||||||
this.chatPanel.connect(chatRoomId);
|
this.chatPanel.connect(chatRoomId);
|
||||||
startTasks();
|
startTasks();
|
||||||
this.setVisible(true);
|
this.setVisible(true);
|
||||||
this.repaint();
|
this.repaint();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
hideTables();
|
hideTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,7 @@ public class CounterPluginImpl implements CounterPlugin {
|
||||||
log.info(plugin.toString() + " has been loaded.");
|
log.info(plugin.toString() + " has been loaded.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[Game counter plugin, version 0.1]";
|
return "[Game counter plugin, version 0.1]";
|
||||||
}
|
}
|
||||||
|
@ -78,7 +79,7 @@ public class CounterPluginImpl implements CounterPlugin {
|
||||||
try {
|
try {
|
||||||
ois = new ObjectInputStream(new FileInputStream(data));
|
ois = new ObjectInputStream(new FileInputStream(data));
|
||||||
Object o = ois.readObject();
|
Object o = ois.readObject();
|
||||||
CounterBean c = null;
|
CounterBean c;
|
||||||
if (o instanceof CounterBean) {
|
if (o instanceof CounterBean) {
|
||||||
c = (CounterBean)o;
|
c = (CounterBean)o;
|
||||||
prev = c.getGamesPlayed();
|
prev = c.getGamesPlayed();
|
||||||
|
@ -129,7 +130,7 @@ public class CounterPluginImpl implements CounterPlugin {
|
||||||
c = (CounterBean)o;
|
c = (CounterBean)o;
|
||||||
}
|
}
|
||||||
ois.close();
|
ois.close();
|
||||||
return c.getGamesPlayed();
|
return c == null ? 0 : c.getGamesPlayed();
|
||||||
}
|
}
|
||||||
} catch (EOFException e) {
|
} catch (EOFException e) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -137,9 +137,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
if (game.getActivePlayerId().equals(playerId)) {
|
if (game.getActivePlayerId().equals(playerId)) {
|
||||||
if (logger.isInfoEnabled()) {
|
if (logger.isInfoEnabled()) {
|
||||||
printOutState(game, playerId);
|
printOutState(game, playerId);
|
||||||
Iterator it = game.getOpponents(playerId).iterator();
|
for (UUID opponentId : game.getOpponents(playerId)) {
|
||||||
while (it.hasNext()) {
|
|
||||||
UUID opponentId = (UUID) it.next();
|
|
||||||
printOutState(game, opponentId);
|
printOutState(game, opponentId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -395,7 +393,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
for (UUID targetId : target.possibleTargets(ability.getSourceId(), ability.getControllerId(), game)) {
|
for (UUID targetId : target.possibleTargets(ability.getSourceId(), ability.getControllerId(), game)) {
|
||||||
Game sim = game.copy();
|
Game sim = game.copy();
|
||||||
StackAbility newAbility = (StackAbility) ability.copy();
|
StackAbility newAbility = (StackAbility) ability.copy();
|
||||||
SearchEffect newEffect = getSearchEffect((StackAbility) newAbility);
|
SearchEffect newEffect = getSearchEffect(newAbility);
|
||||||
newEffect.getTarget().addTarget(targetId, newAbility, sim);
|
newEffect.getTarget().addTarget(targetId, newAbility, sim);
|
||||||
sim.getStack().push(newAbility);
|
sim.getStack().push(newAbility);
|
||||||
SimulationNode2 newNode = new SimulationNode2(node, sim, depth, ability.getControllerId());
|
SimulationNode2 newNode = new SimulationNode2(node, sim, depth, ability.getControllerId());
|
||||||
|
@ -1298,7 +1296,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void getSuggestedActions() {
|
protected final void getSuggestedActions() {
|
||||||
try {
|
try {
|
||||||
File file = new File(FILE_WITH_INSTRUCTIONS);
|
File file = new File(FILE_WITH_INSTRUCTIONS);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
|
@ -1323,7 +1321,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
@Override
|
@Override
|
||||||
public void addAction(String action) {
|
public void addAction(String action) {
|
||||||
System.out.println("adding to suggested actions: " + action);
|
System.out.println("adding to suggested actions: " + action);
|
||||||
if (action != null && action.startsWith("cast:") || action.startsWith("play:")) {
|
if (action != null && (action.startsWith("cast:") || action.startsWith("play:"))) {
|
||||||
suggested.add(action.substring(5, action.length()));
|
suggested.add(action.substring(5, action.length()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1036,8 +1036,7 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
List<Permanent> result = new ArrayList<Permanent>();
|
List<Permanent> result = new ArrayList<Permanent>();
|
||||||
for (Iterator it = list.iterator(); it.hasNext();) {
|
for (Entry<Permanent, Integer> entry : list) {
|
||||||
Entry<Permanent, Integer> entry = (Entry<Permanent, Integer>)it.next();
|
|
||||||
result.add(entry.getKey());
|
result.add(entry.getKey());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -1086,9 +1085,7 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
|
||||||
}
|
}
|
||||||
if (!choice.isChosen()) {
|
if (!choice.isChosen()) {
|
||||||
int choiceIdx = (int) (Math.random()*choice.getChoices().size()+1);
|
int choiceIdx = (int) (Math.random()*choice.getChoices().size()+1);
|
||||||
Iterator iterator = choice.getChoices().iterator();
|
for (String next : choice.getChoices()) {
|
||||||
while (iterator.hasNext()) {
|
|
||||||
String next = (String) iterator.next();
|
|
||||||
if (--choiceIdx > 0) {
|
if (--choiceIdx > 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1159,7 +1156,7 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
|
||||||
@Override
|
@Override
|
||||||
public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
|
public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
|
||||||
log.debug("chooseTarget");
|
log.debug("chooseTarget");
|
||||||
if (cards != null && cards.isEmpty()) {
|
if (cards == null || cards.isEmpty()) {
|
||||||
if (!target.isRequired()) {
|
if (!target.isRequired()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1183,7 +1180,7 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
|
||||||
@Override
|
@Override
|
||||||
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
|
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
|
||||||
log.debug("choose 2");
|
log.debug("choose 2");
|
||||||
if (cards != null && cards.isEmpty()) {
|
if (cards == null || cards.isEmpty()) {
|
||||||
if (!target.isRequired()) {
|
if (!target.isRequired()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1585,9 +1582,9 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
|
||||||
if (o1.score.equals(o2.score)) {
|
if (o1.score.equals(o2.score)) {
|
||||||
Integer i1 = RateCard.getColorManaCount(o1.card);
|
Integer i1 = RateCard.getColorManaCount(o1.card);
|
||||||
Integer i2 = RateCard.getColorManaCount(o2.card);
|
Integer i2 = RateCard.getColorManaCount(o2.card);
|
||||||
return -i1.compareTo(i2);
|
return i2.compareTo(i1);
|
||||||
}
|
}
|
||||||
return -o1.score.compareTo(o2.score);
|
return o2.score.compareTo(o1.score);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Set<String> chosenSymbols = new HashSet<String>();
|
Set<String> chosenSymbols = new HashSet<String>();
|
||||||
|
|
|
@ -111,7 +111,9 @@ public class ShapeAnew extends CardImpl<ShapeAnew> {
|
||||||
nonArtifactCards.add(card);
|
nonArtifactCards.add(card);
|
||||||
}
|
}
|
||||||
player.revealCards("Shape Anew", revealed, game);
|
player.revealCards("Shape Anew", revealed, game);
|
||||||
|
if (artifactCard != null) {
|
||||||
artifactCard.putOntoBattlefield(game, Constants.Zone.LIBRARY, source.getId(), player.getId());
|
artifactCard.putOntoBattlefield(game, Constants.Zone.LIBRARY, source.getId(), player.getId());
|
||||||
|
}
|
||||||
player.getLibrary().addAll(nonArtifactCards.getCards(game), game);
|
player.getLibrary().addAll(nonArtifactCards.getCards(game), game);
|
||||||
player.shuffleLibrary(game);
|
player.shuffleLibrary(game);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -127,7 +127,7 @@ public abstract class SearchTargetGraveyardHandLibraryForCardNameAndExileEffect
|
||||||
// cards in Library
|
// cards in Library
|
||||||
Cards cardsInLibrary = new CardsImpl(Zone.LIBRARY);
|
Cards cardsInLibrary = new CardsImpl(Zone.LIBRARY);
|
||||||
cardsInLibrary.addAll(targetPlayer.getLibrary().getCards(game));
|
cardsInLibrary.addAll(targetPlayer.getLibrary().getCards(game));
|
||||||
cardsCount = (cardName.isEmpty() ? 0 :cardsInLibrary.count(filter, game));
|
cardsCount = (cardName.isEmpty() ? 0 : cardsInLibrary.count(filter, game));
|
||||||
if (cardsCount > 0) {
|
if (cardsCount > 0) {
|
||||||
filter.setMessage("card named " + cardName + " in the library of " + targetPlayer.getName());
|
filter.setMessage("card named " + cardName + " in the library of " + targetPlayer.getName());
|
||||||
TargetCardInLibrary target = new TargetCardInLibrary(0, cardsCount, filter);
|
TargetCardInLibrary target = new TargetCardInLibrary(0, cardsCount, filter);
|
||||||
|
@ -143,9 +143,9 @@ public abstract class SearchTargetGraveyardHandLibraryForCardNameAndExileEffect
|
||||||
} else {
|
} else {
|
||||||
player.lookAtCards(targetPlayer.getName() + " library", cardsInLibrary, game);
|
player.lookAtCards(targetPlayer.getName() + " library", cardsInLibrary, game);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
targetPlayer.shuffleLibrary(game);
|
targetPlayer.shuffleLibrary(game);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,8 +65,9 @@ public abstract class Phase<T extends Phase<T>> implements Serializable {
|
||||||
this.preEvent = phase.preEvent;
|
this.preEvent = phase.preEvent;
|
||||||
this.postEvent = phase.postEvent;
|
this.postEvent = phase.postEvent;
|
||||||
this.activePlayerId = phase.activePlayerId;
|
this.activePlayerId = phase.activePlayerId;
|
||||||
if (phase.currentStep != null)
|
if (phase.currentStep != null) {
|
||||||
this.currentStep = phase.currentStep.copy();
|
this.currentStep = phase.currentStep.copy();
|
||||||
|
}
|
||||||
this.count = phase.count;
|
this.count = phase.count;
|
||||||
for (Step step: phase.steps) {
|
for (Step step: phase.steps) {
|
||||||
this.steps.add(step.copy());
|
this.steps.add(step.copy());
|
||||||
|
@ -94,24 +95,29 @@ public abstract class Phase<T extends Phase<T>> implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean play(Game game, UUID activePlayerId) {
|
public boolean play(Game game, UUID activePlayerId) {
|
||||||
if (game.isPaused() || game.isGameOver())
|
if (game.isPaused() || game.isGameOver()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
this.activePlayerId = activePlayerId;
|
this.activePlayerId = activePlayerId;
|
||||||
|
|
||||||
if (beginPhase(game, activePlayerId)) {
|
if (beginPhase(game, activePlayerId)) {
|
||||||
|
|
||||||
for (Step step: steps) {
|
for (Step step: steps) {
|
||||||
if (game.isPaused() || game.isGameOver())
|
if (game.isPaused() || game.isGameOver()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
currentStep = step;
|
currentStep = step;
|
||||||
if (!game.isSimulation() && checkStopOnStepOption(game))
|
if (!game.isSimulation() && checkStopOnStepOption(game)) {
|
||||||
return false;
|
return false;
|
||||||
if (!game.getState().getTurnMods().skipStep(activePlayerId, getStep().getType()))
|
}
|
||||||
|
if (!game.getState().getTurnMods().skipStep(activePlayerId, getStep().getType())) {
|
||||||
playStep(game);
|
playStep(game);
|
||||||
}
|
}
|
||||||
if (game.isPaused() || game.isGameOver())
|
}
|
||||||
|
if (game.isPaused() || game.isGameOver()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
count++;
|
count++;
|
||||||
endPhase(game, activePlayerId);
|
endPhase(game, activePlayerId);
|
||||||
return true;
|
return true;
|
||||||
|
@ -130,8 +136,9 @@ public abstract class Phase<T extends Phase<T>> implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean resumePlay(Game game, PhaseStep stepType, boolean wasPaused) {
|
public boolean resumePlay(Game game, PhaseStep stepType, boolean wasPaused) {
|
||||||
if (game.isPaused() || game.isGameOver())
|
if (game.isPaused() || game.isGameOver()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
this.activePlayerId = game.getActivePlayerId();
|
this.activePlayerId = game.getActivePlayerId();
|
||||||
Iterator<Step> it = steps.iterator();
|
Iterator<Step> it = steps.iterator();
|
||||||
|
@ -143,15 +150,18 @@ public abstract class Phase<T extends Phase<T>> implements Serializable {
|
||||||
resumeStep(game, wasPaused);
|
resumeStep(game, wasPaused);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
step = it.next();
|
step = it.next();
|
||||||
if (game.isPaused() || game.isGameOver())
|
if (game.isPaused() || game.isGameOver()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
currentStep = step;
|
currentStep = step;
|
||||||
if (!game.getState().getTurnMods().skipStep(activePlayerId, currentStep.getType()))
|
if (!game.getState().getTurnMods().skipStep(activePlayerId, currentStep.getType())) {
|
||||||
playStep(game);
|
playStep(game);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (game.isPaused() || game.isGameOver())
|
if (game.isPaused() || game.isGameOver()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
count++;
|
count++;
|
||||||
endPhase(game, activePlayerId);
|
endPhase(game, activePlayerId);
|
||||||
return true;
|
return true;
|
||||||
|
@ -184,17 +194,21 @@ public abstract class Phase<T extends Phase<T>> implements Serializable {
|
||||||
protected void playStep(Game game) {
|
protected void playStep(Game game) {
|
||||||
if (!currentStep.skipStep(game, activePlayerId)) {
|
if (!currentStep.skipStep(game, activePlayerId)) {
|
||||||
prePriority(game, activePlayerId);
|
prePriority(game, activePlayerId);
|
||||||
if (!game.isPaused() && !game.isGameOver())
|
if (!game.isPaused() && !game.isGameOver()) {
|
||||||
currentStep.priority(game, activePlayerId, false);
|
currentStep.priority(game, activePlayerId, false);
|
||||||
if (!game.isPaused() && !game.isGameOver())
|
}
|
||||||
|
if (!game.isPaused() && !game.isGameOver()) {
|
||||||
postPriority(game, activePlayerId);
|
postPriority(game, activePlayerId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void resumeStep(Game game, boolean wasPaused) {
|
protected void resumeStep(Game game, boolean wasPaused) {
|
||||||
boolean resuming = true;
|
boolean resuming = true;
|
||||||
if (currentStep == null || currentStep.getStepPart() == null)
|
if (currentStep == null || currentStep.getStepPart() == null) {
|
||||||
game.end();
|
game.end();
|
||||||
|
return;
|
||||||
|
}
|
||||||
switch (currentStep.getStepPart()) {
|
switch (currentStep.getStepPart()) {
|
||||||
case PRE:
|
case PRE:
|
||||||
if (wasPaused) {
|
if (wasPaused) {
|
||||||
|
@ -205,19 +219,22 @@ public abstract class Phase<T extends Phase<T>> implements Serializable {
|
||||||
prePriority(game, activePlayerId);
|
prePriority(game, activePlayerId);
|
||||||
}
|
}
|
||||||
case PRIORITY:
|
case PRIORITY:
|
||||||
if (!game.isPaused() && !game.isGameOver())
|
if (!game.isPaused() && !game.isGameOver()) {
|
||||||
currentStep.priority(game, activePlayerId, resuming);
|
currentStep.priority(game, activePlayerId, resuming);
|
||||||
|
}
|
||||||
case POST:
|
case POST:
|
||||||
if (!game.isPaused() && !game.isGameOver())
|
if (!game.isPaused() && !game.isGameOver()) {
|
||||||
postPriority(game, activePlayerId);
|
postPriority(game, activePlayerId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void playExtraSteps(Game game, PhaseStep afterStep) {
|
private void playExtraSteps(Game game, PhaseStep afterStep) {
|
||||||
while (true) {
|
while (true) {
|
||||||
Step extraStep = game.getState().getTurnMods().extraStep(activePlayerId, afterStep);
|
Step extraStep = game.getState().getTurnMods().extraStep(activePlayerId, afterStep);
|
||||||
if (extraStep == null)
|
if (extraStep == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
currentStep = extraStep;
|
currentStep = extraStep;
|
||||||
playStep(game);
|
playStep(game);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue