Starsector API
Loading...
Searching...
No Matches
PersonalFleetScript.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.fleets;
2
3import java.util.Random;
4
5import com.fs.starfarer.api.EveryFrameScript;
6import com.fs.starfarer.api.Global;
7import com.fs.starfarer.api.campaign.BattleAPI;
8import com.fs.starfarer.api.campaign.CampaignEventListener.FleetDespawnReason;
9import com.fs.starfarer.api.campaign.CampaignFleetAPI;
10import com.fs.starfarer.api.campaign.listeners.FleetEventListener;
11import com.fs.starfarer.api.characters.PersonAPI;
12import com.fs.starfarer.api.impl.campaign.ids.People;
13
14public abstract class PersonalFleetScript implements EveryFrameScript, FleetEventListener {
15
16 protected String personId;
17
18 protected float minRespawnDelayDays = 1f;
19 protected float maxRespawnDelayDays = 2f;
20
21 protected float minFailedSpawnRespawnDelayDays = 1f;
22 protected float maxFailedSpawnRespawnDelayDays = 2f;
23 protected float currDelay;
24 protected CampaignFleetAPI fleet;
25 protected Random random = new Random();
26 protected boolean done = false;
27
29 this.personId = personId;
30 Global.getSector().addScript(this);
31 }
32
33 public PersonAPI getPerson() {
34 return People.getPerson(personId);
35 }
36
37 public boolean isDone() {
38 return done;
39 }
40
41 public boolean runWhilePaused() {
42 return false;
43 }
44
45 public void advance(float amount) {
46 if (amount <= 0 || isDone()) return;
47
48 if (fleet != null && !fleet.isAlive()) {
49 fleet = null;
50 }
51
52 if (fleet == null) {
53 float days = Global.getSector().getClock().convertToDays(amount);
54 currDelay -= days;
55 if (currDelay <= 0f) {
56 currDelay = 0f;
57
58 if (shouldScriptBeRemoved() || getPerson() == null) {
59 done = true;
60 return;
61 }
62
63 if (canSpawnFleetNow()) {
64 fleet = spawnFleet();
65 if (fleet != null) {
66 fleet.addEventListener(this);
67 }
68 }
69 if (fleet == null) {
72 }
73 }
74 }
75 }
76
77
78 public abstract CampaignFleetAPI spawnFleet();
79 public abstract boolean canSpawnFleetNow();
80 public abstract boolean shouldScriptBeRemoved();
81
82 public void reportFleetDespawnedToListener(CampaignFleetAPI fleet, FleetDespawnReason reason, Object param) {
83 if (fleet == this.fleet) {
84 this.fleet = null;
87 }
88 }
89
90 public void reportBattleOccurred(CampaignFleetAPI fleet, CampaignFleetAPI primaryWinner, BattleAPI battle) {
91 }
92
93 public String getPersonId() {
94 return personId;
95 }
96
97 public void setPersonId(String personId) {
98 this.personId = personId;
99 }
100
101 public float getMinRespawnDelayDays() {
102 return minRespawnDelayDays;
103 }
104
106 this.minRespawnDelayDays = minRespawnDelayDays;
107 }
108
109 public float getMaxRespawnDelayDays() {
110 return maxRespawnDelayDays;
111 }
112
114 this.maxRespawnDelayDays = maxRespawnDelayDays;
115 }
116
120
122 this.minFailedSpawnRespawnDelayDays = minFailedSpawnRespawnDelayDays;
123 }
124
128
130 this.maxFailedSpawnRespawnDelayDays = maxFailedSpawnRespawnDelayDays;
131 }
132
133 public float getCurrDelay() {
134 return currDelay;
135 }
136
137 public void setCurrDelay(float currDelay) {
138 this.currDelay = currDelay;
139 }
140
141 public CampaignFleetAPI getFleet() {
142 return fleet;
143 }
144
145 public void setFleet(CampaignFleetAPI fleet) {
146 this.fleet = fleet;
147 }
148
149 public Random getRandom() {
150 return random;
151 }
152
153 public void setRandom(Random random) {
154 this.random = random;
155 }
156
157
158}
159
static SectorAPI getSector()
Definition Global.java:59
void setMaxFailedSpawnRespawnDelayDays(float maxFailedSpawnRespawnDelayDays)
void reportBattleOccurred(CampaignFleetAPI fleet, CampaignFleetAPI primaryWinner, BattleAPI battle)
void setMinFailedSpawnRespawnDelayDays(float minFailedSpawnRespawnDelayDays)
void reportFleetDespawnedToListener(CampaignFleetAPI fleet, FleetDespawnReason reason, Object param)