Starsector API
Loading...
Searching...
No Matches
CyberneticAugmentation.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.Global;
6import com.fs.starfarer.api.characters.CharacterStatsSkillEffect;
7import com.fs.starfarer.api.characters.DescriptionSkillEffect;
8import com.fs.starfarer.api.characters.MutableCharacterStatsAPI;
9import com.fs.starfarer.api.characters.MutableCharacterStatsAPI.SkillLevelAPI;
10import com.fs.starfarer.api.characters.PersonAPI;
11import com.fs.starfarer.api.characters.ShipSkillEffect;
12import com.fs.starfarer.api.characters.SkillSpecAPI;
13import com.fs.starfarer.api.combat.MutableShipStatsAPI;
14import com.fs.starfarer.api.combat.ShipAPI;
15import com.fs.starfarer.api.combat.ShipAPI.HullSize;
16import com.fs.starfarer.api.fleet.FleetMemberAPI;
17import com.fs.starfarer.api.impl.campaign.ids.Stats;
18import com.fs.starfarer.api.ui.TooltipMakerAPI;
19import com.fs.starfarer.api.util.Misc;
20
22
23 public static float MAX_ELITE_SKILLS_BONUS = 1;
24 public static float ECCM_BONUS = 5;
25
26 public static float BONUS_PER_ELITE_SKILL = 1f;
27
28 public static boolean isOfficer(MutableShipStatsAPI stats) {
29 if (stats.getEntity() instanceof ShipAPI) {
30 ShipAPI ship = (ShipAPI) stats.getEntity();
31 if (ship.getCaptain().isAICore()) return false;
32 return !ship.getCaptain().isDefault();
33 } else {
34 FleetMemberAPI member = stats.getFleetMember();
35 if (member == null) return false;
36 if (member.getCaptain().isAICore()) return false;
37 return !member.getCaptain().isDefault();
38 }
39 }
40
41 public static boolean isFlagship(MutableShipStatsAPI stats) {
42 if (stats.getEntity() instanceof ShipAPI) {
43 ShipAPI ship = (ShipAPI) stats.getEntity();
44 if (ship.getFleetMember() != null &&
45 ship.getFleetMember().getFleetCommander() == ship.getCaptain()) {
46 return true;
47 }
48 return ship.getCaptain().isPlayer();
49 } else {
50 FleetMemberAPI member = stats.getFleetMember();
51 if (member == null) return false;
52 if (member.isFlagship()) {
53 return true;
54 }
55 return member.getCaptain().isPlayer();
56 }
57 }
58
59 public static float getNumEliteSkillsOfFleetCommander(MutableShipStatsAPI stats) {
60 FleetMemberAPI member = stats.getFleetMember();
61 if (member == null && stats.getEntity() instanceof ShipAPI) {
62 ShipAPI ship = (ShipAPI) stats.getEntity();
63 member = ship.getFleetMember();
64 }
65
66 if (member == null) return 0f;
67 PersonAPI person = member.getFleetCommanderForStats();
68 if (person == null) person = member.getFleetCommander();
69 if (person == null) return 0f;
70
71 MutableCharacterStatsAPI fcStats = person.getStats();
72 if (fcStats == null) return 0f;
73 return getNumEliteSkills(fcStats);
74 }
75
76 public static float getNumEliteSkills(MutableCharacterStatsAPI stats) {
77 float count = 0f;
78 for (SkillLevelAPI sl : stats.getSkillsCopy()) {
79 if (sl.getLevel() >= 2f && sl.getSkill().isElite()) {
80 count++;
81 }
82 }
83 return count;
84 }
85
86 public static class Level0 implements DescriptionSkillEffect {
87 public String getString() {
88 int base = (int)Global.getSettings().getInt("officerMaxEliteSkills");
89 return "\n*The base maximum number of elite skills per officer is " + base + ".";
90 }
91 public Color[] getHighlightColors() {
92 Color h = Misc.getDarkHighlightColor();
93 return new Color[] {h};
94 }
95 public String[] getHighlights() {
96 int base = (int)Global.getSettings().getInt("officerMaxEliteSkills");
97 return new String [] {"" + base};
98 }
99 public Color getTextColor() {
100 return null;
101 }
102 }
103
104 public static class Level1 implements CharacterStatsSkillEffect {
105
106 public void apply(MutableCharacterStatsAPI stats, String id, float level) {
107 stats.getDynamic().getMod(Stats.OFFICER_MAX_ELITE_SKILLS_MOD).modifyFlat(id, MAX_ELITE_SKILLS_BONUS);
108 }
109
110 public void unapply(MutableCharacterStatsAPI stats, String id) {
111 stats.getDynamic().getMod(Stats.OFFICER_MAX_ELITE_SKILLS_MOD).unmodify(id);
112 }
113
114 public String getEffectDescription(float level) {
115 return "+" + (int) MAX_ELITE_SKILLS_BONUS + " to maximum number of elite skills* for officers under your command";
116 }
117
118 public String getEffectPerLevelDescription() {
119 return null;
120 }
121
122 public ScopeDescription getScopeDescription() {
123 return ScopeDescription.NONE;
124 }
125 }
126
127 public static class Level2 extends BaseSkillEffectDescription implements ShipSkillEffect {
128 public void createCustomDescription(MutableCharacterStatsAPI stats, SkillSpecAPI skill,
129 TooltipMakerAPI info, float width) {
130 init(stats, skill);
131 float opad = 10f;
132 Color c = Misc.getBasePlayerColor();
133 //info.addPara("Affects: %s", opad + 5f, Misc.getGrayColor(), c, "fleet");
134 info.addPara("Affects: %s", opad + 5f, Misc.getGrayColor(), c, "all ships with officers, including flagship");
135 info.addSpacer(opad);
136
137// info.addPara("Negates up to %s of the weapon range penalty for superior enemy Electronic Warfare", 0f, hc, hc,
138// "" + (int) ECCM_BONUS + "%");
139 info.addPara("Reduces the weapon range penalty due to superior enemy Electronic Warfare by up to %s percentage points", 0f, hc, hc,
140 "" + (int) ECCM_BONUS + "");
141 }
142
143 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
144 if (isOfficer(stats)) {
145 stats.getDynamic().getMod(Stats.ELECTRONIC_WARFARE_PENALTY_MOD).modifyFlat(id, -ECCM_BONUS);
146 }
147 }
148
149 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
150 stats.getDynamic().getMod(Stats.ELECTRONIC_WARFARE_PENALTY_MOD).unmodifyFlat(id);
151 }
152 }
153
154 public static class Level3 extends BaseSkillEffectDescription implements ShipSkillEffect {
155 public void createCustomDescription(MutableCharacterStatsAPI stats, SkillSpecAPI skill,
156 TooltipMakerAPI info, float width) {
157 init(stats, skill);
158 float opad = 10f;
159 Color c = Misc.getBasePlayerColor();
160 //info.addPara("Affects: %s", opad + 5f, Misc.getGrayColor(), c, "fleet");
161 info.addPara("Affects: %s", opad + 5f, Misc.getGrayColor(), c, "all ships with officers (but not AI cores), including flagship");
162 info.addSpacer(opad);
163
164
165 float count = getNumEliteSkills(stats);
166 float bonus = count * BONUS_PER_ELITE_SKILL;
167
168 info.addPara("%s damage dealt and %s damage taken (%s for each elite skill you have)", 0f, hc, hc,
169 "+" + (int) Math.round(bonus) + "%",
170 "-" + (int) Math.round(bonus) + "%",
171 "" + (int) Math.round(BONUS_PER_ELITE_SKILL) + "%"
172 );
173 info.addPara("The damage-dealt bonus is doubled for the flagship", hc, 0f);
174// info.addPara("%s damage taken (%s per your elite skill), doubled for flagship", 0f, hc, hc,
175// "-" + (int) Math.round(bonus) + "%",
176// "" + (int) Math.round(BONUS_PER_ELITE_SKILL) + "%"
177// );
178 }
179
180 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
181 if (isOfficer(stats)) {
182 float count = getNumEliteSkillsOfFleetCommander(stats);
183 float bonusDealt = count * BONUS_PER_ELITE_SKILL;
184 float bonusTaken = count * BONUS_PER_ELITE_SKILL;
185 if (isFlagship(stats)) {
186 bonusDealt *= 2f;
187 //bonusTaken *= 2f;
188 }
189
190 stats.getArmorDamageTakenMult().modifyMult(id, 1f - bonusTaken / 100f);
191 stats.getHullDamageTakenMult().modifyMult(id, 1f - bonusTaken / 100f);
192 stats.getShieldDamageTakenMult().modifyMult(id, 1f - bonusTaken / 100f);
193
194 stats.getBallisticWeaponDamageMult().modifyPercent(id, bonusDealt);
195 stats.getEnergyWeaponDamageMult().modifyPercent(id, bonusDealt);
196 stats.getMissileWeaponDamageMult().modifyPercent(id, bonusDealt);
197 }
198 }
199
200 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
201 stats.getArmorDamageTakenMult().unmodifyMult(id);
202 stats.getHullDamageTakenMult().unmodifyMult(id);
203 stats.getShieldDamageTakenMult().unmodifyMult(id);
204
205 stats.getBallisticWeaponDamageMult().unmodify(id);
206 stats.getEnergyWeaponDamageMult().unmodify(id);
207 stats.getMissileWeaponDamageMult().unmodify(id);
208 }
209 }
210}
211
212
213
214
static SettingsAPI getSettings()
Definition Global.java:51
void init(MutableCharacterStatsAPI stats, SkillSpecAPI skill)