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