Starsector API
Loading...
Searching...
No Matches
MakeshiftEquipment.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.skills;
2
3import com.fs.starfarer.api.Global;
4import com.fs.starfarer.api.campaign.FleetDataAPI;
5import com.fs.starfarer.api.characters.FleetStatsSkillEffect;
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.MutableStat;
11import com.fs.starfarer.api.combat.MutableStat.StatMod;
12import com.fs.starfarer.api.combat.ShipAPI.HullSize;
13import com.fs.starfarer.api.fleet.FleetMemberAPI;
14import com.fs.starfarer.api.fleet.MutableFleetStatsAPI;
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 MakeshiftEquipment {
20
21 public static float SUPPLY_USE_REDUCTION_MAX_PERCENT = 50;
22 public static float SUPPLY_USE_REDUCTION_MAX_UNITS = 100;
23 public static float SURVEY_COST_MULT = 0.5f;
24 public static float MINING_VALUE_MULT = 1.5f;
25
26 public static float UPKEEP_MULT = 0.8f;
27
28
29 public static class Level1 implements FleetStatsSkillEffect {
30 public void apply(MutableFleetStatsAPI stats, String id, float level) {
31 String desc = "Surveying skill";
32 stats.getDynamic().getStat(Stats.SURVEY_COST_MULT).modifyMult(id, SURVEY_COST_MULT, desc);
33 }
34
35 public void unapply(MutableFleetStatsAPI stats, String id) {
36 stats.getDynamic().getStat(Stats.SURVEY_COST_MULT).unmodifyMult(id);
37 }
38
39 public String getEffectDescription(float level) {
40 return "-" + (int) Math.round((1f - SURVEY_COST_MULT) * 100f) + "% resources required to survey planets";
41 }
42
43 public String getEffectPerLevelDescription() {
44 return null;
45 }
46
47 public ScopeDescription getScopeDescription() {
48 return ScopeDescription.FLEET;
49 }
50 }
51
52 public static class Level2 implements FleetStatsSkillEffect {
53 public void apply(MutableFleetStatsAPI stats, String id, float level) {
54 String desc = "Surveying skill";
55 stats.getDynamic().getStat(Stats.PLANET_MINING_VALUE_MULT).modifyMult(id, SURVEY_COST_MULT, desc);
56 }
57
58 public void unapply(MutableFleetStatsAPI stats, String id) {
59 stats.getDynamic().getStat(Stats.PLANET_MINING_VALUE_MULT).unmodify(id);
60 }
61
62 public String getEffectDescription(float level) {
63 return "+" + (int) Math.round((1f - SURVEY_COST_MULT) * 100f) + "% resources extracted from surface deposits on uncolonized planets";
64 }
65
66 public String getEffectPerLevelDescription() {
67 return null;
68 }
69
70 public ScopeDescription getScopeDescription() {
71 return ScopeDescription.FLEET;
72 }
73 }
74
75 public static String SUPPLIES_EFFECT_ID = "surveying_supply_use_mod";
76 public static class Level3 extends BaseSkillEffectDescription implements ShipSkillEffect {
77 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
79 float useMult = getSupplyUseMult(id, getFleetData(stats));
80 stats.getSuppliesPerMonth().modifyMult(id, useMult);
81 }
82
83 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
85 stats.getSuppliesPerMonth().unmodifyMult(id);
86 }
87
88 public String getEffectDescription(float level) {
89 return null;
90 }
91
92 protected float getSupplyUseBase(String id, FleetDataAPI data) {
93 if (data == null) return 0f;
94
95 float supplyUse = 0;
96 for (FleetMemberAPI curr : data.getMembersListCopy()) {
97 MutableStat stat = curr.getStats().getSuppliesPerMonth();
98 StatMod mod = stat.getMultStatMod(id);
99 if (mod != null) {
100 stat.unmodifyMult(mod.source);
101 }
102 supplyUse += stat.getModifiedValue();
103 if (mod != null) {
104 stat.modifyMult(mod.source, mod.value, mod.desc);
105 }
106 }
107 return supplyUse;
108 }
109
110 protected float getSupplyUseMult(String id, FleetDataAPI data) {
111 if (data == null) return 0f;
112
113 String key = "makeshift1";
114 Float bonus = (Float) data.getCacheClearedOnSync().get(key);
115 if (bonus != null) return bonus;
116
117 float supplyUse = getSupplyUseBase(id, data);
118
119 float useMult = 0f;
120
121 if (supplyUse > 0) {
122 float maxReduced = Math.min(supplyUse * (SUPPLY_USE_REDUCTION_MAX_PERCENT * 0.01f),
124 useMult = 1f - maxReduced / supplyUse;
125 //useMult = Math.round(useMult * 100f) / 100f;
126 }
127
128 data.getCacheClearedOnSync().put(key, useMult);
129 return useMult;
130 }
131
132 public void createCustomDescription(MutableCharacterStatsAPI stats, SkillSpecAPI skill,
133 TooltipMakerAPI info, float width) {
134 init(stats, skill);
135
136 //info.addSpacer(5f);
137 info.addPara("Reduces monthly supply consumption for ship maintenance by %s or %s units, whichever is lower",
138 0f, hc, hc,
139 "" + (int) SUPPLY_USE_REDUCTION_MAX_PERCENT + "%",
141 );
142
143 if (isInCampaign()) {
144 FleetDataAPI data = Global.getSector().getPlayerFleet().getFleetData();
145 String id = SUPPLIES_EFFECT_ID;
146 float supplyUse = getSupplyUseBase(id, data);
147 float useMult = getSupplyUseMult(id, data);
148
149 float reduction = supplyUse * (1f - useMult);
150
151 boolean has = stats.getSkillLevel(skill.getId()) > 0;
152 String is = "is";
153 if (!has) is = "would be";
154 info.addPara(indent + "Your fleet requires a base %s supplies per month for maintenance, which " + is + " reduced by %s, or %s units",
155 0f, tc, hc,
156 "" + Misc.getRoundedValueMaxOneAfterDecimal(supplyUse),
157 "" + (int)(Math.round((1f - useMult) * 100f)) + "%",
158 "" + Misc.getRoundedValueMaxOneAfterDecimal(reduction)
159 //"" + Misc.getRoundedValueMaxOneAfterDecimal(Math.min(SUPPLY_USE_REDUCTION_MAX_UNITS, reduction))
160 );
161 }
162
163 info.addSpacer(5f);
164// float opad = 10f;
165// Color c = Misc.getBasePlayerColor();
166// info.addPara("Affects: %s", opad + 5f, Misc.getGrayColor(), c, "governed colony");
167// info.addSpacer(opad);
168// info.addPara("+%s fuel production", 0f, hc, hc,
169// "" + (int) 1f);
170 }
171
172 public ScopeDescription getScopeDescription() {
173 return ScopeDescription.FLEET;
174 }
175 }
176
177
178// public static class Level2 extends BaseSkillEffectDescription implements MarketSkillEffect {
179//
180// public void apply(MarketAPI market, String id, float level) {
181// market.getUpkeepMult().modifyMult(id, UPKEEP_MULT, "Surveying");
182// }
183//
184// public void unapply(MarketAPI market, String id) {
185// market.getUpkeepMult().unmodifyMult(id);
186// }
187//
188// public void createCustomDescription(MutableCharacterStatsAPI stats, SkillSpecAPI skill,
189// TooltipMakerAPI info, float width) {
190// init(stats, skill);
191//
192// float opad = 10f;
193// Color c = Misc.getBasePlayerColor();
194// info.addPara("Affects: %s", opad + 5f, Misc.getGrayColor(), c, "governed colony");
195// info.addSpacer(opad);
196// info.addPara("-%s colony upkeep", 0f, hc, hc,
197// "" + (int)Math.round(Math.abs((1f - UPKEEP_MULT)) * 100f) + "%");
198// }
199//
200// public ScopeDescription getScopeDescription() {
201// return ScopeDescription.GOVERNED_OUTPOST;
202// }
203// }
204}
205
206
207
static SectorAPI getSector()
Definition Global.java:59
void init(MutableCharacterStatsAPI stats, SkillSpecAPI skill)