Advertisement
DarkRevenant

Untitled

May 17th, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.86 KB | None | 0 0
  1. package data.scripts.plugins;
  2.  
  3. import com.fs.starfarer.api.Global;
  4. import com.fs.starfarer.api.combat.CombatEngineAPI;
  5. import com.fs.starfarer.api.combat.CombatEntityAPI;
  6. import com.fs.starfarer.api.combat.DamageType;
  7. import com.fs.starfarer.api.combat.DamagingProjectileAPI;
  8. import com.fs.starfarer.api.combat.EveryFrameCombatPlugin;
  9. import com.fs.starfarer.api.combat.ShipAPI;
  10. import com.fs.starfarer.api.input.InputEventAPI;
  11. import java.awt.Color;
  12.  
  13. import java.util.*;
  14. import org.lwjgl.util.vector.Vector2f;
  15.  
  16. import org.dark.shaders.distortion.DistortionShader;
  17. import org.dark.shaders.distortion.RippleDistortion;
  18. import org.lazywizard.lazylib.VectorUtils;
  19.  
  20. public class ShieldRipple implements EveryFrameCombatPlugin {
  21.  
  22.     public CombatEngineAPI engine;
  23.     public static final Set<DamagingProjectileAPI> projectiles = new LinkedHashSet<>();
  24.  
  25.     @Override
  26.     public void init(CombatEngineAPI engine) {
  27.     }
  28.  
  29.     @Override
  30.     public void advance(float amount, List<InputEventAPI> events) {
  31.         if (engine != Global.getCombatEngine()) {
  32.             projectiles.clear();
  33.             this.engine = Global.getCombatEngine();
  34.         }
  35.  
  36.         if (engine.isPaused()) {
  37.             return;
  38.         }
  39.  
  40.         List<DamagingProjectileAPI> activeProjectiles = engine.getProjectiles();
  41.         for (DamagingProjectileAPI projectile : activeProjectiles) {
  42.             if (projectile.didDamage() || projectile.isFading()) {
  43.                 continue;
  44.             }
  45.  
  46.             if (!projectiles.contains(projectile)) {
  47.                 projectiles.add(projectile);
  48.             }
  49.         }
  50.  
  51.         Iterator<DamagingProjectileAPI> iter = projectiles.iterator();
  52.         while (iter.hasNext()) {
  53.             DamagingProjectileAPI projectile = iter.next();
  54.             if (projectile.didDamage()) {
  55.                 CombatEntityAPI target = projectile.getDamageTarget();
  56.  
  57.                 if (target instanceof ShipAPI) {
  58.                     if (target.getShield() != null && target.getShield().isOn() && target.getShield().isWithinArc(Vector2f.add(projectile.getLocation(), (Vector2f) projectile.getVelocity().scale(amount), null))) {
  59.                         onHit(projectile.getLocation(), projectile.getDamageAmount(), projectile.getDamageType(), VectorUtils.getFacing(VectorUtils.getDirectionalVector(target.getShield().getLocation(), projectile.getLocation())));
  60.                     }
  61.                 }
  62.  
  63.                 iter.remove();
  64.             } else if (!engine.isEntityInPlay(projectile)) {
  65.                 iter.remove();
  66.             }
  67.         }
  68.     }
  69.  
  70.     private void onHit(Vector2f location, float damage, DamageType type, float direction) {
  71.         if (type == DamageType.FRAGMENTATION) {
  72.             damage *= 0.25f;
  73.         }
  74.         if (type == DamageType.HIGH_EXPLOSIVE) {
  75.             damage *= 0.5f;
  76.         }
  77.         if (type == DamageType.KINETIC) {
  78.             damage *= 2f;
  79.         }
  80.  
  81.         if (damage < 100f) {
  82.             return;
  83.         }
  84.         float start = direction - 75f;
  85.         if (start < 0f) {
  86.             start += 360f;
  87.         }
  88.         float end = direction + 75f;
  89.         if (end >= 360f) {
  90.             end -= 360f;
  91.         }
  92.  
  93.         RippleDistortion ripple = new RippleDistortion();
  94.         float fadeTime = (float) Math.sqrt(Math.sqrt(damage)) * 0.1f;
  95.         float intensity = (float) Math.sqrt(damage) * 7f;
  96.         ripple.setSize(intensity);
  97.         ripple.setIntensity(intensity * 0.2f);
  98.         ripple.setLocation(location);
  99.         ripple.setFrameRate(60f / fadeTime);
  100.         ripple.fadeInSize(fadeTime * 1.2f);
  101.         ripple.fadeOutIntensity(fadeTime);
  102.         ripple.setSize(intensity * 0.2f);
  103.         ripple.setArc(start, end);
  104.         Global.getCombatEngine().addFloatingText(location, "" + start + " " + end, 20f, Color.yellow, null, 0, 1);
  105.         DistortionShader.addDistortion(ripple);
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement