Starsector API
Loading...
Searching...
No Matches
EmergencyBurnAbility.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.abilities;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import java.awt.Color;
7
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.campaign.BattleAPI;
10import com.fs.starfarer.api.campaign.BuffManagerAPI.Buff;
11import com.fs.starfarer.api.campaign.CampaignFleetAPI;
12import com.fs.starfarer.api.campaign.econ.MarketAPI;
13import com.fs.starfarer.api.fleet.FleetMemberAPI;
14import com.fs.starfarer.api.fleet.FleetMemberViewAPI;
15import com.fs.starfarer.api.impl.campaign.ids.Stats;
16import com.fs.starfarer.api.impl.campaign.intel.BaseIntelPlugin;
17import com.fs.starfarer.api.impl.campaign.terrain.CRRecoveryBuff;
18import com.fs.starfarer.api.ui.LabelAPI;
19import com.fs.starfarer.api.ui.TooltipMakerAPI;
20import com.fs.starfarer.api.util.Misc;
21import com.fs.starfarer.api.util.Misc.FleetMemberDamageLevel;
22
24
25 public static float SENSOR_RANGE_MULT = 0.5f;
26 //public static final float DETECTABILITY_MULT = 1.25f;
27 public static float DETECTABILITY_PERCENT = 50f;
28 public static float MAX_BURN_MOD = 8f;
29 //public static final float CR_COST_MULT = 1f;
30 public static float CR_COST_MULT = 0.25f;
31 public static float FUEL_USE_MULT = 1f;
32
33 public static float ACCELERATION_MULT = 4f;
34
35 public static float ACTIVATION_DAMAGE_PROB = 0.33f;
36
37// public String getSpriteName() {
38// return Global.getSettings().getSpriteName("abilities", Abilities.EMERGENCY_BURN);
39// }
40
41
42// @Override
43// protected String getActivationText() {
44// return Misc.ucFirst(spec.getName().toLowerCase());
45// }
46
47
48 @Override
49 protected void activateImpl() {
50// if (entity.isInCurrentLocation()) {
51// entity.addFloatingText("Emergency burn", entity.getFaction().getBaseUIColor(), 0.5f);
52// }
53
54// AbilityPlugin goDark = entity.getAbility(Abilities.GO_DARK);
55// if (goDark != null && goDark.isActive()) {
56// goDark.deactivate();
57// }
58// AbilityPlugin sb = entity.getAbility(Abilities.SUSTAINED_BURN);
59// if (sb != null && sb.isActive()) {
60// sb.deactivate();
61// }
62
63 CampaignFleetAPI fleet = getFleet();
64 if (fleet == null) return;
65
66 float crCostFleetMult = fleet.getStats().getDynamic().getValue(Stats.EMERGENCY_BURN_CR_MULT);
67 if (crCostFleetMult > 0) {
68 for (FleetMemberAPI member : getNonReadyShips()) {
69 if ((float) Math.random() < ACTIVATION_DAMAGE_PROB) {
70 Misc.applyDamage(member, null, FleetMemberDamageLevel.LOW, false, null, null,
71 true, null, member.getShipName() + " suffers damage from Emergency Burn activation");
72 }
73 }
74 for (FleetMemberAPI member : fleet.getFleetData().getMembersListCopy()) {
75 float crLoss = member.getDeployCost() * CR_COST_MULT * crCostFleetMult;
76 member.getRepairTracker().applyCREvent(-crLoss, "Emergency burn");
77 }
78 }
79
80 float cost = computeFuelCost();
81 fleet.getCargo().removeFuel(cost);
82
83// float distLY = Misc.getDistanceToPlayerLY(fleet);
84// //if (fleet.isPlayerFleet()) {
85// if (distLY < 4f) {
86// SpatialAnomalyParams params = new SpatialAnomalyParams(fleet, 1f, fleet.getRadius() * 2f + 100f, null);
87// SectorEntityToken anomaly = fleet.getContainingLocation().addTerrain(Terrain.SPATIAL_ANOMALY, params);
88// anomaly.getLocation().set(fleet.getLocation());
89// }
90 }
91
92 @Override
93 protected void applyEffect(float amount, float level) {
94// if (level > 0) {
95// AbilityPlugin goDark = entity.getAbility(Abilities.GO_DARK);
96// if (goDark != null) goDark.forceDisable();
97// AbilityPlugin sb = entity.getAbility(Abilities.SUSTAINED_BURN);
98// if (sb != null) sb.forceDisable();
99//
106// }
107
108 CampaignFleetAPI fleet = getFleet();
109 if (fleet == null) return;
110
111 fleet.getStats().getSensorRangeMod().modifyMult(getModId(), 1f + (SENSOR_RANGE_MULT - 1f) * level, "Emergency burn");
113 fleet.getStats().getFleetwideMaxBurnMod().modifyFlat(getModId(), (int)(MAX_BURN_MOD * level), "Emergency burn");
115 //fleet.getCommanderStats().getDynamic().getStat(Stats.NAVIGATION_PENALTY_MULT).modifyMult(getModId(), 0f);//1f - level);
116
117 for (FleetMemberViewAPI view : fleet.getViews()) {
118 //view.getContrailColor().shift(getModId(), view.getEngineColor().getBase(), 1f, 1f, 0.25f);
119 view.getContrailColor().shift(getModId(), new Color(250,150,100,255), 1f, 1f, .75f);
120 //view.getContrailColor().shift(getModId(), new Color(255,100,255), 1f, 1f, 0.5f);
121 //view.getContrailDurMult().shift(getModId(), 0.5f, 1f, 1f, 1f);
122 //view.getContrailWidthMult().shift(getModId(), 2f, 1f, 1f, 1f);
123 view.getEngineGlowSizeMult().shift(getModId(), 2f, 1f, 1f, 1f);
124 view.getEngineHeightMult().shift(getModId(), 5f, 1f, 1f, 1f);
125 view.getEngineWidthMult().shift(getModId(), 3f, 1f, 1f, 1f);
126 }
127
128 //member.getStats().getBaseCRRecoveryRatePercentPerDay()for (FleetMemberAPI member : fleet.getFleetData().getMembersListCopy()) {
129 String buffId = getModId();
130 float buffDur = 0.1f;
131 boolean needsSync = false;
132 for (FleetMemberAPI member : fleet.getFleetData().getMembersListCopy()) {
133 if (level <= 0) {
134 member.getBuffManager().removeBuff(buffId);
135 needsSync = true;
136 } else {
137 Buff test = member.getBuffManager().getBuff(buffId);
138 if (test instanceof CRRecoveryBuff) {
139 CRRecoveryBuff buff = (CRRecoveryBuff) test;
140 buff.setDur(buffDur);
141 } else {
142 member.getBuffManager().addBuff(new CRRecoveryBuff(buffId, 0f, buffDur));
143 needsSync = true;
144 }
145 }
146 }
147
148 //if (needsSync || fleet.isPlayerFleet()) {
149 if (needsSync) {
150 fleet.forceSync();
151 }
152
153
154// if (level > 0) {
155// SlipstreamTerrainPlugin slipstream = SlipstreamTerrainPlugin.getSlipstreamPlugin(fleet.getContainingLocation());
156// if (slipstream != null) {
157// slipstream.disrupt(fleet, 0.1f);
158// }
159// }
160 }
161
162 @Override
163 protected void deactivateImpl() {
164 cleanupImpl();
165 }
166
167 @Override
168 protected void cleanupImpl() {
169 CampaignFleetAPI fleet = getFleet();
170 if (fleet == null) return;
171
176 //fleet.getCommanderStats().getDynamic().getStat(Stats.NAVIGATION_PENALTY_MULT).unmodify(getModId());
177 }
178
179// @Override
180// public float getActivationDays() {
181// return 0.25f;
182// }
183//
184// @Override
185// public float getCooldownDays() {
186// return 1f;
187// }
188//
189// @Override
190// public float getDeactivationDays() {
191// return 0.25f;
192// }
193//
194// @Override
195// public float getDurationDays() {
196// return 1.5f;
197// }
198
199
200 protected List<FleetMemberAPI> getNonReadyShips() {
201 List<FleetMemberAPI> result = new ArrayList<FleetMemberAPI>();
202 CampaignFleetAPI fleet = getFleet();
203 if (fleet == null) return result;
204
205 for (FleetMemberAPI member : fleet.getFleetData().getMembersListCopy()) {
206 //if (member.isMothballed()) continue;
207 //float crLoss = member.getDeployCost() * CR_COST_MULT * crCostFleetMult;
208 float crLoss = getCRCost(member, fleet);
209 if (Math.round(member.getRepairTracker().getCR() * 100) < Math.round(crLoss * 100)) {
210 result.add(member);
211 }
212 }
213 return result;
214 }
215
216
217// public static boolean isReadyForEBurn(FleetMemberAPI member, CampaignFleetAPI fleet) {
218// float crLoss = getCRCost(member, fleet);
219// return Math.round(member.getRepairTracker().getCR() * 100) < Math.round(crLoss * 100);
220// }
221
222 public static float getCRCost(FleetMemberAPI member, CampaignFleetAPI fleet) {
223 float crCostFleetMult = fleet.getStats().getDynamic().getValue(Stats.EMERGENCY_BURN_CR_MULT);
224 float crLoss = member.getDeployCost() * CR_COST_MULT * crCostFleetMult;
225 return Math.round(crLoss * 100f) / 100f;
226 }
227
228 protected float computeFuelCost() {
229 CampaignFleetAPI fleet = getFleet();
230 if (fleet == null) return 0f;
231
232 float cost = fleet.getLogistics().getFuelCostPerLightYear() * FUEL_USE_MULT;
233 return cost;
234 }
235
236 protected float computeSupplyCost() {
237 CampaignFleetAPI fleet = getFleet();
238 if (fleet == null) return 0f;
239
240 float crCostFleetMult = fleet.getStats().getDynamic().getValue(Stats.EMERGENCY_BURN_CR_MULT);
241
242 float cost = 0f;
243 for (FleetMemberAPI member : fleet.getFleetData().getMembersListCopy()) {
244 cost += member.getDeploymentCostSupplies() * CR_COST_MULT * crCostFleetMult;
245 }
246 return cost;
247 }
248
249
250 @Override
251 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded) {
252 CampaignFleetAPI fleet = getFleet();
253 if (fleet == null) return;
254
255 Color gray = Misc.getGrayColor();
256 Color highlight = Misc.getHighlightColor();
257 Color fuel = Global.getSettings().getColor("progressBarFuelColor");
258 Color bad = Misc.getNegativeHighlightColor();
259
261 LabelAPI title = tooltip.addTitle("Emergency Burn");
262 } else {
263 tooltip.addSpacer(-10f);
264 }
265
266// title.highlightLast(status);
267// title.setHighlightColor(gray);
268
269 float pad = 10f;
270
271
272 tooltip.addPara("Increases the maximum burn level by %s." +
273 " Reduces sensor range by %s and increases the range at" +
274 " which the fleet can be detected by %s.",// +
275// " The fleet will also be unaffected by most terrain " +
276// "movement penalties and hazards while the ability is active.",
277 pad,
278 highlight,
279 "" + (int) MAX_BURN_MOD,
280 "" + (int)((1f - SENSOR_RANGE_MULT) * 100f) + "%",
281 //"" + (int)((DETECTABILITY_MULT - 1f) * 100f) + "%"
282 "" + (int)(DETECTABILITY_PERCENT) + "%"
283 );
284
286 String years = "year's";
287 if (FUEL_USE_MULT != 1) years = "years'";
288 tooltip.addPara("Consumes %s light " + years + " worth of fuel and reduces the combat readiness "
289 + "of all ships by %s of a combat deployment. " +
290 "Prevents combat readiness recovery while active.", pad,
291 highlight,
293 "" + (int) Math.round(CR_COST_MULT * 100f) + "%");
294
295 tooltip.addPara("Ships with insufficient combat readiness may suffer damage when the ability is activated.", pad);
296 } else {
297 float fuelCost = computeFuelCost();
298 float supplyCost = computeSupplyCost();
299
300 if (supplyCost > 0) {
301 tooltip.addPara("Consumes %s fuel and reduces the combat readiness" +
302 " of all ships, costing up to %s supplies to recover. Also prevents combat readiness recovery while active.", pad,
303 highlight,
306 } else {
307 tooltip.addPara("Consumes %s fuel and prevents combat readiness recovery while active.", pad,
308 highlight,
310 }
311
312 if (fuelCost > fleet.getCargo().getFuel()) {
313 tooltip.addPara("Not enough fuel.", bad, pad);
314 }
315
316 List<FleetMemberAPI> nonReady = getNonReadyShips();
317 if (!nonReady.isEmpty()) {
318 //tooltip.addPara("Not all ships have enough combat readiness to initiate an emergency burn. Ships that require higher CR:", pad);
319 tooltip.addPara("Some ships don't have enough combat readiness to safely initiate an emergency burn " +
320 "and may suffer damage if the ability is activated:", pad,
321 Misc.getNegativeHighlightColor(), "may suffer damage");
322 //tooltip.beginGridFlipped(getTooltipWidth(), 1, 30, pad);
323 //tooltip.setGridLabelColor(bad);
324 int j = 0;
325 int max = 4;
326 float initPad = 5f;
327 for (FleetMemberAPI member : nonReady) {
328 if (j >= max) {
329 if (nonReady.size() > max + 1) {
330 tooltip.addPara(BaseIntelPlugin.INDENT + "... and several other ships", initPad);
331 break;
332 }
333 }
334
335 //float crLoss = member.getDeployCost() * CR_COST_MULT;
336 //String cost = "" + Math.round(crLoss * 100) + "%";
337 String str = "";
338 if (!member.isFighterWing()) {
339 str += member.getShipName() + ", ";
340 str += member.getHullSpec().getHullNameWithDashClass();
341 } else {
342 str += member.getVariant().getFullDesignationWithHullName();
343 }
344
345 tooltip.addPara(BaseIntelPlugin.INDENT + str, initPad);
346 initPad = 0f;
347 j++;
348
349 //tooltip.addToGrid(0, j++, str, cost, bad);
350 }
351 //tooltip.addGrid(3f);
352 }
353 }
354
355 //tooltip.addPara("Disables \"Go Dark\" when activated.", pad);
356 addIncompatibleToTooltip(tooltip, expanded);
357 }
358
359 public boolean hasTooltip() {
360 return true;
361 }
362
363
364 @Override
365 public void fleetLeftBattle(BattleAPI battle, boolean engagedInHostilities) {
366 if (engagedInHostilities) {
367 deactivate();
368 }
369 }
370
371 @Override
372 public void fleetOpenedMarket(MarketAPI market) {
373 deactivate();
374 }
375
376
377
378
379// @Override
380// public boolean showProgressIndicator() {
381// if (true) return true;
382// return !getNonReadyShips().isEmpty();
383// }
384// @Override
385// public float getProgressFraction() {
386// return 1f;
387// }
388// @Override
389// public Color getProgressColor() {
390// Color color = Misc.getNegativeHighlightColor();
391// color = Misc.getHighlightColor();
392// return Misc.scaleAlpha(color, Global.getSector().getCampaignUI().getSharedFader().getBrightness());
393// }
394
395
396 protected boolean showAlarm() {
397 return !getNonReadyShips().isEmpty() && !isOnCooldown() && !isActiveOrInProgress() && isUsable();
398 }
399
400 @Override
401 public boolean isUsable() {
402 return super.isUsable() &&
403 getFleet() != null &&
404 //getNonReadyShips().isEmpty() &&
406 }
407 @Override
408 public float getCooldownFraction() {
409 if (showAlarm()) {
410 return 0f;
411 }
412 return super.getCooldownFraction();
413 }
414 @Override
415 public boolean showCooldownIndicator() {
416 return super.showCooldownIndicator();
417 }
418 @Override
419 public boolean isOnCooldown() {
420 return super.getCooldownFraction() < 1f;
421 }
422
423 @Override
424 public Color getCooldownColor() {
425 if (showAlarm()) {
426 Color color = Misc.getNegativeHighlightColor();
428 }
429 return super.getCooldownColor();
430 }
431
432 @Override
434 if (showAlarm()) {
435 return true;
436 }
437 return false;
438 }
439}
440
441
442
443
444
static SettingsAPI getSettings()
Definition Global.java:57
static boolean CODEX_TOOLTIP_MODE
Definition Global.java:15
static SectorAPI getSector()
Definition Global.java:65
void modifyMult(String source, float value)
void modifyMult(String source, float value)
void modifyPercent(String source, float value)
void modifyFlat(String source, float value)
void addIncompatibleToTooltip(TooltipMakerAPI tooltip, boolean expanded)
void fleetLeftBattle(BattleAPI battle, boolean engagedInHostilities)
void createTooltip(TooltipMakerAPI tooltip, boolean expanded)
static float getCRCost(FleetMemberAPI member, CampaignFleetAPI fleet)
static Color getNegativeHighlightColor()
Definition Misc.java:802
static Color getGrayColor()
Definition Misc.java:826
static void applyDamage(FleetMemberAPI member, Random random, FleetMemberDamageLevel level, boolean withCRDamage, String crDamageId, String crDamageReason, boolean withMessage, TextPanelAPI textPanel, String messageText)
Definition Misc.java:5680
static Color scaleAlpha(Color color, float factor)
Definition Misc.java:1309
static Color getHighlightColor()
Definition Misc.java:792
static String getRoundedValueMaxOneAfterDecimal(float value)
Definition Misc.java:673
static String getRoundedValue(float value)
Definition Misc.java:647
List< FleetMemberViewAPI > getViews()
List< FleetMemberAPI > getMembersListCopy()
LabelAPI addPara(String format, float pad, Color hl, String... highlights)
UIComponentAPI addSpacer(float height)