001package com.fs.starfarer.api.impl.campaign.skills;
002
003import com.fs.starfarer.api.Global;
004import com.fs.starfarer.api.campaign.FleetDataAPI;
005import com.fs.starfarer.api.characters.FleetStatsSkillEffect;
006import com.fs.starfarer.api.characters.MutableCharacterStatsAPI;
007import com.fs.starfarer.api.characters.ShipSkillEffect;
008import com.fs.starfarer.api.characters.SkillSpecAPI;
009import com.fs.starfarer.api.combat.MutableShipStatsAPI;
010import com.fs.starfarer.api.combat.MutableStat;
011import com.fs.starfarer.api.combat.MutableStat.StatMod;
012import com.fs.starfarer.api.combat.ShipAPI.HullSize;
013import com.fs.starfarer.api.fleet.FleetMemberAPI;
014import com.fs.starfarer.api.fleet.MutableFleetStatsAPI;
015import com.fs.starfarer.api.impl.campaign.ids.Stats;
016import com.fs.starfarer.api.ui.TooltipMakerAPI;
017import com.fs.starfarer.api.util.Misc;
018
019public class MakeshiftEquipment {
020        
021        public static float SUPPLY_USE_REDUCTION_MAX_PERCENT = 50;
022        public static float SUPPLY_USE_REDUCTION_MAX_UNITS = 100;
023        public static float SURVEY_COST_MULT = 0.5f;
024        public static float MINING_VALUE_MULT = 1.5f;
025        
026        public static float UPKEEP_MULT = 0.8f;
027        
028
029        public static class Level1 implements FleetStatsSkillEffect {
030                public void apply(MutableFleetStatsAPI stats, String id, float level) {
031                        String desc = "Surveying skill";
032                        stats.getDynamic().getStat(Stats.SURVEY_COST_MULT).modifyMult(id, SURVEY_COST_MULT, desc);
033                }
034
035                public void unapply(MutableFleetStatsAPI stats, String id) {
036                        stats.getDynamic().getStat(Stats.SURVEY_COST_MULT).unmodifyMult(id);
037                }
038
039                public String getEffectDescription(float level) {
040                        return "-" + (int) Math.round((1f - SURVEY_COST_MULT) * 100f) + "% resources required to survey planets";
041                }
042
043                public String getEffectPerLevelDescription() {
044                        return null;
045                }
046
047                public ScopeDescription getScopeDescription() {
048                        return ScopeDescription.FLEET;
049                }
050        }
051        
052        public static class Level2 implements FleetStatsSkillEffect {
053                public void apply(MutableFleetStatsAPI stats, String id, float level) {
054                        String desc = "Surveying skill";
055                        stats.getDynamic().getStat(Stats.PLANET_MINING_VALUE_MULT).modifyMult(id, SURVEY_COST_MULT, desc);
056                }
057                
058                public void unapply(MutableFleetStatsAPI stats, String id) {
059                        stats.getDynamic().getStat(Stats.PLANET_MINING_VALUE_MULT).unmodify(id);
060                }
061                
062                public String getEffectDescription(float level) {
063                        return "+" + (int) Math.round((1f - SURVEY_COST_MULT) * 100f) + "% resources extracted from surface deposits on uncolonized planets";
064                }
065                
066                public String getEffectPerLevelDescription() {
067                        return null;
068                }
069                
070                public ScopeDescription getScopeDescription() {
071                        return ScopeDescription.FLEET;
072                }
073        }
074        
075        public static String SUPPLIES_EFFECT_ID = "surveying_supply_use_mod";
076        public static class Level3 extends BaseSkillEffectDescription implements ShipSkillEffect {
077                public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
078                        id = SUPPLIES_EFFECT_ID;
079                        float useMult = getSupplyUseMult(id, getFleetData(stats));
080                        stats.getSuppliesPerMonth().modifyMult(id, useMult);
081                }
082                
083                public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
084                        id = SUPPLIES_EFFECT_ID;
085                        stats.getSuppliesPerMonth().unmodifyMult(id);
086                }
087                
088                public String getEffectDescription(float level) {
089                        return null;
090                }
091                
092                protected float getSupplyUseBase(String id, FleetDataAPI data) {
093                        if (data == null) return 0f;
094                        
095                        float supplyUse = 0;
096                        for (FleetMemberAPI curr : data.getMembersListCopy()) {
097                                MutableStat stat = curr.getStats().getSuppliesPerMonth();
098                                StatMod mod = stat.getMultStatMod(id);
099                                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), 
123                                                                                                           SUPPLY_USE_REDUCTION_MAX_UNITS);
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 + "%", 
140                                        "" + (int) SUPPLY_USE_REDUCTION_MAX_UNITS
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