001package com.fs.starfarer.api.impl.hullmods; 002 003import java.awt.Color; 004 005import com.fs.starfarer.api.GameState; 006import com.fs.starfarer.api.Global; 007import com.fs.starfarer.api.combat.BaseHullMod; 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.combat.ShipHullSpecAPI.ShipTypeHints; 012import com.fs.starfarer.api.combat.ShipSystemAPI; 013import com.fs.starfarer.api.impl.campaign.ids.Stats; 014import com.fs.starfarer.api.impl.campaign.ids.Strings; 015import com.fs.starfarer.api.impl.campaign.skills.NeuralLinkScript; 016import com.fs.starfarer.api.impl.campaign.skills.SupportDoctrine; 017import com.fs.starfarer.api.ui.Alignment; 018import com.fs.starfarer.api.ui.TooltipMakerAPI; 019import com.fs.starfarer.api.util.Misc; 020 021public class NeuralInterface extends BaseHullMod { 022 023 public static float SYSTEM_RESET_TIMEOUT_MULT = 2f; 024 //public static float SYSTEM_RESET_TIMEOUT = 20f; 025 public static final String SYSTEM_RESET_TIMEOUT_KEY = "neural_interface_reset_timeout"; 026 027 @Override 028 public void advanceInCombat(ShipAPI ship, float amount) { 029 String key = SYSTEM_RESET_TIMEOUT_KEY; 030// Float timeout = (Float) Global.getCombatEngine().getCustomData().get(key); 031// if (timeout == null) timeout = 0f; 032// 033// if (ship == Global.getCombatEngine().getPlayerShip()) { 034// timeout -= amount; 035// if (timeout < 0) timeout = 0f; 036// Global.getCombatEngine().getCustomData().put(key, timeout); 037// //System.out.println("NI timeout: " + timeout); 038// } 039 040 Float timeout = (Float) ship.getCustomData().get(key); 041 if (timeout == null) timeout = 0f; 042 timeout -= amount; 043 if (timeout < 0) timeout = 0f; 044 ship.setCustomData(key, timeout); 045 //System.out.println("NI timeout: " + timeout); 046 047 if (ship == Global.getCombatEngine().getPlayerShip()) { 048 if (ship.getCustomData().containsKey(NeuralLinkScript.TRANSFER_COMPLETE_KEY)) { 049 ShipSystemAPI system = ship.getSystem(); 050 if (system != null && timeout <= 0) { 051 boolean didSomething = false; 052 //float maxTimeout = 5f; 053 float maxTimeout = 0f; 054 if (system.getCooldownRemaining() > 0f && system.isCoolingDown()) { 055 maxTimeout = Math.max(system.getCooldownRemaining(), maxTimeout); 056 system.setCooldownRemaining(0); 057 didSomething = true; 058 } 059 if (system.getAmmo() < system.getMaxAmmo() && system.getAmmoPerSecond() > 0) { 060 system.setAmmo(system.getAmmo() + 1); 061 didSomething = true; 062 maxTimeout = Math.max(1f / system.getAmmoPerSecond() * (1f - system.getAmmoReloadProgress()), maxTimeout); 063 } 064 //if (didSomething) { 065 if (maxTimeout > 0) { 066 maxTimeout *= SYSTEM_RESET_TIMEOUT_MULT; 067 //Global.getCombatEngine().getCustomData().put(key, SYSTEM_RESET_TIMEOUT); 068 ship.setCustomData(key, maxTimeout); 069 } 070 } 071 ship.removeCustomData(NeuralLinkScript.TRANSFER_COMPLETE_KEY); 072 } 073 } else { 074 ship.removeCustomData(NeuralLinkScript.TRANSFER_COMPLETE_KEY); 075 } 076 } 077 078 079 public void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id) { 080 stats.getDynamic().getMod(Stats.HAS_NEURAL_LINK).modifyFlat(id, 1f); 081 082 stats.getDynamic().getMod(Stats.DEPLOYMENT_POINTS_MOD).unmodify(SupportDoctrine.SUPPORT_DOCTRINE_DP_REDUCTION_ID); 083 084 boolean sMod = isSMod(stats); 085 if (sMod) { 086 stats.getDynamic().getMod(Stats.INSTANT_NEURAL_TRANSFER_FROM).modifyFlat(id, 1f); 087 } 088 089// if (stats.getFleetMember() != null && stats.getFleetMember().getCaptain() != null) { 090// PersonAPI p = stats.getFleetMember().getCaptain(); 091// if (p.isDefault() && Misc.isAutomated(stats.getFleetMember())) { 092// p.getMemoryWithoutUpdate().set(AICoreOfficerPluginImpl.AUTOMATED_POINTS_MULT, 093// AICoreOfficerPluginImpl.BETA_MULT); 094// } 095// 096// } 097 098 //stats.getDynamic().getMod(Stats.COORDINATED_MANEUVERS_FLAT).modifyFlat(id, (Float) mag.get(hullSize)); 099 //stats.getDynamic().getMod(Stats.COORDINATED_MANEUVERS_FLAT).modifyFlat(id, (Float) mag.get(hullSize)); 100 } 101 102 public String getDescriptionParam(int index, HullSize hullSize) { 103 if (this instanceof NeuralIntegrator) { 104 if (index == 0) return "benefit from your combat skills"; 105 if (index == 1) return "" + (int)NeuralLinkScript.INSTANT_TRANSFER_DP; 106 if (index == 2) return "" + (int) NeuralIntegrator.DP_INCREASE_PERCENT + "%"; 107 } 108 if (index == 0) return "benefit from your combat skills"; 109 if (index == 1) return "" + (int)NeuralLinkScript.INSTANT_TRANSFER_DP; 110 return null; 111 } 112 113 @Override 114 public void addPostDescriptionSection(TooltipMakerAPI tooltip, HullSize hullSize, ShipAPI ship, float width, boolean isForModSpec) { 115 float pad = 3f; 116 float opad = 10f; 117 Color h = Misc.getHighlightColor(); 118 Color bad = Misc.getNegativeHighlightColor(); 119 Color g = Misc.getGrayColor(); 120 121 tooltip.addSectionHeading("Neural system reset", Alignment.MID, opad); 122 tooltip.addPara("After the transfer is complete, the target ship's system cooldown (if any) will be reset, " 123 + "and if the ship system uses charges, it will gain an additonal charge. This effect operates on " 124 + "a cooldown equal to %s the cooldown/charge regeneration time saved by it.", opad, h, 125 "" + (int)SYSTEM_RESET_TIMEOUT_MULT + Strings.X); 126 127// tooltip.addPara("If installed on an automated ship, increases its " 128// + "\"automated ship points\" value as if a Beta Core was installed on the ship.", opad); 129 130 if (Global.getCurrentState() == GameState.CAMPAIGN) { 131 if (Global.getSector().getPlayerStats().getDynamic().getMod(Stats.HAS_NEURAL_LINK).computeEffective(0f) <= 0f) { 132 tooltip.addPara("Requires the Neural Link skill to function", Misc.getNegativeHighlightColor(), opad); 133 } 134 } 135 136 if (isForModSpec || ship == null) return; 137 138 String control = Global.getSettings().getControlStringForEnumName(NeuralLinkScript.TRANSFER_CONTROL); 139 String desc = Global.getSettings().getControlDescriptionForEnumName(NeuralLinkScript.TRANSFER_CONTROL); 140 tooltip.addPara("Use the \"" + desc + "\" control [" + control + "] to switch between ships.", opad, 141 g, h, control); 142 143 144 } 145 146 public boolean isApplicableToShip(ShipAPI ship) { 147 if (Misc.isAutomated(ship)) { 148 return false; 149 } 150 if (ship.getHullSpec().getHints().contains(ShipTypeHints.NO_NEURAL_LINK)) { 151 return false; 152 } 153 return true; 154 } 155 156 public String getUnapplicableReason(ShipAPI ship) { 157 if (Misc.isAutomated(ship)) { 158 return "Can not be installed on automated ships, install Neural Integrator instead"; 159 } 160 if (ship.getHullSpec().getHints().contains(ShipTypeHints.NO_NEURAL_LINK)) { 161 return "Can not be installed on this ship"; 162 } 163 return null; 164 } 165} 166 167 168 169