001package com.fs.starfarer.api.impl.campaign.skills;
002
003import com.fs.starfarer.api.campaign.FleetDataAPI;
004import com.fs.starfarer.api.characters.FleetTotalItem;
005import com.fs.starfarer.api.characters.FleetTotalSource;
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.ShipAPI;
011import com.fs.starfarer.api.combat.ShipAPI.HullSize;
012import com.fs.starfarer.api.fleet.FleetMemberAPI;
013import com.fs.starfarer.api.impl.campaign.ids.Strings;
014import com.fs.starfarer.api.ui.TooltipMakerAPI;
015import com.fs.starfarer.api.util.Misc;
016
017public class CarrierGroup {
018        
019        public static float TOP_SPEED_PERCENT = 10;
020        public static float REPLACEMENT_RATE_PERCENT = 50;
021        
022        public static float OFFICER_MULT = 1.5f;
023        public static boolean isOfficer(MutableShipStatsAPI stats) {
024                if (stats.getEntity() instanceof ShipAPI) {
025                        ShipAPI ship = (ShipAPI) stats.getEntity();
026                        if (ship == null) return false;
027                        return !ship.getCaptain().isDefault();
028                } else {
029                        FleetMemberAPI member = stats.getFleetMember();
030                        if (member == null) return false;
031                        return !member.getCaptain().isDefault();
032                }
033        }
034        public static class Level1 extends BaseSkillEffectDescription implements ShipSkillEffect, FleetTotalSource {
035                
036                public FleetTotalItem getFleetTotalItem() {
037                        return getFighterBaysTotal();
038                }
039                
040                public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
041                        if (hasFighterBays(stats)) {
042                                float rateBonus = computeAndCacheThresholdBonus(stats, "cg_rep_rate", REPLACEMENT_RATE_PERCENT, ThresholdBonusType.FIGHTER_BAYS);
043                                if (isOfficer(stats)) rateBonus *= OFFICER_MULT;
044                                float timeMult = 1f / ((100f + rateBonus) / 100f);
045                                stats.getFighterRefitTimeMult().modifyMult(id, timeMult);
046                                
047                                float speedBonus = computeAndCacheThresholdBonus(stats, "cg_top_speed", TOP_SPEED_PERCENT, ThresholdBonusType.FIGHTER_BAYS);
048                                if (isOfficer(stats)) speedBonus *= OFFICER_MULT;
049                                stats.getMaxSpeed().modifyPercent(id, speedBonus);
050                        }
051//                      else {
052//                              // may be needed to make refit screen show the right values when adding/removing Converted Hangar
053//                              // leaving this be for now
054//                              stats.getFighterRefitTimeMult().unmodifyMult(id);
055//                              stats.getMaxSpeed().unmodifyPercent(id);
056//                      }
057                }
058                
059                public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
060                        stats.getFighterRefitTimeMult().unmodifyMult(id);
061                }
062                
063                public String getEffectDescription(float level) {
064                        return null;
065                }
066                        
067                public void createCustomDescription(MutableCharacterStatsAPI stats, SkillSpecAPI skill, 
068                                                                                        TooltipMakerAPI info, float width) {
069                        init(stats, skill);
070                        
071                        FleetDataAPI data = getFleetData(null);
072                        float rateBonus = computeAndCacheThresholdBonus(data, stats, "cg_rep_rate", REPLACEMENT_RATE_PERCENT, ThresholdBonusType.FIGHTER_BAYS);
073                        
074                        info.addPara("+%s faster fighter replacement rate (maximum: %s)", 0f, hc, hc,
075                                        "" + (int) rateBonus + "%",
076                                        "" + (int) REPLACEMENT_RATE_PERCENT + "%");
077                        
078                        float speedBonus = computeAndCacheThresholdBonus(data, stats, "cg_top_speed", TOP_SPEED_PERCENT, ThresholdBonusType.FIGHTER_BAYS);
079                        
080                        info.addPara("+%s ship top speed (maximum: %s)", 0f, hc, hc,
081                                        "" + (int) speedBonus + "%",
082                                        "" + (int) TOP_SPEED_PERCENT + "%");
083                        
084                        addFighterBayThresholdInfo(info, data);
085                        info.addPara(indent + "Effect increased by %s for ships with officers, including flagship",
086                                        0f, tc, hc, 
087                                        "" + Misc.getRoundedValueMaxOneAfterDecimal(OFFICER_MULT) + Strings.X);
088                }
089                
090                public ScopeDescription getScopeDescription() {
091                        return ScopeDescription.ALL_CARRIERS;
092                }
093
094        }
095        
096
097
098}
099
100
101
102
103