Skip to content

Commit

Permalink
Properly added AddMarineXP command
Browse files Browse the repository at this point in the history
  • Loading branch information
LazyWizard committed Oct 5, 2024
1 parent b43f781 commit 9199122
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 43 deletions.
75 changes: 75 additions & 0 deletions src/main/java/org/lazywizard/console/commands/AddMarineXP.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.lazywizard.console.commands;

import com.fs.starfarer.api.impl.PlayerFleetPersonnelTracker;
import com.fs.starfarer.api.impl.PlayerFleetPersonnelTracker.PersonnelData;
import org.lazywizard.console.BaseCommand;
import org.lazywizard.console.CommonStrings;
import org.lazywizard.console.Console;

import static org.lazywizard.console.CommandUtils.format;
import static org.lazywizard.console.CommandUtils.isFloat;

public class AddMarineXP implements BaseCommand
{
@Override
public CommandResult runCommand(String args, CommandContext context)
{
if (!context.isInCampaign())
{
Console.showMessage(CommonStrings.ERROR_CAMPAIGN_ONLY);
return CommandResult.WRONG_CONTEXT;
}

if (args.isEmpty())
{
final PlayerFleetPersonnelTracker tracker = PlayerFleetPersonnelTracker.getInstance();
tracker.update();
final PersonnelData marines = tracker.getMarineData();
final int numMarines = (int) marines.num;

if (numMarines <= 0)
{
Console.showMessage("You currently have no marines in your fleet.");
return CommandResult.SUCCESS;
}

Console.showMessage("You currently have " + numMarines + " marines in your fleet.\n" +
"Their combined rank is " + marines.getRank().name + ", with a total XP of " +
marines.xp + " out of a maximum of " + marines.num + ".");
return CommandResult.SUCCESS;
}

if (!isFloat(args))
{
return CommandResult.BAD_SYNTAX;
}

float amount = Float.parseFloat(args);
final PlayerFleetPersonnelTracker tracker = PlayerFleetPersonnelTracker.getInstance();
tracker.update();

final PersonnelData marines = tracker.getMarineData();
if (marines.num <= 0)
{
Console.showMessage("There are no marines in your fleet!");
return CommandResult.ERROR;
}

// Cap XP gain/loss
amount = Math.max(0, Math.min(amount, marines.num - marines.xp));
if (amount == 0)
{
Console.showMessage("Marine experience unchanged.");
return CommandResult.SUCCESS;
}

final String oldRank = marines.getRank().name;
marines.addXP(amount);
tracker.update();
final String newRank = marines.getRank().name;

Console.showMessage("Changed marines XP by " + format(amount) + ", current rank is " +
newRank + " (" + (oldRank == newRank ? "unchanged" : "was " + oldRank) + ").");
return CommandResult.SUCCESS;
}
}
6 changes: 3 additions & 3 deletions src/main/java/org/lazywizard/console/commands/AddMarines.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.campaign.CargoAPI;
import org.lazywizard.console.BaseCommand;
import org.lazywizard.console.BaseCommand.CommandContext;
import org.lazywizard.console.BaseCommand.CommandResult;
import org.lazywizard.console.CommonStrings;
import org.lazywizard.console.Console;
import static org.lazywizard.console.CommandUtils.*;

import static org.lazywizard.console.CommandUtils.format;
import static org.lazywizard.console.CommandUtils.isInteger;

public class AddMarines implements BaseCommand
{
Expand Down
38 changes: 0 additions & 38 deletions src/main/java/org/lazywizard/console/commands/AddMarinesXP.java

This file was deleted.

3 changes: 2 additions & 1 deletion src/main/mod/data/console/aliases.default
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"addmod": "addhullmod",
"addmodspec": "addhullmod",
"allmods": "allhullmods",
"allmodspecs": "allhullmods"
"allmodspecs": "allhullmods",
"addmarinesxp": "addmarinexp"
}
2 changes: 1 addition & 1 deletion src/main/mod/data/console/commands.csv
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ AddHullmod,org.lazywizard.console.commands.AddHullmod,"core,cheat,campaign",addh
AddIndustry,org.lazywizard.console.commands.AddIndustry,"core,cheat,market",addindustry <industryId> [optionalParams],"Adds an industry to a market.\nUse 'list industries' to list all valid industries."
AddItem,org.lazywizard.console.commands.AddItem,"core,cheat,campaign",additem <itemID> [optionalAmount],"Adds a resource to your fleet's cargo.\nIf no amount is specified, only one of that item will be given. For industry items or blueprints, see AddSpecial.\nSupports reversed arguments."
AddMarines,org.lazywizard.console.commands.AddMarines,"core,cheat,campaign",addmarines <amount>,"Adds the specified amount of marines to your fleet's cargo."
AddMarinesXP,org.lazywizard.console.commands.AddMarinesXP,"core,cheat,campaign",addmarinesxp <amount>,"Adds the specified amount of XP to your owned marines."
AddMarineXP,org.lazywizard.console.commands.AddMarineXP,"core,cheat,campaign",addmarinexp [optionalAmount],"Adds the specified amount of XP to your owned marines. Total XP needed to obtain all elites is the same as the number of marines you own.\nIf no amount is specified, instead prints information about your current marine force."
AddOfficer,org.lazywizard.console.commands.AddOfficer,"core,cheat,campaign",addofficer [optionalPersonality] [optionalLevel] [optionalFaction] [optionalName],"Adds an officer to your fleet. You can optionally specify his or her personality, starting level, and faction (currently only affects name/portrait). If all of these are left empty, a steady level 1 officer of the player faction will be created."
AddOrdnancePoints,org.lazywizard.console.commands.AddOrdnancePoints,"core,cheat,campaign",addordnancepoints <amount>|clear,"Adds the specified amount of ordnance points as a bonus to all ships in the player fleet. Stacks with previous uses of this command. Use 'clear' to reset the bonus."
AddShip,org.lazywizard.console.commands.AddShip,"core,cheat,campaign",addship <variantID> [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 <shipname>_Hull').\nSupports reversed arguments."
Expand Down

0 comments on commit 9199122

Please sign in to comment.