Starsector API
Loading...
Searching...
No Matches
BaseCustomBountyCreator.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.missions.cb;
2
3import java.awt.Color;
4import java.util.ArrayList;
5import java.util.List;
6import java.util.Random;
7
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.campaign.CampaignFleetAPI;
10import com.fs.starfarer.api.campaign.FactionAPI;
11import com.fs.starfarer.api.campaign.StarSystemAPI;
12import com.fs.starfarer.api.campaign.TextPanelAPI;
13import com.fs.starfarer.api.campaign.econ.MarketAPI;
14import com.fs.starfarer.api.characters.PersonAPI;
15import com.fs.starfarer.api.fleet.FleetMemberAPI;
16import com.fs.starfarer.api.fleet.FleetMemberType;
17import com.fs.starfarer.api.impl.campaign.CoreReputationPlugin.RepRewards;
18import com.fs.starfarer.api.impl.campaign.DebugFlags;
19import com.fs.starfarer.api.impl.campaign.missions.hub.BaseHubMission.Abortable;
20import com.fs.starfarer.api.impl.campaign.missions.hub.BaseHubMission.EntityAdded;
21import com.fs.starfarer.api.impl.campaign.missions.hub.HubMissionWithBarEvent;
22import com.fs.starfarer.api.ui.TooltipMakerAPI;
23import com.fs.starfarer.api.util.Misc;
24
26 public static float DEFAULT_FREQUENCY = 10f;
27
28 public float getBountyDays() {
29 return CBStats.DEFAULT_DAYS;
30 }
31
32 public void addTargetLocationAndDescriptionBulletPoint(TooltipMakerAPI info,
33 Color tc, float pad, HubMissionWithBarEvent mission,
34 CustomBountyData data) {
35 if (data.system != null) {
36 info.addPara("Target is in the " + data.system.getNameWithLowercaseTypeShort() + "", tc, pad);
37 }
38 }
39
40 public void addTargetLocationAndDescription(TooltipMakerAPI info, float width, float height, HubMissionWithBarEvent mission, CustomBountyData data) {
41 float opad = 10f;
42 float pad = 3f;
43 Color h = Misc.getHighlightColor();
44 if (data.system != null) {
45 info.addPara("The target is located in the " + data.system.getNameWithLowercaseType() + ".", opad);
46 }
47 }
48
49 public void addIntelAssessment(TextPanelAPI text, HubMissionWithBarEvent mission, CustomBountyData data) {
50 float opad = 10f;
51 List<FleetMemberAPI> list = new ArrayList<FleetMemberAPI>();
52 List<FleetMemberAPI> members = data.fleet.getFleetData().getMembersListCopy();
53 int max = 7;
54 int cols = 7;
55 float iconSize = 440 / cols;
56 Color h = Misc.getHighlightColor();
57
58
59 for (FleetMemberAPI member : members) {
60 if (list.size() >= max) break;
61
62 if (member.isFighterWing()) continue;
63
64 FleetMemberAPI copy = Global.getFactory().createFleetMember(FleetMemberType.SHIP, member.getVariant());
65 if (member.isFlagship()) {
66 copy.setCaptain(data.fleet.getCommander());
67 }
68 list.add(copy);
69 }
70
71 if (!list.isEmpty()) {
72 TooltipMakerAPI info = text.beginTooltip();
73 info.setParaSmallInsignia();
74 info.addPara(Misc.ucFirst(mission.getPerson().getHeOrShe()) + " taps a data pad, and " +
75 "an intel assessment shows up on your tripad.", 0f);
76 info.addShipList(cols, 1, iconSize, data.fleet.getFaction().getBaseUIColor(), list, opad);
77
78 int num = members.size() - list.size();
79
80 if (num < 5) num = 0;
81 else if (num < 10) num = 5;
82 else if (num < 20) num = 10;
83 else num = 20;
84
85 if (num > 1) {
86 info.addPara("The assessment notes the fleet may contain upwards of %s other ships" +
87 " of lesser significance.", opad, h, "" + num);
88 } else if (num > 0) {
89 info.addPara("The assessment notes the fleet may contain several other ships" +
90 " of lesser significance.", opad);
91 } else {
92 info.addPara("It appears to contain complete information about the scope of the assignment.", opad);
93 }
94 text.addTooltip();
95 }
96 return;
97 }
98
99 public void addFleetDescription(TooltipMakerAPI info, float width, float height, HubMissionWithBarEvent mission, CustomBountyData data) {
100// if (hideoutLocation != null) {
101// SectorEntityToken fake = hideoutLocation.getContainingLocation().createToken(0, 0);
102// fake.setOrbit(Global.getFactory().createCircularOrbit(hideoutLocation, 0, 1000, 100));
103//
104// String loc = BreadcrumbSpecial.getLocatedString(fake);
105// loc = loc.replaceAll("orbiting", "hiding out near");
106// loc = loc.replaceAll("located in", "hiding out in");
107// String sheIs = "She is";
108// if (person.getGender() == Gender.MALE) sheIs = "He is";
109// info.addPara(sheIs + " rumored to be " + loc + ".", opad);
110// }
111
112 PersonAPI person = data.fleet.getCommander();
113 FactionAPI faction = person.getFaction();
114 int cols = 7;
115 float iconSize = width / cols;
116 float opad = 10f;
117 Color h = Misc.getHighlightColor();
118
120
121 }
122 boolean deflate = false;
123 if (!data.fleet.isInflated()) {
124 data.fleet.inflateIfNeeded();
125 deflate = true;
126 }
127
128 List<FleetMemberAPI> list = new ArrayList<FleetMemberAPI>();
129 Random random = new Random(person.getNameString().hashCode() * 170000);
130
131 List<FleetMemberAPI> members = data.fleet.getFleetData().getMembersListCopy();
132 int max = 7;
133 for (FleetMemberAPI member : members) {
134 if (list.size() >= max) break;
135
136 if (member.isFighterWing()) continue;
137
138// float prob = (float) member.getFleetPointCost() / 20f;
139// prob += (float) max / (float) members.size();
140// if (member.isFlagship()) prob = 1f;
141// //if (members.size() <= max) prob = 1f;
142//
143// if (random.nextFloat() > prob) continue;
144
145 FleetMemberAPI copy = Global.getFactory().createFleetMember(FleetMemberType.SHIP, member.getVariant());
146 if (member.isFlagship()) {
147 copy.setCaptain(person);
148 }
149 list.add(copy);
150 }
151
152 if (!list.isEmpty()) {
153 info.addPara("The bounty posting contains partial intel on some of the ships in the target fleet.", opad);
154 info.addShipList(cols, 1, iconSize, faction.getBaseUIColor(), list, opad);
155
156 int num = members.size() - list.size();
157 //num = Math.round((float)num * (1f + random.nextFloat() * 0.5f));
158
159 if (num < 5) num = 0;
160 else if (num < 10) num = 5;
161 else if (num < 20) num = 10;
162 else num = 20;
163
164 if (num > 1) {
165 info.addPara("The intel assessment notes the fleet may contain upwards of %s other ships" +
166 " of lesser significance.", opad, h, "" + num);
167 } else if (num > 0) {
168 info.addPara("The intel assessment notes the fleet may contain several other ships" +
169 " of lesser significance.", opad);
170 }
171 }
172
173 if (deflate) {
174 data.fleet.deflate();
175 }
176 }
177
178 public float getFrequency(HubMissionWithBarEvent mission, int difficulty) {
179 PersonAPI person = mission.getPerson();
180 if (!isRepeatableGlobally() && getNumCompletedGlobal() > 0) return 0f;
181 if (!isRepeatablePerPerson() && getNumCompletedForPerson(person) > 0) return 0f;
182
183 float mult = 1f;
185 mult = 1f / (1f + (float) getNumCompletedGlobal() * 0.5f);
186 }
187 return DEFAULT_FREQUENCY * mult;
188 }
189
191 return "$" + getId() + "_numCompleted";
192 }
193 public String getNumCompletedGlobalKey() {
194 return "$" + getId() + "_numCompleted";
195 }
196
197
198 protected boolean isRepeatablePerPerson() {
199 return true;
200 }
201 protected boolean isRepeatableGlobally() {
202 return true;
203 }
205 return false;
206 }
207
208 public String getId() {
209 return getClass().getSimpleName();
210 }
211
212 public boolean systemMatchesRequirement(StarSystemAPI system) {
213 return true;
214 }
215
216 public float getRepFaction() {
217 return RepRewards.TINY;
218 }
219
220 public float getRepPerson() {
221 return RepRewards.MEDIUM;
222 }
223
224 protected static Object STAGE = new Object();
225 protected void beginFleet(HubMissionWithBarEvent mission, CustomBountyData data) {
226 mission.beginStageTrigger(STAGE);
227 }
228
229 protected CampaignFleetAPI createFleet(HubMissionWithBarEvent mission, CustomBountyData data) {
230 mission.triggerMakeFleetIgnoreOtherFleetsExceptPlayer();
231 mission.triggerFleetOnlyEngageableWhenVisibleToPlayer();
232 mission.endTrigger();
233
234 List<Abortable> before = new ArrayList<Abortable>(mission.getChanges());
235 List<CampaignFleetAPI> fleets = mission.runStageTriggersReturnFleets(STAGE);
236 if (fleets.isEmpty()) return null;
237
238 CampaignFleetAPI fleet = fleets.get(0);
239 mission.getChanges().add(new EntityAdded(fleet)); // so it's removed when the mission is abort()ed
240
241 for (Abortable curr : mission.getChanges()) {
242 if (!before.contains(curr)) {
243 data.abortWhenOtherVersionAccepted.add(curr);
244 }
245 }
246 return fleet;
247 }
248
249 public void notifyCompleted(HubMissionWithBarEvent mission, CustomBountyData data) {
250 PersonAPI person = mission.getPerson();
251
252 String key = getNumCompletedGlobalKey();
253 Integer num = (Integer) Global.getSector().getMemoryWithoutUpdate().get(key);
254 if (num == null) num = 0;
255 num++;
256 Global.getSector().getMemoryWithoutUpdate().set(key, num);
257
259 num = (Integer) person.getMemoryWithoutUpdate().get(key);
260 if (num == null) num = 0;
261 num++;
262 person.getMemoryWithoutUpdate().set(key, num);
263 }
264
265 public void notifyFailed(HubMissionWithBarEvent mission, CustomBountyData data) {
266
267 }
268
269 public int getNumCompletedForPerson(PersonAPI person) {
270 String key = getNumCompletedPerPersonKey();
271 Integer num = (Integer) person.getMemoryWithoutUpdate().get(key);
272 if (num == null) num = 0;
273 return num;
274 }
275
277 String key = getNumCompletedGlobalKey();
278 Integer num = (Integer) Global.getSector().getMemoryWithoutUpdate().get(key);
279 if (num == null) num = 0;
280 return num;
281 }
282
283
284 public int getMinDifficulty() {
285 return MIN_DIFFICULTY;
286 }
287
288 public int getMaxDifficulty() {
289 return MAX_DIFFICULTY;
290 }
291
292 public CustomBountyData createBounty(MarketAPI createdAt, HubMissionWithBarEvent mission, int difficulty, Object bountyStage) {
293 return null;
294 }
295
296 public void notifyAccepted(MarketAPI createdAt, HubMissionWithBarEvent mission, CustomBountyData data) {
297
298 }
299
300 public StarSystemAPI getSystemWithNoTimeLimit(CustomBountyData data) {
301 return data.system;
302 }
303
304 public String getBaseBountyName(HubMissionWithBarEvent mission, CustomBountyData data) {
305 return "Bounty";
306 }
307
308 public String getBountyNamePostfix(HubMissionWithBarEvent mission, CustomBountyData data) {
309 return null;
310 }
311
312 public void setRepChangesBasedOnDifficulty(CustomBountyData data, int difficulty) {
313 if (difficulty <= 3) {
314 data.repPerson = RepRewards.SMALL;
315 data.repFaction = RepRewards.TINY;
316 } else if (difficulty <= 7) {
317 data.repPerson = RepRewards.MEDIUM;
318 data.repFaction = RepRewards.SMALL;
319 } else {
320 data.repPerson = RepRewards.HIGH;
321 data.repFaction = RepRewards.SMALL;
322 }
323 }
324
325 public void updateInteractionData(HubMissionWithBarEvent mission, CustomBountyData data) {
326
327 }
328 public String getIconName() {
329 return null;
330 }
331
332}
333
334
335
336
static FactoryAPI getFactory()
Definition Global.java:35
static SectorAPI getSector()
Definition Global.java:59
String getBaseBountyName(HubMissionWithBarEvent mission, CustomBountyData data)
void notifyCompleted(HubMissionWithBarEvent mission, CustomBountyData data)
String getBountyNamePostfix(HubMissionWithBarEvent mission, CustomBountyData data)
void addIntelAssessment(TextPanelAPI text, HubMissionWithBarEvent mission, CustomBountyData data)
CustomBountyData createBounty(MarketAPI createdAt, HubMissionWithBarEvent mission, int difficulty, Object bountyStage)
void addFleetDescription(TooltipMakerAPI info, float width, float height, HubMissionWithBarEvent mission, CustomBountyData data)
void beginFleet(HubMissionWithBarEvent mission, CustomBountyData data)
void updateInteractionData(HubMissionWithBarEvent mission, CustomBountyData data)
float getFrequency(HubMissionWithBarEvent mission, int difficulty)
void notifyAccepted(MarketAPI createdAt, HubMissionWithBarEvent mission, CustomBountyData data)
CampaignFleetAPI createFleet(HubMissionWithBarEvent mission, CustomBountyData data)
void notifyFailed(HubMissionWithBarEvent mission, CustomBountyData data)
void addTargetLocationAndDescriptionBulletPoint(TooltipMakerAPI info, Color tc, float pad, HubMissionWithBarEvent mission, CustomBountyData data)
void addTargetLocationAndDescription(TooltipMakerAPI info, float width, float height, HubMissionWithBarEvent mission, CustomBountyData data)
FleetMemberAPI createFleetMember(FleetMemberType type, String variantOrWingId)