Starsector API
Loading...
Searching...
No Matches
PEAvertInteractionDialogPluginImpl.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel.punitive;
2
3import java.awt.Color;
4import java.util.Map;
5
6import org.lwjgl.input.Keyboard;
7
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.campaign.CampaignFleetAPI;
10import com.fs.starfarer.api.campaign.FactionAPI;
11import com.fs.starfarer.api.campaign.InteractionDialogAPI;
12import com.fs.starfarer.api.campaign.InteractionDialogPlugin;
13import com.fs.starfarer.api.campaign.OptionPanelAPI;
14import com.fs.starfarer.api.campaign.RepLevel;
15import com.fs.starfarer.api.campaign.TextPanelAPI;
16import com.fs.starfarer.api.campaign.VisualPanelAPI;
17import com.fs.starfarer.api.campaign.ReputationActionResponsePlugin.ReputationAdjustmentResult;
18import com.fs.starfarer.api.campaign.rules.MemoryAPI;
19import com.fs.starfarer.api.combat.EngagementResultAPI;
20import com.fs.starfarer.api.impl.campaign.CoreReputationPlugin;
21import com.fs.starfarer.api.impl.campaign.CoreReputationPlugin.CustomRepImpact;
22import com.fs.starfarer.api.impl.campaign.CoreReputationPlugin.RepActionEnvelope;
23import com.fs.starfarer.api.impl.campaign.CoreReputationPlugin.RepActions;
24import com.fs.starfarer.api.impl.campaign.ids.Factions;
25import com.fs.starfarer.api.impl.campaign.ids.Sounds;
26import com.fs.starfarer.api.impl.campaign.intel.punitive.PunitiveExpeditionIntel.PunExOutcome;
27import com.fs.starfarer.api.impl.campaign.intel.punitive.PunitiveExpeditionManager.PunExData;
28import com.fs.starfarer.api.impl.campaign.rulecmd.AddRemoveCommodity;
29import com.fs.starfarer.api.impl.campaign.rulecmd.SetStoryOption;
30import com.fs.starfarer.api.ui.IntelUIAPI;
31import com.fs.starfarer.api.ui.TooltipMakerAPI;
32import com.fs.starfarer.api.util.Misc;
33
35
36 private static enum OptionId {
37 INIT,
38 USE_CONNECTIONS,
39 BRIBE,
40 LEAVE,
41
42 CONFIRM,
43 CANCEL,
44 }
45
46 //public static float BRIBE_BASE = 0;
47 public static int BRIBE_MULT = 10000;
48 public static int BRIBE_MAX = 100000;
49
51 public static float REP_COST = 0.2f;
52
57
59
61 protected IntelUIAPI ui;
62
67
69 this.dialog = dialog;
73
75
76 visual.setVisualFade(0.25f, 0.25f);
77 //visual.showImagePortion("illustrations", "quartermaster", 640, 400, 0, 0, 480, 300);
79
80 dialog.setOptionOnEscape("Leave", OptionId.LEAVE);
81
82 optionSelected(null, OptionId.INIT);
83 }
84
85 public Map<String, MemoryAPI> getMemoryMap() {
86 return null;
87 }
88
90 // no combat here, so this won't get called
91 }
92
93 protected int computeBribeAmount() {
95 int numAttempts = 1;
96 if (data != null) numAttempts = data.numAttempts;
97
98 int bribe = (int) (Math.pow(2, numAttempts) * BRIBE_MULT);
99 if (bribe > BRIBE_MAX) bribe = BRIBE_MAX;
100 return bribe;
101// int bribe = (int) Math.round(BRIBE_BASE + data.threshold * BRIBE_MULT);
102// return bribe;
103 }
104
105 protected void printOptionDesc(OptionId option) {
106 Color tc = Misc.getTextColor();
107 FactionAPI faction = intel.getFaction();
108
109 switch (option) {
110 case BRIBE:
111 int bribe = computeBribeAmount();
112 textPanel.addPara("Sufficient funding allocated to proper official and unofficial actors should " +
113 "ensure that the expedition does not go beyond the planning stages.");
114
115 int credits = (int) playerFleet.getCargo().getCredits().get();
116 Color costColor = Misc.getHighlightColor();
117 if (bribe > credits) costColor = Misc.getNegativeHighlightColor();
118
119 textPanel.addPara("A total of %s should be enough to get the job done, and will also " +
120 "ensure that your standing with " + faction.getDisplayNameWithArticle() +
121 " does not suffer.",
122 costColor,
123 Misc.getDGSCredits(bribe));
124
125 textPanel.addPara("You have %s available.", Misc.getHighlightColor(),
126 Misc.getDGSCredits(credits));
127
128 break;
129 case USE_CONNECTIONS:
130 boolean canUseConnections = faction.isAtWorst(Factions.PLAYER, MIN_REP);
131 if (canUseConnections) {
132 textPanel.addPara("You can use your connections to pull a few strings and ensure the operation " +
133 "never gets beyond the planning stages.");
134 } else {
135 textPanel.addPara("You do not have sufficient connections with " + faction.getPersonNamePrefix() +
136 " officials to stall out this kind of an operation.");
137 CoreReputationPlugin.addRequiredStanding(faction, MIN_REP, null, textPanel, null, tc, 0, true);
138 }
139
140 CoreReputationPlugin.addCurrentStanding(faction, null, textPanel, null, tc, 0f);
141
142 if (canUseConnections) {
143 textPanel.addPara("Calling in these favors will reduce your " +
144 "standing with " + faction.getDisplayNameWithArticle() + " by %s points.",
145 Misc.getHighlightColor(), "" + (int) Math.round(REP_COST * 100f));
146 }
147
148 break;
149 }
150 }
151
152 protected void addChoiceOptions() {
154
155 options.addOption("Allocate sufficient funds for bribes and other means of disrupting the planning", OptionId.BRIBE, null);
156 options.addOption("Use your connections to disrupt the planning", OptionId.USE_CONNECTIONS, null);
157
159
160 options.addOption("Dismiss", OptionId.LEAVE, null);
161 options.setShortcut(OptionId.LEAVE, Keyboard.KEY_ESCAPE, false, false, false, true);
162 }
163
164 protected void addDismissOption() {
166 options.addOption("Dismiss", OptionId.LEAVE, null);
167 options.setShortcut(OptionId.LEAVE, Keyboard.KEY_ESCAPE, false, false, false, true);
168 }
169
170 protected OptionId beingConfirmed = null;
171 protected void addConfirmOptions() {
172 if (beingConfirmed == null) return;
173
175
177
178 options.addOption("Take the necessary actions", OptionId.CONFIRM, null);
179 options.addOption("Never mind", OptionId.CANCEL, null);
180 options.setShortcut(OptionId.CANCEL, Keyboard.KEY_ESCAPE, false, false, false, true);
181
182 if (beingConfirmed == OptionId.BRIBE) {
183
184 SetStoryOption.set(dialog, 1, OptionId.CONFIRM, "bribePunitiveExpedition", Sounds.STORY_POINT_SPEND_INDUSTRY,
185 "Issued bribe to avert " + intel.getFaction().getDisplayName() + " punitive expedition");
186
187 int bribe = computeBribeAmount();
188 if (bribe > playerFleet.getCargo().getCredits().get()) {
189 options.setEnabled(OptionId.CONFIRM, false);
190 options.setTooltip(OptionId.CONFIRM, "Not enough credits.");
191 }
192 } else if (beingConfirmed == OptionId.USE_CONNECTIONS) {
193 FactionAPI faction = intel.getFaction();
194 boolean canUseConnections = faction.isAtWorst(Factions.PLAYER, MIN_REP);
195 if (!canUseConnections) {
196 options.setEnabled(OptionId.CONFIRM, false);
197 options.setTooltip(OptionId.CONFIRM, "Standing not high enough.");
198 }
199 }
200 }
201
202
203 public void printInit() {
208
209 textPanel.addPara("The operation is still in the planning stages, " +
210 "and you have several options at your disposal to ensure it never gets off the ground.");
211 }
212
213 public void optionSelected(String text, Object optionData) {
214 if (optionData == null) return;
215
216 OptionId option = (OptionId) optionData;
217
218 if (text != null) {
219 //textPanel.addParagraph(text, Global.getSettings().getColor("buttonText"));
221 }
222
223 switch (option) {
224 case INIT:
225 printInit();
227 break;
228 case BRIBE:
229 beingConfirmed = OptionId.BRIBE;
231 break;
232 case USE_CONNECTIONS:
233 beingConfirmed = OptionId.USE_CONNECTIONS;
235 break;
236 case CONFIRM:
237 if (beingConfirmed == OptionId.BRIBE) {
238 int bribe = computeBribeAmount();
241 } else if (beingConfirmed == OptionId.USE_CONNECTIONS) {
242 CustomRepImpact impact = new CustomRepImpact();
243 impact.delta = -REP_COST;
244 ReputationAdjustmentResult repResult = Global.getSector().adjustPlayerReputation(
245 new RepActionEnvelope(RepActions.CUSTOM,
246 impact, null, textPanel, false, true),
248 }
250 intel.setOutcome(PunExOutcome.AVERTED);
251 intel.forceFail(false);
254 break;
255 case CANCEL:
257 break;
258 case LEAVE:
259 leave();
260 break;
261 }
262 }
263
264 protected void leave() {
265 dialog.dismiss();
267 }
268
269 public void optionMousedOver(String optionText, Object optionData) {
270
271 }
272
273 public void advance(float amount) {
274
275 }
276
277 public Object getContext() {
278 return null;
279 }
280}
281
282
283
static SectorAPI getSector()
Definition Global.java:65
static void addRequiredStanding(FactionAPI faction, RepLevel req, PersonAPI person, TextPanelAPI panel, TooltipMakerAPI info, Color tc, float pad, boolean orBetter)
static void addCurrentStanding(FactionAPI faction, PersonAPI person, TextPanelAPI panel, TooltipMakerAPI info, Color tc, float pad)
void sendUpdate(Object listInfoParam, TextPanelAPI textPanel)
static void addCreditsLossText(int credits, TextPanelAPI text)
static boolean set(String ruleId, InteractionDialogAPI dialog, Map< String, MemoryAPI > memoryMap, String params)
static Color getStoryOptionColor()
Definition Misc.java:782
static Color getTextColor()
Definition Misc.java:839
static String getDGSCredits(float num)
Definition Misc.java:1390
static Color getNegativeHighlightColor()
Definition Misc.java:802
static Color getHighlightColor()
Definition Misc.java:792
boolean isAtWorst(String id, RepLevel level)
void setOptionColor(Object optionId, Color color)
void setOptionOnEscape(String text, Object optionId)
void setTooltip(Object data, String tooltipText)
void addOption(String text, Object data)
void setEnabled(Object data, boolean enabled)
void setShortcut(Object data, int code, boolean ctrl, boolean alt, boolean shift, boolean putLast)
ReputationAdjustmentResult adjustPlayerReputation(Object action, String factionId)
void showPlanetInfo(SectorEntityToken planet)
void setVisualFade(float in, float out)
void updateUIForItem(IntelInfoPlugin plugin)