001package com.fs.starfarer.api.impl.hullmods;
002
003import java.awt.Color;
004
005import com.fs.starfarer.api.combat.BaseHullMod;
006import com.fs.starfarer.api.combat.MutableShipStatsAPI;
007import com.fs.starfarer.api.combat.ShipAPI;
008import com.fs.starfarer.api.combat.ShipAPI.HullSize;
009import com.fs.starfarer.api.combat.WeaponAPI;
010import com.fs.starfarer.api.combat.WeaponAPI.WeaponType;
011import com.fs.starfarer.api.combat.listeners.WeaponBaseRangeModifier;
012import com.fs.starfarer.api.ui.Alignment;
013import com.fs.starfarer.api.ui.TooltipMakerAPI;
014import com.fs.starfarer.api.util.Misc;
015
016public class EnergyBoltCoherer extends BaseHullMod {
017
018        public static float RANGE_BONUS = 200;
019        public static float CREWED_RANGE_BONUS = 100;
020        
021        public static float CREW_CASUALTIES = 50;
022        
023        public void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id) {
024                if (!Misc.isAutomated(stats)) {
025                        stats.getCrewLossMult().modifyPercent(id, CREW_CASUALTIES);
026                }
027        }
028
029        @Override
030        public void applyEffectsAfterShipCreation(ShipAPI ship, String id) {
031                ship.addListener(new EnergyBoltCohererRangeModifier());
032        }
033        
034        public static class EnergyBoltCohererRangeModifier implements WeaponBaseRangeModifier {
035                public EnergyBoltCohererRangeModifier() {
036                }
037                
038                public float getWeaponBaseRangePercentMod(ShipAPI ship, WeaponAPI weapon) {
039                        return 0;
040                }
041                public float getWeaponBaseRangeMultMod(ShipAPI ship, WeaponAPI weapon) {
042                        return 1f;
043                }
044                public float getWeaponBaseRangeFlatMod(ShipAPI ship, WeaponAPI weapon) {
045                        if (weapon.isBeam()) return 0f;
046                        if (weapon.getType() == WeaponType.ENERGY || weapon.getType() == WeaponType.HYBRID) {
047                                if (Misc.isAutomated(ship)) {
048                                        return RANGE_BONUS;
049                                } else {
050                                        return CREWED_RANGE_BONUS;
051                                }
052                        }
053                        return 0f;
054                }
055        }
056
057        public String getDescriptionParam(int index, HullSize hullSize) {
058                return null;
059        }
060        
061        @Override
062        public boolean shouldAddDescriptionToTooltip(HullSize hullSize, ShipAPI ship, boolean isForModSpec) {
063                return false;
064        }
065
066        @Override
067        public void addPostDescriptionSection(TooltipMakerAPI tooltip, HullSize hullSize, ShipAPI ship, float width, boolean isForModSpec) {
068                float pad = 3f;
069                float opad = 10f;
070                Color h = Misc.getHighlightColor();
071                Color bad = Misc.getNegativeHighlightColor();
072                
073                
074                if (!Misc.isAutomated(ship)) {
075                        tooltip.addPara("Originally designed by the Tri-Tachyon Corporation for use on its combat droneships, "
076                                        + "the coherence field strength has to be dialed down to allow operation on crewed vessels.", opad);
077                        tooltip.addPara("Increases the base range of all non-beam Energy and Hybrid weapons by %s.", opad, h,
078                                        "" + (int)CREWED_RANGE_BONUS);
079                        tooltip.addPara("The coherence field is unstable under combat conditions, with stresses on the hull "
080                                        + "resulting in spot failures that release bursts of lethal radiation. "
081                                        + "Crew casualties in combat are increased by %s.", opad, h,
082                                        "" + (int) CREW_CASUALTIES + "%");
083                } else {
084                        tooltip.addPara("Increases the base range of all non-beam Energy and Hybrid weapons by %s.", opad, h,
085                                "" + (int)RANGE_BONUS);
086                }
087                
088                tooltip.addSectionHeading("Interactions with other modifiers", Alignment.MID, opad);
089                tooltip.addPara("Since the base range is increased, this range modifier"
090                                + " - unlike most other flat modifiers in the game - "
091                                + "is increased by percentage modifiers from other hullmods and skills.", opad);
092        }
093        
094//      @Override
095//      public boolean isApplicableToShip(ShipAPI ship) {
096//              return getUnapplicableReason(ship) == null;
097//      }
098//      
099//      public String getUnapplicableReason(ShipAPI ship) {
100//              if (ship != null && 
101//                              ship.getHullSize() != HullSize.CAPITAL_SHIP && 
102//                              ship.getHullSize() != HullSize.DESTROYER && 
103//                              ship.getHullSize() != HullSize.CRUISER) {
104//                      return "Can only be installed on destroyer-class hulls and larger";
105//              }
106//              return null;
107//      }
108        
109}
110
111
112
113
114
115
116
117
118