Merge origin/master

This commit is contained in:
fireshoes 2015-06-24 11:18:54 -05:00
commit 8a1a600a74
11 changed files with 290 additions and 89 deletions

View file

@ -27,6 +27,57 @@
*/ */
package mage.client; package mage.client;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.SplashScreen;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.beans.PropertyVetoException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.prefs.Preferences;
import javax.imageio.ImageIO;
import javax.swing.AbstractButton;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JToggleButton;
import javax.swing.JToolBar.Separator;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import mage.cards.decks.Deck; import mage.cards.decks.Deck;
import mage.cards.repository.CardCriteria; import mage.cards.repository.CardCriteria;
import mage.cards.repository.CardInfo; import mage.cards.repository.CardInfo;
@ -42,7 +93,14 @@ import mage.client.components.tray.MageTray;
import mage.client.constants.Constants.DeckEditorMode; import mage.client.constants.Constants.DeckEditorMode;
import mage.client.deckeditor.DeckEditorPane; import mage.client.deckeditor.DeckEditorPane;
import mage.client.deckeditor.collection.viewer.CollectionViewerPane; import mage.client.deckeditor.collection.viewer.CollectionViewerPane;
import mage.client.dialog.*; import mage.client.dialog.AboutDialog;
import mage.client.dialog.ConnectDialog;
import mage.client.dialog.ErrorDialog;
import mage.client.dialog.FeedbackDialog;
import mage.client.dialog.GameEndDialog;
import mage.client.dialog.PreferencesDialog;
import mage.client.dialog.TableWaitingDialog;
import mage.client.dialog.UserRequestDialog;
import mage.client.draft.DraftPane; import mage.client.draft.DraftPane;
import mage.client.draft.DraftPanel; import mage.client.draft.DraftPanel;
import mage.client.game.GamePane; import mage.client.game.GamePane;
@ -67,37 +125,16 @@ import mage.remote.Session;
import mage.remote.SessionImpl; import mage.remote.SessionImpl;
import mage.utils.MageVersion; import mage.utils.MageVersion;
import mage.view.GameEndView; import mage.view.GameEndView;
import mage.view.UserRequestMessage;
import net.java.truevfs.access.TArchiveDetector;
import net.java.truevfs.access.TConfig;
import net.java.truevfs.kernel.spec.FsAccessOption;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.mage.card.arcane.ManaSymbols; import org.mage.card.arcane.ManaSymbols;
import org.mage.plugins.card.constants.Constants; import org.mage.plugins.card.constants.Constants;
import org.mage.plugins.card.images.DownloadPictures; import org.mage.plugins.card.images.DownloadPictures;
import org.mage.plugins.card.utils.impl.ImageManagerImpl; import org.mage.plugins.card.utils.impl.ImageManagerImpl;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.JToolBar.Separator;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.beans.PropertyVetoException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.prefs.Preferences;
import static mage.client.dialog.PreferencesDialog.KEY_CONNECT_FLAG;
import mage.view.UserRequestMessage;
import net.java.truevfs.access.TArchiveDetector;
import net.java.truevfs.access.TConfig;
import net.java.truevfs.kernel.spec.FsAccessOption;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
@ -521,7 +558,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
} }
public void btnSymbolsActionPerformed(java.awt.event.ActionEvent evt) { public void btnSymbolsActionPerformed(java.awt.event.ActionEvent evt) {
if (JOptionPane.showConfirmDialog(this, "Do you want to download mana symbols?") == JOptionPane.OK_OPTION) { if (JOptionPane.showConfirmDialog(this, "Do you want to download game symbols and additional image files?", "Download additional resources", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION) {
Plugins.getInstance().downloadSymbols(); Plugins.getInstance().downloadSymbols();
} }
} }

View file

@ -1,5 +1,21 @@
package org.mage.plugins.card; package org.mage.plugins.card;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLayeredPane;
import mage.cards.MagePermanent; import mage.cards.MagePermanent;
import mage.cards.action.ActionCallback; import mage.cards.action.ActionCallback;
import mage.constants.Rarity; import mage.constants.Rarity;
@ -20,20 +36,13 @@ import org.mage.plugins.card.constants.Constants;
import org.mage.plugins.card.dl.DownloadGui; import org.mage.plugins.card.dl.DownloadGui;
import org.mage.plugins.card.dl.DownloadJob; import org.mage.plugins.card.dl.DownloadJob;
import org.mage.plugins.card.dl.Downloader; import org.mage.plugins.card.dl.Downloader;
import org.mage.plugins.card.dl.sources.CardFrames;
import org.mage.plugins.card.dl.sources.DirectLinksForDownload; import org.mage.plugins.card.dl.sources.DirectLinksForDownload;
import org.mage.plugins.card.dl.sources.GathererSets; import org.mage.plugins.card.dl.sources.GathererSets;
import org.mage.plugins.card.dl.sources.GathererSymbols; import org.mage.plugins.card.dl.sources.GathererSymbols;
import org.mage.plugins.card.images.ImageCache; import org.mage.plugins.card.images.ImageCache;
import org.mage.plugins.card.info.CardInfoPaneImpl; import org.mage.plugins.card.info.CardInfoPaneImpl;
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.util.*;
import java.util.List;
/** /**
* {@link CardPlugin} implementation. * {@link CardPlugin} implementation.
* *
@ -496,6 +505,11 @@ public class CardPluginImpl implements CardPlugin {
g.getDownloader().add(job); g.getDownloader().add(job);
} }
it = new CardFrames(imagesPath);
for(DownloadJob job:it) {
g.getDownloader().add(job);
}
it = new DirectLinksForDownload(imagesPath); it = new DirectLinksForDownload(imagesPath);
for(DownloadJob job:it) { for(DownloadJob job:it) {
g.getDownloader().add(job); g.getDownloader().add(job);

View file

@ -15,12 +15,11 @@ import java.io.OutputStream;
import java.net.Proxy; import java.net.Proxy;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import javax.swing.BoundedRangeModel; import javax.swing.BoundedRangeModel;
import javax.swing.DefaultBoundedRangeModel; import javax.swing.DefaultBoundedRangeModel;
import org.mage.plugins.card.dl.beans.properties.Property; import org.mage.plugins.card.dl.beans.properties.Property;
import org.mage.plugins.card.dl.lm.AbstractLaternaBean; import org.mage.plugins.card.dl.lm.AbstractLaternaBean;
import org.mage.plugins.card.utils.CardImageUtils;
/** /**
@ -86,9 +85,11 @@ public class DownloadJob extends AbstractLaternaBean {
*/ */
public void setError(String message, Exception error) { public void setError(String message, Exception error) {
if (message == null) { if (message == null) {
message = error.toString();
message = "Download of " + this.getName() + "from " + this.getSource().toString() + " caused error: " + error.toString();
} }
log.warn(message, error); // log.warn(message, error);
log.warn(message);
this.state.setValue(State.ABORTED); this.state.setValue(State.ABORTED);
this.error.setValue(error); this.error.setValue(error);
this.message.setValue(message); this.message.setValue(message);
@ -132,11 +133,11 @@ public class DownloadJob extends AbstractLaternaBean {
} }
public static Source fromURL(final String url) { public static Source fromURL(final String url) {
return fromURL(null, url); return fromURL(CardImageUtils.getProxyFromPreferences(), url);
} }
public static Source fromURL(final URL url) { public static Source fromURL(final URL url) {
return fromURL(null, url); return fromURL(CardImageUtils.getProxyFromPreferences(), url);
} }
public static Source fromURL(final Proxy proxy, final String url) { public static Source fromURL(final Proxy proxy, final String url) {
@ -159,6 +160,12 @@ public class DownloadJob extends AbstractLaternaBean {
public int length() throws IOException { public int length() throws IOException {
return getConnection().getContentLength(); return getConnection().getContentLength();
} }
@Override
public String toString() {
return proxy != null ? proxy.type().toString()+" " :"" + url;
}
}; };
} }
@ -182,6 +189,11 @@ public class DownloadJob extends AbstractLaternaBean {
public int length() throws IOException { public int length() throws IOException {
return getConnection().getContentLength(); return getConnection().getContentLength();
} }
@Override
public String toString() {
return proxy != null ? proxy.type().toString()+" " :"" + url;
}
}; };
} }

