Starsector API
Loading...
Searching...
No Matches
FighterDoctrine.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.skills;
2
3import java.awt.Color;
4
5import com.fs.starfarer.api.GameState;
6import com.fs.starfarer.api.Global;
7import com.fs.starfarer.api.campaign.FleetDataAPI;
8import com.fs.starfarer.api.characters.CustomSkillDescription;
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.MutableShipStatsAPI;
13import com.fs.starfarer.api.combat.ShipAPI.HullSize;
14import com.fs.starfarer.api.fleet.FleetMemberAPI;
15import com.fs.starfarer.api.impl.campaign.ids.Stats;
16import com.fs.starfarer.api.ui.TooltipMakerAPI;
17import com.fs.starfarer.api.util.Misc;
18
19public class FighterDoctrine {
20
21 public static final float FIGHTER_CREW_LOSS_REDUCTION = 15f;
22 public static final float FIGHTER_RAMAGE_REDUCTION = 15f;
23 public static final float FIGHTER_REPLACEMENT_RATE_BONUS = 15f;
24
25
26 public static class Test implements ShipSkillEffect, CustomSkillDescription {
27
28 protected float getReplacementRateBonus(MutableShipStatsAPI stats) {
29 FleetMemberAPI member = stats.getFleetMember();
30 if (member == null) return 0f;
31 FleetDataAPI data = member.getFleetDataForStats();
32 if (data == null) data = member.getFleetData();
33 if (data == null) return 0f;
34
35 return getReplacementRateBonus(data);
36 }
37
38
39 protected float getReplacementRateBonus(FleetDataAPI data) {
40 String key = "fd1";
41 Float bonus = (Float) data.getCacheClearedOnSync().get(key);
42 if (bonus != null) return bonus;
43
44 float bays = 0;
45 for (FleetMemberAPI curr : data.getMembersListCopy()) {
46 bays += curr.getNumFlightDecks();
47 }
48
49 bonus = (float) Math.round(300f / (Math.max(bays, 6)));
50 data.getCacheClearedOnSync().put(key, bonus);
51 return bonus;
52 }
53
54
55 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
56 float bonus = getReplacementRateBonus(stats);
57 float timeMult = 1f / ((100f + bonus) / 100f);
58 stats.getFighterRefitTimeMult().modifyMult(id, timeMult);
59 }
60
61 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
62 stats.getFighterRefitTimeMult().unmodify(id);
63 }
64
65
66 public boolean hasCustomDescription() {
67 return true;
68 }
69
70 public void createCustomDescription(MutableCharacterStatsAPI stats, SkillSpecAPI skill,
71 TooltipMakerAPI info, float width) {
72
73 Color textColor = Misc.getTextColor();
74 Color highlightColor = Misc.getHighlightColor();
75 Color darkHighlightColor = Misc.setAlpha(highlightColor, 155);
76 int alpha = 255;
77 float level = stats.getSkillLevel(skill.getId());
78 if (level <= 0) {
79 textColor = Misc.getGrayColor();
80 highlightColor = darkHighlightColor;
81 alpha = 155;
82 }
83
85 float bonus = getReplacementRateBonus(Global.getSector().getPlayerFleet().getFleetData());
86 info.addPara("%s faster fighter replacements " +
87 "(based on number of fighter bays in fleet)", 0f, textColor, highlightColor,
88 "" + (int)(bonus) + "%");
89 }
90 }
91
92 public String getEffectDescription(float level) {
93 float bonus = getReplacementRateBonus(Global.getSector().getPlayerFleet().getFleetData());
94 return "" + (int)(bonus) + "% faster fighter replacements (based on number of fighter bays in fleet)";
95 }
96
97
98 public String getEffectPerLevelDescription() {
99 return null;
100 }
101
102 public ScopeDescription getScopeDescription() {
103 return ScopeDescription.ALL_SHIPS;
104 }
105 }
106
107
108 public static class Level1 implements ShipSkillEffect {
109
110 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
111 stats.getDynamic().getStat(Stats.FIGHTER_CREW_LOSS_MULT).modifyMult(id, 1f - FIGHTER_CREW_LOSS_REDUCTION / 100f);
112 }
113
114 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
115 stats.getDynamic().getStat(Stats.FIGHTER_CREW_LOSS_MULT).unmodify(id);
116 }
117
118 public String getEffectDescription(float level) {
119 return "-" + (int)(FIGHTER_CREW_LOSS_REDUCTION) + "% crew lost due to fighter losses in combat";
120 }
121
122 public String getEffectPerLevelDescription() {
123 return null;
124 }
125
126 public ScopeDescription getScopeDescription() {
127 return ScopeDescription.ALL_SHIPS;
128 }
129 }
130
131 public static class Level2 implements ShipSkillEffect {
132 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
133 stats.getHullDamageTakenMult().modifyMult(id, 1f - FIGHTER_RAMAGE_REDUCTION / 100f);
134 stats.getArmorDamageTakenMult().modifyMult(id, 1f - FIGHTER_RAMAGE_REDUCTION / 100f);
135 stats.getShieldDamageTakenMult().modifyMult(id, 1f - FIGHTER_RAMAGE_REDUCTION / 100f);
136 }
137
138 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
139 stats.getHullDamageTakenMult().unmodify(id);
140 stats.getArmorDamageTakenMult().unmodify(id);
141 stats.getShieldDamageTakenMult().unmodify(id);
142 }
143
144 public String getEffectDescription(float level) {
145 return "-" + (int)(FIGHTER_RAMAGE_REDUCTION) + "% damage taken";
146 }
147
148 public String getEffectPerLevelDescription() {
149 return null;
150 }
151
152 public ScopeDescription getScopeDescription() {
153 return ScopeDescription.ALL_FIGHTERS;
154 }
155 }
156
157 public static class Level3 implements ShipSkillEffect {
158
159 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
160 float timeMult = 1f / ((100f + FIGHTER_REPLACEMENT_RATE_BONUS) / 100f);
161 stats.getFighterRefitTimeMult().modifyMult(id, timeMult);
162 }
163
164 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
165 stats.getFighterRefitTimeMult().unmodify(id);
166 }
167
168 public String getEffectDescription(float level) {
169 return "" + (int)(FIGHTER_REPLACEMENT_RATE_BONUS) + "% faster fighter replacements";
170 }
171
172 public String getEffectPerLevelDescription() {
173 return null;
174 }
175
176 public ScopeDescription getScopeDescription() {
177 return ScopeDescription.ALL_SHIPS;
178 }
179 }
180
181}
static GameState getCurrentState()
Definition Global.java:21
static SectorAPI getSector()
Definition Global.java:59