Is there a way to override the current dialogue and force it into a ship recovery from within that dialog script?
that probably didn't make sense, so here's what I'm trying to do specifically (trimmed slightly for length):
1) Manager EveryFrameScript is added by ModPlugin, and under certain conditions adds Event EveryFrameScript instance and serves it a system (this part works fine, and I'm pretty sure isn't breaking the rest of it)
2) Event EveryFrameScript spawns a derelict, and assigns it some custom special interaction dialogue. That (the spawning and assigning) looks like this:
protected void spawnWreck(StarSystemAPI system) {
WeightedRandomPicker<String> factions = SalvageSpecialAssigner.getNearbyFactions(null, system.getLocation(), 15f, 5f, 5f);
String faction = factions.pick();
String variantId = DerelictShipEntityPlugin.pickLargeVariantId(faction, new Random());
ShipCondition condition = Math.random() > 0.5f ? ShipCondition.PRISTINE : ShipCondition.GOOD;
DerelictShipEntityPlugin.DerelictShipData params = new DerelictShipEntityPlugin.DerelictShipData(new ShipRecoverySpecial.PerShipData(variantId, condition), false);
params.durationDays = duration;
entity = (CustomCampaignEntityAPI) BaseThemeGenerator.addSalvageEntity(system, Entities.WRECK, Factions.NEUTRAL, params);
entity.addTag(Tags.EXPIRES);
DerelictShipEntityPlugin plugin = new DerelictShipEntityPlugin();
plugin.init(entity, params);
Misc.setSalvageSpecial(entity, (Object) new VayraGhostShipSpecial.VayraGhostShipSpecialData((CustomCampaignEntityAPI) entity));
entity.setName("Derelict Ship (" + Global.getSettings().getVariant(variantId).getFullDesignationWithHullName() + ")");
}
3) Here's where it gets complicated. The special interaction dialogue script contains this specialData subclass:
public static class VayraGhostShipSpecialData implements SalvageSpecialInteraction.SalvageSpecialData {
public Danger danger;
public Type type;
public CustomCampaignEntityAPI entity;
public ShipVariantAPI variant;
public VayraGhostShipSpecialData(CustomCampaignEntityAPI entity) {
this.entity = entity;
DerelictShipEntityPlugin plugin = (DerelictShipEntityPlugin) entity.getCustomPlugin();
PerShipData shipData = plugin.getData().ship;
this.variant = shipData.variant;
if (this.variant == null) {
this.variant = Global.getSettings().getVariant(shipData.variantId);
}
shipData.variantId = null;
this.variant = this.variant.clone();
this.danger = DANGERS.pick();
log.info("picked danger level " + this.danger);
if (this.danger.equals(Danger.NONE)) {
this.type = null;
log.info("not picking a danger type");
} else {
this.type = TYPES.pick();
log.info("picked danger type " + this.type);
}
}
@Override
public SalvageSpecialInteraction.SalvageSpecialPlugin createSpecialPlugin() {
return new VayraGhostShipSpecial();
}
}
And does all this:
@Override
public void optionSelected(String optionText, Object optionData) {
if (CONFIRM.equals(optionData)) {
(a whole bunch of stuff/other options go here)
} else if (NEVER_AGAIN.equals(optionData)) {
setDone(true);
setShowAgain(false);
setEndWithContinue(false);
}
if (recoverable) {
SalvageSpecialAssigner.ShipRecoverySpecialCreator creator = new SalvageSpecialAssigner.ShipRecoverySpecialCreator(null, 0, 0, false, null, null);
ShipRecoverySpecialData specialData = (ShipRecoverySpecialData) creator.createSpecial(entity, null);
Misc.setSalvageSpecial(entity, specialData);
ShipRecoverySpecial special = new ShipRecoverySpecial();
special.init(dialog, specialData);
setDone(true);
setShowAgain(false);
}
}
Problem is, even if recoverable == true, the ship isn't recoverable - like I can't attach a new salvageSpecial to it from inside another salvageSpecial, or while another one is attached or something.
Presumably I'm doing something real dumb here, but I can't quite figure out what the "right" way to do this is. Any help would be much appreciated.