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 TARGET_LEADING_BONUS = 50f;
26
27 public static float OFFICER_MULT = 1.5f;
28 public static boolean isOfficer(MutableShipStatsAPI stats) {
29 if (stats.getEntity() instanceof ShipAPI) {
30 ShipAPI ship = (ShipAPI) stats.getEntity();
31 if (ship == null) return false;
32 if (ship.isFighter() && ship.getWing() != null && ship.getWing().getSourceShip() != null) {
33 ship = ship.getWing().getSourceShip();
34 }
35 return ship.getCaptain() != null && !ship.getCaptain().isDefault();
36 } else {
37 FleetMemberAPI member = stats.getFleetMember();
38 if (member == null) return false;
39 return !member.getCaptain().isDefault();
40 }
41 }
42
43 public static class Level1 extends BaseSkillEffectDescription implements ShipSkillEffect {
44
45 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
46 float crewLossReduction = computeAndCacheThresholdBonus(stats, "fu_crew_loss", CREW_LOSS_PERCENT, ThresholdBonusType.FIGHTER_BAYS);
47 if (isOfficer(stats)) crewLossReduction *= OFFICER_MULT;
48 stats.getDynamic().getStat(Stats.FIGHTER_CREW_LOSS_MULT).modifyMult(id, 1f - crewLossReduction / 100f);
49 }
50
51 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
52 stats.getDynamic().getStat(Stats.FIGHTER_CREW_LOSS_MULT).unmodifyMult(id);
53 }
54
55 public String getEffectDescription(float level) {
56 return null;
57 }
58
59 public void createCustomDescription(MutableCharacterStatsAPI stats, SkillSpecAPI skill,
60 TooltipMakerAPI info, float width) {
61 init(stats, skill);
62
63
64 FleetDataAPI data = getFleetData(null);
65 float crewLossReduction = computeAndCacheThresholdBonus(data, stats, "fu_crew_loss", CREW_LOSS_PERCENT, ThresholdBonusType.FIGHTER_BAYS);
66
67 info.addPara("-%s crew lost due to fighter losses in combat (maximum: %s)", 0f, hc, hc,
68 "" + (int) crewLossReduction + "%",
69 "" + (int) CREW_LOSS_PERCENT + "%");
70 //info.addSpacer(5f);
71 }
72
73 public ScopeDescription getScopeDescription() {
74 return ScopeDescription.ALL_SHIPS;
75 }
76
77 }
78
79
80 public static class Level2 extends BaseSkillEffectDescription implements ShipSkillEffect, FleetTotalSource {
81
82 public FleetTotalItem getFleetTotalItem() {
83 return getFighterBaysTotal();
84 }
85
86 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
87// float damBonus = getDamageBonus(stats);
88// stats.getBallisticWeaponDamageMult().modifyPercent(id, damBonus);
89// stats.getEnergyWeaponDamageMult().modifyPercent(id, damBonus);
90// stats.getMissileWeaponDamageMult().modifyPercent(id, damBonus);
91
92 float speedBonus = getMaxSpeedBonus(stats);
93 if (isOfficer(stats)) speedBonus *= OFFICER_MULT;
94 stats.getMaxSpeed().modifyPercent(id, speedBonus);
95 stats.getAcceleration().modifyPercent(id, speedBonus * 2f);
96 stats.getDeceleration().modifyPercent(id, speedBonus * 2f);
97
98 float aimBonus = getAimBonus(stats);
99 if (isOfficer(stats)) aimBonus *= OFFICER_MULT;
100 stats.getAutofireAimAccuracy().modifyFlat(id, aimBonus * 0.01f);
101 }
102
103 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
104// stats.getBallisticWeaponDamageMult().unmodifyPercent(id);
105// stats.getEnergyWeaponDamageMult().unmodifyPercent(id);
106// stats.getMissileWeaponDamageMult().unmodifyPercent(id);
107
108 stats.getMaxSpeed().unmodifyPercent(id);
109 stats.getAcceleration().unmodifyPercent(id);
110 stats.getDeceleration().unmodifyPercent(id);
111
112 stats.getAutofireAimAccuracy().unmodifyFlat(id);
113 }
114
115 public String getEffectDescription(float level) {
116 return null;
117 }
118
119// protected float getDamageBonus(MutableShipStatsAPI stats) {
120// FleetDataAPI data = getFleetData(stats);
121// return getDamageBonus(data);
122// }
123// protected float getDamageBonus(FleetDataAPI data) {
124// if (data == null) return DAMAGE_PERCENT;
125// String key = "fighter_uplink_damage";
126// Float bonus = (Float) data.getCacheClearedOnSync().get(key);
127// if (bonus != null) return bonus;
128//
129// float bays = getNumFighterBays(data);
130// bonus = getThresholdBasedRoundedBonus(DAMAGE_PERCENT, bays, FIGHTER_BAYS_THRESHOLD);
131//
132// data.getCacheClearedOnSync().put(key, bonus);
133// return bonus;
134// }
135 protected float getMaxSpeedBonus(MutableShipStatsAPI stats) {
136 FleetDataAPI data = getFleetData(stats);
137 return getMaxSpeedBonus(data);
138 }
139
140 protected float getMaxSpeedBonus(FleetDataAPI data) {
141 if (data == null) return MAX_SPEED_PERCENT;
142 String key = "fighter_uplink_max_speed";
143 Float bonus = (Float) data.getCacheClearedOnSync().get(key);
144 if (bonus != null) return bonus;
145
146 float bays = getNumFighterBays(data);
148
149 data.getCacheClearedOnSync().put(key, bonus);
150 return bonus;
151 }
152
153 protected float getAimBonus(MutableShipStatsAPI stats) {
154 FleetDataAPI data = getFleetData(stats);
155 return getAimBonus(data);
156 }
157
158 protected float getAimBonus(FleetDataAPI data) {
159 if (data == null) return TARGET_LEADING_BONUS;
160 String key = "fighter_uplink_aim";
161 Float bonus = (Float) data.getCacheClearedOnSync().get(key);
162 if (bonus != null) return bonus;
163
164 float bays = getNumFighterBays(data);
166
167 data.getCacheClearedOnSync().put(key, bonus);
168 return bonus;
169 }
170
171 public void createCustomDescription(MutableCharacterStatsAPI stats, SkillSpecAPI skill,
172 TooltipMakerAPI info, float width) {
173 init(stats, skill);
174
175 /*
176+37% target leading accuracy (maximum: +50%)
177 Maximum at 6 or less fighter bays in fleet, your fleet has 8 fighter bays
178 */
179
180 FleetDataAPI data = getFleetData(null);
181 //float damBonus = getDamageBonus(data);
182 float speedBonus = getMaxSpeedBonus(data);
183 float aimBonus = getAimBonus(data);
184 //float bays = getNumFighterBays(data);
185
186// info.addPara("+%s damage dealt (maximum: %s)", 0f, hc, hc,
187// "" + (int) damBonus + "%",
188// "" + (int) DAMAGE_PERCENT + "%");
189// addFighterBayThresholdInfo(info, data);
190//
191// info.addSpacer(5f);
192
193 info.addPara("+%s top speed (maximum: %s)", 0f, hc, hc,
194 "" + (int) speedBonus + "%",
195 "" + (int) MAX_SPEED_PERCENT + "%");
196 info.addPara("+%s target leading accuracy (maximum: %s)", 0f, hc, hc,
197 "" + (int) aimBonus + "%",
198 "" + (int) TARGET_LEADING_BONUS + "%");
199 addFighterBayThresholdInfo(info, data);
200 info.addPara(indent + "Effect increased by %s for ships with offcers, including flagship",
201 0f, tc, hc,
202 "" + Misc.getRoundedValueMaxOneAfterDecimal(OFFICER_MULT) + Strings.X);
203
204 //info.addSpacer(5f);
205 }
206
207 public ScopeDescription getScopeDescription() {
208 return ScopeDescription.ALL_FIGHTERS;
209 }
210
211 }
212
213
214
215}
216
217
218
219
220
void init(MutableCharacterStatsAPI stats, SkillSpecAPI skill)
float computeAndCacheThresholdBonus(MutableShipStatsAPI stats, String key, float maxBonus, ThresholdBonusType type)
float getThresholdBasedRoundedBonus(float maxBonus, float value, float threshold)