Starsector API
Loading...
Searching...
No Matches
DamageControl.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.skills;
2
3import java.awt.Color;
4
5import org.lwjgl.util.vector.Vector2f;
6
7import com.fs.starfarer.api.characters.AfterShipCreationSkillEffect;
8import com.fs.starfarer.api.characters.DescriptionSkillEffect;
9import com.fs.starfarer.api.characters.MutableCharacterStatsAPI;
10import com.fs.starfarer.api.characters.ShipSkillEffect;
11import com.fs.starfarer.api.characters.SkillSpecAPI;
12import com.fs.starfarer.api.combat.CombatEntityAPI;
13import com.fs.starfarer.api.combat.DamageAPI;
14import com.fs.starfarer.api.combat.MutableShipStatsAPI;
15import com.fs.starfarer.api.combat.ShipAPI;
16import com.fs.starfarer.api.combat.ShipAPI.HullSize;
17import com.fs.starfarer.api.combat.listeners.AdvanceableListener;
18import com.fs.starfarer.api.combat.listeners.DamageTakenModifier;
19import com.fs.starfarer.api.impl.campaign.ids.Stats;
20import com.fs.starfarer.api.ui.TooltipMakerAPI;
21import com.fs.starfarer.api.util.Misc;
22
23public class DamageControl {
24
25 public static float SECONDS_PER_PROC = 2f;
26
27 public static float INSTA_REPAIR = 0.25f;
28 public static float CREW_LOSS_REDUCTION = 50;
29 public static float MODULE_REPAIR_BONUS = 50;
30 public static float HULL_DAMAGE_REDUCTION = 25;
31 public static float EMP_DAMAGE_REDUCTION = 25;
32
33 public static float ELITE_DAMAGE_THRESHOLD = 500;
34 public static float ELITE_DAMAGE_REDUCTION_PERCENT = 60;
35
36 public static float ELITE_DAMAGE_TO_HULL_PERCENT = 15;
37
38 public static class Level2 implements ShipSkillEffect {
39
40 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
41 stats.getCrewLossMult().modifyMult(id, 1f - CREW_LOSS_REDUCTION / 100f);
42 }
43
44 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
45 stats.getCrewLossMult().unmodify(id);
46 }
47
48 public String getEffectDescription(float level) {
49 return "-" + (int)(CREW_LOSS_REDUCTION) + "% crew lost due to hull damage in combat";
50 }
51
52 public String getEffectPerLevelDescription() {
53 return null;
54 }
55
56 public ScopeDescription getScopeDescription() {
57 return ScopeDescription.PILOTED_SHIP;
58 }
59 }
60
61 public static class Level1 implements ShipSkillEffect {
62
63 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
64 stats.getDynamic().getMod(Stats.INDIVIDUAL_SHIP_RECOVERY_MOD).modifyFlat(id, 1000f);
65 }
66
67 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
68 stats.getDynamic().getMod(Stats.INDIVIDUAL_SHIP_RECOVERY_MOD).unmodify(id);
69 }
70
71 public String getEffectDescription(float level) {
72 return "If lost in combat, ship is almost always recoverable";
73 }
74
75 public String getEffectPerLevelDescription() {
76 return null;
77 }
78
79 public ScopeDescription getScopeDescription() {
80 return ScopeDescription.PILOTED_SHIP;
81 }
82 }
83
84 public static class Level3 implements ShipSkillEffect {
85
86 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
87 float timeMult = 1f / ((100f + MODULE_REPAIR_BONUS) / 100f);
88 stats.getCombatWeaponRepairTimeMult().modifyMult(id, timeMult);
89 stats.getCombatEngineRepairTimeMult().modifyMult(id, timeMult);
90 }
91
92 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
93 stats.getCombatWeaponRepairTimeMult().unmodify(id);
94 stats.getCombatEngineRepairTimeMult().unmodify(id);
95 }
96
97 public String getEffectDescription(float level) {
98 return "" + (int)(MODULE_REPAIR_BONUS) + "% faster in-combat weapon and engine repairs";
99 }
100
101 public String getEffectPerLevelDescription() {
102 return null;
103 }
104
105 public ScopeDescription getScopeDescription() {
106 return ScopeDescription.PILOTED_SHIP;
107 }
108 }
109
110 public static class Level4 implements ShipSkillEffect {
111
112 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
113 stats.getHullDamageTakenMult().modifyMult(id, 1f - HULL_DAMAGE_REDUCTION / 100f);
114 }
115
116 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
117 stats.getHullDamageTakenMult().unmodify(id);
118 }
119
120 public String getEffectDescription(float level) {
121 return "-" + (int)(HULL_DAMAGE_REDUCTION) + "% hull damage taken";
122 }
123
124 public String getEffectPerLevelDescription() {
125 return null;
126 }
127
128 public ScopeDescription getScopeDescription() {
129 return ScopeDescription.PILOTED_SHIP;
130 }
131 }
132
133 public static class Level5 implements ShipSkillEffect {
134 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
135 stats.getDynamic().getMod(Stats.INSTA_REPAIR_FRACTION).modifyFlat(id, INSTA_REPAIR);
136 }
137
138 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
139 stats.getDynamic().getMod(Stats.INSTA_REPAIR_FRACTION).unmodify(id);
140 }
141
142 public String getEffectDescription(float level) {
143 return "" + (int) Math.round(INSTA_REPAIR * 100f) + "% of hull and armor damage taken repaired after combat ends, at no cost";
144 }
145
146 public String getEffectPerLevelDescription() {
147 return null;
148 }
149
150 public ScopeDescription getScopeDescription() {
151 return ScopeDescription.PILOTED_SHIP;
152 }
153 }
154
155 public static class Level6 extends BaseSkillEffectDescription implements AfterShipCreationSkillEffect {
156 public void applyEffectsAfterShipCreation(ShipAPI ship, String id) {
157 ship.addListener(new DamageControlDamageTakenMod(ship));
158 }
159
160 public void unapplyEffectsAfterShipCreation(ShipAPI ship, String id) {
161 ship.removeListenerOfClass(DamageControlDamageTakenMod.class);
162 }
163
164 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {}
165 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {}
166
167 public String getEffectDescription(float level) {
168 return null;
169 }
170
171 public void createCustomDescription(MutableCharacterStatsAPI stats, SkillSpecAPI skill,
172 TooltipMakerAPI info, float width) {
173 init(stats, skill);
174
175 Color c = hc;
176 float level = stats.getSkillLevel(skill.getId());
177 if (level < 2) {
178 c = dhc;
179 }
180 String seconds = "" + (int) SECONDS_PER_PROC + " seconds";
181 if (SECONDS_PER_PROC == 1f) seconds = "second";
182 //info.addPara("Single-hit hull damage above %s points has the portion above %s reduced by %s",
183 info.addPara("At most once every " + seconds + ", single-hit hull damage above %s points has the portion above %s reduced by %s",
184 0f, c, c,
185 "" + (int) ELITE_DAMAGE_THRESHOLD,
186 "" + (int) ELITE_DAMAGE_THRESHOLD,
187 "" + (int) ELITE_DAMAGE_REDUCTION_PERCENT + "%"
188 );
189 }
190
191 public ScopeDescription getScopeDescription() {
192 return ScopeDescription.PILOTED_SHIP;
193 }
194 }
195
196
197 public static class DamageControlDamageTakenMod implements DamageTakenModifier, AdvanceableListener {
198 protected ShipAPI ship;
199 protected float sinceProc = SECONDS_PER_PROC + 1f;
200 public DamageControlDamageTakenMod(ShipAPI ship) {
201 this.ship = ship;
202 }
203
204 public void advance(float amount) {
205 sinceProc += amount;
206 }
207
208 public String modifyDamageTaken(Object param, CombatEntityAPI target,
209 DamageAPI damage, Vector2f point,
210 boolean shieldHit) {
211 if (!shieldHit && sinceProc > SECONDS_PER_PROC) {
212 float mult = 1f - ELITE_DAMAGE_REDUCTION_PERCENT / 100f;
213 ship.setNextHitHullDamageThresholdMult(ELITE_DAMAGE_THRESHOLD, mult);
214 sinceProc = 0f;
215 }
216 return null;
217 }
218 }
219
220 public static class Level7 implements ShipSkillEffect {
221
222 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
223 stats.getDamageToTargetHullMult().modifyPercent(id, ELITE_DAMAGE_TO_HULL_PERCENT);
224 }
225
226 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
227 stats.getDamageToTargetHullMult().unmodifyPercent(id);
228 }
229
230 public String getEffectDescription(float level) {
231 return "+" + (int)(ELITE_DAMAGE_TO_HULL_PERCENT) + "% damage dealt to hull";
232 }
233
234 public String getEffectPerLevelDescription() {
235 return null;
236 }
237
238 public ScopeDescription getScopeDescription() {
239 return ScopeDescription.PILOTED_SHIP;
240 }
241 }
242
243
244
245 public static class Level8Desc implements DescriptionSkillEffect {
246 public String getString() {
247 return "\n\n*Normally, a damaged but functional module would not be repaired until 5 seconds have passed "
248 + "without it taking damage.";
249 }
250 public Color[] getHighlightColors() {
251 Color h = Misc.getHighlightColor();
252 h = Misc.getDarkHighlightColor();
253 return new Color[] {h};
254 }
255 public String[] getHighlights() {
256 return new String [] {"5"};
257 }
258 public Color getTextColor() {
259 return null;
260 }
261 }
262 public static class Level8 implements ShipSkillEffect {
263
264 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
265 stats.getDynamic().getMod(Stats.CAN_REPAIR_MODULES_UNDER_FIRE).modifyFlat(id, 1f);
266 }
267
268 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
269 stats.getDynamic().getMod(Stats.CAN_REPAIR_MODULES_UNDER_FIRE).unmodifyFlat(id);
270 }
271
272 public String getEffectDescription(float level) {
273 return "Repairs of damaged but functional weapons and engines can continue while they are under fire*";
274 }
275
276 public String getEffectPerLevelDescription() {
277 return null;
278 }
279
280 public ScopeDescription getScopeDescription() {
281 return ScopeDescription.PILOTED_SHIP;
282 }
283 }
284
285
286}
287
288
289
290
291
292
void init(MutableCharacterStatsAPI stats, SkillSpecAPI skill)