Starsector API
Loading...
Searching...
No Matches
AcausalDisruptorStats.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.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.combat.WeaponAPI;
16import com.fs.starfarer.api.combat.WeaponAPI.WeaponType;
17import com.fs.starfarer.api.input.InputEventAPI;
18import com.fs.starfarer.api.util.Misc;
19
21 //public static final float ENERGY_DAM_PENALTY_MULT = 0.5f;
22 public static float ENERGY_DAM_PENALTY_MULT = 1f;
23
24 public static float DISRUPTION_DUR = 1f;
25 protected static float MIN_DISRUPTION_RANGE = 500f;
26
27 public static final Color OVERLOAD_COLOR = new Color(255,155,255,255);
28
29 public static final Color JITTER_COLOR = new Color(255,155,255,75);
30 public static final Color JITTER_UNDER_COLOR = new Color(255,155,255,155);
31
32
33 public void apply(MutableShipStatsAPI stats, String id, State state, float effectLevel) {
34 ShipAPI ship = null;
35 //boolean player = false;
36 if (stats.getEntity() instanceof ShipAPI) {
37 ship = (ShipAPI) stats.getEntity();
38 //player = ship == Global.getCombatEngine().getPlayerShip();
39 } else {
40 return;
41 }
42
43 //stats.getEnergyWeaponDamageMult().modifyMult(id, 1f - (1f - ENERGY_DAM_PENALTY_MULT) * effectLevel);
45
46 float jitterLevel = effectLevel;
47 if (state == State.OUT) {
48 jitterLevel *= jitterLevel;
49 }
50 float maxRangeBonus = 50f;
51 //float jitterRangeBonus = jitterLevel * maxRangeBonus;
52 float jitterRangeBonus = jitterLevel * maxRangeBonus;
53 if (state == State.OUT) {
54 //jitterRangeBonus = maxRangeBonus + (1f - jitterLevel) * maxRangeBonus;
55 }
56
57 ship.setJitterUnder(this, JITTER_UNDER_COLOR, jitterLevel, 21, 0f, 3f + jitterRangeBonus);
58 //ship.setJitter(this, JITTER_COLOR, jitterLevel, 4, 0f, 0 + jitterRangeBonus * 0.67f);
59 ship.setJitter(this, JITTER_COLOR, jitterLevel, 4, 0f, 0 + jitterRangeBonus);
60
61 String targetKey = ship.getId() + "_acausal_target";
62 Object foundTarget = Global.getCombatEngine().getCustomData().get(targetKey);
63 if (state == State.IN) {
64 if (foundTarget == null) {
65 ShipAPI target = findTarget(ship);
66 if (target != null) {
67 Global.getCombatEngine().getCustomData().put(targetKey, target);
68 }
69 }
70 } else if (effectLevel >= 1) {
71 if (foundTarget instanceof ShipAPI) {
72 ShipAPI target = (ShipAPI) foundTarget;
73 if (target.getFluxTracker().isOverloadedOrVenting()) target = ship;
74 applyEffectToTarget(ship, target);
75 }
76 } else if (state == State.OUT && foundTarget != null) {
77 Global.getCombatEngine().getCustomData().remove(targetKey);
78 }
79 }
80
81
82 public void unapply(MutableShipStatsAPI stats, String id) {
84 }
85
86 protected ShipAPI findTarget(ShipAPI ship) {
87 float range = getMaxRange(ship);
88 boolean player = ship == Global.getCombatEngine().getPlayerShip();
89 ShipAPI target = ship.getShipTarget();
90 if (ship.getShipAI() != null && ship.getAIFlags().hasFlag(AIFlags.TARGET_FOR_SHIP_SYSTEM)){
91 target = (ShipAPI) ship.getAIFlags().getCustom(AIFlags.TARGET_FOR_SHIP_SYSTEM);
92 }
93
94 if (target != null) {
95 float dist = Misc.getDistance(ship.getLocation(), target.getLocation());
96 float radSum = ship.getCollisionRadius() + target.getCollisionRadius();
97 if (dist > range + radSum) target = null;
98 } else {
99 if (target == null || target.getOwner() == ship.getOwner()) {
100 if (player) {
101 target = Misc.findClosestShipEnemyOf(ship, ship.getMouseTarget(), HullSize.FRIGATE, range, true);
102 } else {
103 Object test = ship.getAIFlags().getCustom(AIFlags.MANEUVER_TARGET);
104 if (test instanceof ShipAPI) {
105 target = (ShipAPI) test;
106 float dist = Misc.getDistance(ship.getLocation(), target.getLocation());
107 float radSum = ship.getCollisionRadius() + target.getCollisionRadius();
108 if (dist > range + radSum || target.isFighter()) target = null;
109 }
110 }
111 }
112 }
113
114 if (target != null && target.isFighter()) target = null;
115 if (target == null) {
116 target = Misc.findClosestShipEnemyOf(ship, ship.getLocation(), HullSize.FRIGATE, range, true);
117 }
118 if (target == null || target.getFluxTracker().isOverloadedOrVenting()) target = ship;
119
120 return target;
121 }
122
123
124 public static float getMaxRange(ShipAPI ship) {
125 if (true) {
127 //return MIN_DISRUPTION_RANGE;
128 }
129
130 float range = 0f;
131
132 for (WeaponAPI w : ship.getAllWeapons()) {
133 if (w.getType() == WeaponType.BALLISTIC || w.getType() == WeaponType.ENERGY) {
134 float curr = w.getRange();
135 if (curr > range) range = curr;
136 }
137 }
138
139 return range + MIN_DISRUPTION_RANGE;
140 }
141
142
143 protected void applyEffectToTarget(final ShipAPI ship, final ShipAPI target) {
144 if (target.getFluxTracker().isOverloadedOrVenting()) {
145 return;
146 }
147 if (target == ship) return;
148
151 //target.getEngineController().forceFlameout(true);
152
153 if (target.getFluxTracker().showFloaty() ||
155 target == Global.getCombatEngine().getPlayerShip()) {
157 target.getFluxTracker().showOverloadFloatyIfNeeded("System Disruption!", OVERLOAD_COLOR, 4f, true);
158 }
159
161 @Override
162 public void advance(float amount, List<InputEventAPI> events) {
163 if (!target.getFluxTracker().isOverloadedOrVenting()) {
164 target.resetOverloadColor();
166 }
167 }
168 });
169 }
170
171 public StatusData getStatusData(int index, State state, float effectLevel) {
172 //float percent = (1f - ENERGY_DAM_PENALTY_MULT) * effectLevel * 100;
173 float percent = (1f - ENERGY_DAM_PENALTY_MULT) * 100;
174 if (index == 0 && percent > 0) {
175 return new StatusData((int)percent + "% less energy damage", false);
176 }
177 return null;
178 }
179
180
181 @Override
182 public String getInfoText(ShipSystemAPI system, ShipAPI ship) {
183 if (system.isOutOfAmmo()) return null;
184 if (system.getState() != SystemState.IDLE) return null;
185
186 ShipAPI target = findTarget(ship);
187 if (target != null && target != ship) {
188 return "READY";
189 }
190 if ((target == null || target == ship) && ship.getShipTarget() != null) {
191 return "OUT OF RANGE";
192 }
193 return "NO TARGET";
194 //return super.getInfoText(system, ship);
195 }
196
197
198 @Override
199 public boolean isUsable(ShipSystemAPI system, ShipAPI ship) {
200 ShipAPI target = findTarget(ship);
201 return target != null && target != ship;
202 //return super.isUsable(system, ship);
203 }
204
205
206
207}
208
209
210
211
212
213
214
215
static CombatEngineAPI getCombatEngine()
Definition Global.java:69
void modifyMult(String source, float value)
float computeEffective(float baseValue)
boolean isUsable(ShipSystemAPI system, ShipAPI ship)
StatusData getStatusData(int index, State state, float effectLevel)
void applyEffectToTarget(final ShipAPI ship, final ShipAPI target)
void unapply(MutableShipStatsAPI stats, String id)
void apply(MutableShipStatsAPI stats, String id, State state, float effectLevel)
String getInfoText(ShipSystemAPI system, ShipAPI ship)
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 removePlugin(EveryFrameCombatPlugin plugin)
void addPlugin(EveryFrameCombatPlugin plugin)
void beginOverloadWithTotalBaseDuration(float totalDur)
void setJitterUnder(Object source, Color color, float intensity, int copies, float range)
MutableShipStatsAPI getMutableStats()
List< WeaponAPI > getAllWeapons()
void setJitter(Object source, Color color, float intensity, int copies, float range)