Starsector API
Loading...
Searching...
No Matches
EntropyAmplifierStats.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.combat;
2
3import java.util.List;
4
5import java.awt.Color;
6
7import com.fs.starfarer.api.Global;
8import com.fs.starfarer.api.combat.BaseEveryFrameCombatPlugin;
9import com.fs.starfarer.api.combat.EveryFrameCombatPlugin;
10import com.fs.starfarer.api.combat.MutableShipStatsAPI;
11import com.fs.starfarer.api.combat.ShipAPI;
12import com.fs.starfarer.api.combat.ShipAPI.HullSize;
13import com.fs.starfarer.api.combat.ShipSystemAPI;
14import com.fs.starfarer.api.combat.ShipSystemAPI.SystemState;
15import com.fs.starfarer.api.combat.ShipwideAIFlags.AIFlags;
16import com.fs.starfarer.api.input.InputEventAPI;
17import com.fs.starfarer.api.util.Misc;
18
20 public static Object KEY_SHIP = new Object();
21 public static Object KEY_TARGET = new Object();
22
23 public static float DAM_MULT = 1.5f;
24 protected static float RANGE = 1500f;
25
26 public static Color TEXT_COLOR = new Color(255,55,55,255);
27
28 public static Color JITTER_COLOR = new Color(255,50,50,75);
29 public static Color JITTER_UNDER_COLOR = new Color(255,100,100,155);
30
31
32 public static class TargetData {
33 public ShipAPI ship;
34 public ShipAPI target;
35 public EveryFrameCombatPlugin targetEffectPlugin;
36 public float currDamMult;
37 public float elaspedAfterInState;
38 public TargetData(ShipAPI ship, ShipAPI target) {
39 this.ship = ship;
40 this.target = target;
41 }
42 }
43
44
45 public void apply(MutableShipStatsAPI stats, final String id, State state, float effectLevel) {
46 ShipAPI ship = null;
47 if (stats.getEntity() instanceof ShipAPI) {
48 ship = (ShipAPI) stats.getEntity();
49 } else {
50 return;
51 }
52
53 final String targetDataKey = ship.getId() + "_entropy_target_data";
54
55 Object targetDataObj = Global.getCombatEngine().getCustomData().get(targetDataKey);
56 if (state == State.IN && targetDataObj == null) {
57 ShipAPI target = findTarget(ship);
58 Global.getCombatEngine().getCustomData().put(targetDataKey, new TargetData(ship, target));
59 if (target != null) {
60 if (target.getFluxTracker().showFloaty() ||
62 target == Global.getCombatEngine().getPlayerShip()) {
63 target.getFluxTracker().showOverloadFloatyIfNeeded("Amplified Entropy!", TEXT_COLOR, 4f, true);
64 }
65 }
66 } else if (state == State.IDLE && targetDataObj != null) {
67 Global.getCombatEngine().getCustomData().remove(targetDataKey);
68 ((TargetData)targetDataObj).currDamMult = 1f;
69 targetDataObj = null;
70 }
71 if (targetDataObj == null || ((TargetData) targetDataObj).target == null) return;
72
73 final TargetData targetData = (TargetData) targetDataObj;
74 targetData.currDamMult = 1f + (DAM_MULT - 1f) * effectLevel;
75 //System.out.println("targetData.currDamMult: " + targetData.currDamMult);
76 if (targetData.targetEffectPlugin == null) {
77 targetData.targetEffectPlugin = new BaseEveryFrameCombatPlugin() {
78 @Override
79 public void advance(float amount, List<InputEventAPI> events) {
80 if (Global.getCombatEngine().isPaused()) return;
81 if (targetData.target == Global.getCombatEngine().getPlayerShip()) {
83 targetData.ship.getSystem().getSpecAPI().getIconSpriteName(),
84 targetData.ship.getSystem().getDisplayName(),
85 "" + (int)((targetData.currDamMult - 1f) * 100f) + "% more damage taken", true);
86 }
87
88 if (targetData.currDamMult <= 1f || !targetData.ship.isAlive()) {
89 targetData.target.getMutableStats().getHullDamageTakenMult().unmodify(id);
90 targetData.target.getMutableStats().getArmorDamageTakenMult().unmodify(id);
91 targetData.target.getMutableStats().getShieldDamageTakenMult().unmodify(id);
92 targetData.target.getMutableStats().getEmpDamageTakenMult().unmodify(id);
93 Global.getCombatEngine().removePlugin(targetData.targetEffectPlugin);
94 } else {
95 targetData.target.getMutableStats().getHullDamageTakenMult().modifyMult(id, targetData.currDamMult);
96 targetData.target.getMutableStats().getArmorDamageTakenMult().modifyMult(id, targetData.currDamMult);
97 targetData.target.getMutableStats().getShieldDamageTakenMult().modifyMult(id, targetData.currDamMult);
98 targetData.target.getMutableStats().getEmpDamageTakenMult().modifyMult(id, targetData.currDamMult);
99 }
100 }
101 };
102 Global.getCombatEngine().addPlugin(targetData.targetEffectPlugin);
103 }
104
105
106 if (effectLevel > 0) {
107 if (state != State.IN) {
108 targetData.elaspedAfterInState += Global.getCombatEngine().getElapsedInLastFrame();
109 }
110 float shipJitterLevel = 0;
111 if (state == State.IN) {
112 shipJitterLevel = effectLevel;
113 } else {
114 float durOut = 0.5f;
115 shipJitterLevel = Math.max(0, durOut - targetData.elaspedAfterInState) / durOut;
116 }
117 float targetJitterLevel = effectLevel;
118
119 float maxRangeBonus = 50f;
120 float jitterRangeBonus = shipJitterLevel * maxRangeBonus;
121
122 Color color = JITTER_COLOR;
123 if (shipJitterLevel > 0) {
124 //ship.setJitterUnder(KEY_SHIP, JITTER_UNDER_COLOR, shipJitterLevel, 21, 0f, 3f + jitterRangeBonus);
125 ship.setJitter(KEY_SHIP, color, shipJitterLevel, 4, 0f, 0 + jitterRangeBonus * 1f);
126 }
127
128 if (targetJitterLevel > 0) {
129 //target.setJitterUnder(KEY_TARGET, JITTER_UNDER_COLOR, targetJitterLevel, 5, 0f, 15f);
130 targetData.target.setJitter(KEY_TARGET, color, targetJitterLevel, 3, 0f, 5f);
131 }
132 }
133 }
134
135
136 public void unapply(MutableShipStatsAPI stats, String id) {
137
138 }
139
140 protected ShipAPI findTarget(ShipAPI ship) {
141 float range = getMaxRange(ship);
142 boolean player = ship == Global.getCombatEngine().getPlayerShip();
143 ShipAPI target = ship.getShipTarget();
144
145 if (ship.getShipAI() != null && ship.getAIFlags().hasFlag(AIFlags.TARGET_FOR_SHIP_SYSTEM)){
146 target = (ShipAPI) ship.getAIFlags().getCustom(AIFlags.TARGET_FOR_SHIP_SYSTEM);
147 }
148
149 if (target != null) {
150 float dist = Misc.getDistance(ship.getLocation(), target.getLocation());
151 float radSum = ship.getCollisionRadius() + target.getCollisionRadius();
152 if (dist > range + radSum) target = null;
153 } else {
154 if (target == null || target.getOwner() == ship.getOwner()) {
155 if (player) {
156 target = Misc.findClosestShipEnemyOf(ship, ship.getMouseTarget(), HullSize.FRIGATE, range, true);
157 } else {
158 Object test = ship.getAIFlags().getCustom(AIFlags.MANEUVER_TARGET);
159 if (test instanceof ShipAPI) {
160 target = (ShipAPI) test;
161 float dist = Misc.getDistance(ship.getLocation(), target.getLocation());
162 float radSum = ship.getCollisionRadius() + target.getCollisionRadius();
163 if (dist > range + radSum || target.isFighter()) target = null;
164 }
165 }
166 }
167 }
168
169 if (target != null && target.isFighter()) target = null;
170 if (target == null) {
171 target = Misc.findClosestShipEnemyOf(ship, ship.getLocation(), HullSize.FRIGATE, range, true);
172 }
173
174 return target;
175 }
176
177
178 public static float getMaxRange(ShipAPI ship) {
180 }
181
182
183 public StatusData getStatusData(int index, State state, float effectLevel) {
184 if (effectLevel > 0) {
185 if (index == 0) {
186 float damMult = 1f + (DAM_MULT - 1f) * effectLevel;
187 return new StatusData("" + (int)((damMult - 1f) * 100f) + "% more damage to target", false);
188 }
189 }
190 return null;
191 }
192
193
194 @Override
195 public String getInfoText(ShipSystemAPI system, ShipAPI ship) {
196 if (system.isOutOfAmmo()) return null;
197 if (system.getState() != SystemState.IDLE) return null;
198
199 ShipAPI target = findTarget(ship);
200 if (target != null && target != ship) {
201 return "READY";
202 }
203 if ((target == null) && ship.getShipTarget() != null) {
204 return "OUT OF RANGE";
205 }
206 return "NO TARGET";
207 }
208
209
210 @Override
211 public boolean isUsable(ShipSystemAPI system, ShipAPI ship) {
212 //if (true) return true;
213 ShipAPI target = findTarget(ship);
214 return target != null && target != ship;
215 }
216
217}
218
219
220
221
222
223
224
225
static CombatEngineAPI getCombatEngine()
Definition Global.java:69
void modifyMult(String source, float value)
float computeEffective(float baseValue)
String getInfoText(ShipSystemAPI system, ShipAPI ship)
boolean isUsable(ShipSystemAPI system, ShipAPI ship)
void apply(MutableShipStatsAPI stats, final String id, State state, float effectLevel)
StatusData getStatusData(int index, State state, float effectLevel)
static ShipAPI findClosestShipEnemyOf(ShipAPI ship, Vector2f locFromForSorting, HullSize smallestToNote, float maxRange, boolean considerShipRadius)
Definition Misc.java:2497
static float getDistance(SectorEntityToken from, SectorEntityToken to)
Definition Misc.java:599
void maintainStatusForPlayerShip(Object key, String spriteName, String title, String data, boolean isDebuff)
void removePlugin(EveryFrameCombatPlugin plugin)
void addPlugin(EveryFrameCombatPlugin plugin)
MutableShipStatsAPI getMutableStats()
void setJitter(Object source, Color color, float intensity, int copies, float range)