Advertisement
DarkRevenant

Untitled

Jun 19th, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.16 KB | None | 0 0
  1. package data.scripts.plugins;
  2.  
  3. import com.fs.starfarer.api.Global;
  4. import com.fs.starfarer.api.combat.CollisionClass;
  5. import com.fs.starfarer.api.combat.CombatEngineAPI;
  6. import com.fs.starfarer.api.combat.CombatEntityAPI;
  7. import com.fs.starfarer.api.combat.DamagingProjectileAPI;
  8. import com.fs.starfarer.api.combat.EveryFrameCombatPlugin;
  9. import com.fs.starfarer.api.combat.ShieldAPI;
  10. import com.fs.starfarer.api.combat.ShipAPI;
  11. import com.fs.starfarer.api.combat.ShipSystemAPI;
  12. import com.fs.starfarer.api.input.InputEventAPI;
  13.  
  14. import java.awt.Color;
  15. import java.util.ArrayList;
  16. import java.util.HashMap;
  17. import java.util.List;
  18. import java.util.Map;
  19. import org.lwjgl.util.vector.Vector2f;
  20.  
  21. import org.lazywizard.lazylib.CollisionUtils;
  22. import org.lazywizard.lazylib.MathUtils;
  23. import org.lazywizard.lazylib.combat.CombatUtils;
  24.  
  25. public class exigency_ShieldBypass implements EveryFrameCombatPlugin {
  26.  
  27.     // Projectile ID (String), bypass effect data (ProjData)
  28.     private static final Map<String, ProjData> PROJ_DATA = new HashMap<>();
  29.     private static CombatEngineAPI activeEngine;
  30.  
  31.     static {
  32.         // Add all projectiles that should pierce shields here
  33.         PROJ_DATA.put("exigency_rr_shot",
  34.                 new ProjData("exigency_shieldpierce", // Shield pierce sound
  35.                         2f, // Shield pierce sound pitch
  36.                         Color.WHITE, // Shield pierce particle color
  37.                         "hit_heavy", // Hit sound
  38.                         1f, // Hit sound pitch
  39.                         0f, // Hit force
  40.                         150f, // Explosion size
  41.                         1.5f, // Explosion duration
  42.                         new Color(255, 165, 130, 200), // Explosion color
  43.                         5.0f, // Shield pierce particle size
  44.                         0.5f, // Shield pierce particle opacity
  45.                         0.5f)); // Shield pierce particle duration
  46.  
  47.         PROJ_DATA.put("exigency_super_cigen_shot",
  48.                 new ProjData("exigency_shieldpierce", // Shield pierce sound
  49.                         1.5f, // Shield pierce sound pitch
  50.                         new Color(255, 225, 200), // Shield pierce particle color
  51.                         "hit_heavy", // Hit sound
  52.                         1f, // Hit sound pitch
  53.                         350f, // Hit force
  54.                         250f, // Explosion size
  55.                         1.5f, // Explosion duration
  56.                         new Color(255, 185, 150, 255), // Explosion color
  57.                         7.0f, // Shield pierce particle size
  58.                         0.6f, // Shield pierce particle opacity
  59.                         0.6f)); // Shield pierce particle duration
  60.  
  61.         PROJ_DATA.put("exigency_cigenrepeater_shot",
  62.                 new ProjData("exigency_shieldpierce_small", // Shield pierce sound
  63.                         3f, // Shield pierce sound pitch
  64.                         Color.WHITE, // Shield pierce particle color
  65.                         "hit_light", // Hit sound
  66.                         1f, // Hit sound pitch
  67.                         0f, // Hit force
  68.                         0.1f, // Explosion size
  69.                         0.1f, // Explosion duration
  70.                         new Color(255, 165, 130, 10), // Explosion color
  71.                         2.5f, // Shield pierce particle size
  72.                         0.5f, // Shield pierce particle opacity
  73.                         0.5f)); // Shield pierce particle duration
  74.     }
  75.  
  76.     @Override
  77.     public void advance(float amount, List<InputEventAPI> events) {
  78.         if (activeEngine.isPaused()) {
  79.             return;
  80.         }
  81.  
  82.         String spec;
  83.         ProjData data;
  84.  
  85.         // Scan all shots on the map for shield piercing projectiles
  86.         for (DamagingProjectileAPI proj : activeEngine.getProjectiles()) {
  87.             spec = proj.getProjectileSpecId();
  88.  
  89.             // Is this projectile shield piercing?
  90.             if (!PROJ_DATA.containsKey(spec)) {
  91.                 continue;
  92.             }
  93.  
  94.             data = PROJ_DATA.get(spec);
  95.  
  96.             // We'll do collision checks manually
  97.             proj.setCollisionClass(CollisionClass.NONE);
  98.  
  99.             // Find nearby ships and asteroids
  100.             List<CombatEntityAPI> toCheck = new ArrayList<>();
  101.             toCheck.addAll(CombatUtils.getShipsWithinRange(proj.getLocation(), proj.getCollisionRadius() + 5f));
  102.             toCheck.addAll(CombatUtils.getAsteroidsWithinRange(proj.getLocation(), proj.getCollisionRadius() + 5f));
  103.             // Don't include the ship that fired this projectile!
  104.             toCheck.remove(proj.getSource());
  105.             for (CombatEntityAPI entity : toCheck) {
  106.                 // Check for an active phase cloak/shield
  107.                 if (entity instanceof ShipAPI) {
  108.                     ShipAPI ship = (ShipAPI) entity;
  109.                     // Pass right through a cloaked ship
  110.                     ShipSystemAPI cloak = ship.getPhaseCloak();
  111.                     if (cloak != null && cloak.isActive()) {
  112.                         continue;
  113.                     }
  114.  
  115.                     // Play sound / show effects when passing through a shield
  116.                     ShieldAPI shield = ship.getShield();
  117.                     if (shield != null && shield.isOn() && shield.isWithinArc(proj.getLocation()) && MathUtils.isWithinRange(proj.getLocation(), shield.getLocation(), shield.getRadius())) {
  118.                         Global.getSoundPlayer().playLoop(data.shieldPierceSound, proj, data.shieldPierceSoundPitch, 1f, proj.getLocation(), proj.getVelocity());
  119.                         activeEngine.addSmokeParticle(proj.getLocation(), Vector2f.add(ship.getVelocity(), MathUtils.getRandomPointInCircle(null, data.explosionSize / 4f), null), data.pierceSize, data.pierceOpacity, data.pierceDuration, data.shieldPierceColor);
  120.                     }
  121.                 }
  122.  
  123.                 if (CollisionUtils.isPointWithinBounds(proj.getLocation(), entity)) {
  124.                     // Apply damage and destroy the projectile
  125.                     CombatUtils.applyForce(entity, proj.getVelocity(), data.hitForce);
  126.                     activeEngine.applyDamage(entity, proj.getLocation(), proj.getDamageAmount(), proj.getDamageType(), proj.getEmpAmount(), true, true, proj.getSource());
  127.                     activeEngine.spawnExplosion(proj.getLocation(), entity.getVelocity(), data.explosionColor, data.explosionSize, data.explosionDuration);
  128.                     activeEngine.spawnExplosion(MathUtils.getRandomPointOnCircumference(proj.getLocation(), data.explosionSize / 4f), entity.getVelocity(), data.explosionColor, data.explosionSize / 3f, data.explosionDuration / 2f);
  129.                     Global.getSoundPlayer().playSound(data.hitSound, data.hitSoundPitch, 1f, proj.getLocation(), entity.getVelocity());
  130.                     activeEngine.removeEntity(proj);
  131.                 }
  132.             }
  133.         }
  134.     }
  135.  
  136.     @Override
  137.     public void init(CombatEngineAPI engine) {
  138.         activeEngine = engine;
  139.     }
  140.  
  141.     private static final class ProjData {
  142.  
  143.         private final String hitSound, shieldPierceSound;
  144.         private final float hitSoundPitch, shieldPierceSoundPitch, explosionSize, explosionDuration, pierceSize, pierceDuration, pierceOpacity, hitForce;
  145.         private final Color shieldPierceColor, explosionColor;
  146.  
  147.         private ProjData(String shieldPierceSound, float shieldPierceSoundPitch, Color shieldPierceColor, String hitSound, float hitSoundPitch, float hitForce, float explosionSize, float explosionDuration, Color explosionColor, float pierceSize, float pierceOpacity, float pierceDuration) {
  148.             this.shieldPierceSound = shieldPierceSound;
  149.             this.shieldPierceSoundPitch = shieldPierceSoundPitch;
  150.             this.shieldPierceColor = shieldPierceColor;
  151.             this.pierceSize = pierceSize;
  152.             this.pierceDuration = pierceDuration;
  153.             this.pierceOpacity = pierceOpacity;
  154.             this.hitSound = hitSound;
  155.             this.hitSoundPitch = hitSoundPitch;
  156.             this.hitForce = hitForce;
  157.             this.explosionSize = explosionSize;
  158.             this.explosionDuration = explosionDuration;
  159.             this.explosionColor = explosionColor;
  160.         }
  161.     }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement