Starsector API
Loading...
Searching...
No Matches
AbyssalLocationDespawner.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.enc;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import com.fs.starfarer.api.EveryFrameScript;
7import com.fs.starfarer.api.Global;
8import com.fs.starfarer.api.campaign.CampaignFleetAPI;
9import com.fs.starfarer.api.campaign.JumpPointAPI;
10import com.fs.starfarer.api.campaign.JumpPointAPI.JumpDestination;
11import com.fs.starfarer.api.campaign.NascentGravityWellAPI;
12import com.fs.starfarer.api.campaign.SectorEntityToken;
13import com.fs.starfarer.api.campaign.StarSystemAPI;
14import com.fs.starfarer.api.util.IntervalUtil;
15import com.fs.starfarer.api.util.Misc;
16
18
19 protected IntervalUtil interval = new IntervalUtil(1f, 2f);
20 protected StarSystemAPI system;
21 //protected float elapsed;
22
23 public AbyssalLocationDespawner(StarSystemAPI system) {
24 this.system = system;
25 }
26
27 public void advance(float amount) {
28 if (system == null) return;
29
30
31 interval.advance(amount);
32 if (interval.intervalElapsed()) {
33
34 // this part is now handled by StrandedGiveTJScript
35// if (system.isCurrentLocation()) {
36// elapsed += interval.getIntervalDuration();
37// CampaignFleetAPI pf = Global.getSector().getPlayerFleet();
38// if (!pf.hasAbility(Abilities.TRANSVERSE_JUMP) && elapsed > 60f &&
39// !Global.getSector().getCampaignUI().isShowingDialog() &&
40// !Global.getSector().getCampaignUI().isShowingMenu()) {
41// Misc.showRuleDialog(pf, "StrandedInDeepSpace");
42// }
43// return;
44// } else {
45// elapsed = 0f;
46// }
47
48 if (system.getDaysSinceLastPlayerVisit() < 10f) {
49 return;
50 }
51
52 CampaignFleetAPI pf = Global.getSector().getPlayerFleet();
53 if (pf == null) {
54 return;
55 }
56 float distLY = Misc.getDistanceLY(pf.getLocationInHyperspace(), system.getLocation());
57 if (distLY < 5) {
58 return;
59 }
60
61 Global.getSector().removeStarSystemNextFrame(system);
62
63
64 List<SectorEntityToken> remove = new ArrayList<SectorEntityToken>();
65 for (SectorEntityToken curr : Global.getSector().getHyperspace().getJumpPoints()) {
66 JumpPointAPI jp = (JumpPointAPI) curr;
67 if (jp.getDestinations().isEmpty()) continue;
68 JumpDestination dest = jp.getDestinations().get(0);
69 if (dest.getDestination() == null) continue;
70 if (system == dest.getDestination().getStarSystem()) {
71 remove.add(curr);
72 }
73 }
74
75 for (NascentGravityWellAPI curr : Global.getSector().getHyperspace().getGravityWells()) {
76 if (curr.getTarget() == null) continue;
77 if (system == curr.getTarget().getStarSystem()) {
78 remove.add(curr);
79 }
80 }
81
82 remove.add(system.getHyperspaceAnchor());
83
84 for (SectorEntityToken curr : remove) {
85 Global.getSector().getHyperspace().removeEntity(curr);
86 }
87
88 system = null;
89 }
90 }
91
92 public boolean isDone() {
93 return system == null;
94 }
95
96 public boolean runWhilePaused() {
97 return false;
98 }
99}
100
101
102
static SectorAPI getSector()
Definition Global.java:59