Getting an error when overwriting the campaign tutorial.
Heres the error:
Spoiler
266221 [Thread-4] ERROR com.fs.starfarer.combat.CombatMain - java.lang.ClassCastException: com.fs.starfarer.api.impl.campaign.tutorial.TutorialMissionEvent cannot be cast to archeus.campaign.tutorial.ArcheusTutorialMissionEvent
java.lang.ClassCastException: com.fs.starfarer.api.impl.campaign.tutorial.TutorialMissionEvent cannot be cast to archeus.campaign.tutorial.ArcheusTutorialMissionEvent
at archeus.campaign.tutorial.ArcheusCampaignTutorialScript.startTutorialMissionEve nt(ArcheusCampaignTutorialScript.java:431)
at archeus.campaign.tutorial.ArcheusCampaignTutorialScript.advance(ArcheusCampaignTutorialScript.java:284)
at com.fs.starfarer.campaign.BaseLocation.advanceEvenIfPaused(Unknown Source)
at com.fs.starfarer.campaign.CampaignEngine.advance(Unknown Source)
at com.fs.starfarer.campaign.CampaignState.advance(Unknown Source)
at com.fs.starfarer.BaseGameState.traverse(Unknown Source)
at com.fs.state.AppDriver.begin(Unknown Source)
at com.fs.starfarer.combat.CombatMain.main(Unknown Source)
at com.fs.starfarer.StarfarerLauncher$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
And here's the lines of code its referencing in ArcheusCampaignTutorialScript.java:
Spoiler
protected void startTutorialMissionEvent() {
CampaignEventManagerAPI eventManager = Global.getSector().getEventManager();
CampaignEventTarget target = new CampaignEventTarget(ancyra);
target.setExtra(Misc.genUID());
event = (ArcheusTutorialMissionEvent) eventManager.primeEvent(target, Events.TUTORIAL_MISSION, this);
eventManager.startEvent(event);
}
I know this isn't much detail yet, but its late. What I'm curious about for the moment is whether its the script itself or the event script that its trying to start that contains the issue.
Is it still trying to call the original TutorialMissionEvent script somewhere I'm missing or is that not it?
EDIT: Hm. Looking at is closer I'm pretty sure its just that I've overwritten the event variable but not every script in the tutorial package that assigns something to it.
EDIT2: Ok, so I don't see anywhere that the event variable is referenced other than in the tutorial script.
Is it something behind the scenes with EventManagerAPI? I defined the variable as a "ArcheusTutorialMissionEvent" here:
Spoiler
protected ArcheusTutorialMissionEvent event;
So it should never be attempting to cast it to a regular "TutorialMissionEvent" variable in the first place.
Any clue where it is attempting to do this?
The full script:
Spoiler
package archeus.campaign.tutorial;
import com.fs.starfarer.api.EveryFrameScript;
import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.campaign.CampaignFleetAPI;
import com.fs.starfarer.api.campaign.CampaignTerrainAPI;
import com.fs.starfarer.api.campaign.CoreUITabId;
import com.fs.starfarer.api.campaign.PlanetAPI;
import com.fs.starfarer.api.campaign.SectorEntityToken;
import com.fs.starfarer.api.campaign.StarSystemAPI;
import com.fs.starfarer.api.campaign.events.CampaignEventManagerAPI;
import com.fs.starfarer.api.campaign.events.CampaignEventTarget;
import com.fs.starfarer.api.characters.AbilityPlugin;
import com.fs.starfarer.api.fleet.FleetMemberAPI;
import com.fs.starfarer.api.fleet.FleetMemberType;
import com.fs.starfarer.api.impl.campaign.DModManager;
import com.fs.starfarer.api.impl.campaign.fleets.FleetFactory;
import com.fs.starfarer.api.impl.campaign.ids.Abilities;
import com.fs.starfarer.api.impl.campaign.ids.Events;
import com.fs.starfarer.api.impl.campaign.ids.Factions;
import com.fs.starfarer.api.impl.campaign.ids.FleetTypes;
import com.fs.starfarer.api.impl.campaign.ids.HullMods;
import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.special.TransmitterTrapSpeci al;
import com.fs.starfarer.api.ui.HintPanelAPI;
import com.fs.starfarer.api.util.Misc;
import com.fs.starfarer.api.impl.campaign.tutorial.TutorialWelcomeDialogPluginImpl;
import com.fs.starfarer.api.impl.campaign.tutorial.TutorialLayInCourseDialogPluginImpl;
import com.fs.starfarer.api.impl.campaign.tutorial.TutorialTransponderDialogPluginImpl;
import com.fs.starfarer.api.impl.campaign.tutorial.TutorialSustainedBurnDialogPluginIm pl;
import com.fs.starfarer.api.impl.campaign.tutorial.TutorialPirateApproachesDialogPlugi nImpl;
import com.fs.starfarer.api.impl.campaign.tutorial.TutorialLevelUpDialogPluginImpl;
import com.fs.starfarer.api.impl.campaign.tutorial.TutorialLeashAssignmentAI;
import archeus.campaign.tutorial.ArcheusRogueMinerMiscFleetManager;
public class ArcheusCampaignTutorialScript implements EveryFrameScript {
public static final String USE_TUTORIAL_RESPAWN = "$tutorialRespawn";
public static enum CampaignTutorialStage {
SHOW_WELCOME_DIALOG,
SHOW_DEBRIS_HINT,
HEADING_TO_DEBRIS,
REACHED_DEBRIS,
SAVE_NAG_1,
SHOW_PIRATE_DIALOG,
SHOW_PIRATE_HINT,
PIRATE_APPROACHES,
SAVE_NAG_2,
SHOW_LEVELUP_DIALOG,
SHOW_LEVELUP_HINT,
WAIT_CHAR_TAB,
SHOW_LAY_IN_COURSE_DIALOG,
SHOW_LAY_IN_COURSE_HINT,
WAITING_TO_LAY_IN_COURSE,
SHOW_SUSTAINED_BURN_DIALOG,
SHOW_SUSTAINED_BURN_HINT,
WAIT_SUSTAINED_BURN_USE,
SHOW_TRANSPONDER_DIALOG,
SHOW_TRANSPONDER_HINT,
WAIT_TRANSPONDER_USE,
DONE,
WAITING_TO_QUICKSAVE,
}
protected boolean askedPlayerToSave = false;
protected boolean playerSaved = false;
protected float elapsed = 0f;
protected float lastCheckDistToAncyra = -1f;
protected StarSystemAPI system;
protected PlanetAPI ancyra;
protected SectorEntityToken derinkuyu;
protected CampaignTutorialStage stage = CampaignTutorialStage.SHOW_WELCOME_DIALOG;
protected boolean orbitalResetDone = false;
protected CampaignTerrainAPI debrisField;
protected CampaignFleetAPI pirateFleet;
protected CampaignFleetAPI detachment;
protected ArcheusTutorialMissionEvent event;
public ArcheusCampaignTutorialScript(StarSystemAPI system) {
this.system = system;
debrisField = (CampaignTerrainAPI) system.getEntityById("debris_tutorial");
ancyra = (PlanetAPI) system.getEntityById("ancyra");
derinkuyu = system.getEntityById("derinkuyu_station");
Global.getSector().getMemoryWithoutUpdate().set(USE_TUTORIAL_RESPAWN, true);
}
protected Object readResolve() {
return this;
}
protected Object writeReplace() {
if (askedPlayerToSave) {
playerSaved = true;
HintPanelAPI hints = Global.getSector().getCampaignUI().getHintPanel();
if (hints != null) {
hints.clearHints(false);
}
}
return this;
}
protected CampaignTutorialStage quickSaveFrom = null;
protected boolean quickSaveNag(CampaignTutorialStage nagStage, CampaignTutorialStage next, float timeout) {
HintPanelAPI hints = Global.getSector().getCampaignUI().getHintPanel();
if (stage == nagStage) {
quickSaveFrom = nagStage;
hints.clearHints();
String control = Global.getSettings().getControlStringForEnumName("QUICK_SAVE");
if (timeout > 0) {
hints.setHint(0, "- Press %s to quick-save, if you like", true, Misc.getHighlightColor(), control);
} else {
hints.setHint(0, "- Press %s to quick-save and advance the tutorial", true, Misc.getHighlightColor(), control);
}
stage = CampaignTutorialStage.WAITING_TO_QUICKSAVE;
elapsed = 0f;
askedPlayerToSave = true;
playerSaved = false;
return true;
}
if (quickSaveFrom == nagStage && stage == CampaignTutorialStage.WAITING_TO_QUICKSAVE &&
(playerSaved || (timeout > 0 && elapsed > timeout))) {
hints.clearHints();
stage = next;
elapsed = 0f;
playerSaved = false;
askedPlayerToSave = false;
quickSaveFrom = null;
return true;
}
return false;
}
protected boolean charTabWasOpen = false;
public void advance(float amount) {
if (amount == 0) return;
if (Global.getSector().isInFastAdvance()) return;
CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
if (playerFleet == null) return;
HintPanelAPI hints = Global.getSector().getCampaignUI().getHintPanel();
if (hints == null) return;
//playerFleet.addAbility(Abilities.SENSOR_BURST);
if (lastCheckDistToAncyra < 0) {
lastCheckDistToAncyra = Misc.getDistance(playerFleet.getLocation(), ancyra.getLocation());
}
if (!orbitalResetDone) {
system.getEntityById("ancyra").setCircularOrbitAngle(55f);
system.getEntityById("ancyra_relay").setCircularOrbitAngle(55 - 60);;
system.getEntityById("pontus").setCircularOrbitAngle(230);
system.getEntityById("pontus_L4").setCircularOrbitAngle(230 + 60);
system.getEntityById("pontus_L5").setCircularOrbitAngle(230 - 60);
system.getEntityById("galatia_probe").setCircularOrbitAngle(230);
system.getEntityById("galatia_jump_point_alpha").setCircularOrbitAngle(230 + 180f);
system.getEntityById("tetra").setCircularOrbitAngle(340);
system.getEntityById("derinkuyu_station").setCircularOrbitAngle(135);
system.getEntityById("galatia_jump_point_fringe").setCircularOrbitAngle(160);;
orbitalResetDone = true;
}
elapsed += amount;
if (stage == CampaignTutorialStage.SHOW_WELCOME_DIALOG && elapsed > 1f) {
if (Global.getSector().getCampaignUI().showInteractionDialog(new TutorialWelcomeDialogPluginImpl(), null)) {
addFleets();
stage = CampaignTutorialStage.SHOW_DEBRIS_HINT;
}
return;
}
if (stage == CampaignTutorialStage.SHOW_DEBRIS_HINT) {
String control = Global.getSettings().getControlStringForAbilitySlot(5);
hints.setHint(1, "- Move up into the debris field");
hints.setHint(0, "- Press %s to start scavenging", false, Misc.getHighlightColor(), control);
hints.makeDim(0);
stage = CampaignTutorialStage.HEADING_TO_DEBRIS;
return;
}
if (stage == CampaignTutorialStage.HEADING_TO_DEBRIS) {
if (debrisField.getPlugin().containsEntity(playerFleet)) {
stage = CampaignTutorialStage.REACHED_DEBRIS;
hints.fadeOutHint(1);
//hints.makeNormal(0);
String control = Global.getSettings().getControlStringForAbilitySlot(5);
hints.setHint(0, "- Press %s to start scavenging", true, Misc.getHighlightColor(), control);
}
return;
}
if (stage == CampaignTutorialStage.REACHED_DEBRIS) {
AbilityPlugin scavenge = playerFleet.getAbility(Abilities.SCAVENGE);
if (scavenge != null && scavenge.isOnCooldown()) {
stage = CampaignTutorialStage.SAVE_NAG_1;
}
return;
}
if (quickSaveNag(CampaignTutorialStage.SAVE_NAG_1, CampaignTutorialStage.SHOW_PIRATE_DIALOG, 0)) {
return;
}
if (stage == CampaignTutorialStage.SHOW_PIRATE_DIALOG && elapsed >= 1f) {
if (Global.getSector().getCampaignUI().showInteractionDialog(new TutorialPirateApproachesDialogPluginImpl(), null)) {
stage = CampaignTutorialStage.SHOW_PIRATE_HINT;
}
return;
}
if (stage == CampaignTutorialStage.SHOW_PIRATE_HINT) {
addPirateFleet();
hints.setHint(0, "- Wait for the pirates to approach, then engage and defeat them!");
stage = CampaignTutorialStage.PIRATE_APPROACHES;
return;
}
if (stage == CampaignTutorialStage.PIRATE_APPROACHES) {
if (pirateFleet == null || !pirateFleet.isAlive()) {
hints.clearHints();
stage = CampaignTutorialStage.SAVE_NAG_2;
elapsed = 0f;
long xp = Global.getSector().getPlayerPerson().getStats().getXP();
long add = Global.getSettings().getLevelupPlugin().getXPForLevel(2) - xp;
Global.getSector().getPlayerPerson().getStats().addPoints(3);
Global.getSector().getPlayerPerson().getStats().addXP(add);
}
return;
}
if (quickSaveNag(CampaignTutorialStage.SAVE_NAG_2, CampaignTutorialStage.SHOW_LEVELUP_DIALOG, 0)) {
return;
}
if (stage == CampaignTutorialStage.SHOW_LEVELUP_DIALOG && elapsed >= 1f) {
if (Global.getSector().getCampaignUI().showInteractionDialog(new TutorialLevelUpDialogPluginImpl(), null)) {
stage = CampaignTutorialStage.SHOW_LEVELUP_HINT;
}
return;
}
if (stage == CampaignTutorialStage.SHOW_LEVELUP_HINT) {
String character = Global.getSettings().getControlStringForEnumName("CORE_CHARACTER");
hints.setHint(0, "- Press %s to open the character tab and consider your options", true, Misc.getHighlightColor(), character);
stage = CampaignTutorialStage.WAIT_CHAR_TAB;
return;
}
if (stage == CampaignTutorialStage.WAIT_CHAR_TAB) {
CoreUITabId tab = Global.getSector().getCampaignUI().getCurrentCoreTab();
if (tab == CoreUITabId.CHARACTER) {
charTabWasOpen = true;
}
if (charTabWasOpen && !Global.getSector().getCampaignUI().isShowingDialog()) {
stage = CampaignTutorialStage.SHOW_LAY_IN_COURSE_DIALOG;
elapsed = 0f;
hints.clearHints();
}
}
if (stage == CampaignTutorialStage.SHOW_LAY_IN_COURSE_DIALOG && elapsed >= 1f) {
startTutorialMissionEvent();
if (Global.getSector().getCampaignUI().showInteractionDialog(
new TutorialLayInCourseDialogPluginImpl(ancyra.getMarket(), event.getMainContact()), null)) {
stage = CampaignTutorialStage.SHOW_LAY_IN_COURSE_HINT;
}
return;
}
if (stage == CampaignTutorialStage.SHOW_LAY_IN_COURSE_HINT) {
String intel = Global.getSettings().getControlStringForEnumName("CORE_INTEL");
String map = Global.getSettings().getControlStringForEnumName("CORE_MAP");
hints.setHint(1, "- Press %s to open the intel tab, then click on the display that reads IN-SYSTEM", false, Misc.getHighlightColor(), intel);
hints.setHint(0, "- Click on " + ancyra.getName() + " and select " +
"%s, then press %s to close the map", false, Misc.getHighlightColor(), "\"Lay in Course\"", map);
stage = CampaignTutorialStage.WAITING_TO_LAY_IN_COURSE;
// hints.setHint(1, "- Press %s to open the map", Misc.getHighlightColor(), map);
// hints.setHint(0, "- Find " + ancyra.getName() + ", left-click on it and select " +
// "\"Lay in Course\", then close the map", Misc.getHighlightColor(), "\"Lay in Course\"");
// stage = CampaignTutorialStage.WAITING_TO_LAY_IN_COURSE;
return;
}
if (stage == CampaignTutorialStage.WAITING_TO_LAY_IN_COURSE) {
float dist = Misc.getDistance(playerFleet.getLocation(), ancyra.getLocation());
boolean closedIn = dist < lastCheckDistToAncyra * 0.75f;
if (closedIn || (playerFleet.getInteractionTarget() != null &&
playerFleet.getInteractionTarget().getMarket() == ancyra.getMarket())) {
lastCheckDistToAncyra = dist;
hints.clearHints();
stage = CampaignTutorialStage.SHOW_SUSTAINED_BURN_DIALOG;
elapsed = 0;
}
return;
}
if (stage == CampaignTutorialStage.SHOW_SUSTAINED_BURN_DIALOG && elapsed > 10f) {
if (Global.getSector().getCampaignUI().showInteractionDialog(new TutorialSustainedBurnDialogPluginImpl(ancyra.getMarket()), null)) {
stage = CampaignTutorialStage.SHOW_SUSTAINED_BURN_HINT;
}
return;
}
if (stage == CampaignTutorialStage.SHOW_SUSTAINED_BURN_HINT) {
String control = Global.getSettings().getControlStringForAbilitySlot(4);
hints.setHint(0, "- Press %s to engage sustained burn", true, Misc.getHighlightColor(), control);
stage = CampaignTutorialStage.WAIT_SUSTAINED_BURN_USE;
elapsed = 0;
return;
}
if (stage == CampaignTutorialStage.WAIT_SUSTAINED_BURN_USE) {
AbilityPlugin sb = playerFleet.getAbility(Abilities.SUSTAINED_BURN);
float dist = Misc.getDistance(playerFleet.getLocation(), ancyra.getLocation());
boolean closedIn = dist < lastCheckDistToAncyra * 0.75f;
if ((sb != null && sb.isActive() && elapsed > 5f) || closedIn) {
lastCheckDistToAncyra = dist;
hints.clearHints();
stage = CampaignTutorialStage.SHOW_TRANSPONDER_DIALOG;
elapsed = 0f;
}
return;
}
if (stage == CampaignTutorialStage.SHOW_TRANSPONDER_DIALOG) {
float dist = Misc.getDistance(playerFleet.getLocation(), ancyra.getLocation());
if (dist < 6000) {
if (Global.getSector().getCampaignUI().showInteractionDialog(new TutorialTransponderDialogPluginImpl(ancyra.getMarket()), null)) {
stage = CampaignTutorialStage.SHOW_TRANSPONDER_HINT;
}
}
return;
}
if (stage == CampaignTutorialStage.SHOW_TRANSPONDER_HINT) {
String control = Global.getSettings().getControlStringForAbilitySlot(0);
hints.setHint(0, "- Press %s twice to turn on the transponder", true, Misc.getHighlightColor(), control);
stage = CampaignTutorialStage.WAIT_TRANSPONDER_USE;
elapsed = 0;
return;
}
if (stage == CampaignTutorialStage.WAIT_TRANSPONDER_USE) {
AbilityPlugin transponder = playerFleet.getAbility(Abilities.TRANSPONDER);
if ((transponder != null && transponder.isActive())) {
hints.clearHints();
stage = CampaignTutorialStage.DONE;
elapsed = 0f;
}
return;
}
}
protected void addFleets() {
addSecurityDetachment();
SectorEntityToken inner = system.getEntityById("galatia_jump_point_alpha");
SectorEntityToken fringe = system.getEntityById("galatia_jump_point_fringe");
SectorEntityToken derinkuyu = system.getEntityById("derinkuyu_station");
CampaignFleetAPI g1 = ArcheusRogueMinerMiscFleetManager.createGuardFleet(false);
g1.addScript(new TutorialLeashAssignmentAI(g1, system, derinkuyu));
system.addEntity(g1);
g1.setLocation(derinkuyu.getLocation().x, derinkuyu.getLocation().y);
CampaignFleetAPI g2 = ArcheusRogueMinerMiscFleetManager.createGuardFleet(Misc.isEasy());
if (!Misc.isEasy()) {
FleetMemberAPI member = Global.getFactory().createFleetMember(FleetMemberType.SHIP, "venture_d_pirates_Combat");
member.setVariant(member.getVariant().clone(), false, false);
g2.getFleetData().addFleetMember(member);
}
g2.getFleetData().sort();
g2.addScript(new TutorialLeashAssignmentAI(g2, system, inner));
system.addEntity(g2);
g2.setLocation(inner.getLocation().x, inner.getLocation().y);
CampaignFleetAPI g3 = ArcheusRogueMinerMiscFleetManager.createGuardFleet(true);
g3.addScript(new TutorialLeashAssignmentAI(g3, system, inner));
system.addEntity(g3);
g3.setLocation(inner.getLocation().x, inner.getLocation().y);
CampaignFleetAPI g4 = ArcheusRogueMinerMiscFleetManager.createGuardFleet(true);
g4.addScript(new TutorialLeashAssignmentAI(g4, system, fringe));
system.addEntity(g4);
g4.setLocation(fringe.getLocation().x, fringe.getLocation().y);
CampaignFleetAPI g5 = ArcheusRogueMinerMiscFleetManager.createGuardFleet(true);
g5.addScript(new TutorialLeashAssignmentAI(g5, system, fringe));
system.addEntity(g5);
g5.setLocation(fringe.getLocation().x, fringe.getLocation().y);
}
protected void startTutorialMissionEvent() {
CampaignEventManagerAPI eventManager = Global.getSector().getEventManager();
CampaignEventTarget target = new CampaignEventTarget(ancyra);
target.setExtra(Misc.genUID());
event = (ArcheusTutorialMissionEvent) eventManager.primeEvent(target, Events.TUTORIAL_MISSION, this);
eventManager.startEvent(event);
}
protected void addPirateFleet() {
pirateFleet = ArcheusRogueMinerMiscFleetManager.createEmptyRogueFleet("Rogue Miner", false);
pirateFleet.getMemoryWithoutUpdate().set(MemFlags.MEMORY_KEY_NO_SHIP_RECOVERY, true);
FleetMemberAPI member = Global.getFactory().createFleetMember(FleetMemberType.SHIP, "cerberus_d_pirates_Standard");
pirateFleet.getFleetData().addFleetMember(member);
system.addEntity(pirateFleet);
CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
pirateFleet.setLocation(playerFleet.getLocation().x + 750f, playerFleet.getLocation().y + 750f);
TransmitterTrapSpecial.makeFleetInterceptPlayer(pirateFleet, true, 100f);
}
protected void addSecurityDetachment() {
detachment = FleetFactory.createEmptyFleet(Factions.HEGEMONY, FleetTypes.PATROL_MEDIUM, ancyra.getMarket());
detachment.setName("Security Detachment");
detachment.setNoFactionInName(true);
//detachment.getFleetData().addFleetMember("eagle_xiv_Elite");
detachment.getFleetData().addFleetMember("dominator_XIV_Elite");
detachment.getFleetData().addFleetMember("mora_Strike");
detachment.getFleetData().addFleetMember("enforcer_XIV_Elite");
detachment.getFleetData().addFleetMember("enforcer_XIV_Elite");
detachment.getFleetData().addFleetMember("brawler_Elite");
detachment.getFleetData().addFleetMember("wolf_hegemony_Assault");
detachment.getFleetData().addFleetMember("wolf_hegemony_Assault");
detachment.addAbility(Abilities.TRANSPONDER);
detachment.addAbility(Abilities.GO_DARK);
detachment.addAbility(Abilities.SENSOR_BURST);
detachment.addAbility(Abilities.EMERGENCY_BURN);
detachment.getMemoryWithoutUpdate().set(MemFlags.MEMORY_KEY_PATROL_FLEET, true);
detachment.getMemoryWithoutUpdate().set(MemFlags.MEMORY_KEY_NO_JUMP, true);
system.addEntity(detachment);
detachment.setLocation(ancyra.getLocation().x, ancyra.getLocation().y);
detachment.addScript(new TutorialLeashAssignmentAI(detachment, system, ancyra));
detachment.setId("tutorial_security_detachment");
}
public boolean isDone() {
return stage == CampaignTutorialStage.DONE;
}
public boolean runWhilePaused() {
return stage == CampaignTutorialStage.WAIT_CHAR_TAB;
}
}
And the Event script its attempting to call:
Spoiler
package archeus.campaign.tutorial;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.campaign.BaseOnMessageDeliveryScript;
import com.fs.starfarer.api.campaign.CampaignFleetAPI;
import com.fs.starfarer.api.campaign.CargoAPI;
import com.fs.starfarer.api.campaign.CommDirectoryEntryAPI;
import com.fs.starfarer.api.campaign.FactionAPI;
import com.fs.starfarer.api.campaign.InteractionDialogAPI;
import com.fs.starfarer.api.campaign.OnMessageDeliveryScript;
import com.fs.starfarer.api.campaign.PlanetAPI;
import com.fs.starfarer.api.campaign.SectorEntityToken;
import com.fs.starfarer.api.campaign.StarSystemAPI;
import com.fs.starfarer.api.campaign.CommDirectoryEntryAPI.EntryType;
import com.fs.starfarer.api.campaign.comm.CommMessageAPI;
import com.fs.starfarer.api.campaign.comm.MessagePriority;
import com.fs.starfarer.api.campaign.econ.MarketAPI;
import com.fs.starfarer.api.campaign.events.CampaignEventManagerAPI;
import com.fs.starfarer.api.campaign.events.CampaignEventTarget;
import com.fs.starfarer.api.campaign.rules.MemoryAPI;
import com.fs.starfarer.api.characters.PersonAPI;
import com.fs.starfarer.api.fleet.FleetMemberAPI;
import com.fs.starfarer.api.fleet.FleetMemberType;
import com.fs.starfarer.api.impl.campaign.JumpPointInteractionDialogPluginImpl;
import com.fs.starfarer.api.impl.campaign.events.BaseEventPlugin;
import com.fs.starfarer.api.impl.campaign.ids.Abilities;
import com.fs.starfarer.api.impl.campaign.ids.Commodities;
import com.fs.starfarer.api.impl.campaign.ids.Entities;
import com.fs.starfarer.api.impl.campaign.ids.Events;
import com.fs.starfarer.api.impl.campaign.ids.Factions;
import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
import com.fs.starfarer.api.impl.campaign.ids.Ranks;
import com.fs.starfarer.api.impl.campaign.ids.Submarkets;
import com.fs.starfarer.api.impl.campaign.ids.Tags;
import com.fs.starfarer.api.impl.campaign.rulecmd.AddRemoveCommodity;
import com.fs.starfarer.api.impl.campaign.submarkets.StoragePlugin;
import com.fs.starfarer.api.loading.WeaponSlotAPI;
import com.fs.starfarer.api.ui.HintPanelAPI;
import com.fs.starfarer.api.util.Misc;
import com.fs.starfarer.api.util.Misc.Token;
import com.fs.starfarer.api.impl.campaign.tutorial.TutorialLeashAssignmentAI;
import com.fs.starfarer.api.impl.campaign.tutorial.SaveNagScript;
public class ArcheusTutorialMissionEvent extends BaseEventPlugin {
public static final String TUT_STAGE = "$tutStage";
public static final String REASON = "tut";
public static enum TutorialMissionStage {
INIT,
GO_GET_DATA,
GOT_DATA,
GO_GET_AI_CORE,
GOT_AI_CORE,
GO_RECOVER_SHIPS,
RECOVERED_SHIPS,
GO_STABILIZE,
STABILIZED,
DELIVER_REPORT,
DONE,
;
}
protected float elapsedDays = 0;
protected boolean ended = false;
//protected TutorialMissionEventData data;
protected StarSystemAPI system;
protected PlanetAPI ancyra;
protected PlanetAPI pontus;
protected PlanetAPI tetra;
protected SectorEntityToken derinkuyu;
protected SectorEntityToken probe;
protected SectorEntityToken inner;
protected SectorEntityToken fringe;
protected SectorEntityToken detachment;
protected SectorEntityToken relay;
protected PersonAPI mainContact;
protected PersonAPI dataContact;
protected PersonAPI jangalaContact;
protected PlanetAPI jangala;
protected TutorialMissionStage stage = TutorialMissionStage.INIT;
@Override
public void init(String type, CampaignEventTarget eventTarget) {
super.init(type, eventTarget, false);
}
@Override
public void setParam(Object param) {
//data = (TutorialMissionEventData) param;
}
@Override
public void startEvent() {
super.startEvent();
system = Global.getSector().getStarSystem("galatia");
ancyra = (PlanetAPI) system.getEntityById("ancyra");
pontus = (PlanetAPI) system.getEntityById("pontus");
tetra = (PlanetAPI) system.getEntityById("tetra");
derinkuyu = system.getEntityById("derinkuyu_station");
probe = system.getEntityById("galatia_probe");
inner = system.getEntityById("galatia_jump_point_alpha");
fringe = system.getEntityById("galatia_jump_point_fringe");
detachment = system.getEntityById("tutorial_security_detachment");
relay = system.getEntityById("ancyra_relay");
// mainContact = ancyra.getFaction().createRandomPerson();
// mainContact.setRankId(Ranks.CITIZEN);
// mainContact.setPostId(Ranks.POST_STATION_COMMANDER);
// ancyra.getMarket().getCommDirectory().addPerson(mainContact);
mainContact = createMainContact(ancyra);
dataContact = Global.getSector().getFaction(Factions.INDEPENDENT).createRandomPerson();
dataContact.setRankId(Ranks.AGENT);
dataContact.setPostId(Ranks.POST_AGENT);
derinkuyu.getMarket().getCommDirectory().addPerson(dataContact);
String stageId = "start";
Global.getSector().reportEventStage(this, stageId, Global.getSector().getPlayerFleet(),
MessagePriority.DELIVER_IMMEDIATELY, createSetMessageLocationScript(ancyra));
mainContact.getMemoryWithoutUpdate().set("$tut_mainContact", true);
mainContact.getMemoryWithoutUpdate().set("$tut_eventRef", this);
Misc.makeImportant(mainContact, REASON);
updateStage(TutorialMissionStage.INIT);
}
public static PersonAPI createMainContact(PlanetAPI ancyra) {
PersonAPI mainContact = ancyra.getFaction().createRandomPerson();
mainContact.setRankId(Ranks.CITIZEN);
mainContact.setPostId(Ranks.POST_STATION_COMMANDER);
ancyra.getMarket().getCommDirectory().addPerson(mainContact);
return mainContact;
}
public static PersonAPI getJangalaContact() {
StarSystemAPI corvus = Global.getSector().getStarSystem("Corvus");
PlanetAPI jangala = (PlanetAPI) corvus.getEntityById("jangala");
for (CommDirectoryEntryAPI entry : jangala.getMarket().getCommDirectory().getEntriesCopy()) {
if (entry.getType() == EntryType.PERSON && entry.getEntryData() instanceof PersonAPI) {
PersonAPI curr = (PersonAPI) entry.getEntryData();
if (Ranks.POST_STATION_COMMANDER.equals(curr.getPostId())) {
return curr;
}
}
}
return null;
}
public PersonAPI getMainContact() {
return mainContact;
}
protected void updateStage(TutorialMissionStage stage) {
this.stage = stage;
Global.getSector().getMemoryWithoutUpdate().set(TUT_STAGE, stage.name());
}
protected void endEvent() {
ended = true;
Global.getSector().getMemoryWithoutUpdate().unset(TUT_STAGE);
}
@Override
public void advance(float amount) {
if (!isEventStarted()) return;
if (isDone()) return;
float days = Global.getSector().getClock().convertToDays(amount);
CampaignFleetAPI player = Global.getSector().getPlayerFleet();
if (player == null) return;
//memory.advance(days);
elapsedDays += days;
if (probe == null) probe = system.getEntityById("galatia_probe");
if (tetra == null) tetra = (PlanetAPI) system.getEntityById("tetra");
if (derinkuyu == null) derinkuyu = system.getEntityById("derinkuyu_station");
if (inner == null) inner = system.getEntityById("galatia_jump_point_alpha");
if (fringe == null) fringe = system.getEntityById("galatia_jump_point_fringe");
if (detachment == null) detachment = system.getEntityById("tutorial_security_detachment");
if (stage == TutorialMissionStage.GO_GET_AI_CORE) {
int cores = (int) player.getCargo().getCommodityQuantity(Commodities.GAMMA_CORE);
float distToProbe = Misc.getDistance(player.getLocation(), probe.getLocation());
if (cores > 0 && (!probe.isAlive() || distToProbe < 300)) {
Global.getSector().reportEventStage(this, "salvage_core_end", Global.getSector().getPlayerFleet(),
MessagePriority.DELIVER_IMMEDIATELY, createSetMessageLocationScript(ancyra));
Misc.makeImportant(mainContact, REASON);
updateStage(TutorialMissionStage.GOT_AI_CORE);
}
}
if (stage == TutorialMissionStage.GO_RECOVER_SHIPS) {
int count = 0;
for (FleetMemberAPI member : player.getFleetData().getMembersListCopy()) {
//if (member.getVariant().getHullSpec().isDHull()) count++;
count++;
}
int wrecks = 0;
for (SectorEntityToken entity : system.getEntitiesWithTag(Tags.SALVAGEABLE)) {
String id = entity.getCustomEntityType();
if (id == null) continue;
if (Entities.WRECK.equals(id)) {
wrecks ++;
}
}
if (count >= 5 || wrecks < 3) {
Global.getSector().reportEventStage(this, "ship_recovery_end", Global.getSector().getPlayerFleet(),
MessagePriority.DELIVER_IMMEDIATELY, createSetMessageLocationScript(ancyra));
Misc.makeImportant(mainContact, REASON);
Misc.makeUnimportant(tetra, REASON);
updateStage(TutorialMissionStage.RECOVERED_SHIPS);
}
}
if (stage == TutorialMissionStage.GO_STABILIZE) {
boolean innerStable = inner.getMemoryWithoutUpdate().getExpire(JumpPointInteractionDialogPluginImpl.UNSTABLE_KEY) > 0;
boolean fringeStable = fringe.getMemoryWithoutUpdate().getExpire(JumpPointInteractionDialogPluginImpl.UNSTABLE_KEY) > 0;
if (innerStable || fringeStable) {
Global.getSector().reportEventStage(this, "stabilize_jump_point_done", Global.getSector().getPlayerFleet(),
MessagePriority.DELIVER_IMMEDIATELY, createSetMessageLocationScript(ancyra));
Misc.makeImportant(mainContact, REASON);
Misc.makeUnimportant(inner, REASON);
updateStage(TutorialMissionStage.STABILIZED);
}
}
}
@Override
public boolean callEvent(String ruleId, final InteractionDialogAPI dialog, List<Token> params, Map<String, MemoryAPI> memoryMap) {
String action = params.get(0).getString(memoryMap);
CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
CargoAPI cargo = playerFleet.getCargo();
if (action.equals("startGetData")) {
Global.getSector().reportEventStage(this, "sneak_start", Global.getSector().getPlayerFleet(),
MessagePriority.DELIVER_IMMEDIATELY, createSetMessageLocationScript(derinkuyu));
dataContact.getMemoryWithoutUpdate().set("$tut_dataContact", true);
dataContact.getMemoryWithoutUpdate().set("$tut_eventRef", this);
Misc.makeImportant(dataContact, REASON);
Misc.makeUnimportant(mainContact, REASON);
detachment.getMemoryWithoutUpdate().set(MemFlags.MEMORY_KEY_PATROL_ALLOW_TOFF, true);
updateStage(TutorialMissionStage.GO_GET_DATA);
saveNag();
} else if (action.equals("endGetData")) {
Global.getSector().reportEventStage(this, "sneak_end", Global.getSector().getPlayerFleet(),
MessagePriority.DELIVER_IMMEDIATELY, createSetMessageLocationScript(ancyra));
Misc.cleanUpMissionMemory(dataContact.getMemoryWithoutUpdate(), "tut_");
Misc.makeUnimportant(dataContact, REASON);
Misc.makeImportant(mainContact, REASON);
updateStage(TutorialMissionStage.GOT_DATA);
} else if (action.equals("goSalvage")) {
Global.getSector().reportEventStage(this, "salvage_core_start", Global.getSector().getPlayerFleet(),
MessagePriority.DELIVER_IMMEDIATELY, createSetMessageLocationScript(pontus));
Misc.makeUnimportant(mainContact, REASON);
Misc.makeImportant(probe, REASON);
updateStage(TutorialMissionStage.GO_GET_AI_CORE);
saveNag();
} else if (action.equals("goRecover")) {
Global.getSector().reportEventStage(this, "ship_recovery_start", Global.getSector().getPlayerFleet(),
MessagePriority.DELIVER_IMMEDIATELY, createSetMessageLocationScript(tetra));
Misc.makeUnimportant(mainContact, REASON);
Misc.makeImportant(tetra, REASON);
FleetMemberAPI member = Global.getFactory().createFleetMember(FleetMemberType.SHIP, "mudskipper_Standard");
playerFleet.getFleetData().addFleetMember(member);
AddRemoveCommodity.addFleetMemberGainText(member, dialog.getTextPanel());
updateStage(TutorialMissionStage.GO_RECOVER_SHIPS);
} else if (action.equals("goStabilize")) {
Global.getSector().reportEventStage(this, "stabilize_jump_point", Global.getSector().getPlayerFleet(),
MessagePriority.DELIVER_IMMEDIATELY, createSetMessageLocationScript(inner));
Misc.makeUnimportant(mainContact, REASON);
Misc.makeImportant(inner, REASON);
addWeaponsToStorage();
inner.getMemoryWithoutUpdate().set(JumpPointInteractionDialogPluginImpl.CAN_STABILIZE, true);
fringe.getMemoryWithoutUpdate().set(JumpPointInteractionDialogPluginImpl.CAN_STABILIZE, true);
updateStage(TutorialMissionStage.GO_STABILIZE);
saveNag();
} else if (action.equals("pickJangalaContact")) {
StarSystemAPI corvus = Global.getSector().getStarSystem("Corvus");
jangala = (PlanetAPI) corvus.getEntityById("jangala");
jangalaContact = getJangalaContact();
MemoryAPI mem = mainContact.getMemoryWithoutUpdate();
mem.set("$jangalaContactPost", jangalaContact.getPost().toLowerCase(), 0);
mem.set("$jangalaContactLastName", jangalaContact.getName().getLast(), 0);
float distLY = Misc.getDistanceLY(playerFleet.getLocationInHyperspace(), jangala.getLocationInHyperspace());
distLY += 4f;
float fuel = playerFleet.getLogistics().getFuelCostPerLightYear() * distLY;
fuel = (float) (Math.ceil(fuel / 10) * 10);
mem.set("$jangalaFuel", (int) fuel);
} else if (action.equals("deliverReport")) {
Global.getSector().reportEventStage(this, "deliver_message", Global.getSector().getPlayerFleet(),
MessagePriority.DELIVER_IMMEDIATELY, createSetMessageLocationScript(jangala));
Misc.makeUnimportant(mainContact, REASON);
Misc.cleanUpMissionMemory(mainContact.getMemoryWithoutUpdate(), REASON + "_");
Misc.makeUnimportant(inner, REASON);
jangalaContact.getMemoryWithoutUpdate().set("$tut_jangalaContact", true);
jangalaContact.getMemoryWithoutUpdate().set("$tut_eventRef", this);
Misc.makeImportant(jangalaContact, REASON);
updateStage(TutorialMissionStage.DELIVER_REPORT);
endGalatiaPortionOfMission();
Global.getSector().getMemoryWithoutUpdate().unset(ArcheusCampaignTutorialScript.USE_TUTORIAL_RESPAWN);
} else if (action.equals("reportDelivered")) {
Global.getSector().reportEventStage(this, "end", Global.getSector().getPlayerFleet(),
MessagePriority.DELIVER_IMMEDIATELY, createSetMessageLocationScript(jangala));
Misc.makeUnimportant(jangalaContact, REASON);
Misc.cleanUpMissionMemory(jangalaContact.getMemoryWithoutUpdate(), REASON + "_");
updateStage(TutorialMissionStage.DONE);
CampaignEventManagerAPI eventManager = Global.getSector().getEventManager();
MarketAPI jangala = Global.getSector().getEconomy().getMarket("jangala");
if (jangala != null) {
eventManager.startEvent(new CampaignEventTarget(jangala), Events.SYSTEM_BOUNTY, null);
}
endEvent();
} else if (action.equals("printRefitHint")) {
String refit = Global.getSettings().getControlStringForEnumName("CORE_REFIT");
String autofit = Global.getSettings().getControlStringForEnumName("REFIT_MANAGE_VARIANTS");
String transponder = "";
if (!playerFleet.isTransponderOn()) {
transponder = "\n\nAlso: you'll need to re-dock with your transponder turned on to take advantage of Ancyra's facilities.";
}
dialog.getTextPanel().addPara("(Once this conversation is over, press %s to open the refit screen. " +
"After selecting a specific ship, you can press %s to %s - pick a desired loadout, " +
"and the ship will be automatically refitted to match it, using what weapons are available." +
transponder + "",
Misc.getHighlightColor(), refit, autofit, "\"autofit\"");
dialog.getTextPanel().addPara("In addition, you now have access to local storage at Ancyra, " +
"and some weapons and supplies have been placed there. To access it, click on the " +
"\"Storage\" button in the trade screen.)",
Misc.getHighlightColor(), refit, autofit, "\"Storage\"");
}
return true;
}
public static void endGalatiaPortionOfMission() {
StarSystemAPI system = Global.getSector().getStarSystem("galatia");
PlanetAPI ancyra = (PlanetAPI) system.getEntityById("ancyra");
PlanetAPI pontus = (PlanetAPI) system.getEntityById("pontus");
PlanetAPI tetra = (PlanetAPI) system.getEntityById("tetra");
SectorEntityToken derinkuyu = system.getEntityById("derinkuyu_station");
SectorEntityToken probe = system.getEntityById("galatia_probe");
SectorEntityToken inner = system.getEntityById("galatia_jump_point_alpha");
SectorEntityToken fringe = system.getEntityById("galatia_jump_point_fringe");
SectorEntityToken relay = system.getEntityById("ancyra_relay");
relay.getMemoryWithoutUpdate().unset(MemFlags.COMM_RELAY_NON_FUNCTIONAL);
Global.getSector().getCharacterData().addAbility(Abilities.TRANSPONDER);
Global.getSector().getCharacterData().addAbility(Abilities.GO_DARK);
Global.getSector().getCharacterData().addAbility(Abilities.SENSOR_BURST);
Global.getSector().getCharacterData().addAbility(Abilities.EMERGENCY_BURN);
Global.getSector().getCharacterData().addAbility(Abilities.SUSTAINED_BURN);
Global.getSector().getCharacterData().addAbility(Abilities.SCAVENGE);
Global.getSector().getCharacterData().addAbility(Abilities.INTERDICTION_PULSE);
Global.getSector().getCharacterData().addAbility(Abilities.DISTRESS_CALL);
FactionAPI hegemony = Global.getSector().getFaction(Factions.HEGEMONY);
if (hegemony.getRelToPlayer().getRel() < 0) {
hegemony.getRelToPlayer().setRel(0);
}
Global.getSector().getEconomy().addMarket(ancyra.getMarket());
Global.getSector().getEconomy().addMarket(derinkuyu.getMarket());
HintPanelAPI hints = Global.getSector().getCampaignUI().getHintPanel();
if (hints != null) {
hints.clearHints(false);
}
CampaignEventManagerAPI eventManager = Global.getSector().getEventManager();
eventManager.startEvent(new CampaignEventTarget(ancyra.getMarket()), Events.SYSTEM_BOUNTY, null);
ArcheusRogueMinerMiscFleetManager script = new ArcheusRogueMinerMiscFleetManager(derinkuyu);
for (int i = 0; i < 20; i++) {
script.advance(1f);
}
system.addScript(script);
for (CampaignFleetAPI fleet : system.getFleets()) {
if (Factions.PIRATES.equals(fleet.getFaction().getId())) {
fleet.removeScriptsOfClass(TutorialLeashAssignmentAI.class);
}
}
inner.getMemoryWithoutUpdate().unset(JumpPointInteractionDialogPluginImpl.UNSTABLE_KEY);
inner.getMemoryWithoutUpdate().unset(JumpPointInteractionDialogPluginImpl.CAN_STABILIZE);
fringe.getMemoryWithoutUpdate().unset(JumpPointInteractionDialogPluginImpl.UNSTABLE_KEY);
fringe.getMemoryWithoutUpdate().unset(JumpPointInteractionDialogPluginImpl.CAN_STABILIZE);
}
protected void saveNag() {
if (!Global.getSector().hasScript(SaveNagScript.class)) {
Global.getSector().addScript(new SaveNagScript(10f));
}
}
public void addWeaponsToStorage() {
StoragePlugin plugin = ((StoragePlugin)ancyra.getMarket().getSubmarket(Submarkets.SUBMARKET_STORAGE).getPlugin());
plugin.setPlayerPaidToUnlock(true);
CargoAPI cargo = plugin.getCargo();
CampaignFleetAPI player = Global.getSector().getPlayerFleet();
for (FleetMemberAPI member : player.getFleetData().getMembersListCopy()) {
//if (member.getVariant().getHullSpec().isDHull()) {
for (WeaponSlotAPI slot : member.getVariant().getHullSpec().getAllWeaponSlotsCopy()) {
//if (member.getVariant().getWeaponId(slot.getId()) == null) {
String weaponId = getWeaponForSlot(slot);
if (weaponId != null) {
cargo.addWeapons(weaponId, 1);
}
//}
}
//}
}
cargo.addFighters("talon_wing", 2);
cargo.addFighters("marauder_wing", 1);
cargo.addFighters("gauntlet_wing", 1);
cargo.addSupplies(75);
cargo.sort();
}
public String getWeaponForSlot(WeaponSlotAPI slot) {
switch (slot.getWeaponType()) {
case BALLISTIC:
case COMPOSITE:
case HYBRID:
case UNIVERSAL:
switch (slot.getSlotSize()) {
case LARGE: return pick("mark9", "hephag", "hellbore");
case MEDIUM: return pick("arbalest", "heavymortar", "shredder");
case SMALL: return pick("lightmg", "lightac", "lightmortar");
}
break;
case MISSILE:
case SYNERGY:
switch (slot.getSlotSize()) {
case LARGE: return pick("hammerrack");
case MEDIUM: return pick("firestorm", "annihilatorpod", "sabot_single");
case SMALL: return pick("rapier", "bola", "annihilator");
}
break;
case ENERGY:
switch (slot.getSlotSize()) {
case LARGE: return pick("miningblaster");
case MEDIUM: return pick("mininglaser", "gravitonbeam", "hvyioncannon");
case SMALL: return pick("pulselaser", "pdlaser", "ioncannon");
}
break;
}
return null;
}
public String pick(String ...strings) {
return strings[new Random().nextInt(strings.length)];
}
public OnMessageDeliveryScript createSetMessageLocationScript(final SectorEntityToken entity) {
return new BaseOnMessageDeliveryScript() {
public void beforeDelivery(CommMessageAPI message) {
if (entity != null && entity.getContainingLocation() instanceof StarSystemAPI) {
message.setStarSystemId(entity.getContainingLocation().getId());
} else {
message.setStarSystemId(system.getId());
}
message.setCenterMapOnEntity(entity);
}
};
}
@Override
public Map<String, String> getTokenReplacements() {
Map<String, String> map = super.getTokenReplacements();
addPersonTokens(map, "mainContact", mainContact);
if (dataContact != null) {
addPersonTokens(map, "dataContact", dataContact);
}
if (jangalaContact != null) {
addPersonTokens(map, "jangalaContact", jangalaContact);
}
//map.put("$sender", "Ancyra Research Facility");
map.put("$systemName", system.getNameWithLowercaseType());
return map;
}
@Override
public String[] getHighlights(String stageId) {
List<String> result = new ArrayList<String>();
if ("posting".equals(stageId)) {
} else if ("success".equals(stageId)) {
} else {
//addTokensToList(result, "$rewardCredits");
}
return result.toArray(new String[0]);
}
@Override
public Color[] getHighlightColors(String stageId) {
return super.getHighlightColors(stageId);
}
@Override
public boolean isDone() {
return ended;
}
@Override
public String getEventName() {
if (stage == TutorialMissionStage.INIT) {
return "Contact " + mainContact.getPost() + " " + mainContact.getName().getLast();
}
if (stage == TutorialMissionStage.DELIVER_REPORT) {
return "Deliver Report to Jangala";
}
if (stage == TutorialMissionStage.DONE) {
return "Deliver Report to Jangala - completed";
}
return "Stabilize the Jump-points";
}
@Override
public CampaignEventCategory getEventCategory() {
return CampaignEventCategory.MISSION;
}
@Override
public String getEventIcon() {
return Global.getSettings().getSpriteName("campaignMissions", "tutorial");
}
@Override
public String getCurrentImage() {
return ancyra.getFaction().getLogo();
}
}
--SOLVED--
Doh! Forgot to overwrite the events entry in events.json! That's why it was still trying to call original tutorial event.
Working as intended now.