Starsector API
Loading...
Searching...
No Matches
HistorianBarEvent.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel.bar.events.historian;
2
3import java.util.LinkedHashMap;
4import java.util.List;
5import java.util.Map;
6import java.util.Random;
7
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.campaign.InteractionDialogAPI;
10import com.fs.starfarer.api.campaign.TextPanelAPI;
11import com.fs.starfarer.api.campaign.econ.MarketAPI;
12import com.fs.starfarer.api.campaign.rules.MemKeys;
13import com.fs.starfarer.api.campaign.rules.MemoryAPI;
14import com.fs.starfarer.api.impl.campaign.intel.bar.events.BarEventManager;
15import com.fs.starfarer.api.impl.campaign.intel.bar.events.BaseBarEvent;
16import com.fs.starfarer.api.impl.campaign.intel.bar.events.historian.HistorianData.HistorianOffer;
17import com.fs.starfarer.api.impl.campaign.plog.PLIntel;
18import com.fs.starfarer.api.impl.campaign.plog.PlaythroughLog;
19import com.fs.starfarer.api.impl.campaign.rulecmd.FireBest;
20import com.fs.starfarer.api.impl.campaign.shared.SharedData;
21import com.fs.starfarer.api.util.Misc;
22
23public class HistorianBarEvent extends BaseBarEvent {
24
25 public static enum OptionId {
26 GREETING,
27 GREETNG_CONTINUE_1,
28 GREETNG_ALREADY_INTRODUCED,
29 GREETNG_PLOG,
30 //GREETNG_PLOG_CONTINUE,
31 WHAT_DO_YOU_HAVE,
32 BACKSTORY_BIT,
33 END_CONVERSATION,
34 }
35
36 public static int MIN_SNAPSHOTS_TO_SHOW_PLOG = 12 * 5;
37
38 public static float PROB_TO_SHOW = 0.5f;
39
40
41 protected long seed;
42 protected MarketAPI market = null;
43
44 protected transient Random random;
45 protected transient List<HistorianOffer> offers = null;
46 //protected transient HistorianBackstoryInfo backstory = null;
47
49 super();
50 seed = Misc.random.nextLong();
51 }
52
53 public boolean shouldShowAtMarket(MarketAPI market) {
55 if (random.nextFloat() > PROB_TO_SHOW) return false;
56 return super.shouldShowAtMarket(market);
57 }
58
59
60 protected void regen(MarketAPI market) {
61 //if (this.market == market) return;
62 this.market = market;
63 done = false;
64
65 random = new Random(seed + market.getId().hashCode());
66// offers = HistorianData.getInstance().getOffers(random, dialog);
67 }
68
69 @Override
70 public void addPromptAndOption(InteractionDialogAPI dialog, Map<String, MemoryAPI> memoryMap) {
71 super.addPromptAndOption(dialog, memoryMap);
72
73 regen(dialog.getInteractionTarget().getMarket());
74
75 TextPanelAPI text = dialog.getTextPanel();
76 text.addPara(getPrompt());
77
78 dialog.getOptionPanel().addOption(getOptionText(), this);
79 //dialog.setOptionColor(this, Misc.getStoryOptionColor());
80
81 }
82
83 protected String getOptionText() {
85 return "Go over to the " + hd.getManOrWoman() + " with the paper book and see what " + hd.getHeOrShe() + " wants";
86 }
87
88 protected String getPrompt() {
90 return "An old " + hd.getManOrWoman() + " sits alone at a table, " +
91 "leafing through what looks like a genuine hardcopy paper book. As you walk by, " +
92 hd.getHeOrShe() + " looks up and offers the seat across from " + hd.getHimOrHer() + ".";
93 }
94
95 @Override
96 public void init(InteractionDialogAPI dialog, Map<String, MemoryAPI> memoryMap) {
97 super.init(dialog, memoryMap);
98
100
101 dialog.getVisualPanel().showPersonInfo(hd.getPerson(), true, true);
102
103 // oh the hacks
104 if (dialog.getInteractionTarget() != null && hd.getPerson() != null) {
105 this.memoryMap = new LinkedHashMap<String, MemoryAPI>(memoryMap);
106 memoryMap = this.memoryMap;
107
108 dialog.getInteractionTarget().setActivePerson(hd.getPerson());
109 MemoryAPI memory = hd.getPerson().getMemory();
110 memoryMap.put(MemKeys.LOCAL, memory);
111 memoryMap.put(MemKeys.PERSON_FACTION, hd.getPerson().getFaction().getMemory());
112 memoryMap.put(MemKeys.ENTITY, dialog.getInteractionTarget().getMemory());
113 }
114
115 if (!hd.isIntroduced()) {
116 optionSelected(null, OptionId.GREETING);
117 } else {
118 boolean hasLog = Global.getSector().getIntelManager().hasIntelOfClass(PLIntel.class);
119 boolean shouldShow = PlaythroughLog.getInstance().getData().size() >= MIN_SNAPSHOTS_TO_SHOW_PLOG;
120 //shouldShow = true;
121 if (!hasLog && shouldShow) {
122 optionSelected(null, OptionId.GREETNG_PLOG);
123 } else {
124 optionSelected(null, OptionId.GREETNG_ALREADY_INTRODUCED);
125 }
126 }
127
128 }
129
130 protected transient HistorianOffer currentOffer = null;
131
132 @Override
133 public void optionSelected(String optionText, Object optionData) {
135
136 if (optionData == OptionId.GREETNG_PLOG) {
137 text.addPara("\"Welcome! I've got something here that I think you'll find very interesting. Your actions over " +
138 "the past several cycles have caused quite a stir in certain corners, and I took it upon myself to " +
139 "look into your history, as it were. Here, let me transfer the synopsis.\"");
140 text.addPara("Your TriPad chimes softly; a new program is ready to be installed.");
141 PLIntel intel = new PLIntel();
142 Global.getSector().getIntelManager().addIntel(intel, false, dialog.getTextPanel());
143 options.clearOptions();
144 options.addOption("\"Thank you! This is fascinating and not at all alarming. Now, what do you have for me?\"", OptionId.WHAT_DO_YOU_HAVE);
145 return;
146 }
147
148// if (optionData == OptionId.GREETNG_PLOG_CONTINUE) {
149// PLIntel intel = new PLIntel();
150// Global.getSector().getIntelManager().addIntel(intel, false, dialog.getTextPanel());
151// options.clearOptions();
152// options.addOption("Continue", OptionId.WHAT_DO_YOU_HAVE);
153// return;
154// }
155
156 if (optionData == OptionId.GREETING) {
157 text.addPara("\"Welcome, welcome, please sit! I'm sure you're wondering why I called you over.\"\n\n" +
158 hd.getUCHeOrShe() + " leans in as if conspiring, \"" +
159 "I think we can help each other, you and I. See, I have the information,\" " +
160 hd.getHeOrShe() + " taps the book, "+"\"And you have the means.\"");
161 text.addPara("\"I am what you might call a historian-adventurer; a rogue archaelogist uncovering the " +
162 "history of the Sector despite the danger of this exceptional era. In the course of my "
163 + "studies I often chance upon hints about where certain " +
164 "pieces of technology might be found. Retrieving those artifacts " +
165 "is, naturally, your role in our arrangement. ... Only if you're interested,"
166 + " of course - but I've done my research " +
167 "on your exploits and I'm sure that you will be interested.\"\n\nSpeech complete, " + hd.getHeOrShe() +
168 " leans back, looking pleased.");
169
170 options.clearOptions();
171 options.addOption("\"I expect you'll be wanting to get paid for this information?\"", OptionId.GREETNG_CONTINUE_1);
172 return;
173 }
174
175 if (optionData == OptionId.GREETNG_CONTINUE_1) {
176 text.addPara("A weary expression passes over the " + hd.getManOrWoman() + "'s face for just a moment before " + hd.getHeOrShe() +
177 " resumes an energetic demeanor.");
178 text.addPara("\"I understand why you would assume that; this is a mercenary age. " +
179 "But no, nothing quite so transactional. " +
180 "History is an uncertain trade, and such an approach " +
181 "would lead to expectations, disappointment, and recrimination. All of which I'm eager to avoid, " +
182 "especially the last.\" An additional wrinkle forms on " + hd.getHisOrHer()+ " face at this.");
183 text.addPara("\"However, if you did find my information valuable, I would gladly accept... donations. Think of it as patronage to " +
184 "fuel my research, which in turn could produce valuable leads. Or it " +
185 "might help to think of it as an investment, but with no obligations incurred " +
186 "by either party. Consider it- you could enrich your own enterprises while contributing to" +
187 " the sum of human knowledge!\"");
188 hd.setIntroduced(true);
189 hd.setRecentlyDonated(); // don't show the donate option first time around
190
191 options.clearOptions();
192 options.addOption("\"Do you have anything for me now?\"", OptionId.WHAT_DO_YOU_HAVE);
193 return;
194 }
195
196 if (optionData == OptionId.GREETNG_ALREADY_INTRODUCED) {
197 text.addPara("\"So good to see you again, " + Global.getSector().getPlayerPerson().getNameString() + "!\"");
198 text.addPara("You spend a couple minutes sharing drinks and conversing about " +
199 "recent goings-on in the Sector. Before long you get down to business.");
200 optionSelected(null, OptionId.WHAT_DO_YOU_HAVE);
201 return;
202 }
203
204 if (optionData == OptionId.WHAT_DO_YOU_HAVE) {
205 text.addPara("The historian tells you about...");
206
207 if (offers == null) {
208 if (random == null) {
209 random = new Random(seed + market.getId().hashCode());
210 }
212 }
213
214// if (backstory == null) {
215// backstory = HistorianData.getInstance().pickBackstoryBit(random);
216// }
217
218 options.clearOptions();
219 if (offers != null) {
220 for (HistorianOffer offer : offers) {
221 offer.addPromptAndOption(dialog);
222 }
223 }
224 //options.addOption("... an interesting bit of Sector history, but nothing that's immediately actionable", OptionId.END_CONVERSATION);
225 options.addOption("... something interesting, but not of immediate import", OptionId.BACKSTORY_BIT);
226 return;
227 }
228
229 boolean forceEnd = false;
230 if (optionData == OptionId.BACKSTORY_BIT) {
231// if (backstory == null) {
232// forceEnd = true;
233// } else {
234 Random currRandom = Misc.getRandom(seed, 11);
235 Global.getSector().getRules().setRandomForNextRulePick(currRandom);
236 boolean shown = FireBest.fire(null, dialog, memoryMap, "HistorianBackstoryBlurb");
237 if (!shown) {
238 SharedData.getData().getUniqueEncounterData().historianBlurbsShown.clear();
239 currRandom = Misc.getRandom(seed, 11);
240 Global.getSector().getRules().setRandomForNextRulePick(currRandom);
241 shown = FireBest.fire(null, dialog, memoryMap, "HistorianBackstoryBlurb");
242 }
243// if (!shown) {
244// HistorianData.getInstance().getShownBackstory().add(backstory.getId());
245// text.addPara(backstory.getText());
246// }
247 options.clearOptions();
248 options.addOption("End the conversation", OptionId.END_CONVERSATION);
249// }
250 }
251
252
253 if (optionData == OptionId.END_CONVERSATION || forceEnd) {
254 text.addPara("You thank " + hd.getHimOrHer() + " for " + hd.getHisOrHer() + " the information and get up to leave.");
255 text.addPara("\"See you again soon, somewhere!\" " + hd.getHeOrShe() + " says. \"In my line of work, even I don't " +
256 "know for sure where I'll end up in a couple of months.\"");
257 done = true;
258
259 if (dialog.getInteractionTarget() != null) {
260 dialog.getInteractionTarget().setActivePerson(null);
261 }
262
263 return;
264 }
265
266 boolean initedOffer = false;
267 if (optionData instanceof HistorianOffer) {
268 currentOffer = (HistorianOffer) optionData;
269 currentOffer.init(dialog);
270 initedOffer = true;
271 //return;
272 }
273
274 if (currentOffer != null) {
275 if (!initedOffer) {
276 currentOffer.optionSelected(optionText, optionData);
277 }
278 if (currentOffer.isInteractionFinished()) {
279 if (currentOffer.shouldRemoveOffer()) {
280 offers.remove(currentOffer);
282 }
283
284 currentOffer.notifyAccepted();
285
286 if (currentOffer.shouldEndConversationOnReturning()) {
287 currentOffer = null;
288 optionSelected(null, OptionId.END_CONVERSATION);
289 } else {
290 currentOffer = null;
291 optionSelected(null, OptionId.WHAT_DO_YOU_HAVE);
292 }
293 }
294 }
295 }
296
297
298// protected String getBacktoryBit() {
299//
300// }
301
302}
303
304
305
306
307
308
309
static SectorAPI getSector()
Definition Global.java:59
void addPromptAndOption(InteractionDialogAPI dialog, Map< String, MemoryAPI > memoryMap)
void init(InteractionDialogAPI dialog, Map< String, MemoryAPI > memoryMap)
List< HistorianOffer > getOffers(Random random, InteractionDialogAPI dialog)