001package com.fs.starfarer.api.impl.campaign.skills;
002
003import com.fs.starfarer.api.campaign.FleetDataAPI;
004import com.fs.starfarer.api.characters.CharacterStatsSkillEffect;
005import com.fs.starfarer.api.characters.FleetStatsSkillEffect;
006import com.fs.starfarer.api.characters.FleetTotalItem;
007import com.fs.starfarer.api.characters.FleetTotalSource;
008import com.fs.starfarer.api.characters.MutableCharacterStatsAPI;
009import com.fs.starfarer.api.characters.ShipSkillEffect;
010import com.fs.starfarer.api.characters.SkillSpecAPI;
011import com.fs.starfarer.api.combat.MutableShipStatsAPI;
012import com.fs.starfarer.api.combat.ShipAPI.HullSize;
013import com.fs.starfarer.api.fleet.MutableFleetStatsAPI;
014import com.fs.starfarer.api.impl.campaign.ids.Stats;
015import com.fs.starfarer.api.ui.TooltipMakerAPI;
016
017public class FieldRepairs {
018        
019        public static final float MIN_HULL = 30f;
020        public static final float MAX_HULL = 40f;
021        
022        public static final float MIN_CR = 30f;
023        public static final float MAX_CR = 40f;
024        
025        public static final float REPAIR_RATE_BONUS = 50f;
026        public static final float INSTA_REPAIR_PERCENT = 25f;
027        //public static final float DMOD_REDUCTION = 2f;
028
029        
030        public static class Level5A implements FleetStatsSkillEffect {
031                public void apply(MutableFleetStatsAPI stats, String id, float level) {
032                        stats.getDynamic().getMod(Stats.RECOVERED_HULL_MIN).modifyFlat(id, MIN_HULL * 0.01f);
033                        stats.getDynamic().getMod(Stats.RECOVERED_HULL_MAX).modifyFlat(id, MAX_HULL * 0.01f);
034                }
035                
036                public void unapply(MutableFleetStatsAPI stats, String id) {
037                        stats.getDynamic().getMod(Stats.RECOVERED_HULL_MIN).unmodify(id);
038                        stats.getDynamic().getMod(Stats.RECOVERED_HULL_MAX).unmodify(id);
039                }
040                
041                public String getEffectDescription(float level) {
042                        return "Recovered ships start with " + (int) MIN_HULL + "-" + (int)MAX_HULL + "% hull integrity";
043                }
044                
045                public String getEffectPerLevelDescription() {
046                        return null;
047                }
048                
049                public ScopeDescription getScopeDescription() {
050                        return ScopeDescription.FLEET;
051                }
052        }
053        
054        public static class Level5B implements FleetStatsSkillEffect {
055                public void apply(MutableFleetStatsAPI stats, String id, float level) {
056                        stats.getDynamic().getMod(Stats.RECOVERED_CR_MIN).modifyFlat(id, MIN_CR * 0.01f);
057                        stats.getDynamic().getMod(Stats.RECOVERED_CR_MAX).modifyFlat(id, MAX_CR * 0.01f);
058                }
059                
060                public void unapply(MutableFleetStatsAPI stats, String id) {
061                        stats.getDynamic().getMod(Stats.RECOVERED_CR_MIN).unmodify(id);
062                        stats.getDynamic().getMod(Stats.RECOVERED_CR_MAX).unmodify(id);
063                }
064                
065                public String getEffectDescription(float level) {
066                        return "Recovered ships start with " + (int) MIN_CR + "-" + (int)MAX_CR + "% combat readiness";
067                }
068                
069                public String getEffectPerLevelDescription() {
070                        return null;
071                }
072                
073                public ScopeDescription getScopeDescription() {
074                        return ScopeDescription.FLEET;
075                }
076        }
077        
078//      public static class Level1 implements CharacterStatsSkillEffect {
079//              public void apply(MutableCharacterStatsAPI stats, String id, float level) {
080//                      stats.getRepairRateMult().modifyPercent(id, REPAIR_RATE_BONUS);
081//              }
082//
083//              public void unapply(MutableCharacterStatsAPI stats, String id) {
084//                      stats.getRepairRateMult().unmodify(id);
085//              }
086//              
087//              public String getEffectDescription(float level) {
088//                      return "" + (int) REPAIR_RATE_BONUS + "% faster ship repairs";
089//              }
090//              
091//              public String getEffectPerLevelDescription() {
092//                      return null;
093//              }
094//
095//              public ScopeDescription getScopeDescription() {
096//                      return ScopeDescription.ALL_SHIPS;
097//              }
098//      }
099        
100        public static class Level1 extends BaseSkillEffectDescription implements CharacterStatsSkillEffect, FleetTotalSource {
101                
102                public FleetTotalItem getFleetTotalItem() {
103                        return getOPTotal();
104                }
105                
106                public void apply(MutableCharacterStatsAPI stats, String id, float level) {
107                        //if (!isCivilian(stats)) {
108                                FleetDataAPI data = null;
109                                if (stats != null && stats.getFleet() != null) {
110                                        data = stats.getFleet().getFleetData();
111                                }
112                                float repBonus = computeAndCacheThresholdBonus(data, stats, "fr_repRate", REPAIR_RATE_BONUS, ThresholdBonusType.OP_ALL);
113                                stats.getRepairRateMult().modifyPercent(id, repBonus);
114                        //}
115                }
116
117                public void unapply(MutableCharacterStatsAPI stats, String id) {
118                        stats.getRepairRateMult().unmodify(id);
119                }
120                
121                public void createCustomDescription(MutableCharacterStatsAPI stats, SkillSpecAPI skill, 
122                                                                                        TooltipMakerAPI info, float width) {
123                        init(stats, skill);
124                        
125                        FleetDataAPI data = null;
126                        if (stats != null && stats.getFleet() != null) {
127                                data = stats.getFleet().getFleetData();
128                        }
129                        float damBonus = computeAndCacheThresholdBonus(data, stats, "fr_repRate", REPAIR_RATE_BONUS, ThresholdBonusType.OP_ALL);
130                        
131                        info.addPara("+%s ship repair rate outside of combat (maximum: %s)", 0f, hc, hc,
132                                        "" + (int) damBonus + "%",
133                                        "" + (int) REPAIR_RATE_BONUS + "%");
134                        //addOPThresholdInfo(info, data, stats, OP_LOW_THRESHOLD);
135                        //info.addSpacer(5f);
136                }
137                
138                public ScopeDescription getScopeDescription() {
139                        return ScopeDescription.ALL_SHIPS;
140                }
141        }
142        
143        public static class Level2 extends BaseSkillEffectDescription implements ShipSkillEffect, FleetTotalSource {
144                
145                public FleetTotalItem getFleetTotalItem() {
146                        return getOPTotal();
147                }
148                
149                public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
150                        //if (!isCivilian(stats)) {
151                                float instaRep = computeAndCacheThresholdBonus(stats, "fr_instaRep", INSTA_REPAIR_PERCENT, ThresholdBonusType.OP_ALL);
152                                stats.getDynamic().getMod(Stats.INSTA_REPAIR_FRACTION).modifyFlat(id, instaRep * 0.01f);
153                        //}
154                }
155                        
156                public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
157                        stats.getDynamic().getMod(Stats.INSTA_REPAIR_FRACTION).unmodifyFlat(id);
158                }
159                
160                public String getEffectDescription(float level) {
161                        return null;
162                }
163                        
164                public void createCustomDescription(MutableCharacterStatsAPI stats, SkillSpecAPI skill, 
165                                                                                        TooltipMakerAPI info, float width) {
166                        init(stats, skill);
167                        
168                        FleetDataAPI data = getFleetData(null);
169                        float instaRep = computeAndCacheThresholdBonus(data, stats, "fr_instaRep", INSTA_REPAIR_PERCENT, ThresholdBonusType.OP_ALL);
170                        
171                        info.addPara("%s of hull and armor damage taken repaired after combat ends, at no cost (maximum: %s)", 0f, hc, hc,
172                                        "" + (int) instaRep + "%",
173                                        "" + (int) INSTA_REPAIR_PERCENT + "%");
174                        addOPThresholdAll(info, data, stats, OP_ALL_THRESHOLD);
175                        
176                        info.addSpacer(5f);
177                }
178                
179                public ScopeDescription getScopeDescription() {
180                        return ScopeDescription.ALL_SHIPS;
181                }
182        }
183        
184        
185        
186//      public static class Level2 implements ShipSkillEffect {
187//              public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
188//                      stats.getDynamic().getMod(Stats.INSTA_REPAIR_FRACTION).modifyFlat(id, INSTA_REPAIR);
189//              }
190//              
191//              public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
192//                      stats.getDynamic().getMod(Stats.INSTA_REPAIR_FRACTION).unmodify(id);
193//              }       
194//              
195//              public String getEffectDescription(float level) {
196//                      return "" + (int) Math.round(INSTA_REPAIR * 100f) + "% of hull and armor damage taken repaired after combat ends, at no cost";
197//              }
198//              
199//              public String getEffectPerLevelDescription() {
200//                      return null;
201//              }
202//              
203//              public ScopeDescription getScopeDescription() {
204//                      return ScopeDescription.ALL_SHIPS;
205//              }
206//      }
207        
208        
209//      public static class Level3 implements FleetStatsSkillEffect {
210//              public void apply(MutableFleetStatsAPI stats, String id, float level) {
211//                      stats.getDynamic().getMod(Stats.SHIP_DMOD_REDUCTION).modifyFlat(id, DMOD_REDUCTION);    
212//              }
213//              
214//              public void unapply(MutableFleetStatsAPI stats, String id) {
215//                      stats.getDynamic().getMod(Stats.SHIP_DMOD_REDUCTION).unmodifyFlat(id);
216//              }
217//              
218//              public String getEffectDescription(float level) {
219//                      //return "Recovered non-friendly ships have an average of " + (int) DMOD_REDUCTION + " less subsystem with lasting damage";
220//                      //return "Recovered ships have up to " + (int) DMOD_REDUCTION + " less d-mods";
221//                      return "Recovered ships have fewer d-mods on average";
222//              }
223//              
224//              public String getEffectPerLevelDescription() {
225//                      return null;
226//              }
227//              
228//              public ScopeDescription getScopeDescription() {
229//                      return ScopeDescription.FLEET;
230//              }
231//      }
232        
233//      public static class Level4 implements FleetStatsSkillEffect {
234//              public void apply(MutableFleetStatsAPI stats, String id, float level) {
235//              }
236//              
237//              public void unapply(MutableFleetStatsAPI stats, String id) {
238//              }
239//              
240//              public String getEffectDescription(float level) {
241//                      if (FieldRepairsScript.MONTHS_PER_DMOD_REMOVAL == 1) {
242//                              return "Chance to remove one d-mod per month from a randomly selected ship in your fleet";
243//                      } else if (FieldRepairsScript.MONTHS_PER_DMOD_REMOVAL == 2) {
244//                              return "Chance to remove a d-mod from a randomly selected ship in your fleet every two months";
245//                      } else {
246//                              return "Chance to remove a d-mod from a randomly selected ship in your fleet every " +
247//                                                      FieldRepairsScript.MONTHS_PER_DMOD_REMOVAL + " months";
248//                      }
249//              }
250//              
251//              public String getEffectPerLevelDescription() {
252//                      return null;
253//              }
254//              
255//              public ScopeDescription getScopeDescription() {
256//                      return ScopeDescription.FLEET;
257//              }
258//      }
259        
260        
261//      public static class Level3B implements ShipSkillEffect {
262//              public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
263//                      stats.getDynamic().getMod(Stats.DMOD_REDUCE_MAINTENANCE).modifyFlat(id, 1f);
264//              }
265//              
266//              public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
267//                      stats.getDynamic().getMod(Stats.DMOD_REDUCE_MAINTENANCE).unmodify(id);
268//              }       
269//              
270//              public String getEffectDescription(float level) {
271//                      return "(D) hull deployment cost reduction also applies to maintenance cost";
272//              }
273//              
274//              public String getEffectPerLevelDescription() {
275//                      return null;
276//              }
277//              
278//              public ScopeDescription getScopeDescription() {
279//                      return ScopeDescription.ALL_SHIPS;
280//              }
281//      }
282}