001package com.fs.starfarer.api.impl.campaign.skills;
002
003import java.awt.Color;
004
005import com.fs.starfarer.api.GameState;
006import com.fs.starfarer.api.Global;
007import com.fs.starfarer.api.campaign.FleetDataAPI;
008import com.fs.starfarer.api.characters.CustomSkillDescription;
009import com.fs.starfarer.api.characters.MutableCharacterStatsAPI;
010import com.fs.starfarer.api.characters.ShipSkillEffect;
011import com.fs.starfarer.api.characters.SkillSpecAPI;
012import com.fs.starfarer.api.combat.MutableShipStatsAPI;
013import com.fs.starfarer.api.combat.ShipAPI.HullSize;
014import com.fs.starfarer.api.fleet.FleetMemberAPI;
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 FighterDoctrine {
020        
021        public static final float FIGHTER_CREW_LOSS_REDUCTION = 15f;
022        public static final float FIGHTER_RAMAGE_REDUCTION = 15f;
023        public static final float FIGHTER_REPLACEMENT_RATE_BONUS = 15f;
024        
025        
026        public static class Test implements ShipSkillEffect, CustomSkillDescription {
027
028                protected float getReplacementRateBonus(MutableShipStatsAPI stats) {
029                        FleetMemberAPI member = stats.getFleetMember();
030                        if (member == null) return 0f;
031                        FleetDataAPI data = member.getFleetDataForStats();
032                        if (data == null) data = member.getFleetData();
033                        if (data == null) return 0f;
034                        
035                        return getReplacementRateBonus(data);
036                }
037                
038                
039                protected float getReplacementRateBonus(FleetDataAPI data) {
040                        String key = "fd1";
041                        Float bonus = (Float) data.getCacheClearedOnSync().get(key);
042                        if (bonus != null) return bonus;
043                        
044                        float bays = 0;
045                        for (FleetMemberAPI curr : data.getMembersListCopy()) {
046                                bays += curr.getNumFlightDecks();
047                        }
048                        
049                        bonus = (float) Math.round(300f / (Math.max(bays, 6)));
050                        data.getCacheClearedOnSync().put(key, bonus);
051                        return bonus;
052                }
053
054                
055                public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
056                        float bonus = getReplacementRateBonus(stats);
057                        float timeMult = 1f / ((100f + bonus) / 100f);
058                        stats.getFighterRefitTimeMult().modifyMult(id, timeMult);
059                }
060                
061                public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
062                        stats.getFighterRefitTimeMult().unmodify(id);
063                }       
064
065                
066                public boolean hasCustomDescription() {
067                        return true;
068                }
069                
070                public void createCustomDescription(MutableCharacterStatsAPI stats, SkillSpecAPI skill, 
071                                                                                        TooltipMakerAPI info, float width) {
072                        
073                        Color textColor = Misc.getTextColor();
074                        Color highlightColor = Misc.getHighlightColor();
075                        Color darkHighlightColor = Misc.setAlpha(highlightColor, 155);
076                        int alpha = 255;
077                        float level = stats.getSkillLevel(skill.getId());
078                        if (level <= 0) {
079                                textColor = Misc.getGrayColor();
080                                highlightColor = darkHighlightColor;
081                                alpha = 155;
082                        }
083                        
084                        if (Global.getCurrentState() == GameState.CAMPAIGN) {
085                                float bonus = getReplacementRateBonus(Global.getSector().getPlayerFleet().getFleetData());
086                                info.addPara("%s faster fighter replacements " +
087                                                         "(based on number of fighter bays in fleet)", 0f, textColor, highlightColor,
088                                                         "" + (int)(bonus) + "%");
089                        }
090                }
091                
092                public String getEffectDescription(float level) {
093                        float bonus = getReplacementRateBonus(Global.getSector().getPlayerFleet().getFleetData());
094                        return "" + (int)(bonus) + "% faster fighter replacements (based on number of fighter bays in fleet)";
095                }
096                
097                
098                public String getEffectPerLevelDescription() {
099                        return null;
100                }
101                
102                public ScopeDescription getScopeDescription() {
103                        return ScopeDescription.ALL_SHIPS;
104                }
105        }
106        
107
108        public static class Level1 implements ShipSkillEffect {
109
110                public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
111                        stats.getDynamic().getStat(Stats.FIGHTER_CREW_LOSS_MULT).modifyMult(id, 1f - FIGHTER_CREW_LOSS_REDUCTION / 100f);
112                }
113                
114                public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
115                        stats.getDynamic().getStat(Stats.FIGHTER_CREW_LOSS_MULT).unmodify(id);
116                }
117                
118                public String getEffectDescription(float level) {
119                        return "-" + (int)(FIGHTER_CREW_LOSS_REDUCTION) + "% crew lost due to fighter losses in combat";
120                }
121                
122                public String getEffectPerLevelDescription() {
123                        return null;
124                }
125                
126                public ScopeDescription getScopeDescription() {
127                        return ScopeDescription.ALL_SHIPS;
128                }
129        }
130
131        public static class Level2 implements ShipSkillEffect {
132                public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
133                        stats.getHullDamageTakenMult().modifyMult(id, 1f - FIGHTER_RAMAGE_REDUCTION / 100f);
134                        stats.getArmorDamageTakenMult().modifyMult(id, 1f - FIGHTER_RAMAGE_REDUCTION / 100f);
135                        stats.getShieldDamageTakenMult().modifyMult(id, 1f - FIGHTER_RAMAGE_REDUCTION / 100f);
136                }
137                
138                public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
139                        stats.getHullDamageTakenMult().unmodify(id);
140                        stats.getArmorDamageTakenMult().unmodify(id);
141                        stats.getShieldDamageTakenMult().unmodify(id);
142                }
143                
144                public String getEffectDescription(float level) {
145                        return "-" + (int)(FIGHTER_RAMAGE_REDUCTION) + "% damage taken";
146                }
147                
148                public String getEffectPerLevelDescription() {
149                        return null;
150                }
151
152                public ScopeDescription getScopeDescription() {
153                        return ScopeDescription.ALL_FIGHTERS;
154                }
155        }
156        
157        public static class Level3 implements ShipSkillEffect {
158
159                public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
160                        float timeMult = 1f / ((100f + FIGHTER_REPLACEMENT_RATE_BONUS) / 100f);
161                        stats.getFighterRefitTimeMult().modifyMult(id, timeMult);
162                }
163                
164                public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
165                        stats.getFighterRefitTimeMult().unmodify(id);
166                }       
167                
168                public String getEffectDescription(float level) {
169                        return "" + (int)(FIGHTER_REPLACEMENT_RATE_BONUS) + "% faster fighter replacements";
170                }
171                
172                public String getEffectPerLevelDescription() {
173                        return null;
174                }
175                
176                public ScopeDescription getScopeDescription() {
177                        return ScopeDescription.ALL_SHIPS;
178                }
179        }
180        
181}