Fractal Softworks Forum
September 20, 2017, 06:16:20 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: New blog post: Economy & Outposts (9/19/17); Starsector 0.8.1a is out!
 
   Home   Help Search Login Register  
Pages: 1 ... 238 239 [240]
  Print  
Author Topic: Misc modding questions that are too minor to warrant their own thread  (Read 368796 times)
xenoargh
Admiral
*****
Posts: 3951


View Profile
« Reply #3585 on: September 13, 2017, 08:57:09 AM »

I have four Factions that all are using EZ Faction doing stuff in my tests here; one's Explorer Society, one's Pirates (the Pirate-station feature request) and a couple of others that aren't public yet.  I'm fairly certain that the issue's related to how the Markets are getting set up, but I'm still not entirely certain how copies could be present, nor am I totally certain I've found any copies; I just built some code to attempt to kill copies but it was late and I was tired when I did; I'm sure it wasn't adequate and when I figure this out, it'll be "really obvious", lol.
Logged

Check out my SS projects Smiley
xenoargh
Admiral
*****
Posts: 3951


View Profile
« Reply #3586 on: September 13, 2017, 11:19:50 AM »

Hmm.  Still seeing things here that lead me to believe there's some weird issues with this.  It's almost like the MarketAPI's getting "attached" to the PlanetAPI twice, which doesn't look possible; SectorEntityToken getMarket() doesn't return multiple MarketAPIs.

What's really strange is... this bug doesn't happen with the Stations.  Just the PlanetAPIs.

I've ruled out multiple copies of the PlanetAPI; I'm not building new Systems.  

Alex, what we're seeing here looks like this, btw:




So... here's the code that builds the planets right now:

Code: (java)
private static SectorEntityToken buildEntity(StarSystemAPI pickedSystem, FactionAPI faction, int minMarketSize, int maxMarketSize, boolean isCapital){
      int marketSize = MathUtils.getRandomNumberInRange(minMarketSize, maxMarketSize);
      if(isCapital) marketSize = maxMarketSize;
      if(pickedSystem == null) return null;

      if(faction == null) return null;
      if(pickedSystem.getStar() == null) return null;
      if(pickedSystem.getStar().getName() == null) return null;
      if(faction.getId() == null) return null;
      if(pickedSystem.isHyperspace() || pickedSystem.isNebula()) return null;
      SectorEntityToken ezColony;
      try{
         String starName = pickedSystem.getStar().getName();
         String factionID = faction.getId();
         String denomination = pickDenomination(pickedSystem,faction,false,true);
         ezColony = pickedSystem.addPlanet(starName + factionID + "planet" + denomination,//Attempts to build a random numbered location id; needs improving
         pickedSystem.getStar(), starName+" "+ denomination,//Probably needs improving
         planetType(faction),//Pulls a string at random
         MathUtils.getRandomNumberInRange(30f,60f),//Angle
         MathUtils.getRandomNumberInRange(50f,300f),//Radius
         MathUtils.getRandomNumberInRange(4000f,8000f),//Orbital radius
         MathUtils.getRandomNumberInRange(100f,300f));//Orbital period
         ezColony.addTag("customColony");
      }catch (Throwable ex) {
         return null;
      }


      ezColony.setFaction(faction.getId());
      ezColony.setInteractionImage("illustrations", ILLUSTRATIONS.get((int)MathUtils.getRandomNumberInRange(0, ILLUSTRATIONS.size()-1)));
      ezColony.addTag(Tags.STATION);
      MarketAPI market = Global.getFactory().createMarket(faction.getId() + ezColony.getId() +"_market"+MathUtils.getRandom(), ezColony.getName(), 0);
      ezColony.setMarket(market);
      market.setPlanetConditionMarketOnly(false);
      market.addCondition(Conditions.SPACEPORT);
      market.addCondition(Conditions.OUTPOST);

      market.setFactionId(faction.getId());

      market.setSurveyLevel(SurveyLevel.FULL);
      market.setPrimaryEntity(ezColony);

      //Set up all of the Market Conditions here
      if(isCapital == true || MathUtils.getRandomNumberInRange(0f, 100f) > 66f) market.addCondition(Conditions.MILITARY_BASE);
      setMarketConditions(market, marketSize, ezColony, false);

      //Set the market's size and population here
      market.setSize(marketSize);
      assignPopulation(market,marketSize);

      market.addSubmarket(Submarkets.SUBMARKET_OPEN);
      if(market.hasCondition(Conditions.MILITARY_BASE)){
         market.addSubmarket(Submarkets.GENERIC_MILITARY);
      }
      market.addSubmarket(Submarkets.SUBMARKET_BLACK);
      market.addSubmarket(Submarkets.SUBMARKET_STORAGE);

      market.getSubmarket(Submarkets.SUBMARKET_OPEN).getCargo().addCommodity(Commodities.FOOD, 1000);
      market.getSubmarket(Submarkets.SUBMARKET_OPEN).getCargo().addCommodity(Commodities.LUXURY_GOODS, 100);
      market.getSubmarket(Submarkets.SUBMARKET_OPEN).getCargo().addCommodity(Commodities.ORGANICS, 3000);
      market.getSubmarket(Submarkets.SUBMARKET_OPEN).getCargo().addCommodity(Commodities.VOLATILES, 3000);
      market.getSubmarket(Submarkets.SUBMARKET_OPEN).getCargo().addCommodity(Commodities.HEAVY_MACHINERY, 1000);
      market.getSubmarket(Submarkets.SUBMARKET_OPEN).getCargo().addCommodity(Commodities.METALS, 1000);
      market.getSubmarket(Submarkets.SUBMARKET_OPEN).getCargo().addCommodity(Commodities.RARE_METALS, 1000);
      market.getSubmarket(Submarkets.SUBMARKET_OPEN).getCargo().addCrew(300);
      market.getSubmarket(Submarkets.SUBMARKET_OPEN).getCargo().addFuel(5000);

      Global.getSector().getEconomy().addMarket(market);
      
      buildCommRelayIfNeeded(pickedSystem,faction);

      Logger log = Global.getLogger(CoreScript.class);
      log.info("Created EZ Faction Colony " + ezColony.getName() + " for Faction " + faction.getDisplayName() + " at System " +pickedSystem.getBaseName());

      return ezColony;
   }


