diff --git a/jars/Dynamic_Tariffs.jar b/jars/Dynamic_Tariffs.jar index 68dcc80..67ac90b 100644 Binary files a/jars/Dynamic_Tariffs.jar and b/jars/Dynamic_Tariffs.jar differ diff --git a/settings.json b/settings.json index b51e18d..ac229eb 100644 --- a/settings.json +++ b/settings.json @@ -1,6 +1,7 @@ { - "dt_percents":[30,15,10,5,2,0], - + "dt_percents":[30,25,20,15,10,5], + "dt_commission":true, + "dt_commModifier":5, "dt_whitelist":["ancyra_market","derinkuyu_market","sindria","volturn","cruor", "nortia","umbra","chicomoztoc","coatl","tigra_city","eventide", "orthrus","sphinx","asharu","jangala","corvus_IIIa","raesvelg", diff --git a/src/dynamictariffs/DynamicTariffsPlugin.java b/src/dynamictariffs/DynamicTariffsPlugin.java index eeaf05d..06973ec 100644 --- a/src/dynamictariffs/DynamicTariffsPlugin.java +++ b/src/dynamictariffs/DynamicTariffsPlugin.java @@ -20,7 +20,9 @@ public void onGameLoad(boolean newGame) { new TariffUtil(); SettingsUtil.readSettings(); for(String market : SettingsUtil.whitelist){ - TariffUtil.modifyTariff(EconUtil.getMarket(market)); + if(EconUtil.marketExists(market)){ + TariffUtil.modifyTariff(EconUtil.getMarket(market)); + } } log.info("DynamicTariffs: Loaded"); } @@ -31,7 +33,9 @@ public void onGameLoad(boolean newGame) { @Override public void beforeGameSave() { for(String market : SettingsUtil.whitelist){ - EconUtil.unmodTariffs(market); + if(EconUtil.marketExists(market)){ + EconUtil.unmodTariffs(market); + } } log.info("DynamicTariffs: Unmodified all Tariffs"); } @@ -42,7 +46,9 @@ public void beforeGameSave() { @Override public void afterGameSave() { for(String market : SettingsUtil.whitelist){ - TariffUtil.modifyTariff(EconUtil.getMarket(market)); + if(EconUtil.marketExists(market)){ + TariffUtil.modifyTariff(EconUtil.getMarket(market)); + } } log.info("DynamicTariffs: Remodified Tariffs"); } diff --git a/src/dynamictariffs/util/EconUtil.java b/src/dynamictariffs/util/EconUtil.java index c0f0c6f..6b6b3d4 100644 --- a/src/dynamictariffs/util/EconUtil.java +++ b/src/dynamictariffs/util/EconUtil.java @@ -5,6 +5,9 @@ import com.fs.starfarer.api.campaign.RepLevel; import com.fs.starfarer.api.impl.campaign.ids.Factions; +import com.fs.starfarer.api.util.Misc; + +import java.util.List; /* * This Class is just here to shorthand some common tasks when @@ -33,5 +36,24 @@ public static RepLevel getRepLevel(MarketAPI market){ public static void unmodTariffs(String marketID){ getMarket(marketID).getTariff().unmodify("dynamictariffs"); } + /* + * Scaedumar found a flaw, need to check if a market exists first + */ + public static boolean marketExists(String marketID){ + MarketAPI market = getMarket(marketID); + List markets = Global.getSector().getEconomy().getMarketsCopy(); + if(markets.contains(market)){ + return true; + } else { + return false; + } + } + /* + * Need to check if the player is commissioned with the given market faction + */ + public static boolean isCommissioned(MarketAPI market){ + String faction = market.getFactionId(); + return faction.equals(Misc.getCommissionFactionId()); + } } diff --git a/src/dynamictariffs/util/SettingsUtil.java b/src/dynamictariffs/util/SettingsUtil.java index ed394d4..88c14db 100644 --- a/src/dynamictariffs/util/SettingsUtil.java +++ b/src/dynamictariffs/util/SettingsUtil.java @@ -18,6 +18,8 @@ public class SettingsUtil { public static int[] percents = new int[6]; public static ArrayList whitelist = new ArrayList(); + public static Boolean commission = false; // States whether or not you want Tariffs to also be modified by commission + public static Integer commModifier = 0; // This will be how much the tariff should change based on commission /* * This reads in the settings.json and populates the percents and whitelist arrays */ @@ -27,6 +29,8 @@ public static void readSettings(){ JSONObject modSettings = settings.loadJSON("settings.json", "dynamictariffs"); JSONArray jsonPercents = modSettings.getJSONArray("dt_percents"); JSONArray jsonWhitelist = modSettings.getJSONArray("dt_whitelist"); + commission = modSettings.getBoolean("dt_commission"); + commModifier = modSettings.getInt("dt_commModifier"); for(int i = 0; i < jsonPercents.length(); i++){ percents[i] = jsonPercents.getInt(i); } diff --git a/src/dynamictariffs/util/TariffUtil.java b/src/dynamictariffs/util/TariffUtil.java index 4e88dc8..149ae31 100644 --- a/src/dynamictariffs/util/TariffUtil.java +++ b/src/dynamictariffs/util/TariffUtil.java @@ -24,7 +24,6 @@ public void reportPlayerOpenedMarket(MarketAPI market) { RepLevel rep = EconUtil.getRepLevel(market); log.info("DynamicTariffs: " + rep + " " + market.getTariff().getModifiedValue()); } - /* * This modifies the Tariff of a given Market based on Rep */ @@ -35,22 +34,22 @@ public static void modifyTariff(MarketAPI market){ switch(rep) { case SUSPICIOUS: - flat = getOffset(percents[0]); + flat = getOffset(percents[0], market); break; case NEUTRAL: - flat = getOffset(percents[1]); + flat = getOffset(percents[1], market); break; case FAVORABLE: - flat = getOffset(percents[2]); + flat = getOffset(percents[2], market); break; case WELCOMING: - flat = getOffset(percents[3]); + flat = getOffset(percents[3], market); break; case FRIENDLY: - flat = getOffset(percents[4]); + flat = getOffset(percents[4], market); break; case COOPERATIVE: - flat = getOffset(percents[5]); + flat = getOffset(percents[5], market); break; default: // This is to stop it warning me about the untradeable rep levels @@ -59,10 +58,18 @@ public static void modifyTariff(MarketAPI market){ market.getTariff().modifyFlat("dynamictariffs", flat); } /* - * This takes a number like 40, subtracts the vanilla tariff - * of 30 to get the offset, then turns it into something like 0.1f + * This takes a number like 40, subtracts the vanilla tariff + * of 30 to get the offset, then turns it into something like 0.1f + * If commissioned it will subtract the commission percent as well */ - public static float getOffset(float percent) { + public static float getOffset(int percent, MarketAPI market) { + if(SettingsUtil.commission && EconUtil.isCommissioned(market)){ + int result = percent - 30 - SettingsUtil.commModifier; + if(result < -30){ + return -30 / 100f; + } + return result / 100f; + } return (percent - 30) / 100f; } /*