Starsector API
Loading...
Searching...
No Matches
RiftLanceEffect.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.combat;
2
3import java.awt.Color;
4
5import org.lwjgl.util.vector.Vector2f;
6
7import com.fs.starfarer.api.Global;
8import com.fs.starfarer.api.combat.BeamAPI;
9import com.fs.starfarer.api.combat.BeamEffectPlugin;
10import com.fs.starfarer.api.combat.CombatEngineAPI;
11import com.fs.starfarer.api.combat.MissileAPI;
12import com.fs.starfarer.api.combat.ShipAPI;
13import com.fs.starfarer.api.combat.WeaponAPI.WeaponType;
14import com.fs.starfarer.api.util.Misc;
15
16public class RiftLanceEffect implements BeamEffectPlugin { //WithReset {
17
18 public static float MINE_SPAWN_CHANCE = 0f;
19
20 protected boolean done = false;
21// public void reset() {
22// done = false;
23// }
24
25 public void advance(float amount, CombatEngineAPI engine, BeamAPI beam) {
26 if (beam.getBrightness() < 1f || done) return;
27 float range = beam.getWeapon().getRange();
28 float length = beam.getLengthPrevFrame();
29
30 if (length > range - 10f || beam.getDamageTarget() != null) {
31 //if (beam.getDamageTarget() != null) {
32 done = true;
33
34 Vector2f loc = beam.getRayEndPrevFrame();
35
36 Color color = getColorForDarkening(beam.getFringeColor());
37 Color undercolor = RiftCascadeEffect.EXPLOSION_UNDERCOLOR;
38 float a = 1f;
39 color = Misc.scaleAlpha(color, a);
40 undercolor = Misc.scaleAlpha(undercolor, a);
41 float size = 75f;
42 size *= 0.5f;
43 float dur = beam.getWeapon().getSpec().getBurstDuration() + beam.getWeapon().getSpec().getBeamChargedownTime();
44
45 if ((float) Math.random() < MINE_SPAWN_CHANCE) {
46 spawnMine(beam.getSource(), loc);
47 } else {
48 Vector2f vel = new Vector2f();
49 if (beam.getDamageTarget() != null) {
50 vel.set(beam.getDamageTarget().getVelocity());
51 }
52 spawnHitDarkening(color, undercolor, loc, vel, size, dur);
53 }
54 }
55 }
56
57 public void spawnHitDarkening(Color color, Color undercolor, Vector2f point, Vector2f vel, float size, float baseDuration) {
59 if (!engine.getViewport().isNearViewport(point, 100f + size * 2f)) return;
60
61 Color c = color;
62
63
64 for (int i = 0; i < 5; i++) {
65 float dur = baseDuration + baseDuration * (float) Math.random();
66 //float nSize = size * (1f + 0.0f * (float) Math.random());
67 //float nSize = size * (0.75f + 0.5f * (float) Math.random());
68 float nSize = size;
69 Vector2f pt = Misc.getPointWithinRadius(point, nSize * 0.5f);
70 Vector2f v = Misc.getUnitVectorAtDegreeAngle((float) Math.random() * 360f);
71 v.scale(nSize + nSize * (float) Math.random() * 0.5f);
72 v.scale(0.2f);
73 Vector2f.add(vel, v, v);
74
75 float maxSpeed = nSize * 1.5f * 0.2f;
76 float minSpeed = nSize * 1f * 0.2f;
77 float overMin = v.length() - minSpeed;
78 if (overMin > 0) {
79 float durMult = 1f - overMin / (maxSpeed - minSpeed);
80 if (durMult < 0.1f) durMult = 0.1f;
81 dur *= 0.5f + 0.5f * durMult;
82 }
83 engine.addNegativeNebulaParticle(pt, v, nSize * 1f, 2f,
84 0.5f / dur, 0f, dur, c);
85 }
86
87 float dur = baseDuration;
88 float rampUp = 0f;
89 c = undercolor;
90 for (int i = 0; i < 12; i++) {
91 Vector2f loc = new Vector2f(point);
92 loc = Misc.getPointWithinRadius(loc, size * 1f);
93 float s = size * 3f * (0.5f + (float) Math.random() * 0.5f);
94 engine.addNebulaParticle(loc, vel, s, 1.5f, rampUp, 0f, dur, c);
95 }
96 }
97
98 public static Color getColorForDarkening(Color from) {
99 Color c = new Color(255 - from.getRed(),
100 255 - from.getGreen(),
101 255 - from.getBlue(), 127);
102 c = Misc.interpolateColor(c, Color.white, 0.4f);
103 return c;
104 }
105
106
107 public void spawnMine(ShipAPI source, Vector2f mineLoc) {
109
110
111 //Vector2f currLoc = mineLoc;
112 MissileAPI mine = (MissileAPI) engine.spawnProjectile(source, null,
113 "riftlance_minelayer",
114 mineLoc,
115 (float) Math.random() * 360f, null);
116 if (source != null) {
118 source, WeaponType.ENERGY, false, mine.getDamage());
119// float extraDamageMult = source.getMutableStats().getMissileWeaponDamageMult().getModifiedValue();
120// mine.getDamage().setMultiplier(mine.getDamage().getMultiplier() * extraDamageMult);
121 }
122
123
124 float fadeInTime = 0.05f;
125 mine.getVelocity().scale(0);
126 mine.fadeOutThenIn(fadeInTime);
127
128 //Global.getCombatEngine().addPlugin(createMissileJitterPlugin(mine, fadeInTime));
129
130 //mine.setFlightTime((float) Math.random());
131 float liveTime = 0f;
132 //liveTime = 0.01f;
133 mine.setFlightTime(mine.getMaxFlightTime() - liveTime);
134 mine.addDamagedAlready(source);
135 mine.setNoMineFFConcerns(true);
136 }
137
138}
139
140
141
142
143
static CombatEngineAPI getCombatEngine()
Definition Global.java:69
void advance(float amount, CombatEngineAPI engine, BeamAPI beam)
void spawnHitDarkening(Color color, Color undercolor, Vector2f point, Vector2f vel, float size, float baseDuration)
void spawnMine(ShipAPI source, Vector2f mineLoc)
static Vector2f getUnitVectorAtDegreeAngle(float degrees)
Definition Misc.java:1196
static Color scaleAlpha(Color color, float factor)
Definition Misc.java:1309
static Color interpolateColor(Color from, Color to, float progress)
Definition Misc.java:1261
static Vector2f getPointWithinRadius(Vector2f from, float r)
Definition Misc.java:711
CombatEntityAPI spawnProjectile(ShipAPI ship, WeaponAPI weapon, String weaponId, Vector2f point, float angle, Vector2f shipVelocity)
void addNegativeNebulaParticle(Vector2f loc, Vector2f vel, float size, float endSizeMult, float rampUpFraction, float fullBrightnessFraction, float totalDuration, Color color)
void applyDamageModifiersToSpawnedProjectileWithNullWeapon(ShipAPI source, WeaponType type, boolean isBeam, DamageAPI damage)
void addNebulaParticle(Vector2f loc, Vector2f vel, float size, float endSizeMult, float rampUpFraction, float fullBrightnessFraction, float totalDuration, Color color)
void setNoMineFFConcerns(boolean noFFConcerns)
void setFlightTime(float flightTime)
boolean isNearViewport(Vector2f loc, float nearDistance)