IDK what's doing this; all I know thus far is that Global.GetSector().GetEconomy().addMarket() is really sensitive to the order of operations; all Conditions and SubMarkets appear to need to be defined first.  I really am pretty stumped by this one; nothing's technically "broken" in an obvious way; the NPE issue reported in the last build of EZ Faction was unrelated.  

It's just presented incorrectly in the game UI.
« Last Edit: September 13, 2017, 12:47:28 PM by Alex » Logged

Check out my SS projects Smiley
Alex
Administrator
Admiral
*****
Posts: 11039


View Profile
« Reply #3587 on: September 13, 2017, 12:58:23 PM »

Weird. Nothing jumps out right off, but that's not *all* of the code, so it's hard to say.

Code: (java)

for (PlanetAPI planet : system.getPlanets()) {
   MarketAPI market = planet.getMarket();
   if (market == null || market.getSurveyLevel() != SurveyLevel.NONE) {
      planets.add(planet);
   }
}
planets.addAll(getStandaloneStations(system));


This is how it picks what entities to display on that screen, btw. One case I can see is if a market has a station and it's the "primary" entity for the market instead of the planet being the primary entity - then it would show up twice, but I'd expect both planet and station to show up then rather than two planets, so never mind.

Edit: I would suggest the time-honored practice of commenting stuff out gradually until the problem goes away.
Logged
xenoargh
Admiral
*****
Posts: 3951


View Profile
« Reply #3588 on: September 13, 2017, 01:51:47 PM »

Ahh.... betcha it's:

ezColony.addTag(Tags.STATION);
Logged

Check out my SS projects Smiley
xenoargh
Admiral
*****
Posts: 3951


View Profile
« Reply #3589 on: September 13, 2017, 01:56:12 PM »

Yup, that was it.  IIRC, I had that in there because I think I saw it in code calling up the Dialog.  The UI bug's resolved by removing that; now I need to make sure the Dialog still works. 

<tests>

Yup.  OK, I'll test for any other weirdness and I can fiiiiiinally release.  Sorry Alex, this was just hard to pin down without clues as to what the UI was evaluating there!
« Last Edit: September 13, 2017, 02:18:37 PM by xenoargh » Logged

Check out my SS projects Smiley
Alex
Administrator
Admiral
*****
Posts: 11039


View Profile
« Reply #3590 on: September 13, 2017, 03:48:09 PM »

Nice, glad you got it sorted out!
Logged
Histidine
Admiral
*****
Posts: 1613



View Profile WWW Email
« Reply #3591 on: September 15, 2017, 05:10:32 AM »

Why does allowing a delegated fleet interaction dialog plugin to pull in nearby enemy fleets cause the "main" fleet to disappear here?

No pull in:


(the fleet interaction is in a rules dialog delegate, derived from derelict defenders)

Pull in:


Even calling BattleAPI.join(dialogInteractionTarget_fleet) doesn't make the original fleet participate.

The fleet interaction rule command:
Code: (java)

package com.fs.starfarer.api.impl.campaign.rulecmd;

import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.campaign.CampaignFleetAPI;
import com.fs.starfarer.api.campaign.InteractionDialogAPI;
import com.fs.starfarer.api.campaign.InteractionDialogPlugin;
import com.fs.starfarer.api.campaign.SectorEntityToken;
import com.fs.starfarer.api.campaign.econ.MarketAPI;
import com.fs.starfarer.api.campaign.rules.MemKeys;
import com.fs.starfarer.api.campaign.rules.MemoryAPI;
import com.fs.starfarer.api.combat.BattleCreationContext;
import com.fs.starfarer.api.impl.campaign.FleetEncounterContext;
import com.fs.starfarer.api.impl.campaign.FleetInteractionDialogPluginImpl;
import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.SalvageGenFromSeed;
import com.fs.starfarer.api.util.Misc;
import exerelin.campaign.NexFleetInteractionDialogPluginImpl;
import exerelin.campaign.fleets.ResponseFleetManager;
import exerelin.utilities.ExerelinUtilsFleet;
import java.util.List;
import java.util.Map;

// based on SalvageDefenderInteraction
public class Nex_InvasionDefenseInteraction extends BaseCommandPlugin {
   
   public boolean execute(String ruleId, InteractionDialogAPI dialog, List<Misc.Token> params, final Map<String, MemoryAPI> memoryMap) {
      if (dialog == null) return false;
      
      boolean isRaid = params.get(0).getBoolean(memoryMap);
      final SectorEntityToken entity = dialog.getInteractionTarget();
      final MarketAPI market = entity.getMarket();
      final MemoryAPI memory = memoryMap.get(MemKeys.MARKET);
      final String defenderMemFlag = isRaid ? "$nex_raidResponseFleet" : "$nex_invasionResponseFleet";

      final CampaignFleetAPI defenders = memory.getFleet(defenderMemFlag);
      if (defenders == null) return false;
      
      dialog.setInteractionTarget(defenders);
      defenders.setLocation(entity.getLocation().x, entity.getLocation().y);
      
      final FleetInteractionDialogPluginImpl.FIDConfig config = new FleetInteractionDialogPluginImpl.FIDConfig();
      config.leaveAlwaysAvailable = true;
      config.showFleetAttitude = false;
      config.showTransponderStatus = false;
      config.showWarningDialogWhenNotHostile = false;
      config.alwaysAttackVsAttack = true;
      //config.pullInEnemies = false;   // DEBUG
      //config.pullInAllies = false;
      
      //config.firstTimeEngageOptionText = "Engage the response fleet";
      //config.afterFirstTimeEngageOptionText = "Re-engage the response fleet";
      
      config.dismissOnLeave = false;
      config.printXPToDialog = true;
      
      //long seed = memory.getLong(MemFlags.SALVAGE_SEED);
      //config.salvageRandom = Misc.getRandom(seed, 75);
      
      final NexFleetInteractionDialogPluginImpl plugin = new NexFleetInteractionDialogPluginImpl(config);
      
      final InteractionDialogPlugin originalPlugin = dialog.getPlugin();
      config.delegate = new FleetInteractionDialogPluginImpl.BaseFIDDelegate() {
         @Override
         public void notifyLeave(InteractionDialogAPI dialog) {
            
            dialog.setPlugin(originalPlugin);
            dialog.setInteractionTarget(entity);
            
            //Global.getSector().getCampaignUI().clearMessages();
            
            if (plugin.getContext() instanceof FleetEncounterContext) {
               FleetEncounterContext context = (FleetEncounterContext) plugin.getContext();
               if (context.didPlayerWinEncounter()) {
                  
                  SalvageGenFromSeed.SDMParams p = new SalvageGenFromSeed.SDMParams();
                  p.entity = entity;
                  p.factionId = defenders.getFaction().getId();
                  
                  SalvageGenFromSeed.SalvageDefenderModificationPlugin plugin = Global.getSector().getGenericPlugins().pickPlugin(
                                    SalvageGenFromSeed.SalvageDefenderModificationPlugin.class, p);
                  if (plugin != null) {
                     plugin.reportDefeated(p, entity, defenders);
                  }
                  
                  memory.unset("$hasDefenders");
                  memory.unset(defenderMemFlag);
                  memory.set("$defenderFleetDefeated", true, 0.5f);
                  FireBest.fire(null, dialog, memoryMap, "BeatDefendersContinue");
               } else {
                  defenders.setContainingLocation(entity.getContainingLocation());
                  defenders.setLocation(entity.getLocation().x, entity.getLocation().y);
                  
                  ResponseFleetManager.getManager().registerResponseFleetAndSetAI(defenders, market,
                        Global.getSector().getPlayerFleet());
                  
                  memory.unset(defenderMemFlag);
                  dialog.dismiss();
               }
               // deduct response fleet points now that fleet has spawned and is permanent (or dead)
               float pointsToDeduct = ExerelinUtilsFleet.getFleetGenPoints(defenders);
               Global.getLogger(this.getClass()).info("Removing " + pointsToDeduct + " reserve points from " + market.getName());
               ResponseFleetManager.modifyReserveSize(market, pointsToDeduct);
               // TODO: figure out what to do with stations
               
            } else {
               dialog.dismiss();
            }
         }
         @Override
         public void battleContextCreated(InteractionDialogAPI dialog, BattleCreationContext bcc) {
            bcc.aiRetreatAllowed = false;
            //bcc.objectivesAllowed = false;
            bcc.enemyDeployAll = true;
         }
      };
      
      
      dialog.setPlugin(plugin);
      plugin.init(dialog);
   
      return true;
   }
}

