001package com.fs.starfarer.api.impl.campaign.abilities;
002
003import java.awt.Color;
004
005import com.fs.starfarer.api.Global;
006import com.fs.starfarer.api.campaign.CampaignFleetAPI;
007import com.fs.starfarer.api.campaign.SectorEntityToken.VisibilityLevel;
008import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
009import com.fs.starfarer.api.impl.campaign.ids.Pings;
010import com.fs.starfarer.api.ui.LabelAPI;
011import com.fs.starfarer.api.ui.TooltipMakerAPI;
012import com.fs.starfarer.api.util.Misc;
013
014public class SensorBurstAbility extends BaseDurationAbility {
015
016        public static final float SENSOR_RANGE_BONUS = 3000f;
017        public static final float DETECTABILITY_RANGE_BONUS = 5000f;
018        //public static final float ACCELERATION_MULT = 4f;
019        
020//      public String getSpriteName() {
021//              return Global.getSettings().getSpriteName("abilities", Abilities.SENSOR_BURST);
022//      }
023        
024//      @Override
025//      protected String getActivationText() {
026//              //return "Active sensor burst";
027//              return Misc.ucFirst(spec.getName().toLowerCase());
028//      }
029
030        @Override
031        protected void activateImpl() {
032                if (entity.isInCurrentLocation()) {
033                        //entity.addFloatingText("Active sensor burst", entity.getFaction().getBaseUIColor(), 0.5f);
034                        
035                        VisibilityLevel level = entity.getVisibilityLevelToPlayerFleet();
036                        if (level != VisibilityLevel.NONE) {
037                                Global.getSector().addPing(entity, Pings.SENSOR_BURST);
038                        }
039                }
040                
041//              AbilityPlugin goDark = entity.getAbility(Abilities.GO_DARK);
042//              if (goDark != null && goDark.isActive()) {
043//                      goDark.deactivate();
044//              }
045//              AbilityPlugin sb = entity.getAbility(Abilities.SUSTAINED_BURN);
046//              if (sb != null && sb.isActive()) {
047//                      sb.deactivate();
048//              }
049        }
050
051        @Override
052        protected void applyEffect(float amount, float level) {
053//              if (level > 0) {
054//                      AbilityPlugin goDark = entity.getAbility(Abilities.GO_DARK);
055//                      if (goDark != null) goDark.forceDisable();
056//                      AbilityPlugin eb = entity.getAbility(Abilities.EMERGENCY_BURN);
057//                      if (eb != null) eb.forceDisable();
058//                      AbilityPlugin sb = entity.getAbility(Abilities.SUSTAINED_BURN);
059//                      if (sb != null) sb.forceDisable();
060//              }
061                
062                
063                CampaignFleetAPI fleet = getFleet();
064                if (fleet == null) return;
065                
066                if (entity.isInCurrentLocation()) {
067                        Global.getSector().getMemoryWithoutUpdate().set(MemFlags.GLOBAL_SENSOR_BURST_JUST_USED_IN_CURRENT_LOCATION, true, 0.1f);
068                }
069                fleet.getMemoryWithoutUpdate().set(MemFlags.JUST_DID_SENSOR_BURST, true, 0.1f);
070                
071//              if (fleet.isPlayerFleet()) {
072//                      System.out.println("Level: " + level);
073//              }
074                
075                //float b = fleet.getStats().getDynamic().getValue(Stats.SENSOR_BURST_BURN_PENALTY_MULT);
076                
077                //fleet.getStats().getFleetwideMaxBurnMod().modifyMult(getModId(), 1f + (0f - 1f * level) * b, "Active sensor burst");
078                //fleet.getStats().getFleetwideMaxBurnMod().modifyMult(getModId(), 1f + (0f - 1f * 1f) * b, "Active sensor burst");
079                //fleet.getStats().getFleetwideMaxBurnMod().modifyMult(getModId(), 0, "Active sensor burst");
080                
081                fleet.getStats().getSensorRangeMod().modifyFlat(getModId(), SENSOR_RANGE_BONUS * level, "Active sensor burst");
082                fleet.getStats().getDetectedRangeMod().modifyFlat(getModId(), DETECTABILITY_RANGE_BONUS * level, "Active sensor burst");
083                
084                //fleet.getStats().getAccelerationMult().modifyMult(getModId(), 1f + (ACCELERATION_MULT - 1f) * level);
085                
086                fleet.goSlowOneFrame();
087        }
088
089        @Override
090        protected void deactivateImpl() {
091                cleanupImpl();
092        }
093        
094        @Override
095        protected void cleanupImpl() {
096                CampaignFleetAPI fleet = getFleet();
097                if (fleet == null) return;
098                
099                fleet.getStats().getSensorRangeMod().unmodify(getModId());
100                fleet.getStats().getDetectedRangeMod().unmodify(getModId());
101                //fleet.getStats().getFleetwideMaxBurnMod().unmodify(getModId());
102                //fleet.getStats().getAccelerationMult().unmodify(getModId());
103        }
104        
105//      @Override
106//      public float getActivationDays() {
107//              return 0.2f;
108//      }
109//
110//      @Override
111//      public float getCooldownDays() {
112//              return 1f;
113//      }
114//
115//      @Override
116//      public float getDeactivationDays() {
117//              return 0.2f;
118//      }
119//
120//      @Override
121//      public float getDurationDays() {
122//              return 0.5f;
123//      }
124
125        @Override
126        public void createTooltip(TooltipMakerAPI tooltip, boolean expanded) {
127                Color gray = Misc.getGrayColor();
128                Color highlight = Misc.getHighlightColor();
129
130                if (!Global.CODEX_TOOLTIP_MODE) {
131                        LabelAPI title = tooltip.addTitle(spec.getName());
132                } else {
133                        tooltip.addSpacer(-10f);
134                }
135
136                float pad = 10f;
137                tooltip.addPara("Turn off engines to reduce interference and link all sensors in the fleet into a single network.", pad);
138                tooltip.addPara("Increases sensor range by %s* units and" +
139                                " increases the range at which the fleet can be detected by %s* units." +
140                                " The fleet is only able to %s** while the ability is active.",
141                                pad, highlight,
142                                "" + (int)SENSOR_RANGE_BONUS,
143                                "" + (int)DETECTABILITY_RANGE_BONUS,
144                                "move slowly"
145                );
146                //tooltip.addPara("Disables \"Go Dark\" when activated.", pad);
147                tooltip.addPara("*2000 units = 1 map grid cell", gray, pad);
148                tooltip.addPara("**A fleet is considered slow-moving at a burn level of half that of its slowest ship.", gray, 0f);
149//              tooltip.addPara("**Maximum burn level of %s", 0f, gray, 
150//                              Misc.getDarkHighlightColor(), 
151//                              "" + Misc.getGoSlowBurnLevel(getFleet()));
152                
153                addIncompatibleToTooltip(tooltip, expanded);
154                
155        }
156
157        public boolean hasTooltip() {
158                return true;
159        }
160        
161}
162
163
164
165
166