View file

@ -11,6 +11,7 @@ import java.io.BufferedOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.ConnectException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -158,6 +159,14 @@ public class Downloader extends AbstractLaternaBean implements Disposable {
} }
} }
job.setState(State.FINISHED); job.setState(State.FINISHED);
} catch(ConnectException ex) {
String message;
if (ex.getMessage() != null) {
message = ex.getMessage();
} else {
message = "Unknown error";
}
logger.warn("Error resource download " + job.getName() +" from "+ job.getSource().toString() + ": " + message);
} catch(IOException ex) { } catch(IOException ex) {
job.setError(ex); job.setError(ex);
} }

View file

@ -0,0 +1,100 @@
/*
* Copyright 2010 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 org.mage.plugins.card.dl.sources;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import org.mage.plugins.card.dl.DownloadJob;
import static org.mage.plugins.card.dl.DownloadJob.fromURL;
import static org.mage.plugins.card.dl.DownloadJob.toFile;
/**
*
* @author LevelX2
*/
public class CardFrames implements Iterable<DownloadJob> {
private static final String FRAMES_PATH = File.separator + "frames";
private static final File DEFAULT_OUT_DIR = new File("plugins" + File.separator + "images" + FRAMES_PATH);
private static File outDir = DEFAULT_OUT_DIR;
static final String BASE_DOWNLOAD_URL = "http://ct-magefree.rhcloud.com/resources/img/";
static final String TEXTURES_FOLDER = "textures";
static final String PT_BOXES_FOLDER = "pt";
private static final String[] TEXTURES = {"U", "R", "G", "B", "W", "A",
"BG_LAND", "BR_LAND", "WU_LAND", "WB_LAND", "UB_LAND", "GW_LAND", "RW_LAND",
"RG_LAND", "GU_LAND", "UR_LAND"
// NOT => "BW_LAND","BU_LAND","WG_LAND","WR_LAND",
};
private static final String[] PT_BOXES = {"U", "R", "G", "B", "W", "A"};
public CardFrames(String path) {
if (path == null) {
useDefaultDir();
} else {
changeOutDir(path);
}
}
@Override
public Iterator<DownloadJob> iterator() {
ArrayList<DownloadJob> jobs = new ArrayList<>();
for (String texture : TEXTURES) {
jobs.add(generateDownloadJob(TEXTURES_FOLDER, texture));
}
for (String pt_box : PT_BOXES) {
jobs.add(generateDownloadJob(PT_BOXES_FOLDER, pt_box));
}
return jobs.iterator();
}
private DownloadJob generateDownloadJob(String dirName, String name) {
File dst = new File(outDir, name + ".png");
String url = BASE_DOWNLOAD_URL + dirName + "/" + name + ".png";
return new DownloadJob("frames-" + dirName + "-" + name, fromURL(url), toFile(dst));
}
private void useDefaultDir() {
outDir = DEFAULT_OUT_DIR;
}
private void changeOutDir(String path) {
File file = new File(path + FRAMES_PATH);
if (file.exists()) {
outDir = file;
} else {
file.mkdirs();
if (file.exists()) {
outDir = file;
}
}
}
}

