Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package data.scripts.weapons;
- import com.fs.starfarer.api.Global;
- import com.fs.starfarer.api.combat.CombatEngineAPI;
- import com.fs.starfarer.api.combat.EveryFrameWeaponEffectPlugin;
- import com.fs.starfarer.api.combat.ShipAPI;
- import com.fs.starfarer.api.combat.WeaponAPI;
- import data.scripts.utils.AL.OriMisc;
- import org.dark.shaders.distortion.DistortionShader;
- import org.dark.shaders.distortion.RippleDistortion;
- import org.lazywizard.lazylib.FastTrig;
- import org.lazywizard.lazylib.MathUtils;
- import org.lazywizard.lazylib.VectorUtils;
- import org.lwjgl.util.vector.Vector2f;
- public class AL_LightsCohesionEveryFrameEffect implements EveryFrameWeaponEffectPlugin {
- private boolean init = false;
- private float lastChargeLevel;
- private boolean fireSoundPlayed = false;
- private AL_BrainGlowEveryFrameEffect glowWeaponEffect;
- private Vector2f up;
- private Vector2f down;
- private Vector2f left;
- private Vector2f right;
- @Override
- public void advance(float amount, CombatEngineAPI engine, WeaponAPI weapon) {
- if (!init) {
- weapon.ensureClonedSpec();
- up = weapon.getSpec().getTurretFireOffsets().get(0);
- down = weapon.getSpec().getTurretFireOffsets().get(1);
- left = weapon.getSpec().getTurretFireOffsets().get(2);
- right = weapon.getSpec().getTurretFireOffsets().get(3);
- for (WeaponAPI otherWeapon : weapon.getShip().getAllWeapons()) {
- if (otherWeapon.getId().equals("AL_Decorative_brainattacker")) {
- glowWeaponEffect = (AL_BrainGlowEveryFrameEffect) otherWeapon.getEffectPlugin();
- break;
- }
- }
- init = true;
- }
- float chargeLevel = weapon.getChargeLevel();
- if (weapon.isFiring()) {
- float invertLevel = (float) FastTrig.cos(Math.PI * chargeLevel * 0.5f);
- ShipAPI ship = weapon.getShip();
- if (glowWeaponEffect != null)
- glowWeaponEffect.lockLevel(chargeLevel);
- if (lastChargeLevel >= chargeLevel) {
- invertLevel = 0f;
- Global.getSoundPlayer().playLoop("AL_lightscohesion_loop", weapon, 1f, 1f, weapon.getLocation(), OriMisc.ZERO);
- }
- Vector2f supposedUp = new Vector2f(30f * invertLevel, 0f);
- Vector2f supposedDown = new Vector2f(-30f * invertLevel, 0f);
- Vector2f supposedLeft = new Vector2f(0, 60f * invertLevel);
- Vector2f supposedRight = new Vector2f(0, -60f * invertLevel);
- float angleToRotate = MathUtils.getShortestRotation(weapon.getCurrAngle(), weapon.getArcFacing() + ship.getFacing() + 90f);
- VectorUtils.rotate(supposedUp, angleToRotate);
- VectorUtils.rotate(supposedDown, angleToRotate);
- VectorUtils.rotate(supposedLeft, angleToRotate);
- VectorUtils.rotate(supposedRight, angleToRotate);
- up.set(supposedUp);
- down.set(supposedDown);
- left.set(supposedLeft);
- right.set(supposedRight);
- if (chargeLevel == 1f && !fireSoundPlayed) {
- RippleDistortion distortion = new RippleDistortion(weapon.getLocation(), OriMisc.ZERO);
- distortion.setFrameRate(60f / 0.2f);
- distortion.setSize(200f);
- distortion.setIntensity(10f);
- distortion.fadeInSize(0.2f);
- distortion.fadeOutIntensity(0.2f);
- DistortionShader.addDistortion(distortion);
- Global.getSoundPlayer().playSound("AL_lightscohesion_fire", 1f, 1f, weapon.getLocation(), OriMisc.ZERO);
- fireSoundPlayed = true;
- }
- } else {
- fireSoundPlayed = false;
- if (glowWeaponEffect != null)
- glowWeaponEffect.unlockLevel();
- }
- lastChargeLevel = chargeLevel;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement