Starsector API
Loading...
Searching...
No Matches
ScientistAICoreIntel.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel.bar.events;
2
3import java.awt.Color;
4import java.util.List;
5import java.util.Map;
6import java.util.Random;
7import java.util.Set;
8
9import org.lwjgl.util.vector.Vector2f;
10
11import com.fs.starfarer.api.Global;
12import com.fs.starfarer.api.campaign.CampaignFleetAPI;
13import com.fs.starfarer.api.campaign.CargoAPI;
14import com.fs.starfarer.api.campaign.CoreInteractionListener;
15import com.fs.starfarer.api.campaign.FactionAPI;
16import com.fs.starfarer.api.campaign.FleetAssignment;
17import com.fs.starfarer.api.campaign.InteractionDialogAPI;
18import com.fs.starfarer.api.campaign.OptionPanelAPI;
19import com.fs.starfarer.api.campaign.SectorEntityToken;
20import com.fs.starfarer.api.campaign.StarSystemAPI;
21import com.fs.starfarer.api.campaign.TextPanelAPI;
22import com.fs.starfarer.api.campaign.econ.CommoditySpecAPI;
23import com.fs.starfarer.api.campaign.listeners.ListenerUtil;
24import com.fs.starfarer.api.campaign.rules.MemoryAPI;
25import com.fs.starfarer.api.impl.campaign.fleets.AutoDespawnScript;
26import com.fs.starfarer.api.impl.campaign.fleets.FleetFactory.PatrolType;
27import com.fs.starfarer.api.impl.campaign.fleets.FleetFactoryV3;
28import com.fs.starfarer.api.impl.campaign.fleets.FleetParamsV3;
29import com.fs.starfarer.api.impl.campaign.ids.Commodities;
30import com.fs.starfarer.api.impl.campaign.ids.Factions;
31import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
32import com.fs.starfarer.api.impl.campaign.ids.Tags;
33import com.fs.starfarer.api.impl.campaign.intel.BaseIntelPlugin;
34import com.fs.starfarer.api.impl.campaign.intel.raid.AssembleStage;
35import com.fs.starfarer.api.impl.campaign.procgen.SalvageEntityGenDataSpec.DropData;
36import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.SalvageEntity;
37import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.special.BaseSalvageSpecial;
38import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.special.TransmitterTrapSpecial;
39import com.fs.starfarer.api.ui.SectorMapAPI;
40import com.fs.starfarer.api.ui.TooltipMakerAPI;
41import com.fs.starfarer.api.util.Misc;
42import com.fs.starfarer.api.util.Misc.Token;
43
45
46 protected SectorEntityToken cache;
47 protected StarSystemAPI cacheSystem;
49 protected boolean keptPromise = true;
50
52 this.cache = cache;
53 cacheSystem = cache.getStarSystem();
54 this.event = event;
55 Misc.makeImportant(cache, "saci");
56
57 cache.getMemoryWithoutUpdate().set("$saic_eventRef", this);
58 }
59
60 @Override
61 public boolean callEvent(String ruleId, InteractionDialogAPI dialog,
62 List<Token> params, Map<String, MemoryAPI> memoryMap) {
63 String action = params.get(0).getString(memoryMap);
64
65 CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
66 CargoAPI cargo = playerFleet.getCargo();
67 MemoryAPI memory = cache.getMemoryWithoutUpdate();
68
69 if (action.equals("putValuesInMemory")) {
70 memory.set("$saic_marketOnOrAt", event.getShownAt().getOnOrAt(), 0);
71 memory.set("$saic_marketName", event.getShownAt().getName(), 0);
72 memory.set("$saic_heOrShe", event.getHeOrShe(), 0);
73 } else if (action.equals("genLootWithCore")) {
74 genLoot(dialog, memoryMap, true);
75 } else if (action.equals("genLootNoCore")) {
76 genLoot(dialog, memoryMap, false);
77 }
78
79 return true;
80 }
81
82 @Override
83 protected void notifyEnding() {
84 super.notifyEnding();
85
86 // actually, probably makes more sense as a one-off
87// float timeout = 120f + (float) Math.random() * 120f;
88// BarEventManager.getInstance().setTimeout(ScientistAICoreBarEventCreator.class, timeout);
89 }
90
91 protected void genLoot(final InteractionDialogAPI dialog, Map<String, MemoryAPI> memoryMap, boolean withCore) {
92 OptionPanelAPI options = dialog.getOptionPanel();
93 TextPanelAPI text = dialog.getTextPanel();
94
95 MemoryAPI memory = cache.getMemoryWithoutUpdate();
96 long seed = memory.getLong(MemFlags.SALVAGE_SEED);
97 Random random = Misc.getRandom(seed, 100);
98
99 DropData d = new DropData();
100 d.chances = 10;
101 d.group = "blueprints";
102 cache.addDropRandom(d);
103
104 d = new DropData();
105 d.chances = 1;
106 d.group = "rare_tech";
107 cache.addDropRandom(d);
108
109 CargoAPI salvage = SalvageEntity.generateSalvage(random,
110 1f, 1f, 1f, 1f, cache.getDropValue(), cache.getDropRandom());
111 CargoAPI extra = BaseSalvageSpecial.getCombinedExtraSalvage(memoryMap);
112 salvage.addAll(extra);
113 BaseSalvageSpecial.clearExtraSalvage(memoryMap);
114 if (!extra.isEmpty()) {
115 ListenerUtil.reportExtraSalvageShown(cache);
116 }
117
118 if (withCore) {
119 salvage.addCommodity(Commodities.ALPHA_CORE, 1);
120 keptPromise = false;
121 } else {
122 keptPromise = true;
123 }
124
125
126 dialog.getVisualPanel().showLoot("Salvaged", salvage, false, true, true, new CoreInteractionListener() {
127 public void coreUIDismissed() {
128 dialog.dismiss();
129 dialog.hideTextPanel();
130 dialog.hideVisualPanel();
131 Misc.fadeAndExpire(cache);
132
133 Global.getSector().addScript(ScientistAICoreIntel.this);
135 cache = null;
136 }
137 });
138 options.clearOptions();
139 dialog.setPromptText("");
140
141 if (keptPromise) {
142 if (random.nextFloat() > 0.5f) {
143 SectorEntityToken loc = cache.getContainingLocation().createToken(cache.getLocation());
144 spawnPiratesToInvestigate(loc, 50f + random.nextFloat() * 50f);
145 if (random.nextFloat() > 0.5f) {
146 spawnPiratesToInvestigate(loc, 50f + random.nextFloat() * 50f);
147 }
148 }
149 }
150 }
151
152
153 protected void addBulletPoints(TooltipMakerAPI info, ListInfoMode mode) {
154
155 Color h = Misc.getHighlightColor();
156 Color g = Misc.getGrayColor();
157 float pad = 3f;
158 float opad = 10f;
159
160 float initPad = pad;
161 if (mode == ListInfoMode.IN_DESC) initPad = opad;
162
163 Color tc = getBulletColorForMode(mode);
164
165 bullet(info);
166 boolean isUpdate = getListInfoParam() != null;
167
168 initPad = 0f;
169
170 unindent(info);
171 }
172
173
174 @Override
175 public void createIntelInfo(TooltipMakerAPI info, ListInfoMode mode) {
176 Color c = getTitleColor(mode);
177 info.addPara(getName(), c, 0f);
178 addBulletPoints(info, mode);
179
180 }
181
182 @Override
183 public void createSmallDescription(TooltipMakerAPI info, float width, float height) {
184 Color h = Misc.getHighlightColor();
185 Color g = Misc.getGrayColor();
186 Color tc = Misc.getTextColor();
187 float pad = 3f;
188 float opad = 10f;
189
190
191 CommoditySpecAPI spec = Global.getSettings().getCommoditySpec(Commodities.ALPHA_CORE);
192 if (spec != null) {
193 info.addImage(spec.getIconName(), width, 80, opad);
194 }
195
196 addBulletPoints(info, ListInfoMode.IN_DESC);
197
198 if (cacheSystem == null) {
199 return; // hack to make old save work...
200 }
201
202 if (isEnding()) {
203 info.addPara("You've found and looted the cache of pre-Collapse technology in the " +
204 cacheSystem.getNameWithLowercaseType() + ".", opad);
205 if (keptPromise) {
206 info.addPara("You've kept your promise to the scientist and placed the AI core in a secure " +
207 "container, to be shipped to " + event.getHimOrHer() + " as soon as you're back " +
208 "in civilized space.", opad);
209 } else {
210 info.addPara("You've taken the AI core promised to the scientist for yourself. " +
211 "Surely, " + event.getHeOrShe() + " was no-one important.", opad);
212 }
213 } else {
214 info.addPara("You've learned that there is a cache of pre-Collapse technology to be found in the " +
215 cacheSystem.getNameWithLowercaseType() + ".", opad);
216
217 info.addPara("The scientist that informed you of this wants the Alpha Core from this " +
218 "cache as payment for " + event.getHisOrHer() + " services.", opad);
219 }
220
221 }
222
223 @Override
224 public String getIcon() {
225 //CommoditySpecAPI spec = Global.getSettings().getCommoditySpec(Commodities.AI_CORES);
226 CommoditySpecAPI spec = Global.getSettings().getCommoditySpec(Commodities.ALPHA_CORE);
227 return spec.getIconName();
228 }
229
230 @Override
231 public Set<String> getIntelTags(SectorMapAPI map) {
232 Set<String> tags = super.getIntelTags(map);
233 tags.add(Tags.INTEL_MISSIONS);
234 tags.add(Tags.INTEL_ACCEPTED);
235 tags.add(Tags.INTEL_EXPLORATION);
236 return tags;
237 }
238
239 public String getSortString() {
240 return "Technology Cache";
241 }
242
243 public String getName() {
244 if (isEnded() || isEnding()) {
245 return "Technology Cache - Looted";
246 }
247 return "Technology Cache";
248 }
249
250 @Override
251 public FactionAPI getFactionForUIColors() {
252 return super.getFactionForUIColors();
253 }
254
255 public String getSmallDescriptionTitle() {
256 return getName();
257 }
258
259 @Override
260 public SectorEntityToken getMapLocation(SectorMapAPI map) {
261 return cache;
262 }
263
264 @Override
265 public boolean shouldRemoveIntel() {
266 return super.shouldRemoveIntel();
267 //return false;
268 }
269
270 @Override
271 public String getCommMessageSound() {
272 return "ui_discovered_entity";
273 }
274
275
276
277 public static void spawnPiratesToInvestigate(SectorEntityToken locToken, float fp) {
278
279 PatrolType type;
280 if (fp < AssembleStage.FP_SMALL * 1.5f) {
281 type = PatrolType.FAST;
282 } else if (fp < AssembleStage.FP_MEDIUM * 1.5f) {
283 type = PatrolType.COMBAT;
284 } else {
285 type = PatrolType.HEAVY;
286 }
287
288 FleetParamsV3 params = new FleetParamsV3(
289 null,
290 Global.getSector().getPlayerFleet().getLocationInHyperspace(),
291 Factions.PIRATES,
292 null,
293 type.getFleetType(),
294 fp, // combatPts
295 0f, // freighterPts
296 fp * 0.1f, // tankerPts
297 0f, // transportPts
298 0f, // linerPts
299 0f, // utilityPts
300 0f // qualityMod
301 );
302
303 CampaignFleetAPI fleet = FleetFactoryV3.createFleet(params);
304 if (fleet.isEmpty()) fleet = null;
305
306 if (fleet != null) {
307 fleet.addScript(new AutoDespawnScript(fleet));
308
309 fleet.setTransponderOn(false);
310 fleet.getMemoryWithoutUpdate().set(MemFlags.MEMORY_KEY_PIRATE, true);
311
312 float range = 2000f + (float) Math.random() * 2000f;
313 Vector2f loc = Misc.getPointAtRadius(locToken.getLocation(), range);
314
315 locToken.getContainingLocation().addEntity(fleet);
316 fleet.setLocation(loc.x, loc.y);
317
318 TransmitterTrapSpecial.makeFleetInterceptPlayer(fleet, false, true, 30f);
319
320 fleet.addAssignment(FleetAssignment.PATROL_SYSTEM, locToken, 1000f);
321 //fleet.addDropRandom("blueprints_guaranteed", 1);
322 }
323
324 }
325
326}
327
328
329
330
331
332
333
static SettingsAPI getSettings()
Definition Global.java:51
static SectorAPI getSector()
Definition Global.java:59
ScientistAICoreIntel(SectorEntityToken cache, ScientistAICoreBarEvent event)
static void spawnPiratesToInvestigate(SectorEntityToken locToken, float fp)
void genLoot(final InteractionDialogAPI dialog, Map< String, MemoryAPI > memoryMap, boolean withCore)
boolean callEvent(String ruleId, InteractionDialogAPI dialog, List< Token > params, Map< String, MemoryAPI > memoryMap)
void createSmallDescription(TooltipMakerAPI info, float width, float height)
CommoditySpecAPI getCommoditySpec(String commodityId)