Advertisement
DarkRevenant

Untitled

Jun 5th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.76 KB | None | 0 0
  1. package data.scripts.weapons;
  2.  
  3. import com.fs.starfarer.api.Global;
  4. import com.fs.starfarer.api.combat.CombatEngineAPI;
  5. import com.fs.starfarer.api.combat.DamageType;
  6. import com.fs.starfarer.api.combat.EveryFrameWeaponEffectPlugin;
  7. import com.fs.starfarer.api.combat.ShipAPI;
  8. import com.fs.starfarer.api.combat.WeaponAPI;
  9.  
  10. import java.awt.Color;
  11. import java.util.ArrayList;
  12. import java.util.HashMap;
  13. import java.util.Iterator;
  14. import java.util.List;
  15. import java.util.Map;
  16. import org.lwjgl.util.vector.Vector2f;
  17.  
  18. import org.dark.shaders.light.LightShader;
  19. import org.dark.shaders.light.StandardLight;
  20. import org.lazywizard.lazylib.MathUtils;
  21. import org.lazywizard.lazylib.VectorUtils;
  22. import org.lazywizard.lazylib.combat.CombatUtils;
  23. import org.lazywizard.lazylib.combat.entities.SimpleEntity;
  24.  
  25. public class EMPBomb implements EveryFrameWeaponEffectPlugin {
  26.  
  27.     private boolean used = false;
  28.     private CombatEngineAPI currentEngine;
  29.     private static final List<MegaArc> arcs = new ArrayList<>();
  30.     private static final List<MegaArc> newarcs = new ArrayList<>();
  31.  
  32.     private static final Map<String, Float> bossShips = new HashMap<>();
  33.  
  34.     static {
  35.         bossShips.put("ssp_superhyperion", 4f);
  36.         bossShips.put("ssp_oberon", 2f);
  37.         bossShips.put("ssp_ultron", 3f);
  38.         bossShips.put("ssp_zeus", 2f);
  39.         bossShips.put("ssp_ezekiel", 4f);
  40.         bossShips.put("ssp_cristarium", 2f);
  41.         bossShips.put("ssp_zero", 4f);
  42.     }
  43.  
  44.     @Override
  45.     public void advance(float amount, CombatEngineAPI engine, WeaponAPI weapon) {
  46.         if (engine != currentEngine) {
  47.             arcs.clear();
  48.             newarcs.clear();
  49.             currentEngine = engine;
  50.             return;
  51.         }
  52.  
  53.         if (weapon.getChargeLevel() > 0f & !used) {
  54.             Vector2f point = MathUtils.getRandomPointOnCircumference(weapon.getShip().getLocation(), weapon.getShip().getCollisionRadius() * 5f);
  55.             Vector2f vel = VectorUtils.getDirectionalVector(point, weapon.getShip().getLocation());
  56.             vel.scale((float) Math.random() * 125f + 150f);
  57.             engine.addSmoothParticle(point, vel, (float) Math.random() * 10f + 10f, 0.5f, 1f, new Color(255, 255, 255));
  58.             Global.getSoundPlayer().playLoop("high_intensity_laser_loop", weapon.getShip(), 1f + weapon.getChargeLevel() * 4f, 3f, weapon.getShip().getLocation(), weapon.getShip().getVelocity());
  59.         }
  60.  
  61.         if (weapon.getCooldownRemaining() > 0f) {
  62.             if (!used) {
  63.                 used = true;
  64.  
  65.                 StandardLight light = new StandardLight();
  66.                 light.setLocation(weapon.getShip().getLocation());
  67.                 light.setIntensity(3f);
  68.                 light.setSize(3500f);
  69.                 light.setColor(new Color(255, 255, 255));
  70.                 light.fadeOut(2f);
  71.                 LightShader.addLight(light);
  72.  
  73.                 for (int i = 0; i < 40; i++) {
  74.                     Vector2f direction = new Vector2f(1f, 0f);
  75.                     VectorUtils.rotate(direction, (float) Math.random() * 360f, direction);
  76.                     arcs.add(new MegaArc(weapon.getShip(), weapon.getShip().getLocation(), direction, (float) Math.random() * 1250f + 1250f, (float) Math.random() * 20f + 15f, (float) Math.random() * 1.5f + 0.5f));
  77.                 }
  78.  
  79.                 engine.addSmoothParticle(weapon.getShip().getLocation(), new Vector2f(), 1250f, 2f, 2f, new Color(255, 255, 255));
  80.                 engine.addHitParticle(weapon.getShip().getLocation(), new Vector2f(), 750f, 2f, 2f, new Color(255, 255, 255));
  81.                 Global.getSoundPlayer().playSound("vortex_blast", 1f, 1f, weapon.getShip().getLocation(), new Vector2f());
  82.                 Global.getSoundPlayer().playSound("shieldbreaker_blast", 1f, 0.75f, weapon.getShip().getLocation(), new Vector2f());
  83.  
  84.                 List<ShipAPI> ships = CombatUtils.getShipsWithinRange(weapon.getShip().getLocation(), 3000f);
  85.                 for (ShipAPI ship : ships) {
  86.                     if (ship != weapon.getShip() && !bossShips.containsKey(ship.getHullSpec().getHullId())) {
  87.                         ship.getFluxTracker().forceOverload(10f + (3000f - MathUtils.getDistance(weapon.getShip(), ship)) / 250f);
  88.                     }
  89.                 }
  90.             }
  91.         }
  92.  
  93.         if (weapon.getCooldownRemaining() <= 0f) {
  94.             if (used) {
  95.                 used = false;
  96.             }
  97.         }
  98.  
  99.         Iterator<MegaArc> iter = arcs.iterator();
  100.         while (iter.hasNext()) {
  101.             MegaArc arc = iter.next();
  102.             if (Math.random() >= 0.33f) {
  103.                 if (arc.advance(amount * 3f)) {
  104.                     iter.remove();
  105.                 }
  106.             }
  107.         }
  108.  
  109.         iter = newarcs.iterator();
  110.         while (iter.hasNext()) {
  111.             MegaArc arc = iter.next();
  112.             arcs.add(arc);
  113.             iter.remove();
  114.         }
  115.     }
  116.  
  117.     private static final class MegaArc {
  118.  
  119.         private final ShipAPI source;
  120.         private final Vector2f location = new Vector2f();
  121.         private final Vector2f direction = new Vector2f();
  122.         private final float speed;
  123.         private final float thickness;
  124.         private float remaining;
  125.  
  126.         private MegaArc(ShipAPI source, Vector2f location, Vector2f direction, float speed, float thickness, float lifetime) {
  127.             this.source = source;
  128.             this.location.set(location);
  129.             this.direction.set(direction);
  130.             this.speed = speed;
  131.             this.thickness = thickness;
  132.             this.remaining = lifetime;
  133.         }
  134.  
  135.         private boolean advance(float amount) {
  136.             Vector2f newLocation = new Vector2f(direction);
  137.             newLocation.scale(speed * amount);
  138.             Vector2f.add(newLocation, location, newLocation);
  139.             Global.getCombatEngine().spawnEmpArc(source, location, new SimpleEntity(newLocation), new SimpleEntity(newLocation), DamageType.ENERGY, 0f, 0f, 10000f, null, thickness, new Color(200, 225, 255, 150), new Color(255, 255, 255, 255));
  140.             location.set(newLocation);
  141.             VectorUtils.rotate(direction, (float) Math.random() * 60f - 30f, direction);
  142.  
  143.             if (Math.random() > 0.95) {
  144.                 Global.getSoundPlayer().playSound("vortex_absorb", 1f, 0.5f, location, new Vector2f());
  145.                 Vector2f newDirection = new Vector2f(1f, 0f);
  146.                 VectorUtils.rotate(newDirection, (float) Math.random() * 360f, newDirection);
  147.                 newarcs.add(new MegaArc(source, location, newDirection, speed + (float) Math.random() * 200f - 100f, Math.max(thickness - (float) Math.random() * 5f, 2.5f), Math.max(remaining + (float) Math.random() * 0.3f - 0.15f, 0.01f)));
  148.             }
  149.  
  150.             remaining -= amount;
  151.             return remaining <= 0f;
  152.         }
  153.     }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement