Starsector API
Loading...
Searching...
No Matches
SkillsChangeRemoveExcessOPEffect.java
Go to the documentation of this file.
1package com.fs.starfarer.api.characters;
2
3import java.util.LinkedHashMap;
4import java.util.Map;
5
6import com.fs.starfarer.api.Global;
7import com.fs.starfarer.api.combat.ShipHullSpecAPI;
8import com.fs.starfarer.api.combat.ShipVariantAPI;
9import com.fs.starfarer.api.fleet.FleetMemberAPI;
10import com.fs.starfarer.api.loading.HullModSpecAPI;
11import com.fs.starfarer.api.loading.VariantSource;
12import com.fs.starfarer.api.ui.Alignment;
13import com.fs.starfarer.api.ui.ButtonAPI;
14import com.fs.starfarer.api.ui.TooltipMakerAPI;
15import com.fs.starfarer.api.util.Misc;
16
18
19 public static class OPEffectData {
20 FleetMemberAPI member;
21 int maxOP;
22 int currOP;
23 }
24
25 public static class OPDataMap {
26 Map<FleetMemberAPI, OPEffectData> map = new LinkedHashMap<FleetMemberAPI, OPEffectData>();
27 }
28 public void setMap(OPDataMap map, Map<String, Object> dataMap) {
29 String key = getClass().getSimpleName();
30 dataMap.put(key, map);
31 }
32 public OPDataMap getMap(Map<String, Object> dataMap) {
33 String key = getClass().getSimpleName();
34 OPDataMap map = (OPDataMap)dataMap.get(key);
35 if (map == null) {
36 map = new OPDataMap();
37 dataMap.put(key, map);
38 }
39 return map;
40 }
41
42 public static int getMaxOP(ShipHullSpecAPI hull, MutableCharacterStatsAPI stats) {
43 return hull.getOrdnancePoints(stats);
44 }
45
46
48 OPDataMap result = new OPDataMap();
49
50 for (FleetMemberAPI member : Global.getSector().getPlayerFleet().getFleetData().getMembersListCopy()) {
51 OPEffectData data = new OPEffectData();
52 int maxOPPre = getMaxOP(member.getHullSpec(), from);
53 int maxOPPost = getMaxOP(member.getHullSpec(), to);
54
55 int op = member.getVariant().computeOPCost(to);
56
57 data.member = member;
58 data.maxOP = maxOPPost;
59 data.currOP = op;
60
61 if (maxOPPost < maxOPPre && op > maxOPPost) {
62 result.map.put(member, data);
63 }
64 }
65 return result;
66 }
67
68
69 @Override
71 return !getEffects(from, to).map.isEmpty();
72 }
73
74 @Override
75 public void printEffects(MutableCharacterStatsAPI from, MutableCharacterStatsAPI to, TooltipMakerAPI info, Map<String, Object> dataMap) {
76 super.prepare();
77
78 OPDataMap map = getEffects(from, to);
79 setMap(map, dataMap);
80
81 info.addSectionHeading("Excess ordnance points", base, dark, Alignment.MID, 15f);
82
83 info.addPara("Ships using more than their maximum ordnance points will have "
84 + "vents, capacitors, hullmods, and other equipment removed to bring them under the limit.", 10f,
85 Misc.getNegativeHighlightColor(),
86 "vents, capacitors, hullmods, and other equipment removed"
87 );
88 }
89
90 @Override
91 public void infoButtonPressed(ButtonAPI button, Object param, Map<String, Object> dataMap) {
92 }
93
94 @Override
95 public void applyEffects(MutableCharacterStatsAPI from, MutableCharacterStatsAPI to, Map<String, Object> dataMap) {
96 OPDataMap map = getMap(dataMap);
97
98 for (OPEffectData data : map.map.values()) {
99 clampOP(data.member, to);
100 }
101 }
102
103 public static void clampOP(FleetMemberAPI member, MutableCharacterStatsAPI stats) {
104 int maxOP = getMaxOP(member.getHullSpec(), stats);
105 int op = member.getVariant().computeOPCost(stats);
106 int remove = op - maxOP;
107 if (remove > 0) {
108 ShipVariantAPI variant = member.getVariant();
109 variant = variant.clone();
110 variant.setSource(VariantSource.REFIT);
111
112 int caps = variant.getNumFluxCapacitors();
113 int curr = Math.min(caps, remove);
114 variant.setNumFluxCapacitors(caps - curr);
115 remove -= curr;
116 if (remove > 0) {
117 int vents = variant.getNumFluxVents();
118 curr = Math.min(vents, remove);
119 variant.setNumFluxVents(vents - curr);
120 remove -= curr;
121 }
122 if (remove > 0) {
123 for (String modId : variant.getNonBuiltInHullmods()) {
124 HullModSpecAPI mod = Global.getSettings().getHullModSpec(modId);
125 curr = mod.getCostFor(member.getHullSpec().getHullSize());
126 variant.removeMod(modId);
127 remove -= curr;
128 if (remove <= 0) break;
129 }
130 }
131 // would need to add these to player cargo; gets potentially messy - don't do it
132// if (remove > 0) {
133// for (String slotId : variant.getNonBuiltInWeaponSlots()) {
134// WeaponSpecAPI spec = variant.getWeaponSpec(slotId);
135// curr = (int)Math.round(spec.getOrdnancePointCost(stats, member.getStats()));
136// variant.clearSlot(slotId);
137// remove -= curr;
138// if (remove <= 0) break;
139// }
140// }
141// if (remove > 0) {
142// for (int i = 0; i < variant.getWings().size(); i++) {
143// if (i < variant.getHullSpec().getBuiltInWings().size()) continue;
144// FighterWingSpecAPI spec = variant.getWing(i);
145// curr = (int)Math.round(spec.getOpCost(member.getStats()));
146// variant.setWingId(i, "");
147// remove -= curr;
148// if (remove <= 0) break;
149// }
150// }
151
152 member.setVariant(variant, false, false);
153 }
154 }
155
156}
157
158
159
160
161
162
163
static SettingsAPI getSettings()
Definition Global.java:51
static SectorAPI getSector()
Definition Global.java:59
static int getMaxOP(ShipHullSpecAPI hull, MutableCharacterStatsAPI stats)
OPDataMap getEffects(MutableCharacterStatsAPI from, MutableCharacterStatsAPI to)
void applyEffects(MutableCharacterStatsAPI from, MutableCharacterStatsAPI to, Map< String, Object > dataMap)
static void clampOP(FleetMemberAPI member, MutableCharacterStatsAPI stats)
void printEffects(MutableCharacterStatsAPI from, MutableCharacterStatsAPI to, TooltipMakerAPI info, Map< String, Object > dataMap)
void infoButtonPressed(ButtonAPI button, Object param, Map< String, Object > dataMap)
boolean hasEffects(MutableCharacterStatsAPI from, MutableCharacterStatsAPI to)
HullModSpecAPI getHullModSpec(String modId)