001package com.fs.starfarer.api.impl.combat; 002 003import org.lwjgl.util.vector.Vector2f; 004 005import com.fs.starfarer.api.combat.BeamAPI; 006import com.fs.starfarer.api.combat.BeamEffectPlugin; 007import com.fs.starfarer.api.combat.CombatEngineAPI; 008import com.fs.starfarer.api.combat.CombatEntityAPI; 009import com.fs.starfarer.api.combat.DamageType; 010import com.fs.starfarer.api.combat.ShipAPI; 011import com.fs.starfarer.api.impl.campaign.ids.Stats; 012import com.fs.starfarer.api.util.IntervalUtil; 013 014public class IonBeamEffect implements BeamEffectPlugin { 015 016 private IntervalUtil fireInterval = new IntervalUtil(0.25f, 1.75f); 017 private boolean wasZero = true; 018 019 020 public void advance(float amount, CombatEngineAPI engine, BeamAPI beam) { 021 CombatEntityAPI target = beam.getDamageTarget(); 022 if (target instanceof ShipAPI && beam.getBrightness() >= 1f) { 023 float dur = beam.getDamage().getDpsDuration(); 024 // needed because when the ship is in fast-time, dpsDuration will not be reset every frame as it should be 025 if (!wasZero) dur = 0; 026 wasZero = beam.getDamage().getDpsDuration() <= 0; 027 fireInterval.advance(dur); 028 029 if (fireInterval.intervalElapsed()) { 030 ShipAPI ship = (ShipAPI) target; 031 boolean hitShield = target.getShield() != null && target.getShield().isWithinArc(beam.getRayEndPrevFrame()); 032 float pierceChance = ((ShipAPI)target).getHardFluxLevel() - 0.1f; 033 pierceChance *= ship.getMutableStats().getDynamic().getValue(Stats.SHIELD_PIERCED_MULT); 034 035 boolean piercedShield = hitShield && (float) Math.random() < pierceChance; 036 //piercedShield = true; 037 038 if (!hitShield || piercedShield) { 039 Vector2f point = beam.getRayEndPrevFrame(); 040 float emp = beam.getDamage().getFluxComponent() * 1f; 041 float dam = beam.getDamage().getDamage() * 1f; 042 engine.spawnEmpArcPierceShields( 043 beam.getSource(), point, beam.getDamageTarget(), beam.getDamageTarget(), 044 DamageType.ENERGY, 045 dam, // damage 046 emp, // emp 047 100000f, // max range 048 "tachyon_lance_emp_impact", 049 beam.getWidth() + 9f, 050 beam.getFringeColor(), 051 beam.getCoreColor() 052 ); 053 } 054 } 055 } 056// Global.getSoundPlayer().playLoop("system_emp_emitter_loop", 057// beam.getDamageTarget(), 1.5f, beam.getBrightness() * 0.5f, 058// beam.getTo(), new Vector2f()); 059 } 060}