Starsector API
Loading...
Searching...
No Matches
EventTestPluginImpl.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.procgen;
2
3import java.awt.Color;
4import java.util.ArrayList;
5import java.util.LinkedHashMap;
6import java.util.List;
7import java.util.Map;
8import java.util.Random;
9
10import org.lwjgl.util.vector.Vector2f;
11
12import com.fs.starfarer.api.Global;
13import com.fs.starfarer.api.campaign.CampaignClockAPI;
14import com.fs.starfarer.api.campaign.CampaignFleetAPI;
15import com.fs.starfarer.api.campaign.FactionAPI;
16import com.fs.starfarer.api.campaign.InteractionDialogAPI;
17import com.fs.starfarer.api.campaign.InteractionDialogPlugin;
18import com.fs.starfarer.api.campaign.LocationAPI;
19import com.fs.starfarer.api.campaign.OptionPanelAPI;
20import com.fs.starfarer.api.campaign.PlanetAPI;
21import com.fs.starfarer.api.campaign.SectorEntityToken;
22import com.fs.starfarer.api.campaign.StarSystemAPI;
23import com.fs.starfarer.api.campaign.TextPanelAPI;
24import com.fs.starfarer.api.campaign.VisualPanelAPI;
25import com.fs.starfarer.api.campaign.comm.IntelInfoPlugin;
26import com.fs.starfarer.api.campaign.econ.Industry;
27import com.fs.starfarer.api.campaign.econ.MarketAPI;
28import com.fs.starfarer.api.campaign.rules.MemoryAPI;
29import com.fs.starfarer.api.characters.MutableCharacterStatsAPI;
30import com.fs.starfarer.api.characters.PersonAPI;
31import com.fs.starfarer.api.combat.EngagementResultAPI;
32import com.fs.starfarer.api.combat.ShipAPI.HullSize;
33import com.fs.starfarer.api.combat.ShipHullSpecAPI;
34import com.fs.starfarer.api.combat.WeaponAPI.AIHints;
35import com.fs.starfarer.api.impl.campaign.AbyssalLightEntityPlugin.AbyssalLightParams;
36import com.fs.starfarer.api.impl.campaign.DebugFlags;
37import com.fs.starfarer.api.impl.campaign.eventide.DuelDialogDelegate;
38import com.fs.starfarer.api.impl.campaign.eventide.DuelPanel;
39import com.fs.starfarer.api.impl.campaign.ids.Entities;
40import com.fs.starfarer.api.impl.campaign.ids.Factions;
41import com.fs.starfarer.api.impl.campaign.ids.Tags;
42import com.fs.starfarer.api.impl.campaign.intel.bases.PirateBaseIntel;
43import com.fs.starfarer.api.impl.campaign.intel.events.HostileActivityEventIntel;
44import com.fs.starfarer.api.impl.campaign.intel.events.ht.HTScanFactor;
45import com.fs.starfarer.api.impl.campaign.intel.events.ht.HyperspaceTopographyEventIntel;
46import com.fs.starfarer.api.impl.campaign.intel.inspection.HegemonyInspectionManager;
47import com.fs.starfarer.api.impl.campaign.intel.misc.LuddicShrineIntel;
48import com.fs.starfarer.api.impl.campaign.intel.punitive.PunitiveExpeditionManager;
49import com.fs.starfarer.api.impl.campaign.intel.punitive.PunitiveExpeditionManager.PunExData;
50import com.fs.starfarer.api.impl.campaign.plog.PLEntry;
51import com.fs.starfarer.api.impl.campaign.plog.PLIntel;
52import com.fs.starfarer.api.impl.campaign.plog.PlaythroughLog;
53import com.fs.starfarer.api.impl.campaign.population.CoreImmigrationPluginImpl;
54import com.fs.starfarer.api.loading.FighterWingSpecAPI;
55import com.fs.starfarer.api.loading.WeaponSpecAPI;
56import com.fs.starfarer.api.util.Misc;
57
58public class EventTestPluginImpl implements InteractionDialogPlugin {
59
60 protected static enum OptionId {
61 INIT,
62 PIRATE_RAID,
63 PUNITIVE_EXPEDITION,
64 INSPECTION,
65 PICK_STRENGTH,
66 PRINT_LOG,
67 TOPOGRAPHY_POINTS,
68 HAEI_POINTS,
69 ADD_LOG_INTEL,
70 INCREASE_COLONY_SIZE,
71 FINISH_CONSTRUCTION,
72 FIGHT,
73 TUTORIAL,
74 LEAVE,
75 }
76
77 protected InteractionDialogAPI dialog;
78 protected TextPanelAPI textPanel;
79 protected OptionPanelAPI options;
80 protected VisualPanelAPI visual;
81
82 protected CampaignFleetAPI playerFleet;
83 protected PlanetAPI planet;
84
85 protected PunExData punExData = null;
86 protected boolean sendInspection = false;
87
88 protected static final Color HIGHLIGHT_COLOR = Global.getSettings().getColor("buttonShortcut");
89
90 public void init(InteractionDialogAPI dialog) {
91 this.dialog = dialog;
92
93 textPanel = dialog.getTextPanel();
94 options = dialog.getOptionPanel();
95 visual = dialog.getVisualPanel();
96
97 playerFleet = Global.getSector().getPlayerFleet();
98 planet = (PlanetAPI) dialog.getInteractionTarget();
99
100 visual.setVisualFade(0.25f, 0.25f);
101
102 //visual.showImageVisual(planet.getCustomInteractionDialogImageVisual());
103
104 visual.showLargePlanet(Global.getSector().getEntityById("mazalot"));
105
106 dialog.setOptionOnEscape("Leave", OptionId.LEAVE);
107 optionSelected(null, OptionId.INIT);
108 }
109
110 public Map<String, MemoryAPI> getMemoryMap() {
111 return null;
112 }
113
114 public void backFromEngagement(EngagementResultAPI result) {
115 // no combat here, so this won't get called
116 }
117
118
119 public void optionSelected(String text, Object optionData) {
120 if (optionData == null) return;
121
122 if (optionData instanceof Integer) {
123 DebugFlags.FAST_RAIDS = true;
124 Integer str = (Integer) optionData;
125 if (punExData != null) {
126 PunitiveExpeditionManager.getInstance().createExpedition(punExData, str);
127 } else if (sendInspection) {
128 HegemonyInspectionManager.getInstance().createInspection(str);
129 }
130 optionSelected(null, OptionId.LEAVE);
131 return;
132 }
133
134 if (optionData instanceof PunExData) {
135 punExData = (PunExData) optionData;
136 optionSelected(null, OptionId.PICK_STRENGTH);
137 return;
138 }
139
140 OptionId option = (OptionId) optionData;
141
142 if (text != null) {
143 //textPanel.addParagraph(text, Global.getSettings().getColor("buttonText"));
144 dialog.addOptionSelectedText(option);
145 //textPanel.addParagraph("");
146 }
147
148 switch (option) {
149 case INIT:
151
152
153 PersonAPI player = Global.getSector().getPlayerPerson();
154 MutableCharacterStatsAPI stats = player.getStats();
155// stats.addXP((long) (6000f * (float) Math.random() + 100f), textPanel, true);
156// stats.spendStoryPoints(2, true, textPanel, false, 1f, null);
157
158 break;
159 case TUTORIAL:
160 final DuelPanel duelPanel = DuelPanel.createTutorial(true, "soe_ambience");
161 dialog.showCustomVisualDialog(1024, 700, new DuelDialogDelegate(null, duelPanel, dialog, null, true));
162 break;
163 case FIGHT:
164 final DuelPanel duelPanel2 = DuelPanel.createDefault(true, true, "soe_ambience");
165 dialog.showCustomVisualDialog(1024, 700, new DuelDialogDelegate("music_soe_fight", duelPanel2, dialog, null, true));
166
167 //Global.getSector().getIntelManager().addIntel(new TestFleetGroupIntel());
168
169 //new PerseanLeagueBlockade(params, blockadeParams)
170
171// new GensHannanMachinations(dialog);
172
173// dialog.showCustomVisualDialog(1024, 700, new CustomVisualDialogDelegate() {
174// public CustomUIPanelPlugin getCustomPanelPlugin() {
175// return duelPanel2;
176// }
177// public void init(CustomPanelAPI panel, DialogCallbacks callbacks) {
178// duelPanel2.init(panel, callbacks, dialog);
179// }
180// public float getNoiseAlpha() {
181// return 0;
182// }
183// public void advance(float amount) {
184//
185// }
186// public void reportDismissed(int option) {
187// }
188// });
189 //dialog.hideTextPanel();
190 break;
191 case PIRATE_RAID:
192 MarketAPI market = getNearestMarket(false);
193 PirateBaseIntel base = findPirateBase();
194 if (base != null && market != null && market.getStarSystem() != null) {
195 base.startRaid(market.getStarSystem(), 500f);
196 base.makeKnown(textPanel);
197 //print("Attempted to start raid; likely succeeded, see if there's new intel.");
198 optionSelected(null, OptionId.LEAVE);
199 }
200 //addText("")
201 break;
202 case INCREASE_COLONY_SIZE:
203 market = getNearestMarket(false);
204 if (market != null) {
205 int was = market.getSize();
206 CoreImmigrationPluginImpl plugin = new CoreImmigrationPluginImpl(market);
207 plugin.increaseMarketSize();
208 textPanel.addPara("Size of " + market.getName() + " increased from " + was + " to " + market.getSize());
209 }
210 break;
211 case FINISH_CONSTRUCTION:
212 market = getNearestMarket(false);
213 if (market != null) {
214 for (Industry curr : new ArrayList<Industry>(market.getIndustries())) {
215 if (curr.isBuilding()) {
216 curr.finishBuildingOrUpgrading();
217 textPanel.addPara("Finished building or upgrading " + curr.getCurrentName());
218 }
219 }
220 }
221 break;
222 case PUNITIVE_EXPEDITION:
223 options.clearOptions();
224 for (PunExData data : PunitiveExpeditionManager.getInstance().getData().values()) {
225 if (!PunitiveExpeditionManager.getInstance().getExpeditionReasons(data).isEmpty()) {
226 options.addOption("Punitive expedition: " + data.faction.getDisplayName(), data);
227 }
228 }
229 options.addOption("Leave", OptionId.LEAVE, null);
230 break;
231 case INSPECTION:
232 sendInspection = true;
233 optionSelected(null, OptionId.PICK_STRENGTH);
234 break;
235 case PICK_STRENGTH:
236 textPanel.addPara("Select strength");
237 options.clearOptions();
238 options.addOption("100", 100);
239 options.addOption("200", 200);
240 options.addOption("300", 300);
241 options.addOption("400", 400);
242 options.addOption("500", 500);
243 options.addOption("600", 600);
244 options.addOption("800", 800);
245 options.addOption("1000", 1000);
246 options.addOption("Leave", OptionId.LEAVE, null);
247 break;
248 case TOPOGRAPHY_POINTS:
249 HyperspaceTopographyEventIntel.addFactorCreateIfNecessary(
250 new HTScanFactor("Dev mode point increase", 50), dialog);
251 break;
252 case HAEI_POINTS:
253 if (HostileActivityEventIntel.get() != null) {
254 HostileActivityEventIntel intel = HostileActivityEventIntel.get();
255 intel.setRandom(new Random());
256 int p = intel.getProgress();
257 if (p < 500 || p == 599) p = 500;
258 else if (p < 550) p = 550;
259 else p = 599;
260 intel.setProgress(p);
261 textPanel.addPara("Progress set to " + p);
262 }
263 //HostileActivityEventIntel.get().addFactor(new BaseOneTimeFactor(50), dialog);
264 break;
265 case PRINT_LOG:
266
267
268 for (int i = 0; i < 10; i++) {
269 Vector2f loc = Misc.getPointWithinRadius(playerFleet.getLocation(), 10000f);
270 if (Misc.getAbyssalDepth(loc) >= 1f) {
271 AbyssalLightParams params = new AbyssalLightParams();
272 SectorEntityToken e2 = Global.getSector().getHyperspace().addCustomEntity(Misc.genUID(), null, Entities.ABYSSAL_LIGHT, Factions.NEUTRAL, params);
273 e2.setLocation(loc.x, loc.y);
274 }
275 }
276
277// SectorEntityToken e2 = Global.getSector().getHyperspace().addCustomEntity(Misc.genUID(), null, Entities.ABYSSAL_LIGHT, Factions.NEUTRAL);
278// e2.setLocation(playerFleet.getLocation().x, playerFleet.getLocation().y);
279
280
281 //new GensHannanMachinations(dialog);
282
283// if (Global.getSector().getCurrentLocation() instanceof StarSystemAPI) {
284// new HostileActivityIntel((StarSystemAPI) Global.getSector().getCurrentLocation());
285// }
286
287 //BaseEventIntel event = new BaseEventIntel();
288 //HyperspaceTopographyEventIntel event = new HyperspaceTopographyEventIntel(dialog.getTextPanel(), true);
289 //Global.getSector().addScript(this);
290 //Global.getSector().getIntelManager().addIntel(event);
291 //Global.getSector().getListenerManager().addListener(this);
292
294
295 textPanel.addPara("Player log:");
296 String log = "";
297 for (PLEntry e : PlaythroughLog.getInstance().getEntries()) {
298 CampaignClockAPI clock = Global.getSector().getClock().createClock(e.getTimestamp());
299 log += clock.getShortDate() + " " + e.getText() + "\n";
300 }
301 textPanel.setFontVictor();
302 textPanel.addPara(log);
303 textPanel.setFontInsignia();
304
305 LocationAPI loc = Global.getSector().getCurrentLocation();
306 String tags = "";
307 for (String tag : Global.getSector().getCurrentLocation().getTags()) {
308 tags += " " + tag + "\n";
309 }
310 textPanel.addPara("\nTags for " + loc.getName() + ":\n" + tags);
311 if (loc instanceof StarSystemAPI) {
312 textPanel.addPara("\nSystem type: " + ((StarSystemAPI)loc).getType());
313 }
314
315 break;
316 case ADD_LOG_INTEL:
317 PLIntel intel = new PLIntel();
318 Global.getSector().getIntelManager().addIntel(intel, false, textPanel);
319
320 LuddicShrineIntel.addShrineIntelIfNeeded("beholder_station", textPanel);
321 LuddicShrineIntel.addShrineIntelIfNeeded("chicomoztoc", textPanel);
322 LuddicShrineIntel.addShrineIntelIfNeeded("gilead", textPanel);
323 LuddicShrineIntel.addShrineIntelIfNeeded("jangala", textPanel);
324 LuddicShrineIntel.addShrineIntelIfNeeded("killa", textPanel);
325 LuddicShrineIntel.addShrineIntelIfNeeded("volturn", textPanel);
326
327// PromoteOfficerIntel intel = new PromoteOfficerIntel(textPanel);
328// Global.getSector().getIntelManager().addIntel(intel, false, textPanel);
329
330// dialog.showCustomProductionPicker(new BaseCustomProductionPickerDelegateImpl());
331
332 //Global.getSector().getIntelManager().addIntel(intel, false, textPanel);
333
334// for (int i = 0; i < 12 * 3; i++) {
335// for (int j = 0; j < 10; j++) {
336// PlaythroughLog.getInstance().reportEconomyTick(i);
337// }
338// PlaythroughLog.getInstance().reportEconomyMonthEnd();
339// }
340 break;
341 case LEAVE:
342 //Global.getSector().setPaused(false);
343 dialog.dismiss();
344 break;
345 }
346 }
347
348 protected MarketAPI getNearestMarket(boolean playerOnly) {
349 MarketAPI nearest = null;
350 float minDist = Float.MAX_VALUE;
351 CampaignFleetAPI pf = Global.getSector().getPlayerFleet();
352 for (MarketAPI curr : Global.getSector().getEconomy().getMarketsCopy()) {
353 if (curr.isHidden()) continue;
354 if (playerOnly && !curr.isPlayerOwned()) continue;
355
356 float dist = Misc.getDistanceLY(pf, curr.getPrimaryEntity());
357 boolean nearer = dist < minDist;
358 if (dist == minDist && dist == 0 && nearest != null) {
359 float d1 = Misc.getDistance(pf, curr.getPrimaryEntity());
360 float d2 = Misc.getDistance(pf, nearest.getPrimaryEntity());
361 nearer = d1 < d2;
362 }
363 if (nearer) {
364 nearest = curr;
365 minDist = dist;
366 }
367 }
368 return nearest;
369 }
370
371 protected void print(String str) {
372 textPanel.appendToLastParagraph("\n" + str);
373 System.out.println(str);
374 }
375
376 protected void createInitialOptions() {
377 options.clearOptions();
378
379 options.addOption("Fight!", OptionId.FIGHT);
380// options.addOption("Fight tutorial", OptionId.TUTORIAL);
381
382 MarketAPI market = getNearestMarket(false);
383 if (market != null) {
384 options.addOption("Send pirate raid to " + market.getContainingLocation().getName(), OptionId.PIRATE_RAID, null);
385 }
386 options.addOption("Send a punitive expedition", OptionId.PUNITIVE_EXPEDITION);
387 options.addOption("Send an AI inspection", OptionId.INSPECTION);
388 options.addOption("Hyperspace Topography +50 points", OptionId.TOPOGRAPHY_POINTS);
389 options.addOption("Hostile Activity: reseed RNG and cycle progress through 400/450/499", OptionId.HAEI_POINTS);
390 options.addOption("Print player log", OptionId.PRINT_LOG);
391 options.addOption("Add player log intel", OptionId.ADD_LOG_INTEL);
392
393 if (market != null) {
394 options.addOption("Increase size of " + market.getName() + " to " + (market.getSize() + 1), OptionId.INCREASE_COLONY_SIZE);
395 options.addOption("Finish construction on " + market.getName(), OptionId.FINISH_CONSTRUCTION);
396 }
397
398 options.addOption("Leave", OptionId.LEAVE, null);
399 }
400
401
402 protected OptionId lastOptionMousedOver = null;
403 public void optionMousedOver(String optionText, Object optionData) {
404
405 }
406
407 public void advance(float amount) {
408
409 }
410
411 public Object getContext() {
412 return null;
413 }
414
415 public PirateBaseIntel findPirateBase() {
416 for (IntelInfoPlugin p : Global.getSector().getIntelManager().getIntel(PirateBaseIntel.class)) {
417 PirateBaseIntel intel = (PirateBaseIntel) p;
418 if (intel.isEnded() || intel.isEnding()) continue;
419 return intel;
420 }
421 return null;
422 }
423
424
426 List<FactionAPI> factions = Global.getSector().getAllFactions();
427
428 System.out.println();
429 System.out.println("----------------------- FIGHTERS -----------------------");
430 System.out.println();
431
432 Map<String, String> oneFactionFighters = new LinkedHashMap<String, String>();
433 for (FighterWingSpecAPI spec : Global.getSettings().getAllFighterWingSpecs()) {
434 if (spec.hasTag(Tags.RESTRICTED)) continue;
435 int count = 0;
436 String id = spec.getId();
437 String fId = null;
438 List<String> all = new ArrayList<String>();
439 for (FactionAPI f : factions) {
440 if (f.isPlayerFaction()) continue;
441 if (f.getKnownFighters().contains(id)) {
442 count++;
443 fId = f.getId();
444 all.add(fId);
445 }
446 }
447 if (count == 0) {
448 //System.out.println("Fighter wing [" + id + "] has no increased sell frequency anywhere");
449 System.out.println("FIGHTER WING [" + id + "] IS NOT USED BY ANY FACTION");
450 }
451 if (count == 1) {
452 oneFactionFighters.put(id, fId);
453 }
454
455 if (count != 0) {
456 System.out.println("Fighter wing [" + id + "] is known by: [" + Misc.getAndJoined(all) + "]");
457 }
458 }
459
460 System.out.println();
461 System.out.println("----------------------- WEAPONS -----------------------");
462 System.out.println();
463
464 for (WeaponSpecAPI spec : Global.getSettings().getAllWeaponSpecs()) {
465 if (spec.hasTag(Tags.RESTRICTED)) continue;
466 if (spec.hasTag(Tags.NO_SELL)) continue;
467 if (spec.getAIHints().contains(AIHints.SYSTEM)) continue;
468 String id = spec.getWeaponId();
469 int count = 0;
470 List<String> all = new ArrayList<String>();
471 for (FactionAPI f : factions) {
472 if (f.isPlayerFaction()) continue;
473 Float p = f.getWeaponSellFrequency().get(id);
474 if (p != null && p > 1f) {
475 count++;
476 }
477 if (f.knowsWeapon(id)) {
478 all.add(f.getId());
479 }
480 }
481 if (count <= 0) {
482 System.out.println("Weapon [" + id + "] is not sold with higher frequency; known by: [" + Misc.getAndJoined(all) + "]");
483 }
484 }
485
486
487 System.out.println();
488 System.out.println("----------------------- SHIPS -----------------------");
489 System.out.println();
490
491 Map<String, String> oneFactionShips = new LinkedHashMap<String, String>();
492 for (ShipHullSpecAPI spec : Global.getSettings().getAllShipHullSpecs()) {
493 if (spec.hasTag(Tags.RESTRICTED)) continue;
494 if (spec.hasTag(Tags.NO_SELL)) continue;
495 if (spec.getHullSize() == HullSize.FIGHTER) continue;
496 String id = spec.getHullId();
497 if (id.endsWith("_default_D")) continue;
498 if (id.endsWith("_default_D")) continue;
499 if (id.startsWith("module_")) continue;
500 int count = 0;
501 String fId = null;
502 List<String> all = new ArrayList<String>();
503 for (FactionAPI f : factions) {
504 if (f.isPlayerFaction()) continue;
505 if (f.getKnownShips().contains(id)) {
506 count++;
507 fId = f.getId();
508 all.add(fId);
509 }
510 }
511// if (count <= 0) {
512// System.out.println("SHIP [" + id + "] IS NOT USED BY ANY FACTION");
513// }
514
515 if (count == 1) {
516 oneFactionShips.put(id, fId);
517 }
518
519 if (count > 0) {
520 System.out.println("Ship [" + id + "] is known by: [" + Misc.getAndJoined(all) + "]");
521 }
522 }
523
524// System.out.println();
525//
526// for (String id : oneFactionShips.keySet()) {
527// System.out.println("Ship [" + id + "] is only known by [" + oneFactionShips.get(id) + "]");
528// }
529 }
530
531}
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
static SettingsAPI getSettings()
Definition Global.java:51
static SectorAPI getSector()
Definition Global.java:59
List< WeaponSpecAPI > getAllWeaponSpecs()
List< ShipHullSpecAPI > getAllShipHullSpecs()
List< FighterWingSpecAPI > getAllFighterWingSpecs()