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.fleet.FleetMemberViewAPI; 008import com.fs.starfarer.api.ui.Alignment; 009import com.fs.starfarer.api.ui.LabelAPI; 010import com.fs.starfarer.api.ui.TooltipMakerAPI; 011import com.fs.starfarer.api.util.Misc; 012 013public class ReversePolarityToggle extends ToggleAbilityWithCost { 014 015 public static String REVERSED_POLARITY = "$reversedPolarity"; 016 public static String POLARITY_SPEED_MULT = "$polaritySpeedMult"; 017 public static String POLARITY_WIND_GLOW_COLOR_KEY = "$polarityWindGlowColor"; 018 public static Color POLARITY_WIND_GLOW_COLOR = new Color(1f, 0.25f, 1f, 0.75f); 019 020 public static float SLIPSTREAM_SPEED_MULT = 0.75f; 021 022 public static float CR_COST_MULT = 0.25f; 023 public static float FUEL_COST_MULT = 1f; 024 025 public static float ACTIVATION_DAMAGE_PROB = 0.33f; 026 027 @Override 028 public float getFuelCostMult(boolean forTooltip) { 029 if (!forTooltip && !isFleetInSlipstream()) return 0f; 030 return FUEL_COST_MULT; 031 } 032 033 @Override 034 public float getCRCostMult(boolean forTooltip) { 035 if (!forTooltip && !isFleetInSlipstream()) return 0f; 036 return CR_COST_MULT; 037 } 038 039 @Override 040 public boolean canRecoverCRWhileActive(boolean forTooltip) { 041 return true; 042 } 043 044 @Override 045 protected String getActivationText() { 046 return "Drive field polarity reversed"; 047 } 048 049 050 @Override 051 public boolean isUsable() { 052 if (!super.isUsable()) return false; 053 if (getFleet() == null) return false; 054 055 CampaignFleetAPI fleet = getFleet(); 056 057 if (!fleet.isInHyperspace()) return false; 058 059 return true; 060 } 061 062 @Override 063 protected void applyStatsEffect(float amount, float level) { 064 CampaignFleetAPI fleet = getFleet(); 065 if (fleet == null) return; 066 067 if (fleet.getContainingLocation() == null || !fleet.getContainingLocation().isHyperspace()) { 068 deactivate(); 069 return; 070 } 071 072 if (level >= 1f && turnedOn) { 073 fleet.getMemoryWithoutUpdate().set(REVERSED_POLARITY, true, getDeactivationDays()); 074 float speedMult = SLIPSTREAM_SPEED_MULT; 075 fleet.getMemoryWithoutUpdate().set(POLARITY_SPEED_MULT, speedMult, getDeactivationDays()); 076 fleet.getMemoryWithoutUpdate().set(POLARITY_WIND_GLOW_COLOR_KEY, POLARITY_WIND_GLOW_COLOR, getDeactivationDays()); 077 } 078 if (level <= 0) { 079 cleanupImpl(); 080 } 081 } 082 083 084 @Override 085 protected void applyFleetVisual(float amount, float level) { 086 CampaignFleetAPI fleet = getFleet(); 087 if (fleet == null) return; 088 089 Color c = new Color(255,0,255,255); 090 Color cDim = new Color(255,0,255,50); 091 Color cDim2 = new Color(255,0,255,120); 092 for (FleetMemberViewAPI view : fleet.getViews()) { 093 //view.getContrailColor().shift(getModId(), view.getEngineColor().getBase(), 1f, 1f, 0.25f); 094 view.getContrailColor().shift(getModId(), cDim2, 1f, 1f, .75f); 095 view.getEngineGlowColor().shift(getModId(), cDim, 1f, 1f, .5f); 096 view.getEngineGlowSizeMult().shift(getModId(), 3f, 1f, 1f, 1f); 097 //view.getEngineHeightMult().shift(getModId(), 5f, 1f, 1f, 1f); 098 //view.getEngineWidthMult().shift(getModId(), 10f, 1f, 1f, 1f); 099 } 100 } 101 102 103 public boolean isFleetInSlipstream() { 104 CampaignFleetAPI fleet = getFleet(); 105 if (fleet == null) return false; 106 return Misc.isInsideSlipstream(fleet); 107 } 108 109 @Override 110 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded) { 111 CampaignFleetAPI fleet = getFleet(); 112 if (fleet == null) return; 113 114 Color gray = Misc.getGrayColor(); 115 Color highlight = Misc.getHighlightColor(); 116 117 String status = " (off)"; 118 if (turnedOn) { 119 status = " (on)"; 120 } 121 122 if (!Global.CODEX_TOOLTIP_MODE) { 123 LabelAPI title = tooltip.addTitle("Reverse Polarity" + status); 124 title.highlightLast(status); 125 title.setHighlightColor(gray); 126 } else { 127 tooltip.addSpacer(-10f); 128 } 129 130 float pad = 10f; 131 132 133 tooltip.addPara("Reverse the polarity of the drive field, causing the fleet to travel " 134 + "against the current of slipstreams.", pad); 135 136 if (SLIPSTREAM_SPEED_MULT != 1f) { 137 tooltip.addPara("Going against the current is less efficient and results in " 138 + "the slipstream current's effect being reduced by %s.", pad, 139 highlight, 140 "" + Math.round(100f * (1f - SLIPSTREAM_SPEED_MULT))+ "%" 141 ); 142 } 143 144 tooltip.addPara("When used outside a slipstream, incurs no cost, penalty, or risk of ship damage.", pad); 145 146 tooltip.addSectionHeading("Use inside slipstreams", Alignment.MID, pad); 147 addCostTooltipSection(tooltip, expanded, "An emergency maneuver when performed inside a slipstream, " 148 + "reversing drive field polarity"); 149 150 151 addIncompatibleToTooltip(tooltip, expanded); 152 } 153 154 155 @Override 156 public void addOtherNotUsableReason(TooltipMakerAPI tooltip, boolean expanded) { 157 CampaignFleetAPI fleet = getFleet(); 158 if (fleet == null) return; 159 160 Color bad = Misc.getNegativeHighlightColor(); 161 if (!fleet.isInHyperspace()) { 162 tooltip.addPara("Can only be used in hyperspace.", bad, 10f); 163 } 164 } 165 166 protected boolean showAlarm() { 167 if (!isFleetInSlipstream()) return false; 168 return super.showAlarm() || isFleetInSlipstream(); 169 } 170 171 172 @Override 173 public Color getCooldownColor() { 174 if (showAlarm()) { 175 Color color = Misc.getNegativeHighlightColor(); 176 if (!super.showAlarm()) { // fleet is inside slipstream, but good CR 177 color = Misc.getHighlightColor(); 178 } 179 return Misc.scaleAlpha(color, Global.getSector().getCampaignUI().getSharedFader().getBrightness() * 0.5f); 180 } 181 return super.getCooldownColor(); 182 } 183// 184 185// public void setFuelUseModifier(CampaignFleetAPI fleet, boolean on) { 186// if (!WITH_FUEL_USE_MULT) return; 187// 188// String id1 = "reverse_polarity_1"; 189// 190// MutableStat stat = fleet.getStats().getDynamic().getStat(Stats.FUEL_USE_NOT_SHOWN_ON_MAP_MULT); 191// stat.unmodifyMult(id1); 192// 193// for (StatMod mod : stat.getMultMods().values()) { 194// if (SlipstreamTerrainPlugin2.FUEL_USE_MODIFIER_DESC.equals(mod.desc)) { 195// if (on) { 196// stat.modifyMult(id1, FUEL_USE_MULT, 197// SlipstreamTerrainPlugin2.FUEL_USE_MODIFIER_DESC + " (reversed polarity)"); 198// } else { 199// stat.unmodifyMult(id1); 200// } 201// break; 202// } 203// } 204// } 205} 206 207 208 209 210