Starsector API
Loading...
Searching...
No Matches
FighterUplink.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.skills;
2
3import com.fs.starfarer.api.campaign.FleetDataAPI;
4import com.fs.starfarer.api.characters.FleetTotalItem;
5import com.fs.starfarer.api.characters.FleetTotalSource;
6import com.fs.starfarer.api.characters.MutableCharacterStatsAPI;
7import com.fs.starfarer.api.characters.ShipSkillEffect;
8import com.fs.starfarer.api.characters.SkillSpecAPI;
9import com.fs.starfarer.api.combat.MutableShipStatsAPI;
10import com.fs.starfarer.api.combat.ShipAPI;
11import com.fs.starfarer.api.combat.ShipAPI.HullSize;
12import com.fs.starfarer.api.fleet.FleetMemberAPI;
13import com.fs.starfarer.api.impl.campaign.ids.Stats;
14import com.fs.starfarer.api.impl.campaign.ids.Strings;
15import com.fs.starfarer.api.ui.TooltipMakerAPI;
16import com.fs.starfarer.api.util.Misc;
17
18public class FighterUplink {
19
20 //public static float DAMAGE_PERCENT = 10;
21
22 public static float MAX_SPEED_PERCENT = 20;
23 public static float CREW_LOSS_PERCENT = 50;
24
25 public static float DAMAGE_BONUS_PERCENT = 10;
26
27 public static float TARGET_LEADING_BONUS = 50f;
28
29 public static float OFFICER_MULT = 1.5f;
30 public static boolean isOfficer(MutableShipStatsAPI stats) {
31 if (stats.getEntity() instanceof ShipAPI) {
32 ShipAPI ship = (ShipAPI) stats.getEntity();
33 if (ship == null) return false;
34 if (ship.isFighter() && ship.getWing() != null && ship.getWing().getSourceShip() != null) {
35 ship = ship.getWing().getSourceShip();
36 }
37 return ship.getCaptain() != null && !ship.getCaptain().isDefault();
38 } else {
39 FleetMemberAPI member = stats.getFleetMember();
40 if (member == null) return false;
41 return !member.getCaptain().isDefault();
42 }
43 }
44
45 public static class Level1 extends BaseSkillEffectDescription implements ShipSkillEffect {
46
47 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
48 float crewLossReduction = computeAndCacheThresholdBonus(stats, "fu_crew_loss", CREW_LOSS_PERCENT, ThresholdBonusType.FIGHTER_BAYS);
49 if (isOfficer(stats)) crewLossReduction *= OFFICER_MULT;
50 stats.getDynamic().getStat(Stats.FIGHTER_CREW_LOSS_MULT).modifyMult(id, 1f - crewLossReduction / 100f);
51 }
52
53 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
55 }
56
57 public String getEffectDescription(float level) {
58 return null;
59 }
60
61 public void createCustomDescription(MutableCharacterStatsAPI stats, SkillSpecAPI skill,
62 TooltipMakerAPI info, float width) {
63 init(stats, skill);
64
65
66 FleetDataAPI data = getFleetData(null);
67 float crewLossReduction = computeAndCacheThresholdBonus(data, stats, "fu_crew_loss", CREW_LOSS_PERCENT, ThresholdBonusType.FIGHTER_BAYS);
68
69 info.addPara("-%s crew lost due to fighter losses in combat (maximum: %s)", 0f, hc, hc,
70 "" + (int) crewLossReduction + "%",
71 "" + (int) CREW_LOSS_PERCENT + "%");
72 //info.addSpacer(5f);
73 }
74
75 public ScopeDescription getScopeDescription() {
76 return ScopeDescription.ALL_SHIPS;
77 }
78
79 }
80
81
82 public static class Level2 extends BaseSkillEffectDescription implements ShipSkillEffect, FleetTotalSource {
83
84 public FleetTotalItem getFleetTotalItem() {
85 return getFighterBaysTotal();
86 }
87
88 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
89// float damBonus = getDamageBonus(stats);
90// stats.getBallisticWeaponDamageMult().modifyPercent(id, damBonus);
91// stats.getEnergyWeaponDamageMult().modifyPercent(id, damBonus);
92// stats.getMissileWeaponDamageMult().modifyPercent(id, damBonus);
93
94 float speedBonus = getMaxSpeedBonus(stats);
95 if (isOfficer(stats)) speedBonus *= OFFICER_MULT;
96 stats.getMaxSpeed().modifyPercent(id, speedBonus);
97 stats.getAcceleration().modifyPercent(id, speedBonus * 2f);
98 stats.getDeceleration().modifyPercent(id, speedBonus * 2f);
99
100 float aimBonus = getAimBonus(stats);
101 if (isOfficer(stats)) aimBonus *= OFFICER_MULT;
102 stats.getAutofireAimAccuracy().modifyFlat(id, aimBonus * 0.01f);
103
104 float damBonus = getDamageBonus(stats);
105 if (isOfficer(stats)) damBonus *= OFFICER_MULT;
106 stats.getBallisticWeaponDamageMult().modifyPercent(id, damBonus);
107 stats.getEnergyWeaponDamageMult().modifyPercent(id, damBonus);
108 stats.getMissileWeaponDamageMult().modifyPercent(id, damBonus);
109 }
110
111 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
112// stats.getBallisticWeaponDamageMult().unmodifyPercent(id);
113// stats.getEnergyWeaponDamageMult().unmodifyPercent(id);
114// stats.getMissileWeaponDamageMult().unmodifyPercent(id);
115
116 stats.getMaxSpeed().unmodifyPercent(id);
117 stats.getAcceleration().unmodifyPercent(id);
118 stats.getDeceleration().unmodifyPercent(id);
119
120 stats.getAutofireAimAccuracy().unmodifyFlat(id);
121
122 stats.getBallisticWeaponDamageMult().unmodifyPercent(id);
123 stats.getEnergyWeaponDamageMult().unmodifyPercent(id);
124 stats.getMissileWeaponDamageMult().unmodifyPercent(id);
125 }
126
127 public String getEffectDescription(float level) {
128 return null;
129 }
130
131// protected float getDamageBonus(MutableShipStatsAPI stats) {
132// FleetDataAPI data = getFleetData(stats);
133// return getDamageBonus(data);
134// }
135// protected float getDamageBonus(FleetDataAPI data) {
136// if (data == null) return DAMAGE_PERCENT;
137// String key = "fighter_uplink_damage";
138// Float bonus = (Float) data.getCacheClearedOnSync().get(key);
139// if (bonus != null) return bonus;
140//
141// float bays = getNumFighterBays(data);
142// bonus = getThresholdBasedRoundedBonus(DAMAGE_PERCENT, bays, FIGHTER_BAYS_THRESHOLD);
143//
144// data.getCacheClearedOnSync().put(key, bonus);
145// return bonus;
146// }
147 protected float getMaxSpeedBonus(MutableShipStatsAPI stats) {
148 FleetDataAPI data = getFleetData(stats);
149 return getMaxSpeedBonus(data);
150 }
151
152 protected float getMaxSpeedBonus(FleetDataAPI data) {
153 if (data == null) return MAX_SPEED_PERCENT;
154 String key = "fighter_uplink_max_speed";
155 Float bonus = (Float) data.getCacheClearedOnSync().get(key);
156 if (bonus != null) return bonus;
157
158 float bays = getNumFighterBays(data);
160
161 data.getCacheClearedOnSync().put(key, bonus);
162 return bonus;
163 }
164
165 protected float getAimBonus(MutableShipStatsAPI stats) {
166 FleetDataAPI data = getFleetData(stats);
167 return getAimBonus(data);
168 }
169
170 protected float getAimBonus(FleetDataAPI data) {
171 if (data == null) return TARGET_LEADING_BONUS;
172 String key = "fighter_uplink_aim";
173 Float bonus = (Float) data.getCacheClearedOnSync().get(key);
174 if (bonus != null) return bonus;
175
176 float bays = getNumFighterBays(data);
178
179 data.getCacheClearedOnSync().put(key, bonus);
180 return bonus;
181 }
182
183 protected float getDamageBonus(MutableShipStatsAPI stats) {
184 FleetDataAPI data = getFleetData(stats);
185 return getDamageBonus(data);
186 }
187
188 protected float getDamageBonus(FleetDataAPI data) {
189 if (data == null) return DAMAGE_BONUS_PERCENT;
190 String key = "fighter_uplink_damage";
191 Float bonus = (Float) data.getCacheClearedOnSync().get(key);
192 if (bonus != null) return bonus;
193
194 float bays = getNumFighterBays(data);
196
197 data.getCacheClearedOnSync().put(key, bonus);
198 return bonus;
199 }
200
201 public void createCustomDescription(MutableCharacterStatsAPI stats, SkillSpecAPI skill,
202 TooltipMakerAPI info, float width) {
203 init(stats, skill);
204
205 /*
206+37% target leading accuracy (maximum: +50%)
207 Maximum at 6 or less fighter bays in fleet, your fleet has 8 fighter bays
208 */
209
210 FleetDataAPI data = getFleetData(null);
211 //float damBonus = getDamageBonus(data);
212 float speedBonus = getMaxSpeedBonus(data);
213 float aimBonus = getAimBonus(data);
214 float damBonus = getDamageBonus(data);
215 //float bays = getNumFighterBays(data);
216
217// info.addPara("+%s damage dealt (maximum: %s)", 0f, hc, hc,
218// "" + (int) damBonus + "%",
219// "" + (int) DAMAGE_PERCENT + "%");
220// addFighterBayThresholdInfo(info, data);
221//
222// info.addSpacer(5f);
223
224 info.addPara("+%s top speed (maximum: %s)", 0f, hc, hc,
225 "" + (int) speedBonus + "%",
226 "" + (int) MAX_SPEED_PERCENT + "%");
227 info.addPara("+%s target leading accuracy (maximum: %s)", 0f, hc, hc,
228 "" + (int) aimBonus + "%",
229 "" + (int) TARGET_LEADING_BONUS + "%");
230 info.addPara("+%s damage dealt (maximum: %s)", 0f, hc, hc,
231 "" + (int) damBonus + "%",
232 "" + (int) DAMAGE_BONUS_PERCENT + "%");
233 addFighterBayThresholdInfo(info, data);
234 info.addPara(indent + "Effect increased by %s for ships with officers, including flagship",
235 0f, tc, hc,
236 "" + Misc.getRoundedValueMaxOneAfterDecimal(OFFICER_MULT) + Strings.X);
237
238 //info.addSpacer(5f);
239 }
240
241 public ScopeDescription getScopeDescription() {
242 return ScopeDescription.ALL_FIGHTERS;
243 }
244
245 }
246
247
248
249}
250
251
252
253
254
void modifyMult(String source, float value)
void init(MutableCharacterStatsAPI stats, SkillSpecAPI skill)
float computeAndCacheThresholdBonus(MutableShipStatsAPI stats, String key, float maxBonus, ThresholdBonusType type)
float getThresholdBasedRoundedBonus(float maxBonus, float value, float threshold)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)