Starsector API
Loading...
Searching...
No Matches
AttackSwarmPhaseModeScript.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.combat.threat;
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.CombatEngineAPI;
10import com.fs.starfarer.api.combat.ShipAPI;
11import com.fs.starfarer.api.combat.WeaponAPI;
12import com.fs.starfarer.api.impl.campaign.ids.Tags;
13import com.fs.starfarer.api.input.InputEventAPI;
14import com.fs.starfarer.api.util.Misc;
15
17
18 public static float DURATION = 20f;
19
20
21 protected float timeLeft = 0f;
22 protected ShipAPI ship;
24 protected float origRadius = 120f;
25 protected float origFlashFrequency = 1f;
26 protected float origFlashRateMult= 1f;
27 protected float glowFadeDelay = 2f;
28
33 this.ship = ship;
34 this.timeLeft = dur;
35
37
39 }
40
41 public void turnOnPhaseMode() {
43 if (swarm == null) return;
44
45 origColor = swarm.params.flashFringeColor;
46 origRadius = swarm.params.flashRadius;
47 origFlashFrequency = swarm.params.flashFrequency;
48 origFlashRateMult = swarm.params.flashRateMult;
49
51 swarm.params.flashFringeColor = color;
52 swarm.params.flashRadius = 180f;
54
55 for (WeaponAPI w : ship.getAllWeapons()) {
56 if (w.usesAmmo() && w.getSpec().hasTag(Tags.FRAGMENT_GLOW)) {
57 //w.setAmmo(Integer.MAX_VALUE);
58 w.setAmmo(1000);
59 //w.setMaxAmmo(Integer.MAX_VALUE);
60 }
61 if (w.getSpec().hasTag(Tags.OVERSEER_CHARGE) ||
62 (ship.isFighter() && w.getSpec().hasTag(Tags.OVERSEER_CHARGE_FIGHTER))) {
63 w.setAmmo(w.getMaxAmmo());
64 }
65 }
66 }
67
68 public void turnOffPhaseMode() {
70 if (swarm == null) return;
71
72 swarm.params.flashFringeColor = origColor;
73 swarm.params.flashRadius = origRadius;
74 swarm.params.flashFrequency = origFlashFrequency;
75 swarm.params.flashRateMult = origFlashRateMult;
77
78 for (WeaponAPI w : ship.getAllWeapons()) {
79 if (w.usesAmmo() && w.getSpec().hasTag(Tags.FRAGMENT_GLOW)) {
80 w.setAmmo(w.getMaxAmmo());
81 }
82 }
83 }
84
85 public void suppressGlow() {
87 if (swarm != null) {
88 swarm.params.flashFrequency = 0f;
89 swarm.params.flashRateMult = 1f;
90 }
91 for (WeaponAPI w : ship.getAllWeapons()) {
92 if (w.usesAmmo() && w.getSpec().hasTag(Tags.FRAGMENT_GLOW)) {
93 w.setAmmo(0);
94 }
95 }
96 }
97
98
99 @Override
100 public void advance(float amount, List<InputEventAPI> events) {
101 if (Global.getCombatEngine().isPaused()) return;
102
103 timeLeft -= amount;
104
105 if (timeLeft <= 0f) {
106 glowFadeDelay -= amount;
107 suppressGlow();
108
109 if (glowFadeDelay <= 0f) {
112 engine.removePlugin(this);
113 }
114 }
115 }
116}
117
118
119
120
121
122
123
124
125
126
127
static CombatEngineAPI getCombatEngine()
Definition Global.java:69
static final String OVERSEER_CHARGE_FIGHTER
Definition Tags.java:305
static RoilingSwarmEffect getSwarmFor(CombatEntityAPI entity)
static Color setAlpha(Color color, int alpha)
Definition Misc.java:1316
void removePlugin(EveryFrameCombatPlugin plugin)
void addPlugin(EveryFrameCombatPlugin plugin)
List< WeaponAPI > getAllWeapons()