Starting options ,
Like how, before the last update, you would just do it in the data/world/factions/player.faction file
Okay, I'll try and break down my working example, although it doesn't do everything you can do and might not be implemented in an optimal way (but it works).
package data.scripts.plugins;
import com.fs.starfarer.api.campaign.CargoAPI;
import com.fs.starfarer.api.campaign.CargoAPI.CrewXPLevel;
import com.fs.starfarer.api.characters.CharacterCreationPlugin;
import com.fs.starfarer.api.characters.MutableCharacterStatsAPI;
import java.util.ArrayList;
import java.util.List;
public class IndustryCharacterCreation extends data.scripts.plugins.CharacterCreationPluginImpl {
// Not using an enum for this because Janino doesn't support it.
// It does, apparently, support using enums defined elsewhere - just can't compile new ones.
The basic stuff for setting up the rest. As was mentioned before, this needs to be in data\scripts\plugins to work properly. I have given the class its own name, so it should not overwrite anything else and potentially become incompatibly with other mods. I extend the class in starsector-core instead of implementing the interface
characterCreationPlugin. I can't comment on what would be best to do, expecially in context with compatibility with other mods.
private ResponseImpl OPTION1 = new ResponseImpl("option 1 text");
private ResponseImpl OPTION2 = new ResponseImpl("option 2 text");
private int stage = 0;
private boolean isEntr = false;
Here we set up the fields we will use.
ResponseImpl is from the class that we extended and if you implemented the interface then you would have to make your own (could just copy-paste it from the extended class). They are the ones that the player can choose from, though we will have to specify when they are shown in
getResponses(). Aside from that we have
stage as the one in the extended class is private and then a boolean as I only wanted to show the second response if the first was selected.
@SuppressWarnings("unchecked")
@Override
public List getResponses() {
List result = new ArrayList();
if (stage == 0) {
result.add(OPTION1);
} else if (stage == 1) {
if (isEntr) {
result.add(OPTION2);
}
}
result.addAll(super.getResponses());
return result;
}
Before talking about this code, I want to mention that there is a method before it called
getPrompt(). You will only need to override it if you need to change the amount of times the player selects a response. There is also a field called
prompts that you can override if you want to change the text above options (the one asking the "questions") or change the amount of times the player selects a response.
About the code itself. The repsonses the player selects from is based of a list. This method,
getResponses(), is where we create that list. We start by creating the list and then check what stage we are in. If we're in the second stage (stage == 1) then we also check if the previous choice was our first option through our field
isEntr. After this we call the same method from our extended class and put the responses in the list that it returns in our list. Finally we return our list.
@Override
public void submit(CharacterCreationPlugin.Response response, CharacterCreationPlugin.CharacterCreationData data) {
super.submit(response, data);
stage++;
MutableCharacterStatsAPI stats = data.getPerson().getStats();
if (response == OPTION1) {
stats.addAptitudePoints(1);
stats.addSkillPoints(2);
data.getStartingCargo().getCredits().add(2000);
isEntr = true;
}
if (response == OPTION2) {
stats.addAptitudePoints(1);
stats.addSkillPoints(2);
data.addStartingShipChoice("buffalo_Standard");
data.getStartingCargo().getCredits().add(2000f);
}
}
The next method is
submit(). This method is called after a response is selected. We start with calling the same method from the extended class, in case that one of ours wasn't selected. Afterwards we increment
stage by 1 and create a variable to access player stats so we won't have to type the whole thing again. Then using an if for each possible repsonse we dertermine which response was selected and do the stuff we want to if it was one of ours. To see how to increase a specific skill or apptitude look at the extended class.
@Override
public void startingShipPicked(String variantId, CharacterCreationPlugin.CharacterCreationData data) {
if (variantId.equals("buffalo_Standard")) {
data.getStartingCargo().addFuel(20);
data.getStartingCargo().addSupplies(20);
data.getStartingCargo().addItems(CargoAPI.CargoItemType.RESOURCES, "omncompl_uncmaterial", 200);
data.getStartingCargo().addCrew(CrewXPLevel.GREEN, 10);
data.getStartingCargo().addMarines(2);
return;
}
super.startingShipPicked(variantId, data);
}
}
b]getPrompt()[/b] will return null once
stage exceeds the amount of prompts availaible. Once that happens, the player will be given a selection of ships to pick from based of the
data.addStartingShipChoice(String Variantid) method. When a ship is selected, this method will be called. We have access to the same amount of information as in
submit() and can thus do the same amount of things. In this case, I just add the starting resources including one from my mod. I added a return; in the if and only call the extended class method at the end, because it has an option if none of the ships it expected was picked and will add extra resources to our ship, which we are not interested in.
The end.