Starsector API
Loading...
Searching...
No Matches
Navigation.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.skills;
2
3import com.fs.starfarer.api.Global;
4import com.fs.starfarer.api.campaign.FleetDataAPI;
5import com.fs.starfarer.api.characters.CharacterStatsSkillEffect;
6import com.fs.starfarer.api.characters.FleetStatsSkillEffect;
7import com.fs.starfarer.api.characters.MutableCharacterStatsAPI;
8import com.fs.starfarer.api.characters.ShipSkillEffect;
9import com.fs.starfarer.api.characters.SkillSpecAPI;
10import com.fs.starfarer.api.combat.MutableShipStatsAPI;
11import com.fs.starfarer.api.combat.StatBonus;
12import com.fs.starfarer.api.combat.MutableStat.StatMod;
13import com.fs.starfarer.api.combat.ShipAPI.HullSize;
14import com.fs.starfarer.api.fleet.FleetMemberAPI;
15import com.fs.starfarer.api.fleet.MutableFleetStatsAPI;
16import com.fs.starfarer.api.impl.campaign.ids.Stats;
17import com.fs.starfarer.api.ui.TooltipMakerAPI;
18import com.fs.starfarer.api.util.Misc;
19
20public class Navigation {
21
22 public static float TERRAIN_PENALTY_REDUCTION = 30f;
23 public static float FUEL_USE_REDUCTION = 25;
24 //public static final float SUSTAINED_BURN_BONUS = 5;
25 public static float FLEET_BURN_BONUS = 1;
26 public static float SB_BURN_BONUS = 1;
27
28 public static float FUEL_USE_REDUCTION_MAX_PERCENT = 50;
29 public static float FUEL_USE_REDUCTION_MAX_FUEL = 25;
30
31 public static String FUEL_EFFECT_ID = "nav_fuel_use_mod";
32
33 public static class Level4 extends BaseSkillEffectDescription implements ShipSkillEffect {
34 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
35 id = FUEL_EFFECT_ID;
36 float useMult = getFuelUseMult(id, getFleetData(stats));
37 stats.getFuelUseMod().modifyMult(id, useMult);
38 }
39
40 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
41 id = FUEL_EFFECT_ID;
42 stats.getFuelUseMod().unmodifyMult(id);
43 }
44
45 public String getEffectDescription(float level) {
46 return null;
47 }
48
49 protected float getFuelUseBase(String id, FleetDataAPI data) {
50 if (data == null) return 0f;
51
52 float fuelUse = 0;
53 for (FleetMemberAPI curr : data.getMembersListCopy()) {
54 StatBonus stat = curr.getStats().getFuelUseMod();
55 StatMod mod = stat.getMultBonus(id);
56 if (mod != null) {
57 stat.unmodifyMult(mod.source);
58 }
59 fuelUse += curr.getFuelUse();
60 if (mod != null) {
61 stat.modifyMult(mod.source, mod.value, mod.desc);
62 }
63 }
64 return fuelUse;
65 }
66
67 protected float getFuelUseMult(String id, FleetDataAPI data) {
68 if (data == null) return 0f;
69
70 String key = "nav1";
71 Float bonus = (Float) data.getCacheClearedOnSync().get(key);
72 if (bonus != null) return bonus;
73
74 float fuelUse = getFuelUseBase(id, data);
75
76 float useMult = 0f;
77
78 if (fuelUse > 0) {
79 float maxReduced = Math.min(fuelUse * (FUEL_USE_REDUCTION_MAX_PERCENT * 0.01f),
81 useMult = 1f - maxReduced / fuelUse;
82 useMult = Math.round(useMult * 100f) / 100f;
83 }
84
85 data.getCacheClearedOnSync().put(key, useMult);
86 return useMult;
87 }
88
89 public void createCustomDescription(MutableCharacterStatsAPI stats, SkillSpecAPI skill,
90 TooltipMakerAPI info, float width) {
91 init(stats, skill);
92
93 info.addPara("Reduces fuel consumption by %s or %s units, whichever is lower",
94 0f, hc, hc,
95 "" + (int) FUEL_USE_REDUCTION_MAX_PERCENT + "%",
97 );
98
99 if (isInCampaign()) {
100 FleetDataAPI data = Global.getSector().getPlayerFleet().getFleetData();
101 String id = FUEL_EFFECT_ID;
102 float fuelUse = getFuelUseBase(id, data);
103 float useMult = getFuelUseMult(id, data);
104
105 float reduction = fuelUse * (1f - useMult);
106
107 boolean has = stats.getSkillLevel(skill.getId()) > 0;
108 String is = "is";
109 if (!has) is = "would be";
110 info.addPara(indent + "Your fleet has a base fuel consumption of %s, which " + is + " reduced by %s, or %s units",
111 0f, tc, hc,
112 "" + Misc.getRoundedValueMaxOneAfterDecimal(fuelUse),
113 "" + (int)(Math.round((1f - useMult) * 100f)) + "%",
114 "" + Misc.getRoundedValueMaxOneAfterDecimal(reduction)
115 );
116 info.addSpacer(5f);
117 }
118 }
119
120 public ScopeDescription getScopeDescription() {
121 return ScopeDescription.FLEET;
122 }
123 }
124
125
126 public static class Level1 implements CharacterStatsSkillEffect {
127 public void apply(MutableCharacterStatsAPI stats, String id, float level) {
128 stats.getDynamic().getStat(Stats.NAVIGATION_PENALTY_MULT).modifyFlat(id,
130 }
131
132 public void unapply(MutableCharacterStatsAPI stats, String id) {
133 stats.getDynamic().getStat(Stats.NAVIGATION_PENALTY_MULT).unmodify(id);
134 }
135
136 public String getEffectDescription(float level) {
137 return "-" + (int) (TERRAIN_PENALTY_REDUCTION) + "% terrain movement penalty from all applicable terrain";
138 }
139
140 public String getEffectPerLevelDescription() {
141 return null;
142 }
143
144 public ScopeDescription getScopeDescription() {
145 return ScopeDescription.FLEET;
146 }
147 }
148
149 public static class Level1B implements FleetStatsSkillEffect {
150 public void apply(MutableFleetStatsAPI stats, String id, float level) {
151 stats.getDynamic().getMod(Stats.CAN_SEE_NASCENT_POINTS).modifyFlat(id, 1);
152 }
153
154 public void unapply(MutableFleetStatsAPI stats, String id) {
155 stats.getDynamic().getMod(Stats.CAN_SEE_NASCENT_POINTS).unmodify(id);
156 }
157
158 public String getEffectDescription(float level) {
159 return "Can detect nascent gravity wells in hyperspace around star systems";
160 }
161
162 public String getEffectPerLevelDescription() {
163 return null;
164 }
165
166 public ScopeDescription getScopeDescription() {
167 return ScopeDescription.FLEET;
168 }
169 }
170
171// public static class Level1B implements FleetStatsSkillEffect {
172// public void apply(MutableFleetStatsAPI stats, String id, float level) {
173// stats.getDynamic().getMod(Stats.CAN_SEE_NASCENT_POINTS).modifyFlat(id, 1);
174// }
175//
176// public void unapply(MutableFleetStatsAPI stats, String id) {
177// stats.getDynamic().getMod(Stats.CAN_SEE_NASCENT_POINTS).unmodify(id);
178// }
179//
180// public String getEffectDescription(float level) {
181// return "Can detect nascent gravity wells around star systems";
182// }
183//
184// public String getEffectPerLevelDescription() {
185// return null;
186// }
187//
188// public ScopeDescription getScopeDescription() {
189// return ScopeDescription.FLEET;
190// }
191// }
192
193// public static class Level2 implements FleetStatsSkillEffect {
194// public void apply(MutableFleetStatsAPI stats, String id, float level) {
195// stats.getFuelUseHyperMult().modifyMult(id, 1f - FUEL_USE_REDUCTION / 100f);
196// stats.getFuelUseNormalMult().modifyMult(id, 1f - FUEL_USE_REDUCTION / 100f);
197// }
198//
199// public void unapply(MutableFleetStatsAPI stats, String id) {
200// stats.getFuelUseHyperMult().unmodify(id);
201// stats.getFuelUseNormalMult().unmodify(id);
202// }
203//
204// public String getEffectDescription(float level) {
205// return "-" + (int) FUEL_USE_REDUCTION + "% fuel consumption";
206// }
207//
208// public String getEffectPerLevelDescription() {
209// return null;
210// }
211//
212// public ScopeDescription getScopeDescription() {
213// return ScopeDescription.FLEET;
214// }
215// }
216
217 public static class Level2 implements ShipSkillEffect {
218 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
219 stats.getFuelUseMod().modifyMult(id, 1f - FUEL_USE_REDUCTION / 100f);
220 }
221
222 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
223 stats.getFuelUseMod().unmodify(id);
224 }
225
226 public String getEffectDescription(float level) {
227 return "-" + (int) FUEL_USE_REDUCTION + "% fuel consumption";
228 }
229
230 public String getEffectPerLevelDescription() {
231 return null;
232 }
233
234 public ScopeDescription getScopeDescription() {
235 return ScopeDescription.ALL_SHIPS;
236 }
237 }
238
239
240 public static class Level3A implements FleetStatsSkillEffect {
241 public void apply(MutableFleetStatsAPI stats, String id, float level) {
242 stats.getFleetwideMaxBurnMod().modifyFlat(id, FLEET_BURN_BONUS, "Navigation");
243 }
244
245 public void unapply(MutableFleetStatsAPI stats, String id) {
246 stats.getFleetwideMaxBurnMod().unmodifyFlat(id);
247 }
248
249 public String getEffectDescription(float level) {
250 return "+" + (int) FLEET_BURN_BONUS + " maximum burn level";
251 }
252
253 public String getEffectPerLevelDescription() {
254 return null;
255 }
256
257 public ScopeDescription getScopeDescription() {
258 return ScopeDescription.FLEET;
259 }
260 }
261
262 public static class Level3B implements FleetStatsSkillEffect {
263 public void apply(MutableFleetStatsAPI stats, String id, float level) {
264 stats.getDynamic().getMod(Stats.SUSTAINED_BURN_BONUS).modifyFlat(id, SB_BURN_BONUS);
265 }
266
267 public void unapply(MutableFleetStatsAPI stats, String id) {
268 stats.getDynamic().getMod(Stats.SUSTAINED_BURN_BONUS).unmodifyFlat(id);
269 }
270
271 public String getEffectDescription(float level) {
272 return "Increases the burn bonus of the \"Sustained Burn\" ability by " + (int) SB_BURN_BONUS;
273 }
274
275 public String getEffectPerLevelDescription() {
276 return null;
277 }
278
279 public ScopeDescription getScopeDescription() {
280 return ScopeDescription.FLEET;
281 }
282 }
283}
284
285
286
static SectorAPI getSector()
Definition Global.java:59
void init(MutableCharacterStatsAPI stats, SkillSpecAPI skill)