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