Advertisement
DarkRevenant

Untitled

Apr 7th, 2014
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.14 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.DamageType;
  8. import com.fs.starfarer.api.combat.DamagingProjectileAPI;
  9. import com.fs.starfarer.api.combat.EveryFrameCombatPlugin;
  10. import com.fs.starfarer.api.combat.ShipAPI;
  11. import com.fs.starfarer.api.combat.ShipEngineControllerAPI.ShipEngineAPI;
  12. import com.fs.starfarer.api.combat.ShipSystemAPI;
  13. import com.fs.starfarer.api.input.InputEventAPI;
  14. import java.awt.Color;
  15. import java.util.HashMap;
  16. import java.util.Iterator;
  17. import java.util.List;
  18. import java.util.Map;
  19. import org.lazywizard.lazylib.CollisionUtils;
  20. import org.lazywizard.lazylib.MathUtils;
  21. import org.lazywizard.lazylib.combat.CombatUtils;
  22. import org.lwjgl.util.vector.Vector2f;
  23.  
  24. public class EngineKillEffect implements EveryFrameCombatPlugin {
  25.  
  26.     // Sound to play while piercing a target's armor (should be loopable!)
  27.     private static final String PIERCE_SOUND = "explosion_missile"; // TEMPORARY
  28.     // Projectile ID (String), pierces shields (boolean)
  29.     private static final Map PROJ_IDS = new HashMap();
  30.     public static final Color effectColor = new Color(165, 215, 145, 150);
  31.     public static final Color effectColorCore = new Color(255, 255, 255, 255);
  32.     private static final float ENGINE_KILL_RADIUS_SQUARED = 30f * 30f;
  33.     CombatEngineAPI engine;
  34.  
  35.     static {
  36.         // Add all projectiles that should pierce armor here
  37.         // Format: Projectile ID (String), pierces shields (boolean)
  38.         PROJ_IDS.put("ms_enginekill", false);
  39.     }
  40.  
  41.     @Override
  42.     public void advance(float amount, List<InputEventAPI> events) {
  43.         // Scan all shots on the map for armor piercing projectiles
  44.         for (Iterator iter = engine.getProjectiles().iterator(); iter.hasNext();) {
  45.             DamagingProjectileAPI proj = (DamagingProjectileAPI) iter.next();
  46.             Vector2f projLocation = proj.getLocation();
  47.             String spec = proj.getProjectileSpecId();
  48.  
  49.             // Is this projectile armor piercing?
  50.             if (!PROJ_IDS.containsKey(spec)) {
  51.                 continue;
  52.             }
  53.  
  54.             // We'll do collision checks manually
  55.             proj.setCollisionClass(CollisionClass.NONE);
  56.  
  57.             // Find nearby ships
  58.             List toCheck = CombatUtils.getShipsWithinRange(projLocation, proj.getCollisionRadius() + 5f);
  59.             // Don't include the ship that fired this projectile!
  60.             toCheck.remove(proj.getSource());
  61.  
  62.             for (Iterator iter2 = toCheck.iterator(); iter2.hasNext();) {
  63.                 CombatEntityAPI entity = (CombatEntityAPI) iter2.next();
  64.  
  65.                 // Check for an active phase cloak
  66.                 if (entity instanceof ShipAPI) {
  67.                     ShipSystemAPI cloak = ((ShipAPI) entity).getPhaseCloak();
  68.  
  69.                     if (cloak != null) {
  70.                         if (cloak.isActive()) {
  71.                             continue;
  72.                         }
  73.                     }
  74.                 } // Check if the projectile is inside the entity's bounds
  75.  
  76.                 if (CollisionUtils.isPointWithinBounds(projLocation, entity)) {
  77.                     if (entity instanceof ShipAPI) {
  78.                         ShipAPI ship = (ShipAPI) entity;
  79.                         List shipEngines = ship.getEngineController().getShipEngines();
  80.  
  81.                         for (Iterator iter3 = shipEngines.iterator(); iter3.hasNext();) {
  82.                             ShipEngineAPI shipEngine = (ShipEngineAPI) iter3.next();
  83.                             // Apply the engine kill effect
  84.                             if (shipEngine.isDisabled() == false) {
  85.                                 Vector2f shipEngineLocation = shipEngine.getLocation();
  86.                                 float distanceSq = MathUtils.getDistanceSquared(shipEngineLocation, projLocation);
  87.  
  88.                                 if (distanceSq <= ENGINE_KILL_RADIUS_SQUARED) {
  89.                                     shipEngine.disable();
  90.                                     engine.spawnEmpArc(proj.getSource(), projLocation, entity, entity,
  91.                                             DamageType.OTHER, 0, 0, 50f,
  92.                                             null, 15f, effectColor, effectColorCore);
  93.                                 }
  94.                             }
  95.                         }
  96.                     }
  97.  
  98.                     // Do other stuff relating to hitting the ship, such as applying damage per second equal to the projectile hit damage
  99.                     engine.applyDamage(entity, projLocation, amount * proj.getDamageAmount(), proj.getDamageType(), amount * proj.getEmpAmount(), true, false, proj.getSource());
  100.  
  101.                     // Play piercing sound (only one sound active per projectile)
  102.                     Global.getSoundPlayer().playLoop(PIERCE_SOUND, proj, 1f, 1f, projLocation, entity.getVelocity());
  103.                 }
  104.             }
  105.         }
  106.     }
  107.  
  108.     @Override
  109.     public void init(CombatEngineAPI engine) {
  110.         this.engine = engine;
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement