From dd0c8e1de6159696dda3be2cb9dbe09ebcbbe040 Mon Sep 17 00:00:00 2001 From: Jaghaimo <1764586+jaghaimo@users.noreply.github.com> Date: Tue, 25 Aug 2020 13:15:27 +0100 Subject: [PATCH 1/2] Enable AddSubmarket and add RemoveSubmarket commands --- .../lazywizard/console/commands/List_.java | 4 ++ .../console/commands/RemoveSubmarket.java | 45 +++++++++++++++++++ src/main/mod/data/console/commands.csv | 2 + 3 files changed, 51 insertions(+) create mode 100644 src/main/java/org/lazywizard/console/commands/RemoveSubmarket.java diff --git a/src/main/java/org/lazywizard/console/commands/List_.java b/src/main/java/org/lazywizard/console/commands/List_.java index 0830c36..c8e8b6f 100644 --- a/src/main/java/org/lazywizard/console/commands/List_.java +++ b/src/main/java/org/lazywizard/console/commands/List_.java @@ -334,6 +334,10 @@ public CommandResult runCommand(String args, CommandContext context) ids.add(spec.getId() + " (" + spec.getName() + ")"); } break; + case "submarkets": + newLinePerItem = true; + ids = getSubmarketIds(); + break; case "officers": newLinePerItem = true; param = "officers in fleet"; diff --git a/src/main/java/org/lazywizard/console/commands/RemoveSubmarket.java b/src/main/java/org/lazywizard/console/commands/RemoveSubmarket.java new file mode 100644 index 0000000..b3477a5 --- /dev/null +++ b/src/main/java/org/lazywizard/console/commands/RemoveSubmarket.java @@ -0,0 +1,45 @@ +package org.lazywizard.console.commands; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import com.fs.starfarer.api.campaign.econ.MarketAPI; +import com.fs.starfarer.api.campaign.econ.SubmarketAPI; + +import org.lazywizard.console.BaseCommand; +import org.lazywizard.console.CommonStrings; +import org.lazywizard.console.Console; +import org.lazywizard.lazylib.CollectionUtils; + +public class RemoveSubmarket implements BaseCommand { + @Override + public CommandResult runCommand(String args, CommandContext context) { + if (!context.isInMarket()) { + Console.showMessage(CommonStrings.ERROR_MARKET_ONLY); + return CommandResult.WRONG_CONTEXT; + } + + final MarketAPI market = context.getMarket(); + if (args.isEmpty()) { + final List submarkets = new ArrayList<>(); + for (SubmarketAPI submarket : market.getSubmarketsCopy()) { + submarkets.add(submarket.getSpecId()); + } + + Collections.sort(submarkets, String.CASE_INSENSITIVE_ORDER); + Console.showMessage("Existing submarkets of current market: " + CollectionUtils.implode(submarkets) + "."); + return CommandResult.SUCCESS; + } + + final String id = args; + if (!market.hasSubmarket(id)) { + Console.showMessage("Market '" + market.getName() + "' does not have submarket '" + id + "'!"); + return CommandResult.ERROR; + } + + market.removeSubmarket(id); + Console.showMessage("Removed submarket '" + id + "' from market '" + market.getName() + "'."); + return CommandResult.SUCCESS; + } +} diff --git a/src/main/mod/data/console/commands.csv b/src/main/mod/data/console/commands.csv index c8e136e..4eac4f5 100644 --- a/src/main/mod/data/console/commands.csv +++ b/src/main/mod/data/console/commands.csv @@ -13,6 +13,7 @@ AddOrdnancePoints,org.lazywizard.console.commands.AddOrdnancePoints,"core,campai AddShip,org.lazywizard.console.commands.AddShip,"core,campaign",addship [optionalAmount],"Tries to create a ship with the supplied variant ID and adds it to your fleet. This command is case-sensitive, but it will try with different capitalization if it fails. If an amount is given, it will spawn that many ships of that ID in your fleet. Ensure you have the required supplies!\nA ship name with no variant attached will generate an empty hull (the same result as 'addship _Hull').\nSupports reversed arguments." AddSkillPoints,org.lazywizard.console.commands.AddSkillPoints,"core,campaign",addskillpoints ,"Adds the specified amount of skill points to your character." AddSpecial,org.lazywizard.console.commands.AddSpecial,"core,campaign",addspecial [optionalData],"Adds a special item to your fleet's cargo with the given data, or null data if no dara argument is passed in.\nNote that this will cause a game crash if no or invalid data is passed into an object that requires it!" +AddSubmarket,org.lazywizard.console.commands.AddSubmarket,"core,market",addsubmarket [optionalParams],"Adds a submarket to a market.\nUse 'list submarkets' to list all valid submarkets." AddSupplies,org.lazywizard.console.commands.AddSupplies,"core,campaign",addsupplies [optionalAmount],"Adds the specified amount of supplies to your fleet's cargo, or up to 50% of your current cargo capacity if no amount is entered." AddWeapon,org.lazywizard.console.commands.AddWeapon,"core,campaign",addweapon [optionalAmount],"Adds a weapon to your fleet's cargo.\nIf an amount is specified, a stack of that size will be given.\nSupports reversed arguments." AddWing,org.lazywizard.console.commands.AddWing,"core,campaign",addwing [optionalAmount],"Tries to create a wing LPC with the supplied variant ID and adds it to your fleet's cargo.\nIf an amount is given, it will spawn that many LPCs in your cargo.\nSupports reversed arguments." @@ -66,6 +67,7 @@ Reload,org.lazywizard.console.commands.ReloadConsole,"core,console",reload (no a RemoveCondition,org.lazywizard.console.commands.RemoveCondition,"core,market",removecondition ,"Removes a condition from a market.\nUse without arguments to list all existing conditions of the current market." RemoveHulks,org.lazywizard.console.commands.RemoveHulks,"core,combat",removehulks (no arguments),"Destroys all hulks on the battle map. This will affect loot and ship recovery after the battle is over!" RemoveIndustry,org.lazywizard.console.commands.RemoveIndustry,"core,market",removeindustry ,"Removes an industry from a market.\nUse without arguments to list all existing industries of the current market." +RemoveSubmarket,org.lazywizard.console.commands.RemoveSubmarket,"core,market",removesubmarket ,"Removes a submarket from a market.\nUse without arguments to list all existing submarkets of the current market." Repair,org.lazywizard.console.commands.Repair,"core,campaign,combat",repair (no arguments),"Repairs all friendly ships on the battle map if used in combat, or all ships in your fleet on the campaign map." Respec,org.lazywizard.console.commands.Respec,"core,campaign",respec [optionalOfficerNameOrNumber],"Resets skills and attributes to zero and refunds all spent points. If an argument is entered, respecs that officer. Use 'list officers' for a list of respeccable officers in your fleet." Reveal,org.lazywizard.console.commands.Reveal,"core,campaign,combat",reveal (no arguments),"Toggles fog of war on the battle map, or gives infinite sensor range on the campaign map." From 881d05ae3f720f8c7b80e7a8c7a71cc4d13e6f11 Mon Sep 17 00:00:00 2001 From: Jaghaimo <1764586+jaghaimo@users.noreply.github.com> Date: Tue, 25 Aug 2020 15:01:25 +0100 Subject: [PATCH 2/2] Remove optionalParams Co-authored-by: Robert Maguire --- src/main/mod/data/console/commands.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/mod/data/console/commands.csv b/src/main/mod/data/console/commands.csv index 4eac4f5..1bd91f7 100644 --- a/src/main/mod/data/console/commands.csv +++ b/src/main/mod/data/console/commands.csv @@ -13,7 +13,7 @@ AddOrdnancePoints,org.lazywizard.console.commands.AddOrdnancePoints,"core,campai AddShip,org.lazywizard.console.commands.AddShip,"core,campaign",addship [optionalAmount],"Tries to create a ship with the supplied variant ID and adds it to your fleet. This command is case-sensitive, but it will try with different capitalization if it fails. If an amount is given, it will spawn that many ships of that ID in your fleet. Ensure you have the required supplies!\nA ship name with no variant attached will generate an empty hull (the same result as 'addship _Hull').\nSupports reversed arguments." AddSkillPoints,org.lazywizard.console.commands.AddSkillPoints,"core,campaign",addskillpoints ,"Adds the specified amount of skill points to your character." AddSpecial,org.lazywizard.console.commands.AddSpecial,"core,campaign",addspecial [optionalData],"Adds a special item to your fleet's cargo with the given data, or null data if no dara argument is passed in.\nNote that this will cause a game crash if no or invalid data is passed into an object that requires it!" -AddSubmarket,org.lazywizard.console.commands.AddSubmarket,"core,market",addsubmarket [optionalParams],"Adds a submarket to a market.\nUse 'list submarkets' to list all valid submarkets." +AddSubmarket,org.lazywizard.console.commands.AddSubmarket,"core,market",addsubmarket ,"Adds a submarket to a market.\nUse 'list submarkets' to list all valid submarkets." AddSupplies,org.lazywizard.console.commands.AddSupplies,"core,campaign",addsupplies [optionalAmount],"Adds the specified amount of supplies to your fleet's cargo, or up to 50% of your current cargo capacity if no amount is entered." AddWeapon,org.lazywizard.console.commands.AddWeapon,"core,campaign",addweapon [optionalAmount],"Adds a weapon to your fleet's cargo.\nIf an amount is specified, a stack of that size will be given.\nSupports reversed arguments." AddWing,org.lazywizard.console.commands.AddWing,"core,campaign",addwing [optionalAmount],"Tries to create a wing LPC with the supplied variant ID and adds it to your fleet's cargo.\nIf an amount is given, it will spawn that many LPCs in your cargo.\nSupports reversed arguments."