Starsector API
Loading...
Searching...
No Matches
QuartermasterCargoSwapBarEvent.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.ArrayList;
5import java.util.List;
6
7import com.fs.starfarer.api.Global;
8import com.fs.starfarer.api.campaign.CargoAPI;
9import com.fs.starfarer.api.campaign.CargoAPI.CargoItemType;
10import com.fs.starfarer.api.campaign.PersonImportance;
11import com.fs.starfarer.api.campaign.TextPanelAPI;
12import com.fs.starfarer.api.campaign.econ.CommoditySpecAPI;
13import com.fs.starfarer.api.campaign.econ.Industry;
14import com.fs.starfarer.api.campaign.econ.MarketAPI;
15import com.fs.starfarer.api.characters.PersonAPI;
16import com.fs.starfarer.api.impl.campaign.CoreReputationPlugin.CustomRepImpact;
17import com.fs.starfarer.api.impl.campaign.CoreReputationPlugin.RepActionEnvelope;
18import com.fs.starfarer.api.impl.campaign.CoreReputationPlugin.RepActions;
19import com.fs.starfarer.api.impl.campaign.econ.impl.BaseIndustry;
20import com.fs.starfarer.api.impl.campaign.ids.Commodities;
21import com.fs.starfarer.api.impl.campaign.ids.Factions;
22import com.fs.starfarer.api.impl.campaign.ids.Industries;
23import com.fs.starfarer.api.impl.campaign.ids.Ranks;
24import com.fs.starfarer.api.impl.campaign.ids.Tags;
25import com.fs.starfarer.api.impl.campaign.intel.contacts.ContactIntel;
26import com.fs.starfarer.api.impl.campaign.rulecmd.AddRemoveCommodity;
27import com.fs.starfarer.api.util.Misc;
28import com.fs.starfarer.api.util.WeightedRandomPicker;
29
31
33 super();
34 }
35
36 public boolean shouldShowAtMarket(MarketAPI market) {
37 if (!super.shouldShowAtMarket(market)) return false;
39 if (commodity == null) return false;
40
41 if (!market.getFactionId().equals(Factions.HEGEMONY)) {
42 return false;
43 }
44 boolean hasMilitaryBase = false;
45 for (Industry ind : market.getIndustries()) {
46 if (ind.getSpec().hasTag(Industries.TAG_MILITARY) || ind.getSpec().hasTag(Industries.TAG_COMMAND)) {
47 hasMilitaryBase = true;
48 break;
49 }
50 }
51 if (!hasMilitaryBase) return false;
52
53
54 return true;
55 }
56
57 protected int playerGiveQuantity = 0;
58 protected String playerGiveCommodity = null;
59 @Override
60 protected String getCommodityId() {
61 String[] possible = new String[] {
62 Commodities.HAND_WEAPONS,
63 Commodities.HEAVY_MACHINERY,
64 Commodities.SUPPLIES,
65 Commodities.FUEL,
66 Commodities.RARE_METALS,
67 Commodities.METALS,
68 };
69
70 List <String> playerHas = new ArrayList<String>();
71 List <String> playerNotHas = new ArrayList<String>();
72
73 CargoAPI cargo = Global.getSector().getPlayerFleet().getCargo();
74
75
76 float value = getValue();
77 for (String c : possible) {
78 int q = (int) cargo.getQuantity(CargoItemType.RESOURCES, c);
79 CommoditySpecAPI spec = Global.getSettings().getCommoditySpec(c);
80 int num = (int) (value / spec.getBasePrice());
81 if (q >= num) {
82 playerHas.add(c);
83 } else if (q < num) {
84 playerNotHas.add(c);
85 }
86 }
87
88 if (playerHas.isEmpty() || playerNotHas.isEmpty()) return null;
89
90 WeightedRandomPicker<String> take = new WeightedRandomPicker<String>(random);
91 take.addAll(playerNotHas);
92
93 WeightedRandomPicker<String> give = new WeightedRandomPicker<String>(random);
94 give.addAll(playerHas);
95
96 String pick = take.pick();
97 playerGiveCommodity = give.pick();
98
99 CommoditySpecAPI spec = Global.getSettings().getCommoditySpec(playerGiveCommodity);
100 int num = (int) (value / spec.getBasePrice());
101 playerGiveQuantity = (int) (num * 0.33f);
102
103 if (playerGiveQuantity <= 0) return null;
104
105 return pick;
106 }
107
108 @Override
109 protected PersonAPI createPerson() {
110 for (PersonAPI person : market.getPeopleCopy()) {
111 if (Ranks.POST_SUPPLY_OFFICER.equals(person.getPostId())) {
113 return person;
114 }
115 }
116
117 PersonAPI person = Global.getSector().getFaction(getPersonFaction()).createRandomPerson(random);
118 person.setRankId(getPersonRank());
119 person.setPostId(getPersonRank());
121 return person;
122 }
123
124 @Override
125 protected void adjustPerson(PersonAPI person) {
126 super.adjustPerson(person);
127 person.setImportanceAndVoice(PersonImportance.MEDIUM, random);
128 person.addTag(Tags.CONTACT_MILITARY);
129 }
130
131 @Override
132 protected String getPersonFaction() {
133 return Factions.HEGEMONY;
134 }
135
136 @Override
137 protected String getPersonRank() {
138 return Ranks.SPACE_COMMANDER;
139 }
140
141 @Override
142 protected String getPersonPost() {
143 return Ranks.POST_SUPPLY_OFFICER;
144 }
145
146 protected float getValue() {
147 float value = (1000 + 100 * random.nextInt(6)) * BaseIndustry.getSizeMult(market.getSize());
148 return value;
149 }
150
151 @Override
152 protected int computeQuantity() {
153 String c = commodity;
154 CommoditySpecAPI spec = Global.getSettings().getCommoditySpec(c);
155 int num = (int) (getValue() / spec.getBasePrice());
156 return num;
157 }
158
159 @Override
160 protected float getPriceMult() {
161 return 0;
162 }
163
164 @Override
165 protected String getPrompt() {
166 return "None other than the station's quartermaster, who looks rather sullen, is sitting at the bar.";
167 }
168
169 @Override
170 protected String getOptionText() {
171 return "Approach the quartermaster and offer to buy " + getHimOrHer() + " a drink";
172 }
173
174 @Override
175 protected String getMainText() {
176 CommoditySpecAPI take = Global.getSettings().getCommoditySpec(commodity);
177 CommoditySpecAPI give = Global.getSettings().getCommoditySpec(playerGiveCommodity);
178
179 CargoAPI cargo = Global.getSector().getPlayerFleet().getCargo();
180 int qty = (int) cargo.getQuantity(CargoItemType.RESOURCES, give.getId());
181 String units = "units";
182 if (qty == 1) units = "unit";
183
184 return "In venerated tradition going back thousands of cycles, the quartermaster " +
185 "vents to you about how " + getHisOrHer() + " provision request got mixed up and " +
186 getHeOrShe() + " was shipped %s units of " + take.getLowerCaseName() + " instead of %s units of " +
187 give.getLowerCaseName() + ". \"A mining drone with half its Ludd-damned " +
188 "computer fried on rads would do a better job than the idiots in Fleet Supply\" " +
189 getHeOrShe() + " growls, knocking back the rest of " + getHisOrHer() + " drink and " +
190 "slamming the glass down.\n\n" +
191 "You have %s " + units + " of " + give.getLowerCaseName() + " on board.";
192 }
193
194 @Override
195 protected String [] getMainTextTokens() {
196 CommoditySpecAPI give = Global.getSettings().getCommoditySpec(playerGiveCommodity);
197 CargoAPI cargo = Global.getSector().getPlayerFleet().getCargo();
198 int qty = (int) cargo.getQuantity(CargoItemType.RESOURCES, give.getId());
199 return new String [] { Misc.getWithDGS(quantity), Misc.getWithDGS(playerGiveQuantity) ,
200 Misc.getWithDGS(qty)};
201 }
202 @Override
203 protected Color [] getMainTextColors() {
204 return new Color [] { Misc.getHighlightColor(), Misc.getHighlightColor(), Misc.getHighlightColor()};
205 }
206
207 @Override
208 protected String getConfirmText() {
209 CommoditySpecAPI take = Global.getSettings().getCommoditySpec(commodity);
210 CommoditySpecAPI give = Global.getSettings().getCommoditySpec(playerGiveCommodity);
211 return "Offer to swap " + playerGiveQuantity + " " + give.getLowerCaseName() + " " +
212 "for " + quantity + " " + take.getLowerCaseName() + ", as a favor from you to " + getHimOrHer();
213 }
214
215 @Override
216 protected String getCancelText() {
217 return "Do nothing but commiserate with the quartermaster as you finish your drink.";
218 }
219
220 @Override
221 protected String getAcceptText() {
222 CommoditySpecAPI take = Global.getSettings().getCommoditySpec(commodity);
223 CommoditySpecAPI give = Global.getSettings().getCommoditySpec(playerGiveCommodity);
224 return "You exchange comms with the quartermaster and the very next day " + getHeOrShe() +
225 " smoothes things along with the port authorities and arranges for the quickest cargo " +
226 "transfer you've ever seen, trading your %s " + give.getLowerCaseName() + " for " +
227 "%s " + take.getLowerCaseName() + ". Afterward, the quartermaster " +
228 "sends you a personal thank-you note.";
229 }
230
231 @Override
232 protected String [] getAcceptTextTokens() {
233 return new String [] { Misc.getWithDGS(playerGiveQuantity), Misc.getWithDGS(quantity) };
234 }
235 @Override
236 protected Color [] getAcceptTextColors() {
237 return new Color [] { Misc.getHighlightColor(), Misc.getHighlightColor() };
238 }
239
240 @Override
241 protected void doExtraConfirmActions() {
242 CargoAPI cargo = Global.getSector().getPlayerFleet().getCargo();
243 cargo.removeCommodity(playerGiveCommodity, playerGiveQuantity);
244
245 TextPanelAPI text = dialog.getTextPanel();
246 AddRemoveCommodity.addCommodityLossText(playerGiveCommodity, playerGiveQuantity, text);
247
248 CustomRepImpact impact = new CustomRepImpact();
249 impact.delta = 0.1f;
250
251 Global.getSector().adjustPlayerReputation(
252 new RepActionEnvelope(RepActions.CUSTOM,
253 impact, null, text, true, true),
254 person);
255
256 impact = new CustomRepImpact();
257 impact.delta = 0.03f;
258 Global.getSector().adjustPlayerReputation(
259 new RepActionEnvelope(RepActions.CUSTOM,
260 impact, null, text, true, true),
261 person.getFaction().getId());
262
263 ContactIntel.addPotentialContact(person, market, text);
264 }
265
266
267 @Override
268 protected String getDeclineText() {
269 return "You drink to the bureaucrats in Fleet Supply \"mistaking the airlock for " +
270 "the head-hatch\", empty your glass, and make your exit.";
271 }
272
273
274
275}
276
277
278
static SettingsAPI getSettings()
Definition Global.java:51
static SectorAPI getSector()
Definition Global.java:59
CommoditySpecAPI getCommoditySpec(String commodityId)