Starsector API
Loading...
Searching...
No Matches
HubMissionBarEventWrapper.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.missions.hub;
2
3import java.util.Map;
4import java.util.Random;
5
6import com.fs.starfarer.api.Global;
7import com.fs.starfarer.api.campaign.InteractionDialogAPI;
8import com.fs.starfarer.api.campaign.econ.MarketAPI;
9import com.fs.starfarer.api.campaign.rules.MemKeys;
10import com.fs.starfarer.api.campaign.rules.MemoryAPI;
11import com.fs.starfarer.api.impl.campaign.intel.bar.events.BaseBarEvent;
12import com.fs.starfarer.api.impl.campaign.rulecmd.FireBest;
13import com.fs.starfarer.api.loading.BarEventSpec;
14import com.fs.starfarer.api.util.Misc;
15
16public class HubMissionBarEventWrapper extends BaseBarEvent {
17
18 protected long seed;
19 //protected PersonAPI person;
20
21 protected transient BarEventSpec spec = null;
22 protected String specId = null;
23
24 protected transient Random genRandom;
25 protected transient HubMissionWithBarEvent mission;
26
28 this.specId = specId;
29 seed = Misc.genRandomSeed();
31 }
32
33 protected Object readResolve() {
35 return this;
36 }
37
38 public String getBarEventId() {
39 return specId;
40 }
41
42
43 @Override
44 public boolean shouldShowAtMarket(MarketAPI market) {
45 //return super.shouldShowAtMarket(market);
46// if (spec.getId().equals("extr")) {
47// System.out.println("wfwefwe");
48// }
49 if (shownAt != null && shownAt != market) return false;
50
52
53 //if (mission == null) {
54 genRandom = new Random(seed + market.getId().hashCode() * 181783497276652981L);
55
56 if (genRandom.nextFloat() > spec.getProb()) return false;
57
58 mission = spec.createMission();
61 //}
62
63 return mission.shouldShowAtMarket(market);
64 }
65
66
67 public String getSpecId() {
68 return specId;
69 }
70
72 return mission;
73 }
74
75 public void abortMission() {
76 if (mission != null) {
77 mission.abort();
78 mission = null;
79 }
80 }
81
82 @Override
83 public void addPromptAndOption(InteractionDialogAPI dialog, Map<String, MemoryAPI> memoryMap) {
84// abortMission();
85
86 MarketAPI market = dialog.getInteractionTarget().getMarket();
87// genRandom = new Random(seed + market.getId().hashCode());
88//
89// mission = spec.createMission();
90// mission.setMissionId(specId);
91// mission.setGenRandom(genRandom);
92 mission.createAndAbortIfFailed(market, true);
93 //mission.setGenRandom(null);
95 mission = null;
96 return;
97 }
98
99 MemoryAPI prev = memoryMap.get(MemKeys.LOCAL);
100 if (mission.getPerson() != null) {
101 memoryMap.put(MemKeys.ENTITY, prev);
102 memoryMap.put(MemKeys.LOCAL, mission.getPerson().getMemoryWithoutUpdate());
103 memoryMap.put(MemKeys.PERSON_FACTION, mission.getPerson().getFaction().getMemory());
104 }
105 mission.updateInteractionData(dialog, memoryMap);
106
107 FireBest.fire(null, dialog, memoryMap, mission.getTriggerPrefix() + "_blurbBar true");
108 FireBest.fire(null, dialog, memoryMap, mission.getTriggerPrefix() + "_optionBar true");
109
110 memoryMap.put(MemKeys.LOCAL, prev);
111 memoryMap.remove(MemKeys.ENTITY);
112 memoryMap.remove(MemKeys.PERSON_FACTION);
113
114
115 //BaseMissionHub.getCreatedMissionsList(mission.getPerson(), market).add((BaseHubMission) mission);
116 }
117
118
119
120}
121
122
123
124
125
126
127
128
static SettingsAPI getSettings()
Definition Global.java:51
void createAndAbortIfFailed(MarketAPI market, boolean barEvent)
void updateInteractionData(InteractionDialogAPI dialog, Map< String, MemoryAPI > memoryMap)
void addPromptAndOption(InteractionDialogAPI dialog, Map< String, MemoryAPI > memoryMap)
BarEventSpec getBarEventSpec(String id)