View file

@ -8,12 +8,10 @@ package org.mage.plugins.card.dl.sources;
import com.google.common.collect.AbstractIterator; import com.google.common.collect.AbstractIterator;
import org.mage.plugins.card.dl.DownloadJob;
import java.io.File; import java.io.File;
import java.util.Iterator;
import static java.lang.String.format; import static java.lang.String.format;
import java.util.Iterator;
import org.mage.plugins.card.dl.DownloadJob;
import static org.mage.plugins.card.dl.DownloadJob.fromURL; import static org.mage.plugins.card.dl.DownloadJob.fromURL;
import static org.mage.plugins.card.dl.DownloadJob.toFile; import static org.mage.plugins.card.dl.DownloadJob.toFile;
@ -70,7 +68,9 @@ public class GathererSymbols implements Iterable<DownloadJob> {
sym = "" + (numeric++); sym = "" + (numeric++);
} else { } else {
sizeIndex++; sizeIndex++;
if(sizeIndex == sizes.length) return endOfData(); if(sizeIndex == sizes.length) {
return endOfData();
}
symIndex = 0; symIndex = 0;
numeric = 0; numeric = 0;
@ -80,9 +80,17 @@ public class GathererSymbols implements Iterable<DownloadJob> {
String symbol = sym.replaceAll("/", ""); String symbol = sym.replaceAll("/", "");
File dst = new File(dir, symbol + ".jpg"); File dst = new File(dir, symbol + ".jpg");
if(symbol.equals("T")) symbol = "tap"; switch (symbol) {
else if(symbol.equals("Q")) symbol = "untap"; case "T":
else if(symbol.equals("S")) symbol = "snow"; symbol = "tap";
break;
case "Q":
symbol = "untap";
break;
case "S":
symbol = "snow";
break;
}
String url = format(urlFmt, sizes[sizeIndex], symbol); String url = format(urlFmt, sizes[sizeIndex], symbol);

View file

@ -1,8 +1,14 @@
package org.mage.plugins.card.utils; package org.mage.plugins.card.utils;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.HashMap; import java.util.HashMap;
import java.util.prefs.Preferences;
import mage.client.MageFrame;
import mage.client.constants.Constants; import mage.client.constants.Constants;
import mage.client.dialog.PreferencesDialog; import mage.client.dialog.PreferencesDialog;
import mage.remote.Connection;
import mage.remote.Connection.ProxyType;
import net.java.truevfs.access.TFile; import net.java.truevfs.access.TFile;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.mage.plugins.card.images.CardDownloadData; import org.mage.plugins.card.images.CardDownloadData;
@ -150,4 +156,15 @@ public class CardImageUtils {
return imageDir + TFile.separator + imageName; return imageDir + TFile.separator + imageName;
} }
public static Proxy getProxyFromPreferences() {
Preferences prefs = MageFrame.getPreferences();
Connection.ProxyType proxyType = Connection.ProxyType.valueByText(prefs.get("proxyType", "None"));
if (!proxyType.equals(ProxyType.NONE)) {
String proxyServer = prefs.get("proxyAddress", "");
int proxyPort = Integer.parseInt(prefs.get("proxyPort", "0"));
return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyServer, proxyPort));
}
return null;
}
} }

