001package com.fs.starfarer.api.impl.campaign.skills;
002
003import java.awt.Color;
004
005import com.fs.starfarer.api.characters.CharacterStatsSkillEffect;
006import com.fs.starfarer.api.characters.DescriptionSkillEffect;
007import com.fs.starfarer.api.characters.MutableCharacterStatsAPI;
008import com.fs.starfarer.api.characters.ShipSkillEffect;
009import com.fs.starfarer.api.characters.SkillSpecAPI;
010import com.fs.starfarer.api.combat.MutableShipStatsAPI;
011import com.fs.starfarer.api.combat.ShipAPI.HullSize;
012import com.fs.starfarer.api.fleet.FleetMemberAPI;
013import com.fs.starfarer.api.impl.campaign.ids.Stats;
014import com.fs.starfarer.api.ui.TooltipMakerAPI;
015import com.fs.starfarer.api.util.Misc;
016
017public class CoordinatedManeuvers {
018        
019        public static final float CP_BONUS = 3f;
020        
021        public static float NAV_FRIGATES = 6f;
022        public static float NAV_DESTROYERS = 3f;
023        public static float NAV_OTHER = 1f;
024        
025        public static float CP_REGEN_FRIGATES = 50f;
026        public static float CP_REGEN_DESTROYERS = 25f;
027        
028
029        public static class Level0 implements DescriptionSkillEffect {
030                public String getString() {
031                        String max = (int)CoordinatedManeuversScript.BASE_MAXIMUM + "%";
032//                      String buoy = "+" + (int)CoordinatedManeuversScript.PER_BUOY + "%";
033//                      return "Does not apply to fighters. Bonus from each ship only applies to other ships.\n" +
034//                                 "Nav buoys grant " + buoy + " each, up to a maximum of " + max + " without skill.";
035//                      return "Nav buoys grant " + buoy + " top speed each, up to a maximum of " + max + " without skills. " +
036//                                      "Does not apply to fighters. Bonus from each ship does not apply to itself.";
037                        return "*The total nav rating for the deployed ships of the fleet increases the top speed of all ships " +
038                                   "in the fleet, up to a maximum of " +
039                                   "" + max + ". Does not apply to fighters.";                  
040                }
041                public Color[] getHighlightColors() {
042                        Color h = Misc.getHighlightColor();
043                        h = Misc.getDarkHighlightColor();
044                        return new Color[] {h, h};
045                }
046                public String[] getHighlights() {
047                        String max = (int)CoordinatedManeuversScript.BASE_MAXIMUM + "%";
048                        String jammer = "+" + (int)CoordinatedManeuversScript.PER_BUOY + "%";
049                        return new String [] {jammer, max};
050                }
051                public Color getTextColor() {
052                        return null;
053                }
054        }
055        
056        public static boolean isFrigateOrDestroyerAndOfficer(MutableShipStatsAPI stats) {
057                FleetMemberAPI member = stats.getFleetMember();
058                if (member == null) return false;
059                // applies at least 1% in all cases now
060                //if (!member.isFrigate() && !member.isDestroyer()) return false;
061                
062                return !member.getCaptain().isDefault();
063        }
064        //return "Every deployed ship grants +1-4% (depending on ship size) to top speed of allied ships";
065        public static class Level1A extends BaseSkillEffectDescription implements ShipSkillEffect {
066                public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
067                        if (isFrigateOrDestroyerAndOfficer(stats)) {
068                                float bonus = 0f;
069                                if (hullSize == HullSize.FRIGATE) bonus = NAV_FRIGATES;
070                                if (hullSize == HullSize.DESTROYER) bonus = NAV_DESTROYERS;
071                                if (hullSize == HullSize.CRUISER || hullSize == HullSize.CAPITAL_SHIP) bonus = NAV_OTHER;
072                                if (bonus > 0f) {
073                                        stats.getDynamic().getMod(Stats.COORDINATED_MANEUVERS_FLAT).modifyFlat(id, bonus);
074                                }
075                        }
076                }
077                public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
078                        stats.getDynamic().getMod(Stats.COORDINATED_MANEUVERS_FLAT).unmodify(id);
079                }
080                public String getEffectDescription(float level) {
081//                      return "+" + (int)NAV_FRIGATES + "% to nav rating* of fleet when piloting a frigate, " +
082//                                 "+" + (int) NAV_DESTROYERS + "% when piloting a destroyer";
083                        return null;
084                }
085                
086                public void createCustomDescription(MutableCharacterStatsAPI stats, SkillSpecAPI skill, 
087                                TooltipMakerAPI info, float width) {
088                        init(stats, skill);
089
090                        float opad = 10f;
091                        info.addPara("+%s to nav rating* of fleet for deployed frigates, " +
092                                             "+%s for destroyers, +%s for larger hulls", 0f, hc, hc,
093                                             "" + (int) NAV_FRIGATES + "%",
094                                             "" + (int) NAV_DESTROYERS + "%",
095                                             "" + (int) NAV_OTHER + "%"
096                                             );
097                        //info.addSpacer(opad);
098                        
099//                      Color c = Misc.getBasePlayerColor();
100//                      info.addPara("Affects: %s", opad, Misc.getGrayColor(), c, "fleet");
101//                      info.addSpacer(opad);
102                }
103                
104                public String getEffectPerLevelDescription() {
105                        return null;
106                }
107                public ScopeDescription getScopeDescription() {
108                        return ScopeDescription.PILOTED_SHIP;
109                }
110        }
111        
112        public static class Level1B extends BaseSkillEffectDescription implements CharacterStatsSkillEffect {
113
114                public void apply(MutableCharacterStatsAPI stats, String id, float level) {
115                        stats.getCommandPoints().modifyFlat(id, CP_BONUS);
116                }
117
118                public void unapply(MutableCharacterStatsAPI stats, String id) {
119                        stats.getCommandPoints().unmodify(id);
120                }
121                
122                public void createCustomDescription(MutableCharacterStatsAPI stats, SkillSpecAPI skill, 
123                                TooltipMakerAPI info, float width) {
124                        init(stats, skill);
125
126//                      float opad = 10f;
127//                      Color c = Misc.getBasePlayerColor();
128//                      info.addPara("Affects: %s", opad + 5f, Misc.getGrayColor(), c, "fleet");
129//                      info.addSpacer(opad);
130                        info.addPara("+%s command points", 0f, hc, hc,
131                                        "" + (int) CP_BONUS + "");
132                }
133                
134                public String getEffectDescription(float level) {
135                        return "+" + (int) CP_BONUS + " command points";
136                }
137                
138                public String getEffectPerLevelDescription() {
139                        return null;
140                }
141
142                public ScopeDescription getScopeDescription() {
143                        return ScopeDescription.FLEET;
144                }
145        }
146        
147        public static class Level1C extends BaseSkillEffectDescription implements ShipSkillEffect {
148                public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
149                        if (isFrigateOrDestroyerAndOfficer(stats)) {
150                                float bonus = 0f;
151                                if (hullSize == HullSize.FRIGATE) bonus = CP_REGEN_FRIGATES;
152                                if (hullSize == HullSize.DESTROYER) bonus = CP_REGEN_DESTROYERS;
153                                if (bonus > 0f) {
154                                        stats.getDynamic().getMod(Stats.COMMAND_POINT_RATE_FLAT).modifyFlat(id, bonus * 0.01f);
155                                }
156                        }
157                }
158                public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
159                        stats.getDynamic().getMod(Stats.COMMAND_POINT_RATE_FLAT).unmodify(id);
160                }
161                public String getEffectDescription(float level) {
162                        return null;
163                }
164                
165                public void createCustomDescription(MutableCharacterStatsAPI stats, SkillSpecAPI skill, 
166                                TooltipMakerAPI info, float width) {
167                        init(stats, skill);
168
169                        info.addPara("+%s to command point recovery rate from deployed frigates, " +
170                                             "+%s from destroyers", 0f, hc, hc,
171                                             "" + (int) CP_REGEN_FRIGATES + "%",
172                                             "" + (int) CP_REGEN_DESTROYERS + "%");
173                }
174                
175                public String getEffectPerLevelDescription() {
176                        return null;
177                }
178                public ScopeDescription getScopeDescription() {
179                        return ScopeDescription.PILOTED_SHIP;
180                }
181        }
182}