Starsector API
Loading...
Searching...
No Matches
TenebrousExpulsionSystemScript.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.combat.dweller;
2
3import org.lwjgl.util.vector.Vector2f;
4
5import com.fs.starfarer.api.Global;
6import com.fs.starfarer.api.combat.CombatEngineAPI;
7import com.fs.starfarer.api.combat.CombatFleetManagerAPI;
8import com.fs.starfarer.api.combat.MutableShipStatsAPI;
9import com.fs.starfarer.api.combat.ShipAPI;
10import com.fs.starfarer.api.combat.ShipwideAIFlags.AIFlags;
11import com.fs.starfarer.api.impl.combat.BaseShipSystemScript;
12import com.fs.starfarer.api.impl.combat.dweller.VortexLauncherEffect.DisturbShroudPlugin;
13import com.fs.starfarer.api.util.Misc;
14
16
17 public static String EJECTA_WING = "shrouded_ejecta_wing";
18
19 public static float REFIRE_DELAY = 0.15f;
20 public static float LAUNCH_ARC = 90f;
21 public static float BACK_OFF_ACCEL = 500f;
22
23 protected Vector2f fireDir;
24 protected float elapsedActive = REFIRE_DELAY;
25
26 protected void init(ShipAPI ship) {
27 }
28
29
30 @Override
31 public void apply(MutableShipStatsAPI stats, String id, State state, float effectLevel) {
32 ShipAPI ship = null;
33 if (stats.getEntity() instanceof ShipAPI) {
34 ship = (ShipAPI) stats.getEntity();
35 } else {
36 return;
37 }
38
39 if (state == State.IN) {
40 if (fireDir == null) {
41 float dir = ship.getFacing();
42 if (ship.getMouseTarget() != null) {
44 }
45 if (ship.getShipAI() != null && ship.getAIFlags().hasFlag(AIFlags.SYSTEM_TARGET_COORDS)){
47 (Vector2f) ship.getAIFlags().getCustom(AIFlags.SYSTEM_TARGET_COORDS));
48 }
50 }
51 }
52
53
54 if (state == State.ACTIVE && fireDir != null) {
56 elapsedActive += amount;
57 while (elapsedActive >= REFIRE_DELAY) {
60 }
61 }
62
63 if (state == State.OUT && fireDir != null) {
65 ship.getVelocity().x -= fireDir.x * BACK_OFF_ACCEL * amount;
66 ship.getVelocity().y -= fireDir.y * BACK_OFF_ACCEL * amount;
67 }
68
69 if (state == State.IDLE || state == State.COOLDOWN) {
70 fireDir = null;
72 }
73
74 }
75
76 public static void fireShroudedEjecta(ShipAPI ship, Vector2f fireDir) {
77 float dir = Misc.getAngleInDegrees(fireDir);
81
82 // wing has size 1, so no other members besides the "leader"
83 // point is to spawn a ship but without it showing up in the deployment dialog etc
84 ShipAPI ejecta = manager.spawnShipOrWing(EJECTA_WING,
85 ship.getLocation(), dir, 0f, null);
86 manager.setSuppressDeploymentMessages(false);
87
88 Vector2f takeoffVel = Misc.getUnitVectorAtDegreeAngle(
89 dir + LAUNCH_ARC/2f - (float) Math.random() * LAUNCH_ARC);
90 float velMult = 1f;
91 velMult = 0.5f + (float) Math.random() * 1f;
92 takeoffVel.scale(ejecta.getMaxSpeed() * velMult);
93
94 Vector2f.add(ejecta.getVelocity(), takeoffVel, ejecta.getVelocity());
95
97 if (shroud != null) {
98 shroud.custom1 = ship;
99 }
100
101 DwellerShroud sourceShroud = DwellerShroud.getShroudFor(ship);
102 if (sourceShroud != null) {
103 Vector2f offset = Vector2f.sub(ejecta.getLocation(), sourceShroud.getAttachedTo().getLocation(), new Vector2f());
105 new DisturbShroudPlugin(1f, fireDir, ejecta, offset, sourceShroud,
106 (int) (sourceShroud.getNumMembersToMaintain() * 0.1f)));
107
108 }
109
110 Global.getSoundPlayer().playSound("system_tenebrous_expulsion_fire", 1f, 1f, ejecta.getLocation(), ejecta.getVelocity());
111 }
112
113
114 public StatusData getStatusData(int index, State state, float effectLevel) {
115 return null;
116 }
117
118}
119
120
121
122
123
124
125
126
static SoundPlayerAPI getSoundPlayer()
Definition Global.java:49
static CombatEngineAPI getCombatEngine()
Definition Global.java:69
static DwellerShroud getShroudFor(CombatEntityAPI entity)
void apply(MutableShipStatsAPI stats, String id, State state, float effectLevel)
static Vector2f getUnitVectorAtDegreeAngle(float degrees)
Definition Misc.java:1196
static float getAngleInDegrees(Vector2f v)
Definition Misc.java:1126
SoundAPI playSound(String id, float pitch, float volume, Vector2f loc, Vector2f vel)
CombatFleetManagerAPI getFleetManager(FleetSide side)
void addPlugin(EveryFrameCombatPlugin plugin)
ShipAPI spawnShipOrWing(String specId, Vector2f location, float facing)
void setSuppressDeploymentMessages(boolean suppressDeploymentMessages)