diff --git a/MekWarsClient/resources/mekwars/guiClient.properties b/MekWarsClient/resources/mekwars/guiClient.properties new file mode 100644 index 00000000..b90857bc --- /dev/null +++ b/MekWarsClient/resources/mekwars/guiClient.properties @@ -0,0 +1,5 @@ +errors.noOpList.text=No OpList. This usually means that you were unable to connect to the server to fetch a copy. Do you wish to exit? +errors.badConfigDir.text=Unable to set the configuration directory, please check the application can create the directory '{0}' +errors.header.text=Startup Error! +options.exit.text=Exit +options.continue.text=Continue diff --git a/MekWarsClient/src/mekwars/client/GUIClient.java b/MekWarsClient/src/mekwars/client/GUIClient.java index cde97c8b..d95802b5 100644 --- a/MekWarsClient/src/mekwars/client/GUIClient.java +++ b/MekWarsClient/src/mekwars/client/GUIClient.java @@ -27,6 +27,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Locale; +import java.util.ResourceBundle; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JLabel; @@ -57,10 +58,12 @@ public class GUIClient { private GUIClientConfig config; private CMainFrame mainFrame; private Locale locale = Locale.US; + private ResourceBundle resourceMap; public GUIClient(MWClient mwClient, GUIClientConfig config) { this.mwClient = mwClient; this.config = config; + this.resourceMap = ResourceBundle.getBundle("mekwars.guiClient", locale); } public void init() { @@ -98,6 +101,10 @@ public Locale getLocale() { return locale; } + public String getResourceString(String string) { + return resourceMap.getString(string); + } + /* * Rewritten in order to allow ConfigPage to reset the skin on the fly. * diff --git a/MekWarsClient/src/mekwars/client/MWClient.java b/MekWarsClient/src/mekwars/client/MWClient.java index 66217463..426828b3 100644 --- a/MekWarsClient/src/mekwars/client/MWClient.java +++ b/MekWarsClient/src/mekwars/client/MWClient.java @@ -40,6 +40,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.security.MessageDigest; +import java.text.MessageFormat; import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -1271,16 +1272,30 @@ public void setLastPing(long lastping) { LastPing = lastping; } - /* + /** * Connect the DataFetcher to the server and get all relevent information from it. */ public void connectDataFetcher() { try { FileSystem.getInstance().setConfigDir(Config); - dataFetcher = new DataFetchClient(Integer.parseInt(Config - .getParam("DATAPORT")), Integer.parseInt(Config - .getParam("SOCKETTIMEOUTDELAY"))); + } catch (IOException exception) { + LOGGER.error("Unable to set config directory", exception); + JOptionPane.showMessageDialog( + null, + MessageFormat.format( + guiClient.getResourceString("errors.badConfigDir.text"), + Config + ), + guiClient.getResourceString("errors.header.text"), + JOptionPane.ERROR_MESSAGE + ); + System.exit(0); + } + dataFetcher = new DataFetchClient(Integer.parseInt(Config + .getParam("DATAPORT")), Integer.parseInt(Config + .getParam("SOCKETTIMEOUTDELAY"))); + try { BufferedReader dis = new BufferedReader(new InputStreamReader( new FileInputStream(FileSystem.getInstance().getDataLastUpdated().toString() ))); @@ -1288,7 +1303,7 @@ public void connectDataFetcher() { dataFetcher.setLastTimestamp(lastTS); dis.close(); } catch (Exception exception) { - LOGGER.error("Couldn't read timestamp of last datafetch. Will need to fetch all planetchanges since last full update.", exception); + LOGGER.warn("Couldn't read timestamp of last datafetch. Will need to fetch all planetchanges since last full update.", exception); } // Start the data fetcher, get ops/map/etc @@ -1302,13 +1317,15 @@ public void connectDataFetcher() { try { dataFetcher.checkForMostRecentOpList(); } catch (IOException e) { - Object[] options = { "Exit", "Continue" }; + Object[] options = { + guiClient.getResourceString("options.exit.text"), + guiClient.getResourceString("options.continue.text"), + }; int selectedValue = JOptionPane .showOptionDialog( null, - "No OpList. This usually means that you were unable to " - + "connect to the server to fetch a copy. Do you wish to exit?", - "Startup " + "error!", + guiClient.getResourceString("errors.header.text"), + guiClient.getResourceString("errors.noOpList.text"), JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]); @@ -2825,7 +2842,6 @@ public int getMinPlanetOwnerShip(Planet p) { } public int getTotalRepairCosts(Entity unit) { - int cost = 0; int systemCrits = 0; int engineCrits = 0; @@ -2918,76 +2934,10 @@ public void setServerOpFlags(StringTokenizer st) { } public int getTechLaborCosts(Entity unit, int techType) { - int cost = 0; int techCost = Integer.parseInt(getServerConfigs(UnitUtils .techDescription(techType) + "TechRepairCost")); - int totalCrits = 0; - boolean damagedEngine = false; - - for (int critLocation = 0; critLocation < unit.locations(); critLocation++) { - // These three location have rear armor so the user might be - // selecting that armor instead of crit. - if ((critLocation == Mech.LOC_CT) || (critLocation == Mech.LOC_LT) - || (critLocation == Mech.LOC_RT)) { - if (unit.getArmor(critLocation, false) != unit.getOArmor( - critLocation, false)) { - cost += techCost; - } - if (unit.getArmor(critLocation, true) != unit.getOArmor( - critLocation, true)) { - cost += techCost; - } - if (unit.getInternal(critLocation) != unit - .getOInternal(critLocation)) { - cost += techCost; - } - }// end toros armor - else { - if (unit.getArmor(critLocation, false) != unit.getOArmor( - critLocation, false)) { - cost += techCost; - } - if (unit.getInternal(critLocation) != unit - .getOInternal(critLocation)) { - cost += techCost; - } - }// end armor - // check for damage system crits. - for (int critSlot = 0; critSlot < unit - .getNumberOfCriticals(critLocation); critSlot++) { - - CriticalSlot cs = unit.getCritical(critLocation, critSlot); - - if (cs == null) { - continue; - } - - if (cs.isBreached()) { - continue; - } - - if (!cs.isDamaged()) { - continue; - } - - if (UnitUtils.isEngineCrit(cs)) { - damagedEngine = true; - continue; - } - totalCrits++; - - }// end slot for - }// end location for - - // check for damaged engines - if (damagedEngine) { - totalCrits = +UnitUtils.getNumberOfEngineCrits(unit); - } - - cost += (techCost * totalCrits) + techCost; - - return cost; + return UnitUtils.getTechLaborCosts(unit, techCost); } public void retrieveOpData(String type, String data) { @@ -3092,7 +3042,6 @@ public HashMap getBlackMarketEquipmentList() { } public void updatePartsBlackMarket(String data, int year) { - StringTokenizer ST = new StringTokenizer(data, "#"); boolean allowTechCrossOver = Boolean.parseBoolean(this .getServerConfigs("AllowCrossOverTech")); diff --git a/MekWarsClient/src/mekwars/client/campaign/CCampaign.java b/MekWarsClient/src/mekwars/client/campaign/CCampaign.java index 0bde5a92..418b7eeb 100644 --- a/MekWarsClient/src/mekwars/client/campaign/CCampaign.java +++ b/MekWarsClient/src/mekwars/client/campaign/CCampaign.java @@ -48,12 +48,6 @@ public class CCampaign { public CCampaign(MWClient client) { mwclient = client; Player = new CPlayer(mwclient); - File f = new File(MWClient.CAMPAIGN_PATH); - if (f.exists() && !f.isDirectory()) {f.delete();} - if (!f.exists()) { - try {f.mkdirs();} - catch (Exception e) {LOGGER.error("Exception: ", e);} - } } public boolean decodeCommand(String command) { diff --git a/MekWarsClient/src/mekwars/client/common/campaign/clientutils/GameHost.java b/MekWarsClient/src/mekwars/client/common/campaign/clientutils/GameHost.java index 3655ce24..c6cc9546 100644 --- a/MekWarsClient/src/mekwars/client/common/campaign/clientutils/GameHost.java +++ b/MekWarsClient/src/mekwars/client/common/campaign/clientutils/GameHost.java @@ -39,7 +39,6 @@ public abstract class GameHost implements GameListener, IGameHost { public static final int STATUS_FIGHTING = 4; public static final String CAMPAIGN_PREFIX = "/"; // prefix for campaign commands - public static final String CAMPAIGN_PATH = "data/campaign/"; public static final String COMMAND_DELIMITER = "|"; // delimiter for client commands public String myUsername = "";// public b/c used in RGTS command to set server status. HACK! diff --git a/MekWarsClient/src/mekwars/client/io/FileSystem.java b/MekWarsClient/src/mekwars/client/io/FileSystem.java index 06fe097a..776037ae 100644 --- a/MekWarsClient/src/mekwars/client/io/FileSystem.java +++ b/MekWarsClient/src/mekwars/client/io/FileSystem.java @@ -17,7 +17,9 @@ package mekwars.client.io; +import java.io.IOException; import java.nio.file.FileSystems; +import java.nio.file.Files; import java.nio.file.Path; import mekwars.common.campaign.clientutils.IClientConfig; import mekwars.common.io.AbstractFileSystem; @@ -30,8 +32,6 @@ public class FileSystem extends AbstractFileSystem { .getPath(DIRECTORY_NAME_SERVERS); public static final String FILE_NAME_DATA_LAST_UPDATED = "dataLastUpdated.dat"; - private static final Path FILE_DATA_LAST_UPDATED = FileSystems.getDefault() - .getPath(FILE_NAME_DATA_LAST_UPDATED); private static final Path[] DIRECTORIES = new Path[] { DIRECTORY_DATA, @@ -57,8 +57,11 @@ public Path getDataLastUpdated() { /** * Sets the config directory to configDir. */ - public void setConfigDir(String configDir) { - this.configDir = FileSystems.getDefault().getPath(configDir); + public void setConfigDir(String configDir) throws IOException { + Path configPath = FileSystems.getDefault().getPath(configDir); + + this.configDir = configPath; + Files.createDirectories(configPath); } /** @@ -70,7 +73,7 @@ public void setConfigDir(String configDir) { * @throws IllegalArgumentException When config does not have the SERVERIP or SERVERPORT config * values */ - public void setConfigDir(IClientConfig config) throws Exception { + public void setConfigDir(IClientConfig config) throws IOException { String serverIp = config.getParam("SERVERIP"); String serverPort = config.getParam("SERVERPORT"); @@ -82,7 +85,10 @@ public void setConfigDir(IClientConfig config) throws Exception { } String configDirName = DIRECTORY_NAME_SERVERS + serverIp + "." + serverPort; - this.configDir = FileSystems.getDefault().getPath(configDirName); + Path configPath = FileSystems.getDefault().getPath(configDirName); + + this.configDir = configPath; + Files.createDirectories(configPath); calculateChecksums(); } diff --git a/MekWarsCommon/src/mekwars/common/util/UnitUtils.java b/MekWarsCommon/src/mekwars/common/util/UnitUtils.java index d21e8e79..f0eb939f 100644 --- a/MekWarsCommon/src/mekwars/common/util/UnitUtils.java +++ b/MekWarsCommon/src/mekwars/common/util/UnitUtils.java @@ -2744,4 +2744,74 @@ public static boolean isInnerSphereOnlyAmmo(EnumSet munitionType) { ); return innersphereMunitions.containsAll(munitionType); } + + public static int getTechLaborCosts(Entity unit, int techCost) { + int cost = 0; + int totalCrits = 0; + boolean damagedEngine = false; + + for (int critLocation = 0; critLocation < unit.locations(); critLocation++) { + // These three location have rear armor so the user might be + // selecting that armor instead of crit. + if ((critLocation == Mech.LOC_CT) || (critLocation == Mech.LOC_LT) + || (critLocation == Mech.LOC_RT)) { + if (unit.getArmor(critLocation, false) != unit.getOArmor( + critLocation, false)) { + cost += techCost; + } + if (unit.getArmor(critLocation, true) != unit.getOArmor( + critLocation, true)) { + cost += techCost; + } + if (unit.getInternal(critLocation) != unit + .getOInternal(critLocation)) { + cost += techCost; + } + } else { + if (unit.getArmor(critLocation, false) != unit.getOArmor( + critLocation, false)) { + cost += techCost; + } + if (unit.getInternal(critLocation) != unit + .getOInternal(critLocation)) { + cost += techCost; + } + } + + // check for damage system crits. + for (int critSlot = 0; critSlot < unit + .getNumberOfCriticals(critLocation); critSlot++) { + + CriticalSlot cs = unit.getCritical(critLocation, critSlot); + + if (cs == null) { + continue; + } + + if (cs.isBreached()) { + continue; + } + + if (!cs.isDamaged()) { + continue; + } + + if (UnitUtils.isEngineCrit(cs)) { + damagedEngine = true; + continue; + } + totalCrits++; + + }// end slot for + }// end location for + + // check for damaged engines + if (damagedEngine) { + totalCrits = +UnitUtils.getNumberOfEngineCrits(unit); + } + + cost += (techCost * totalCrits) + techCost; + + return cost; + } }