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