Starsector API
Loading...
Searching...
No Matches
NeuralInterface.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.hullmods;
2
3import java.awt.Color;
4
5import com.fs.starfarer.api.GameState;
6import com.fs.starfarer.api.Global;
7import com.fs.starfarer.api.combat.BaseHullMod;
8import com.fs.starfarer.api.combat.MutableShipStatsAPI;
9import com.fs.starfarer.api.combat.ShipAPI;
10import com.fs.starfarer.api.combat.ShipAPI.HullSize;
11import com.fs.starfarer.api.combat.ShipHullSpecAPI.ShipTypeHints;
12import com.fs.starfarer.api.combat.ShipSystemAPI;
13import com.fs.starfarer.api.impl.campaign.ids.Stats;
14import com.fs.starfarer.api.impl.campaign.ids.Strings;
15import com.fs.starfarer.api.impl.campaign.skills.NeuralLinkScript;
16import com.fs.starfarer.api.impl.campaign.skills.SupportDoctrine;
17import com.fs.starfarer.api.ui.Alignment;
18import com.fs.starfarer.api.ui.TooltipMakerAPI;
19import com.fs.starfarer.api.util.Misc;
20
21public class NeuralInterface extends BaseHullMod {
22
23 public static float SYSTEM_RESET_TIMEOUT_MULT = 2f;
24 //public static float SYSTEM_RESET_TIMEOUT = 20f;
25 public static final String SYSTEM_RESET_TIMEOUT_KEY = "neural_interface_reset_timeout";
26
27 @Override
28 public void advanceInCombat(ShipAPI ship, float amount) {
29 String key = SYSTEM_RESET_TIMEOUT_KEY;
30// Float timeout = (Float) Global.getCombatEngine().getCustomData().get(key);
31// if (timeout == null) timeout = 0f;
32//
33// if (ship == Global.getCombatEngine().getPlayerShip()) {
34// timeout -= amount;
35// if (timeout < 0) timeout = 0f;
36// Global.getCombatEngine().getCustomData().put(key, timeout);
37// //System.out.println("NI timeout: " + timeout);
38// }
39
40 Float timeout = (Float) ship.getCustomData().get(key);
41 if (timeout == null) timeout = 0f;
42 timeout -= amount;
43 if (timeout < 0) timeout = 0f;
44 ship.setCustomData(key, timeout);
45 //System.out.println("NI timeout: " + timeout);
46
47 if (ship == Global.getCombatEngine().getPlayerShip()) {
48 if (ship.getCustomData().containsKey(NeuralLinkScript.TRANSFER_COMPLETE_KEY)) {
49 ShipSystemAPI system = ship.getSystem();
50 if (system != null && timeout <= 0) {
51 boolean didSomething = false;
52 //float maxTimeout = 5f;
53 float maxTimeout = 0f;
54 if (system.getCooldownRemaining() > 0f && system.isCoolingDown()) {
55 maxTimeout = Math.max(system.getCooldownRemaining(), maxTimeout);
56 system.setCooldownRemaining(0);
57 didSomething = true;
58 }
59 if (system.getAmmo() < system.getMaxAmmo() && system.getAmmoPerSecond() > 0) {
60 system.setAmmo(system.getAmmo() + 1);
61 didSomething = true;
62 maxTimeout = Math.max(1f / system.getAmmoPerSecond() * (1f - system.getAmmoReloadProgress()), maxTimeout);
63 }
64 //if (didSomething) {
65 if (maxTimeout > 0) {
66 maxTimeout *= SYSTEM_RESET_TIMEOUT_MULT;
67 //Global.getCombatEngine().getCustomData().put(key, SYSTEM_RESET_TIMEOUT);
68 ship.setCustomData(key, maxTimeout);
69 }
70 }
71 ship.removeCustomData(NeuralLinkScript.TRANSFER_COMPLETE_KEY);
72 }
73 } else {
74 ship.removeCustomData(NeuralLinkScript.TRANSFER_COMPLETE_KEY);
75 }
76 }
77
78
79 public void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id) {
80 stats.getDynamic().getMod(Stats.HAS_NEURAL_LINK).modifyFlat(id, 1f);
81
82 stats.getDynamic().getMod(Stats.DEPLOYMENT_POINTS_MOD).unmodify(SupportDoctrine.SUPPORT_DOCTRINE_DP_REDUCTION_ID);
83
84// if (stats.getFleetMember() != null && stats.getFleetMember().getCaptain() != null) {
85// PersonAPI p = stats.getFleetMember().getCaptain();
86// if (p.isDefault() && Misc.isAutomated(stats.getFleetMember())) {
87// p.getMemoryWithoutUpdate().set(AICoreOfficerPluginImpl.AUTOMATED_POINTS_MULT,
88// AICoreOfficerPluginImpl.BETA_MULT);
89// }
90//
91// }
92
93 //stats.getDynamic().getMod(Stats.COORDINATED_MANEUVERS_FLAT).modifyFlat(id, (Float) mag.get(hullSize));
94 //stats.getDynamic().getMod(Stats.COORDINATED_MANEUVERS_FLAT).modifyFlat(id, (Float) mag.get(hullSize));
95 }
96
97 public String getDescriptionParam(int index, HullSize hullSize) {
98 if (this instanceof NeuralIntegrator) {
99 if (index == 0) return "benefit from your combat skills";
100 if (index == 1) return "" + (int)NeuralLinkScript.INSTANT_TRANSFER_DP;
101 if (index == 2) return "" + (int) NeuralIntegrator.DP_INCREASE_PERCENT + "%";
102 }
103 if (index == 0) return "benefit from your combat skills";
104 if (index == 1) return "" + (int)NeuralLinkScript.INSTANT_TRANSFER_DP;
105 return null;
106 }
107
108 @Override
109 public void addPostDescriptionSection(TooltipMakerAPI tooltip, HullSize hullSize, ShipAPI ship, float width, boolean isForModSpec) {
110 float pad = 3f;
111 float opad = 10f;
112 Color h = Misc.getHighlightColor();
113 Color bad = Misc.getNegativeHighlightColor();
114 Color g = Misc.getGrayColor();
115
116 tooltip.addSectionHeading("Neural system reset", Alignment.MID, opad);
117 tooltip.addPara("After the transfer is complete, the target ship's system cooldown (if any) will be reset, "
118 + "and if the ship system uses charges, it will gain an additonal charge. This effect operates on "
119 + "a cooldown equal to %s the cooldown/charge regeneration time saved by it.", opad, h,
120 "" + (int)SYSTEM_RESET_TIMEOUT_MULT + Strings.X);
121
122// tooltip.addPara("If installed on an automated ship, increases its "
123// + "\"automated ship points\" value as if a Beta Core was installed on the ship.", opad);
124
126 if (Global.getSector().getPlayerStats().getDynamic().getMod(Stats.HAS_NEURAL_LINK).computeEffective(0f) <= 0f) {
127 tooltip.addPara("Requires the Neural Link skill to function", Misc.getNegativeHighlightColor(), opad);
128 }
129 }
130
131 if (isForModSpec || ship == null) return;
132
133 String control = Global.getSettings().getControlStringForEnumName(NeuralLinkScript.TRANSFER_CONTROL);
134 String desc = Global.getSettings().getControlDescriptionForEnumName(NeuralLinkScript.TRANSFER_CONTROL);
135 tooltip.addPara("Use the \"" + desc + "\" control [" + control + "] to switch between ships.", opad,
136 g, h, control);
137
138
139 }
140
141 public boolean isApplicableToShip(ShipAPI ship) {
142 if (Misc.isAutomated(ship)) {
143 return false;
144 }
145 if (ship.getHullSpec().getHints().contains(ShipTypeHints.NO_NEURAL_LINK)) {
146 return false;
147 }
148 return true;
149 }
150
151 public String getUnapplicableReason(ShipAPI ship) {
152 if (Misc.isAutomated(ship)) {
153 return "Can not be installed on automated ships, install Neural Integrator instead";
154 }
155 if (ship.getHullSpec().getHints().contains(ShipTypeHints.NO_NEURAL_LINK)) {
156 return "Can not be installed on this ship";
157 }
158 return null;
159 }
160}
161
162
163
164
static SettingsAPI getSettings()
Definition Global.java:51
static CombatEngineAPI getCombatEngine()
Definition Global.java:63
static GameState getCurrentState()
Definition Global.java:21
static SectorAPI getSector()
Definition Global.java:59
void addPostDescriptionSection(TooltipMakerAPI tooltip, HullSize hullSize, ShipAPI ship, float width, boolean isForModSpec)
void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id)
String getDescriptionParam(int index, HullSize hullSize)
String getControlDescriptionForEnumName(String name)
String getControlStringForEnumName(String name)