Logged

Originem
Commander
***
Posts: 140


Dancing like a boss.


View Profile
« Reply #3592 on: September 15, 2017, 08:29:38 AM »

How to get the ship's origin hull id with d-mod?
If I want to get the hull id without d-mod, should that be it:
member.getHullSpec().isDHull() ? member.getHullSpec().getDParentHullId() : member.getHullSpec().getBaseHullId()
Logged

Everything belong to AL once and for all.
Alex
Administrator
Admiral
*****
Posts: 11039


View Profile
« Reply #3593 on: September 15, 2017, 09:56:33 AM »

For d-hulls, use getDParentHullId(). getBaseHullId() is for skins, to get the parent hull of the skin.


@Histidine:
Hmm, not sure why that would be. Could you take a look at FleetInteractionDialogPluginImpl.pullInNearbyFleets()? That might point to why the fleet is being skipped over.

If you're going to add stuff to the battle manually via .join(), I think you also need to make a few more calls, e.g. at least
b.genCombined();
and
b.takeSnapshots();

Also, depending on where in the code you do that, there may be a disparity between the combined fleet that's displayed and the actual combined fleet.

Logged
Histidine
Admiral
*****
Posts: 1613



View Profile WWW Email
« Reply #3594 on: September 16, 2017, 12:08:24 AM »

It seems as if BattleAPI.genCombined() or BattleAPI.takeSnapshots() "loses" the main enemy fleet, presumably because it's not in the same containingLocation as the other participants (see screenshot).

I worked around the issue by adding the defender fleet to the star system prior to creating the encounter dialog, and removing it afterwards.

Logged

passwalker
Lieutenant
**
Posts: 64



View Profile
« Reply #3595 on: September 16, 2017, 04:05:00 AM »

sup.
wheree can i see how EMP ability works, script wise? as in how it picks random target in range and such.
Logged

Any and ALL sprites i ever posted on this forum are FREE to use. even if i'm using them myself. Don't ever, EVER ask for permission, or i will come to your home and EAT YOUR DOG!!!
- all my stuff in on place http://fractalsoftworks.com/forum/index.php?topic=12896.msg218548#msg218548
- Terraformer faction mod http://fractalsoftworks.com/forum/index.php?topic=12907.msg218093#msg218093 - very WIP, coder assistance needed.
my keyboard has malfunctioning buttons E and W. misspelling happens often.
AxleMC131
Admiral
*****
Posts: 967


Amateur World-Builder


View Profile
« Reply #3596 on: September 16, 2017, 02:13:59 PM »

sup.
wheree can i see how EMP ability works, script wise? as in how it picks random target in range and such.

Assuming this gets an answer, I'd like to know too?
Logged



"I ain't one to punch first, but if the mil' wants a piece of me tonight, then they're sure as hell gonna regret it in the morning!"
- Johnson "Johnny" Parker
Morrokain
Captain
****
Posts: 328


Megalith Dreadnought - Archean Order


View Profile
« Reply #3597 on: Today at 12:12:29 AM »

Getting an error when overwriting the campaign tutorial.

Heres the error:
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:

   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.  Huh Is it something behind the scenes with EventManagerAPI? I defined the variable as a "ArcheusTutorialMissionEvent" here:

   protected ArcheusTutorialMissionEvent event;

So it should never be attempting to cast it to a regular "TutorialMissionEvent" variable in the first place.  Angry

Any clue where it is attempting to do this?

The full script:

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:

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.  Smiley
« Last Edit: Today at 12:32:40 PM by Morrokain » Logged
Pages: 1 ... 238 239 [240]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.20 | SMF © 2006-2011, Simple Machines
Simple Audio Video Embedder
Valid XHTML 1.0! Valid CSS!