here's the onFire effect that adds the fired projectile to a list of projectiles that a "manager" class iterates over
getFirstListenerofClass is a lil method I made that's effectively just Ship().getListeners(classname.class).get(0);, but a little fancified.
public class lightspikeDriverOnFire implements OnFireEffectPlugin {
@Override
public void onFire(DamagingProjectileAPI projectile, WeaponAPI weapon, CombatEngineAPI engine) {
lightspikeDriverEFS.lsdActualEfs listener = getFirstListenerOfClass(weapon.getShip(), lightspikeDriverEFS.lsdActualEfs.class);
if (listener == null) return;
listener.addProj(projectile);
}
}
and here's the actual manager class, in the form of an EveryFrameWeaponEffect that adds an advanceableListener to the ship (though tbh that could probably just be done in the onfire, check if it's null, if yes add one, if no use the existing one)
public class lightspikeDriverEFS implements EveryFrameWeaponEffectPlugin {
@Override
public void advance(float amount, CombatEngineAPI engine, WeaponAPI weapon) {
if (!weapon.getShip().hasListenerOfClass(lsdActualEfs.class)) {
weapon.getShip().addListener(new lsdActualEfs(weapon.getShip()));
}
}
public static class lsdActualEfs implements AdvanceableListener, DamageDealtModifier {
protected final ShipAPI ship;
private final ArrayList<DamagingProjectileAPI> projs = new ArrayList<>();
public lsdActualEfs(ShipAPI ship) {
this.ship = ship;
}
public void addProj(DamagingProjectileAPI proj) {
projs.add(proj);
}
@Override
public void advance(float amount) {
for (DamagingProjectileAPI proj : new ArrayList<>(projs)) {
/*
* do your checking here, probably just a CombatEngineAPI.isEntityInPlay(); check on the projectile before spawning the arcs or so
* also, that for loop creates a new arrayList to prevent concurrentModificationExceptions when removing projectiles from the list so that you don't need to do a second loop over the list
*/
}
}
}
}