001package com.fs.starfarer.api.impl.campaign.skills;
002
003import java.awt.Color;
004
005import com.fs.starfarer.api.characters.MutableCharacterStatsAPI;
006import com.fs.starfarer.api.characters.ShipSkillEffect;
007import com.fs.starfarer.api.characters.SkillSpecAPI;
008import com.fs.starfarer.api.combat.MutableShipStatsAPI;
009import com.fs.starfarer.api.combat.ShipAPI;
010import com.fs.starfarer.api.combat.ShipAPI.HullSize;
011import com.fs.starfarer.api.fleet.FleetMemberAPI;
012import com.fs.starfarer.api.impl.campaign.ids.HullMods;
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 SupportDoctrine {
018
019        public static float COMMAND_POINT_REGEN_PERCENT = 100f;
020        
021        public static String SUPPORT_DOCTRINE_DP_REDUCTION_ID = "support_doctrine_dp_reduction";
022        public static float DP_REDUCTION = 0.2f;
023        public static float DP_REDUCTION_MAX = 10f;
024        
025        public static boolean isNoOfficer(MutableShipStatsAPI stats) {
026                if (stats.getEntity() instanceof ShipAPI) {
027                        ShipAPI ship = (ShipAPI) stats.getEntity();
028//                      if (ship == Global.getCombatEngine().getShipPlayerIsTransferringCommandFrom()) {
029//                              return false; // player is transferring command, no bonus until the shuttle is done flying
030//                              // issue: won't get called again when transfer finishes
031//                      }
032                        return ship.getCaptain().isDefault();
033                } else {
034                        FleetMemberAPI member = stats.getFleetMember();
035                        if (member == null) return true;
036                        return member.getCaptain().isDefault();
037                }
038        }
039        
040        public static boolean isOriginalNoOfficer(MutableShipStatsAPI stats) {
041                if (stats.getEntity() instanceof ShipAPI) {
042                        ShipAPI ship = (ShipAPI) stats.getEntity();
043//                      if (ship == Global.getCombatEngine().getShipPlayerIsTransferringCommandFrom()) {
044//                              return false; // player is transferring command, no bonus until the shuttle is done flying
045//                      }
046                        return ship.getOriginalCaptain() != null && ship.getOriginalCaptain().isDefault();
047                } else {
048                        FleetMemberAPI member = stats.getFleetMember();
049                        if (member == null) return true;
050                        return member.getCaptain().isDefault();
051                }
052        }
053        
054        
055        public static class Level1 implements ShipSkillEffect {
056                public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
057                        if (isNoOfficer(stats)) {
058                                new Helmsmanship.Level1().apply(stats, hullSize, id, level);
059                                new Helmsmanship.Level2().apply(stats, hullSize, id, level);
060                                
061                                new DamageControl.Level2().apply(stats, hullSize, id, level);
062                                new DamageControl.Level3().apply(stats, hullSize, id, level);
063                                new DamageControl.Level4().apply(stats, hullSize, id, level);
064                                
065                                new CombatEndurance.Level1().apply(stats, hullSize, id, level);
066                                new CombatEndurance.Level2().apply(stats, hullSize, id, level);
067                                new CombatEndurance.Level3().apply(stats, hullSize, id, level);
068                                
069                                new OrdnanceExpertise.Level1().apply(stats, hullSize, id, level);
070                        } 
071                }
072                
073                public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
074                        new Helmsmanship.Level1().unapply(stats, hullSize, id);
075                        new Helmsmanship.Level2().unapply(stats, hullSize, id);
076                        
077                        new DamageControl.Level2().unapply(stats, hullSize, id);
078                        new DamageControl.Level3().unapply(stats, hullSize, id);
079                        new DamageControl.Level4().unapply(stats, hullSize, id);
080                        
081                        new CombatEndurance.Level1().unapply(stats, hullSize, id);
082                        new CombatEndurance.Level2().unapply(stats, hullSize, id);
083                        new CombatEndurance.Level3().unapply(stats, hullSize, id);
084                        
085                        new OrdnanceExpertise.Level1().unapply(stats, hullSize, id);
086                }
087                
088                public String getEffectDescription(float level) {
089                        return "Gain non-elite Helmsmanship, Damage Control, Combat Endurance, and Ordnance Expertise";
090                }
091                
092                public String getEffectPerLevelDescription() {
093                        return null;
094                }
095                
096                public ScopeDescription getScopeDescription() {
097                        return ScopeDescription.PILOTED_SHIP;
098                }
099        }
100        
101        public static class Level2 implements ShipSkillEffect {
102                public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
103                        if (isNoOfficer(stats)) {
104                                float baseCost = stats.getSuppliesToRecover().getBaseValue();
105                                float reduction = Math.min(DP_REDUCTION_MAX, baseCost * DP_REDUCTION);
106                                
107                                if (stats.getFleetMember() == null || stats.getFleetMember().getVariant() == null || 
108                                                (!stats.getFleetMember().getVariant().hasHullMod(HullMods.NEURAL_INTERFACE) &&
109                                                 !stats.getFleetMember().getVariant().hasHullMod(HullMods.NEURAL_INTEGRATOR))
110                                                                ) {
111                                        stats.getDynamic().getMod(Stats.DEPLOYMENT_POINTS_MOD).modifyFlat(SUPPORT_DOCTRINE_DP_REDUCTION_ID, -reduction);
112                                }
113                        } 
114                }
115                
116                public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
117                        stats.getDynamic().getMod(Stats.DEPLOYMENT_POINTS_MOD).unmodifyFlat(SUPPORT_DOCTRINE_DP_REDUCTION_ID);
118                }
119                
120                public String getEffectDescription(float level) {
121                        String max = "" + (int) DP_REDUCTION_MAX;
122                        String percent = "" + (int)Math.round(DP_REDUCTION * 100f) + "%";
123                        return "Deployment point cost reduced by " + percent + " or " + max + " points, whichever is less";
124                }
125                
126                public String getEffectPerLevelDescription() {
127                        return null;
128                }
129                
130                public ScopeDescription getScopeDescription() {
131                        return ScopeDescription.PILOTED_SHIP;
132                }
133        }
134        
135        
136        public static class Level3 extends BaseSkillEffectDescription implements ShipSkillEffect {
137                public void createCustomDescription(MutableCharacterStatsAPI stats, SkillSpecAPI skill, 
138                                TooltipMakerAPI info, float width) {
139                        init(stats, skill);
140                        float opad = 10f;
141                        Color c = Misc.getBasePlayerColor();
142                        //info.addPara("Affects: %s", opad + 5f, Misc.getGrayColor(), c, "fleet");
143                        info.addPara("Affects: %s", opad + 5f, Misc.getGrayColor(), c, "fleet");
144                        info.addSpacer(opad);
145                        info.addPara("%s faster command point recovery unless command was transferred to a ship originally without an officer", 0f, hc, hc,
146                                        "" + (int) COMMAND_POINT_REGEN_PERCENT + "%");
147                }
148
149                public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
150                        if (!isOriginalNoOfficer(stats)) {
151                                stats.getDynamic().getMod(Stats.COMMAND_POINT_RATE_FLAT).modifyFlat(id, COMMAND_POINT_REGEN_PERCENT * 0.01f);
152                        }
153                }
154
155                public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
156                        stats.getDynamic().getMod(Stats.COMMAND_POINT_RATE_FLAT).unmodify(id);
157                }
158        }
159        
160}
161
162
163
164
165