Starsector API
Loading...
Searching...
No Matches
RecallDeviceStats.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.combat;
2
3import java.awt.Color;
4import java.util.ArrayList;
5import java.util.List;
6
7import com.fs.starfarer.api.Global;
8import com.fs.starfarer.api.combat.MutableShipStatsAPI;
9import com.fs.starfarer.api.combat.ShipAPI;
10
12 public static final Object KEY_JITTER = new Object();
13 public static final Color JITTER_COLOR = new Color(100,165,255,155);
14
15
16 public void apply(MutableShipStatsAPI stats, String id, State state, float effectLevel) {
17 ShipAPI ship = null;
18 if (stats.getEntity() instanceof ShipAPI) {
19 ship = (ShipAPI) stats.getEntity();
20 } else {
21 return;
22 }
23
24
25 if (effectLevel > 0) {
26 float jitterLevel = effectLevel;
27
28 boolean firstTime = false;
29 final String fightersKey = ship.getId() + "_recall_device_target";
30 List<ShipAPI> fighters = null;
31 if (!Global.getCombatEngine().getCustomData().containsKey(fightersKey)) {
32 fighters = getFighters(ship);
33 Global.getCombatEngine().getCustomData().put(fightersKey, fighters);
34 firstTime = true;
35 } else {
36 fighters = (List<ShipAPI>) Global.getCombatEngine().getCustomData().get(fightersKey);
37 }
38 if (fighters == null) { // shouldn't be possible, but still
39 fighters = new ArrayList<ShipAPI>();
40 }
41
42 for (ShipAPI fighter : fighters) {
43 if (fighter.isHulk()) continue;
44
45 float maxRangeBonus = fighter.getCollisionRadius() * 1f;
46 float jitterRangeBonus = 5f + jitterLevel * maxRangeBonus;
47
48 if (firstTime) {
49 Global.getSoundPlayer().playSound("system_phase_skimmer", 1f, 0.5f, fighter.getLocation(), fighter.getVelocity());
50 }
51
52 fighter.setJitter(KEY_JITTER, JITTER_COLOR, jitterLevel, 10, 0f, jitterRangeBonus);
53 if (fighter.isAlive()) {
54 fighter.setPhased(true);
55 }
56
57 if (state == State.IN) {
58 float alpha = 1f - effectLevel * 0.5f;
59 fighter.setExtraAlphaMult(alpha);
60 }
61
62 if (effectLevel == 1) {
63 if (fighter.getWing() != null && fighter.getWing().getSource() != null) {
64 fighter.getWing().getSource().makeCurrentIntervalFast();
65 fighter.getWing().getSource().land(fighter);
66 } else {
67 fighter.setExtraAlphaMult(1);
68 }
69 }
70 }
71 }
72 }
73
74 public static List<ShipAPI> getFighters(ShipAPI carrier) {
75 List<ShipAPI> result = new ArrayList<ShipAPI>();
76
77 for (ShipAPI ship : Global.getCombatEngine().getShips()) {
78 if (!ship.isFighter()) continue;
79 if (ship.getWing() == null) continue;
80 if (ship.getWing().getSourceShip() == carrier) {
81 result.add(ship);
82 }
83 }
84
85 return result;
86 }
87
88
89 public void unapply(MutableShipStatsAPI stats, String id) {
90 ShipAPI ship = null;
91 if (stats.getEntity() instanceof ShipAPI) {
92 ship = (ShipAPI) stats.getEntity();
93 } else {
94 return;
95 }
96
97 final String fightersKey = ship.getId() + "_recall_device_target";
98 Global.getCombatEngine().getCustomData().remove(fightersKey);
99
100// for (ShipAPI fighter : getFighters(ship)) {
101// fighter.setPhased(false);
102// fighter.setCopyLocation(null, 1f, fighter.getFacing());
103// }
104 }
105
106
107 public StatusData getStatusData(int index, State state, float effectLevel) {
108 return null;
109 }
110
111
112}
113
114
115
116
117
118
119
120
static SoundPlayerAPI getSoundPlayer()
Definition Global.java:43
static CombatEngineAPI getCombatEngine()
Definition Global.java:63
StatusData getStatusData(int index, State state, float effectLevel)
static List< ShipAPI > getFighters(ShipAPI carrier)
void apply(MutableShipStatsAPI stats, String id, State state, float effectLevel)
void unapply(MutableShipStatsAPI stats, String id)
SoundAPI playSound(String id, float pitch, float volume, Vector2f loc, Vector2f vel)