Advertisement
DarkRevenant

Untitled

May 19th, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.38 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.  
  12. import java.util.*;
  13. import org.lwjgl.util.vector.Vector2f;
  14.  
  15. import org.dark.shaders.distortion.DistortionShader;
  16. import org.dark.shaders.distortion.RippleDistortion;
  17. import org.lazywizard.lazylib.VectorUtils;
  18.  
  19. public class ShieldRipple implements EveryFrameCombatPlugin {
  20.  
  21.     public CombatEngineAPI engine;
  22.     public static final Set<DamagingProjectileAPI> projectiles = new LinkedHashSet<>();
  23.  
  24.     @Override
  25.     public void init(CombatEngineAPI engine) {
  26.     }
  27.  
  28.     @Override
  29.     public void advance(float amount, List<InputEventAPI> events) {
  30.         if (engine != Global.getCombatEngine()) {
  31.             projectiles.clear();
  32.             this.engine = Global.getCombatEngine();
  33.         }
  34.  
  35.         if (engine.isPaused()) {
  36.             return;
  37.         }
  38.  
  39.         List<DamagingProjectileAPI> activeProjectiles = engine.getProjectiles();
  40.         for (DamagingProjectileAPI projectile : activeProjectiles) {
  41.             if (projectile.didDamage() || projectile.isFading()) {
  42.                 continue;
  43.             }
  44.  
  45.             if (!projectiles.contains(projectile)) {
  46.                 projectiles.add(projectile);
  47.             }
  48.         }
  49.  
  50.         Iterator<DamagingProjectileAPI> iter = projectiles.iterator();
  51.         while (iter.hasNext()) {
  52.             DamagingProjectileAPI projectile = iter.next();
  53.             if (projectile.didDamage()) {
  54.                 CombatEntityAPI target = projectile.getDamageTarget();
  55.  
  56.                 if (target instanceof ShipAPI) {
  57.                     if (target.getShield() != null && target.getShield().isOn() && target.getShield().isWithinArc(projectile.getLocation())) {
  58.                         createHitRipple(projectile.getLocation(), target.getVelocity(), projectile.getDamageAmount(), projectile.getDamageType(), VectorUtils.getFacing(VectorUtils.getDirectionalVector(target.getShield().getLocation(), projectile.getLocation())), target.getShield().getRadius());
  59.                     }
  60.                 }
  61.  
  62.                 iter.remove();
  63.             } else if (!engine.isEntityInPlay(projectile)) {
  64.                 iter.remove();
  65.             }
  66.         }
  67.     }
  68.  
  69.     private void createHitRipple(Vector2f location, Vector2f velocity, float damage, DamageType type, float direction, float shieldRadius) {
  70.         if (type == DamageType.FRAGMENTATION) {
  71.             damage *= 0.25f;
  72.         }
  73.         if (type == DamageType.HIGH_EXPLOSIVE) {
  74.             damage *= 0.5f;
  75.         }
  76.         if (type == DamageType.KINETIC) {
  77.             damage *= 2f;
  78.         }
  79.  
  80.         if (damage < 50f) {
  81.             return;
  82.         }
  83.  
  84.         float fadeTime = (float) Math.pow(damage, 0.25) * 0.1f;
  85.         float size = (float) Math.pow(damage, 0.3333333) * 15f;
  86.  
  87.         float ratio = Math.min(size / shieldRadius, 1f);
  88.         float arc = 90f - ratio * 14.54136f; // Don't question the magic number
  89.  
  90.         float start = direction - arc;
  91.         if (start < 0f) {
  92.             start += 360f;
  93.         }
  94.         float end = direction + arc;
  95.         if (end >= 360f) {
  96.             end -= 360f;
  97.         }
  98.  
  99.         RippleDistortion ripple = new RippleDistortion();
  100.         ripple.setSize(size);
  101.         ripple.setIntensity(size * 0.3f);
  102.         ripple.setLocation(location);
  103.         ripple.setVelocity(velocity);
  104.         ripple.setFrameRate(60f / fadeTime);
  105.         ripple.fadeInSize(fadeTime * 1.2f);
  106.         ripple.fadeOutIntensity(fadeTime);
  107.         ripple.setSize(size * 0.2f);
  108.         ripple.setArc(start, end);
  109.         DistortionShader.addDistortion(ripple);
  110.  
  111.         ripple = new RippleDistortion();
  112.         ripple.setSize(size);
  113.         ripple.setIntensity(size * 0.1f);
  114.         ripple.setLocation(location);
  115.         ripple.setVelocity(velocity);
  116.         ripple.setFrameRate(60f / fadeTime);
  117.         ripple.fadeInSize(fadeTime * 1.2f);
  118.         ripple.fadeOutIntensity(fadeTime);
  119.         ripple.setSize(size * 0.2f);
  120.         ripple.setArc(end, start);
  121.         DistortionShader.addDistortion(ripple);
  122.     }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement