mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
remove warnings, use FileUtil to read text files
This commit is contained in:
@@ -22,8 +22,6 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.google.common.base.Supplier;
|
|
||||||
|
|
||||||
import forge.Card;
|
import forge.Card;
|
||||||
|
|
||||||
import forge.Command;
|
import forge.Command;
|
||||||
|
|||||||
@@ -805,7 +805,7 @@ public class ComputerUtilAttack {
|
|||||||
for (int i = 0; i < attackersLeft.size(); i++) {
|
for (int i = 0; i < attackersLeft.size(); i++) {
|
||||||
final Card attacker = attackersLeft.get(i);
|
final Card attacker = attackersLeft.get(i);
|
||||||
if (this.aiAggression < 5 && !attacker.hasFirstStrike() && !attacker.hasDoubleStrike()
|
if (this.aiAggression < 5 && !attacker.hasFirstStrike() && !attacker.hasDoubleStrike()
|
||||||
&& CombatUtil.getTotalFirstStrikeBlockPower(attacker, AllZone.getHumanPlayer())
|
&& CombatUtil.getTotalFirstStrikeBlockPower(attacker, ai.getOpponent())
|
||||||
>= attacker.getKillDamage()) {
|
>= attacker.getKillDamage()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -957,7 +957,7 @@ public class MagicStack extends MyObservable {
|
|||||||
AllZone.getInputControl().setInput(target);
|
AllZone.getInputControl().setInput(target);
|
||||||
} else {
|
} else {
|
||||||
// AI choosing what to haunt
|
// AI choosing what to haunt
|
||||||
final List<Card> oppCreats = CardLists.filterControlledBy(creats, AllZone.getHumanPlayer());
|
final List<Card> oppCreats = CardLists.filterControlledBy(creats, source.getController().getOpponent());
|
||||||
if (oppCreats.size() != 0) {
|
if (oppCreats.size() != 0) {
|
||||||
haunterDiesWork.setTargetCard(CardFactoryUtil.getWorstCreatureAI(oppCreats));
|
haunterDiesWork.setTargetCard(CardFactoryUtil.getWorstCreatureAI(oppCreats));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -17,27 +17,24 @@
|
|||||||
*/
|
*/
|
||||||
package forge.properties;
|
package forge.properties;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.google.common.io.Files;
|
||||||
|
|
||||||
import forge.Constant;
|
import forge.Constant;
|
||||||
import forge.Constant.Preferences;
|
import forge.Constant.Preferences;
|
||||||
import forge.gui.home.EMenuItem;
|
import forge.gui.home.EMenuItem;
|
||||||
import forge.gui.match.VMatchUI;
|
import forge.gui.match.VMatchUI;
|
||||||
import forge.gui.match.nonsingleton.VField;
|
import forge.gui.match.nonsingleton.VField;
|
||||||
import forge.gui.match.views.VDev;
|
import forge.gui.match.views.VDev;
|
||||||
|
import forge.util.FileUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds default preference values in an enum.
|
* Holds default preference values in an enum.
|
||||||
@@ -165,25 +162,16 @@ public class ForgePreferences {
|
|||||||
// This code is here temporarily to facilitate this transfer.
|
// This code is here temporarily to facilitate this transfer.
|
||||||
// After a while, this can be deleted. Doublestrike 21-5-12
|
// After a while, this can be deleted. Doublestrike 21-5-12
|
||||||
final File oldFile = new File("forge.preferences");
|
final File oldFile = new File("forge.preferences");
|
||||||
|
|
||||||
if (oldFile.exists()) {
|
if (oldFile.exists()) {
|
||||||
final File newFile = new File(NewConstants.PREFS_GLOBAL_FILE);
|
final File newFile = new File(NewConstants.PREFS_GLOBAL_FILE);
|
||||||
final InputStream in = new FileInputStream(oldFile);
|
Files.copy(oldFile, newFile);
|
||||||
final OutputStream out = new FileOutputStream(newFile);
|
|
||||||
|
|
||||||
byte[] buf = new byte[1024];
|
|
||||||
int len;
|
|
||||||
while ((len = in.read(buf)) > 0) {
|
|
||||||
out.write(buf, 0, len);
|
|
||||||
}
|
|
||||||
in.close();
|
|
||||||
out.close();
|
|
||||||
|
|
||||||
oldFile.delete();
|
oldFile.delete();
|
||||||
} // END TEMPORARY CONSOLIDATION FACILITATION
|
} // END TEMPORARY CONSOLIDATION FACILITATION
|
||||||
|
|
||||||
final BufferedReader input = new BufferedReader(new FileReader(NewConstants.PREFS_GLOBAL_FILE));
|
List<String> lines = FileUtil.readFile(NewConstants.PREFS_GLOBAL_FILE);
|
||||||
String line = null;
|
for( String line :lines ) {
|
||||||
while ((line = input.readLine()) != null) {
|
|
||||||
if (line.startsWith("#") || (line.length() == 0)) {
|
if (line.startsWith("#") || (line.length() == 0)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,18 +17,18 @@
|
|||||||
*/
|
*/
|
||||||
package forge.quest.data;
|
package forge.quest.data;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import forge.properties.ForgeProps;
|
import forge.properties.ForgeProps;
|
||||||
import forge.properties.NewConstants.Quest;
|
import forge.properties.NewConstants.Quest;
|
||||||
|
import forge.util.FileUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds default preference values in an enum. Loads preferred values when
|
* Holds default preference values in an enum. Loads preferred values when
|
||||||
@@ -226,24 +226,19 @@ public class QuestPreferences implements Serializable {
|
|||||||
/** Instantiates a QuestPreferences object. */
|
/** Instantiates a QuestPreferences object. */
|
||||||
public QuestPreferences() {
|
public QuestPreferences() {
|
||||||
this.preferenceValues = new HashMap<QPref, String>();
|
this.preferenceValues = new HashMap<QPref, String>();
|
||||||
try {
|
|
||||||
final BufferedReader input = new BufferedReader(new FileReader(ForgeProps.getFile(Quest.PREFS)));
|
List<String> lines = FileUtil.readFile(ForgeProps.getFile(Quest.PREFS));
|
||||||
String line = null;
|
|
||||||
while ((line = input.readLine()) != null) {
|
for (String line : lines ) {
|
||||||
if (line.startsWith("#") || (line.length() == 0)) {
|
if (line.startsWith("#") || (line.length() == 0)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String[] split = line.split("=");
|
final String[] split = line.split("=");
|
||||||
|
|
||||||
if (split.length == 2) {
|
if (split.length == 2) {
|
||||||
this.setPreference(split[0], split[1]);
|
this.setPreference(split[0], split[1]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (final FileNotFoundException ex) {
|
|
||||||
// ex.printStackTrace();
|
|
||||||
} catch (final IOException ex) {
|
|
||||||
// ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,18 +17,17 @@
|
|||||||
*/
|
*/
|
||||||
package forge.quest.io;
|
package forge.quest.io;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import com.esotericsoftware.minlog.Log;
|
import com.esotericsoftware.minlog.Log;
|
||||||
|
|
||||||
import forge.error.ErrorViewer;
|
|
||||||
import forge.properties.ForgeProps;
|
import forge.properties.ForgeProps;
|
||||||
import forge.properties.NewConstants;
|
import forge.properties.NewConstants;
|
||||||
|
import forge.util.FileUtil;
|
||||||
import forge.util.MyRandom;
|
import forge.util.MyRandom;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -76,61 +75,52 @@ public class ReadPriceList {
|
|||||||
* @return a {@link java.util.HashMap} object.
|
* @return a {@link java.util.HashMap} object.
|
||||||
*/
|
*/
|
||||||
private HashMap<String, Integer> readFile(final File file) {
|
private HashMap<String, Integer> readFile(final File file) {
|
||||||
BufferedReader in;
|
|
||||||
final HashMap<String, Integer> map = new HashMap<String, Integer>();
|
final HashMap<String, Integer> map = new HashMap<String, Integer>();
|
||||||
final Random r = MyRandom.getRandom();
|
final Random r = MyRandom.getRandom();
|
||||||
try {
|
|
||||||
|
List<String> lines = FileUtil.readFile(file);
|
||||||
|
for (String line : lines) {
|
||||||
|
if ( line.trim().length() == 0 ) break;
|
||||||
|
|
||||||
|
if (line.startsWith(ReadPriceList.COMMENT))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
final String[] s = line.split("=");
|
||||||
|
final String name = s[0].trim();
|
||||||
|
final String price = s[1].trim();
|
||||||
|
|
||||||
in = new BufferedReader(new FileReader(file));
|
// System.out.println("Name: " + name + ", Price: " +
|
||||||
String line = in.readLine();
|
// price);
|
||||||
|
|
||||||
// stop reading if end of file or blank line is read
|
try {
|
||||||
while ((line != null) && (line.trim().length() != 0)) {
|
int val = Integer.parseInt(price.trim());
|
||||||
if (!line.startsWith(ReadPriceList.COMMENT)) {
|
|
||||||
final String[] s = line.split("=");
|
|
||||||
final String name = s[0].trim();
|
|
||||||
final String price = s[1].trim();
|
|
||||||
|
|
||||||
// System.out.println("Name: " + name + ", Price: " +
|
if (!(name.equals("Plains") || name.equals("Island") || name.equals("Swamp")
|
||||||
// price);
|
|| name.equals("Mountain") || name.equals("Forest")
|
||||||
|
|| name.equals("Snow-Covered Plains") || name.equals("Snow-Covered Island")
|
||||||
|
|| name.equals("Snow-Covered Swamp") || name.equals("Snow-Covered Mountain") || name
|
||||||
|
.equals("Snow-Covered Forest"))) {
|
||||||
|
float ff = 0;
|
||||||
|
if (r.nextInt(100) < 90) {
|
||||||
|
ff = r.nextInt(10) * (float) .01;
|
||||||
|
} else {
|
||||||
|
// +/- 50%
|
||||||
|
ff = r.nextInt(50) * (float) .01;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
if (r.nextInt(100) < 50) {
|
||||||
int val = Integer.parseInt(price.trim());
|
val = (int) (val * (1 - ff));
|
||||||
|
} else {
|
||||||
if (!(name.equals("Plains") || name.equals("Island") || name.equals("Swamp")
|
// +ff%
|
||||||
|| name.equals("Mountain") || name.equals("Forest")
|
val = (int) (val * (1 + ff));
|
||||||
|| name.equals("Snow-Covered Plains") || name.equals("Snow-Covered Island")
|
|
||||||
|| name.equals("Snow-Covered Swamp") || name.equals("Snow-Covered Mountain") || name
|
|
||||||
.equals("Snow-Covered Forest"))) {
|
|
||||||
float ff = 0;
|
|
||||||
if (r.nextInt(100) < 90) {
|
|
||||||
ff = r.nextInt(10) * (float) .01;
|
|
||||||
} else {
|
|
||||||
// +/- 50%
|
|
||||||
ff = r.nextInt(50) * (float) .01;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (r.nextInt(100) < 50) {
|
|
||||||
val = (int) (val * (1 - ff));
|
|
||||||
} else {
|
|
||||||
// +ff%
|
|
||||||
val = (int) (val * (1 + ff));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
map.put(name, val);
|
|
||||||
} catch (final NumberFormatException nfe) {
|
|
||||||
Log.warn("NumberFormatException: " + nfe.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
line = in.readLine();
|
|
||||||
} // if
|
|
||||||
|
|
||||||
} catch (final Exception ex) {
|
|
||||||
ErrorViewer.showError(ex);
|
|
||||||
throw new RuntimeException("ReadPriceList : readFile error, " + ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
map.put(name, val);
|
||||||
|
} catch (final NumberFormatException nfe) {
|
||||||
|
Log.warn("NumberFormatException: " + nfe.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
return map;
|
return map;
|
||||||
} // readFile()
|
} // readFile()
|
||||||
|
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ public class HttpUtil {
|
|||||||
httpOut.write(bufferBytesRead);
|
httpOut.write(bufferBytesRead);
|
||||||
httpOut.flush();
|
httpOut.flush();
|
||||||
}
|
}
|
||||||
|
uploadFileReader.close();
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user