View file

@ -107,9 +107,9 @@ public class GameEndView implements Serializable {
} }
} else if (matchPlayer.getPlayer().hasIdleTimeout()) { } else if (matchPlayer.getPlayer().hasIdleTimeout()) {
if (matchPlayer.getPlayer().equals(you)) { if (matchPlayer.getPlayer().equals(you)) {
additonalText.append("You lost the match for beeing idle. "); additonalText.append("You lost the match for being idle. ");
} else { } else {
additonalText.append(matchPlayer.getName()).append(" lost for beeing idle. "); additonalText.append(matchPlayer.getName()).append(" lost for being idle. ");
} }
} else if (matchPlayer.hasQuit()) { } else if (matchPlayer.hasQuit()) {
if (matchPlayer.getPlayer().equals(you)) { if (matchPlayer.getPlayer().equals(you)) {

View file

@ -511,7 +511,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
while (!target.isChosen() && !cardsInHand.isEmpty() && target.getMaxNumberOfTargets() > target.getTargets().size()) { while (!target.isChosen() && !cardsInHand.isEmpty() && target.getMaxNumberOfTargets() > target.getTargets().size()) {
Card card = pickBestCard(cardsInHand, null, target, source, game); Card card = pickBestCard(cardsInHand, null, target, source, game);
if (card != null) { if (card != null) {
if (target.canTarget(card.getId(), source, game)) { if (target.canTarget(getId(), card.getId(), source, game)) {
target.addTarget(card.getId(), source, game); target.addTarget(card.getId(), source, game);
cardsInHand.remove(card); cardsInHand.remove(card);
if (target.isChosen()) { if (target.isChosen()) {
@ -525,7 +525,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
findPlayables(game); findPlayables(game);
if (unplayable.size() > 0) { if (unplayable.size() > 0) {
for (int i = unplayable.size() - 1; i >= 0; i--) { for (int i = unplayable.size() - 1; i >= 0; i--) {
if (target.canTarget(unplayable.values().toArray(new Card[0])[i].getId(), source, game)) { if (target.canTarget(getId(), unplayable.values().toArray(new Card[0])[i].getId(), source, game)) {
target.addTarget(unplayable.values().toArray(new Card[0])[i].getId(), source, game); target.addTarget(unplayable.values().toArray(new Card[0])[i].getId(), source, game);
if (target.isChosen()) { if (target.isChosen()) {
return true; return true;
@ -535,7 +535,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
} }
if (hand.size() > 0) { if (hand.size() > 0) {
for (int i = 0; i < hand.size(); i++) { for (int i = 0; i < hand.size(); i++) {
if (target.canTarget(hand.toArray(new UUID[0])[i], source, game)) { if (target.canTarget(getId(), hand.toArray(new UUID[0])[i], source, game)) {
target.addTarget(hand.toArray(new UUID[0])[i], source, game); target.addTarget(hand.toArray(new UUID[0])[i], source, game);
if (target.isChosen()) { if (target.isChosen()) {
return true; return true;
@ -600,13 +600,13 @@ public class ComputerPlayer extends PlayerImpl implements Player {
if (targets.isEmpty()) { if (targets.isEmpty()) {
if (outcome.isGood()) { if (outcome.isGood()) {
if (target.canTarget(abilityControllerId, source, game)) { if (target.canTarget(getId(), abilityControllerId, source, game)) {
target.addTarget(abilityControllerId, source, game); target.addTarget(abilityControllerId, source, game);
return true; return true;
} }
} }
else { else {
if (target.canTarget(opponentId, source, game)) { if (target.canTarget(getId(), opponentId, source, game)) {
target.addTarget(opponentId, source, game); target.addTarget(opponentId, source, game);
return true; return true;
} }
@ -627,13 +627,13 @@ public class ComputerPlayer extends PlayerImpl implements Player {
} }
if (outcome.isGood()) { if (outcome.isGood()) {
if (target.canTarget(abilityControllerId, source, game)) { if (target.canTarget(getId(),abilityControllerId, source, game)) {
target.addTarget(abilityControllerId, source, game); target.addTarget(abilityControllerId, source, game);
return true; return true;
} }
} }
else { else {
if (target.canTarget(opponentId, source, game)) { if (target.canTarget(getId(),opponentId, source, game)) {
target.addTarget(opponentId, source, game); target.addTarget(opponentId, source, game);
return true; return true;
} }
@ -757,7 +757,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
targets = game.getBattlefield().getActivePermanents(new FilterPlaneswalkerPermanent(), opponentId, game); targets = game.getBattlefield().getActivePermanents(new FilterPlaneswalkerPermanent(), opponentId, game);
if (targets != null && !targets.isEmpty()) { if (targets != null && !targets.isEmpty()) {
for (Permanent planeswalker: targets) { for (Permanent planeswalker: targets) {
if (target.canTarget(planeswalker.getId(), source, game)) { if (target.canTarget(getId(),planeswalker.getId(), source, game)) {
target.addTarget(planeswalker.getId(), source, game); target.addTarget(planeswalker.getId(), source, game);
} }
if (target.isChosen()) { if (target.isChosen()) {
@ -766,7 +766,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
} }
} }
if (!target.isChosen()) { if (!target.isChosen()) {
if (target.canTarget(opponentId, source, game)) { if (target.canTarget(getId() ,opponentId, source, game)) {
target.addTarget(opponentId, source, game); target.addTarget(opponentId, source, game);
} }
} }
@ -818,7 +818,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
card = pickWorstCard(cards, null, target, source, game); card = pickWorstCard(cards, null, target, source, game);
} }
if (source != null) { if (source != null) {
if (target.canTarget(this.getId(), card.getId(), source, game)) { if (target.canTarget(getId(), card.getId(), source, game)) {
return card; return card;
} }
} }
@ -849,21 +849,21 @@ public class ComputerPlayer extends PlayerImpl implements Player {
targets = threats(opponentId, source.getSourceId(), new FilterCreaturePermanent(), game, target.getTargets()); targets = threats(opponentId, source.getSourceId(), new FilterCreaturePermanent(), game, target.getTargets());
} }
for (Permanent permanent: targets) { for (Permanent permanent: targets) {
if (target.canTarget(permanent.getId(), source, game)) { if (target.canTarget(getId() ,permanent.getId(), source, game)) {
if (permanent.getToughness().getValue() <= target.getAmountRemaining()) { if (permanent.getToughness().getValue() <= target.getAmountRemaining()) {
target.addTarget(permanent.getId(), permanent.getToughness().getValue(), source, game); target.addTarget(permanent.getId(), permanent.getToughness().getValue(), source, game);
return true; return true;
} }
} }
} }
if (outcome.isGood() && target.canTarget(playerId, playerId, source, game)) { if (outcome.isGood() && target.canTarget(getId(), getId(), source, game)) {
target.addTarget(opponentId, target.getAmountRemaining(), source, game); target.addTarget(opponentId, target.getAmountRemaining(), source, game);
return true; return true;
} else if (target.canTarget(playerId, opponentId, source, game)){ } else if (target.canTarget(getId(), opponentId, source, game)){
// no permanent target so take opponent // no permanent target so take opponent
target.addTarget(opponentId, target.getAmountRemaining(), source, game); target.addTarget(opponentId, target.getAmountRemaining(), source, game);
return true; return true;
} else if (target.canTarget(playerId, playerId, source, game)) { } else if (target.canTarget(getId(), playerId, source, game)) {
target.addTarget(opponentId, target.getAmountRemaining(), source, game); target.addTarget(opponentId, target.getAmountRemaining(), source, game);
return true; return true;
} }
@ -1778,7 +1778,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
} else if (score > maxScore) { // we need better card } else if (score > maxScore) { // we need better card
if (target != null && source != null && game != null) { if (target != null && source != null && game != null) {
// but also check it can be targeted // but also check it can be targeted
betterCard = target.canTarget(card.getId(), source, game); betterCard = target.canTarget(getId(), card.getId(), source, game);
} else { } else {
// target object wasn't provided, so acceptings it anyway // target object wasn't provided, so acceptings it anyway
betterCard = true; betterCard = true;
@ -1807,7 +1807,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
} else if (score < minScore) { // we need worse card } else if (score < minScore) { // we need worse card
if (target != null && source != null && game != null) { if (target != null && source != null && game != null) {
// but also check it can be targeted // but also check it can be targeted
worseCard = target.canTarget(card.getId(), source, game); worseCard = target.canTarget(getId(), card.getId(), source, game);
} else { } else {
// target object wasn't provided, so accepting it anyway // target object wasn't provided, so accepting it anyway
worseCard = true; worseCard = true;

View file

@ -43,7 +43,6 @@ import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.CardTypePredicate; import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.players.PlayerList;
import mage.target.common.TargetCardInHand; import mage.target.common.TargetCardInHand;
/** /**
@ -76,11 +75,12 @@ class ShowAndTellEffect extends OneShotEffect {
private static final FilterCard filter = new FilterCard("artifact, creature, enchantment, or land card"); private static final FilterCard filter = new FilterCard("artifact, creature, enchantment, or land card");
static { static {
filter.add(Predicates.or( List<CardTypePredicate> cardTypes = new ArrayList<>();
new CardTypePredicate(CardType.ARTIFACT), cardTypes.add(new CardTypePredicate(CardType.ARTIFACT));
new CardTypePredicate(CardType.CREATURE), cardTypes.add(new CardTypePredicate(CardType.CREATURE));
new CardTypePredicate(CardType.ENCHANTMENT), cardTypes.add(new CardTypePredicate(CardType.ENCHANTMENT));
new CardTypePredicate(CardType.LAND))); cardTypes.add(new CardTypePredicate(CardType.LAND));
filter.add(Predicates.or(cardTypes));
} }
public ShowAndTellEffect() { public ShowAndTellEffect() {
@ -105,24 +105,23 @@ class ShowAndTellEffect extends OneShotEffect {
} }
List<Card> cardsToPutIntoPlay = new ArrayList<>(); List<Card> cardsToPutIntoPlay = new ArrayList<>();
TargetCardInHand target = new TargetCardInHand(filter); TargetCardInHand target = new TargetCardInHand(filter);
PlayerList playerList = game.getPlayerList().copy();
playerList.setCurrent(game.getActivePlayerId()); for(UUID playerId: game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(game.getActivePlayerId()); Player player = game.getPlayer(playerId);
do { if (player != null) {
if (player.chooseUse(outcome, "Put an artifact, creature, enchantment, or land card from hand onto the battlefield?", game)) { if (player.chooseUse(outcome, "Put an artifact, creature, enchantment, or land card from hand onto the battlefield?", game)) {
target.clearChosen(); target.clearChosen();
if (player.chooseTarget(outcome, target, source, game)) { if (player.chooseTarget(outcome, target, source, game)) {
Card card = game.getCard(target.getFirstTarget()); Card card = game.getCard(target.getFirstTarget());
if (card != null) { if (card != null) {
cardsToPutIntoPlay.add(card); cardsToPutIntoPlay.add(card);
}
} }
} }
} }
player = playerList.getNextInRange(controller, game); }
} while (!player.getId().equals(game.getActivePlayerId()));
for (Card card: cardsToPutIntoPlay) { for (Card card: cardsToPutIntoPlay) {
player = game.getPlayer(card.getOwnerId()); Player player = game.getPlayer(card.getOwnerId());
if (player != null) { if (player != null) {
player.putOntoBattlefieldWithInfo(card, game, Zone.HAND, source.getSourceId()); player.putOntoBattlefieldWithInfo(card, game, Zone.HAND, source.getSourceId());
} }

View file

@ -48,6 +48,11 @@ public class RenownAbility extends TriggeredAbilityImpl {
return event.getType() == GameEvent.EventType.DAMAGED_PLAYER; return event.getType() == GameEvent.EventType.DAMAGED_PLAYER;
} }
@Override
public boolean checkInterveningIfClause(Game game) {
return getSourceObject(game) != null && !((Permanent)getSourceObject(game)).isRenown();
}
@Override @Override
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
return event.getSourceId().equals(getSourceId()) return event.getSourceId().equals(getSourceId())
@ -83,7 +88,7 @@ class BecomeRenownSourceEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId()); Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null && !permanent.isRenown() && source instanceof RenownAbility) { if (permanent != null && source instanceof RenownAbility) {
game.informPlayers(permanent.getLogName() + " is now renown"); game.informPlayers(permanent.getLogName() + " is now renown");
int renownValue = ((RenownAbility) source).getRenownValue(); int renownValue = ((RenownAbility) source).getRenownValue();
// handle renown = X // handle renown = X