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
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[] {
68 };
69
70 List <String> playerHas = new ArrayList<String>();
71 List <String> playerNotHas = new ArrayList<String>();
72
74
75
76 float value = getValue();
77 for (String c : possible) {
78 int q = (int) cargo.getQuantity(CargoItemType.RESOURCES, 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
91 take.addAll(playerNotHas);
92
94 give.addAll(playerHas);
95
96 String pick = take.pick();
98
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
123
124 @Override
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() {
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;
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() {
178
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() {
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() {
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() {
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() {
244
247
248 CustomRepImpact impact = new CustomRepImpact();
249 impact.delta = 0.1f;
250
252 new RepActionEnvelope(RepActions.CUSTOM,
253 impact, null, text, true, true),
254 person);
255
256 impact = new CustomRepImpact();
257 impact.delta = 0.03f;
259 new RepActionEnvelope(RepActions.CUSTOM,
260 impact, null, text, true, true),
262
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:57
static SectorAPI getSector()
Definition Global.java:65
static void addPotentialContact(PersonAPI contact, MarketAPI market, TextPanelAPI text)
static void addCommodityLossText(String commodityId, int quantity, TextPanelAPI text)
static String getWithDGS(float num)
Definition Misc.java:1381
static Color getHighlightColor()
Definition Misc.java:792
CommoditySpecAPI getCommoditySpec(String commodityId)
float getQuantity(CargoAPI.CargoItemType type, Object data)
void removeCommodity(String id, float quantity)
ReputationAdjustmentResult adjustPlayerReputation(Object action, String factionId)
FactionAPI getFaction(String factionId)
void setImportanceAndVoice(PersonImportance importance, Random random)