Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package data.scripts.plugins;
- import com.fs.starfarer.api.Global;
- import com.fs.starfarer.api.combat.CollisionClass;
- import com.fs.starfarer.api.combat.CombatEngineAPI;
- import com.fs.starfarer.api.combat.CombatEntityAPI;
- import com.fs.starfarer.api.combat.DamageType;
- import com.fs.starfarer.api.combat.DamagingProjectileAPI;
- import com.fs.starfarer.api.combat.EveryFrameCombatPlugin;
- import com.fs.starfarer.api.combat.ShipAPI;
- import com.fs.starfarer.api.combat.ShipEngineControllerAPI.ShipEngineAPI;
- import com.fs.starfarer.api.combat.ShipSystemAPI;
- import com.fs.starfarer.api.input.InputEventAPI;
- import java.awt.Color;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Map;
- import org.lazywizard.lazylib.CollisionUtils;
- import org.lazywizard.lazylib.MathUtils;
- import org.lazywizard.lazylib.combat.CombatUtils;
- import org.lwjgl.util.vector.Vector2f;
- public class EngineKillEffect implements EveryFrameCombatPlugin {
- // Sound to play while piercing a target's armor (should be loopable!)
- private static final String PIERCE_SOUND = "explosion_missile"; // TEMPORARY
- // Projectile ID (String), pierces shields (boolean)
- private static final Map PROJ_IDS = new HashMap();
- public static final Color effectColor = new Color(165, 215, 145, 150);
- public static final Color effectColorCore = new Color(255, 255, 255, 255);
- private static final float ENGINE_KILL_RADIUS_SQUARED = 30f * 30f;
- CombatEngineAPI engine;
- static {
- // Add all projectiles that should pierce armor here
- // Format: Projectile ID (String), pierces shields (boolean)
- PROJ_IDS.put("ms_enginekill", false);
- }
- @Override
- public void advance(float amount, List<InputEventAPI> events) {
- // Scan all shots on the map for armor piercing projectiles
- for (Iterator iter = engine.getProjectiles().iterator(); iter.hasNext();) {
- DamagingProjectileAPI proj = (DamagingProjectileAPI) iter.next();
- Vector2f projLocation = proj.getLocation();
- String spec = proj.getProjectileSpecId();
- // Is this projectile armor piercing?
- if (!PROJ_IDS.containsKey(spec)) {
- continue;
- }
- // We'll do collision checks manually
- proj.setCollisionClass(CollisionClass.NONE);
- // Find nearby ships
- List toCheck = CombatUtils.getShipsWithinRange(projLocation, proj.getCollisionRadius() + 5f);
- // Don't include the ship that fired this projectile!
- toCheck.remove(proj.getSource());
- for (Iterator iter2 = toCheck.iterator(); iter2.hasNext();) {
- CombatEntityAPI entity = (CombatEntityAPI) iter2.next();
- // Check for an active phase cloak
- if (entity instanceof ShipAPI) {
- ShipSystemAPI cloak = ((ShipAPI) entity).getPhaseCloak();
- if (cloak != null) {
- if (cloak.isActive()) {
- continue;
- }
- }
- } // Check if the projectile is inside the entity's bounds
- if (CollisionUtils.isPointWithinBounds(projLocation, entity)) {
- if (entity instanceof ShipAPI) {
- ShipAPI ship = (ShipAPI) entity;
- List shipEngines = ship.getEngineController().getShipEngines();
- for (Iterator iter3 = shipEngines.iterator(); iter3.hasNext();) {
- ShipEngineAPI shipEngine = (ShipEngineAPI) iter3.next();
- // Apply the engine kill effect
- if (shipEngine.isDisabled() == false) {
- Vector2f shipEngineLocation = shipEngine.getLocation();
- float distanceSq = MathUtils.getDistanceSquared(shipEngineLocation, projLocation);
- if (distanceSq <= ENGINE_KILL_RADIUS_SQUARED) {
- shipEngine.disable();
- engine.spawnEmpArc(proj.getSource(), projLocation, entity, entity,
- DamageType.OTHER, 0, 0, 50f,
- null, 15f, effectColor, effectColorCore);
- }
- }
- }
- }
- // Do other stuff relating to hitting the ship, such as applying damage per second equal to the projectile hit damage
- engine.applyDamage(entity, projLocation, amount * proj.getDamageAmount(), proj.getDamageType(), amount * proj.getEmpAmount(), true, false, proj.getSource());
- // Play piercing sound (only one sound active per projectile)
- Global.getSoundPlayer().playLoop(PIERCE_SOUND, proj, 1f, 1f, projLocation, entity.getVelocity());
- }
- }
- }
- }
- @Override
- public void init(CombatEngineAPI engine) {
- this.engine = engine;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement