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.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.input.InputEventAPI;
- import java.util.Iterator;
- import java.util.LinkedHashMap;
- import java.util.List;
- import java.util.Map;
- import org.lwjgl.util.vector.Vector2f;
- import org.dark.shaders.distortion.DistortionShader;
- import org.dark.shaders.distortion.RippleDistortion;
- import org.dark.shaders.distortion.DistortionAPI;
- import org.dark.shaders.distortion.WaveDistortion;
- import org.lazywizard.lazylib.VectorUtils;
- public class DistortionsPlugin implements EveryFrameCombatPlugin {
- public CombatEngineAPI engine;
- public static final Map<DamagingProjectileAPI, DistortionAPI> projectiles = new LinkedHashMap<>();
- @Override
- public void init(CombatEngineAPI engine) {
- }
- @Override
- public void advance(float amount, List<InputEventAPI> events) {
- if (engine != Global.getCombatEngine()) {
- projectiles.clear();
- this.engine = Global.getCombatEngine();
- }
- if (engine.isPaused()) {
- return;
- }
- List<DamagingProjectileAPI> activeProjectiles = engine.getProjectiles();
- for (DamagingProjectileAPI projectile : activeProjectiles) {
- if (projectile.didDamage() || projectile.isFading()) {
- continue;
- }
- if (!projectiles.containsKey(projectile)) {
- if (projectile.getProjectileSpecId() != null && projectile.getProjectileSpecId().equals("mjolnir_shot")) {
- WaveDistortion wave = new WaveDistortion();
- wave.setIntensity(5f);
- wave.setSize(50f);
- wave.setLocation(projectile.getLocation());
- wave.flip(true);
- DistortionShader.addDistortion(wave);
- projectiles.put(projectile, wave);
- } else {
- projectiles.put(projectile, null);
- }
- }
- }
- Iterator<Map.Entry<DamagingProjectileAPI, DistortionAPI>> iter = projectiles.entrySet().iterator();
- while (iter.hasNext()) {
- Map.Entry<DamagingProjectileAPI, DistortionAPI> entry = iter.next();
- DamagingProjectileAPI projectile = entry.getKey();
- if (projectile.didDamage()) {
- CombatEntityAPI target = projectile.getDamageTarget();
- if (target instanceof ShipAPI) {
- if (target.getShield() != null && target.getShield().isOn() && target.getShield().isWithinArc(projectile.getLocation())) {
- createHitRipple(projectile.getLocation(), target.getVelocity(), projectile.getDamageAmount(), projectile.getDamageType(), VectorUtils.getFacing(VectorUtils.getDirectionalVector(target.getShield().getLocation(), projectile.getLocation())), target.getShield().getRadius());
- }
- }
- if (entry.getValue() != null) {
- if (projectile.getProjectileSpecId().equals("mjolnir_shot")) {
- WaveDistortion wave = (WaveDistortion) entry.getValue();
- if (!wave.isFading()) {
- wave.fadeOutIntensity(0.2f);
- }
- }
- }
- iter.remove();
- } else if (projectile.isFading()) {
- if (entry.getValue() != null) {
- if (projectile.getProjectileSpecId().equals("mjolnir_shot")) {
- WaveDistortion wave = (WaveDistortion) entry.getValue();
- if (!wave.isFading()) {
- wave.fadeOutIntensity(0.2f);
- }
- }
- }
- } else if (!engine.isEntityInPlay(projectile)) {
- if (entry.getValue() != null) {
- if (projectile.getProjectileSpecId().equals("mjolnir_shot")) {
- WaveDistortion wave = (WaveDistortion) entry.getValue();
- wave.setLifetime(0f);
- }
- }
- iter.remove();
- } else if (entry.getValue() != null) {
- if (projectile.getProjectileSpecId().equals("mjolnir_shot")) {
- WaveDistortion wave = (WaveDistortion) entry.getValue();
- wave.setLocation(projectile.getLocation());
- }
- }
- }
- }
- private void createHitRipple(Vector2f location, Vector2f velocity, float damage, DamageType type, float direction, float shieldRadius) {
- if (type == DamageType.FRAGMENTATION) {
- damage *= 0.25f;
- }
- if (type == DamageType.HIGH_EXPLOSIVE) {
- damage *= 0.5f;
- }
- if (type == DamageType.KINETIC) {
- damage *= 2f;
- }
- if (damage < 50f) {
- return;
- }
- float fadeTime = (float) Math.pow(damage, 0.25) * 0.1f;
- float size = (float) Math.pow(damage, 0.3333333) * 15f;
- float ratio = Math.min(size / shieldRadius, 1f);
- float arc = 90f - ratio * 14.54136f; // Don't question the magic number
- float start = direction - arc;
- if (start < 0f) {
- start += 360f;
- }
- float end = direction + arc;
- if (end >= 360f) {
- end -= 360f;
- }
- RippleDistortion ripple = new RippleDistortion();
- ripple.setSize(size);
- ripple.setIntensity(size * 0.3f);
- ripple.setLocation(location);
- ripple.setVelocity(velocity);
- ripple.setFrameRate(60f / fadeTime);
- ripple.fadeInSize(fadeTime * 1.2f);
- ripple.fadeOutIntensity(fadeTime);
- ripple.setSize(size * 0.2f);
- ripple.setArc(start, end);
- DistortionShader.addDistortion(ripple);
- ripple = new RippleDistortion();
- ripple.setSize(size);
- ripple.setIntensity(size * 0.1f);
- ripple.setLocation(location);
- ripple.setVelocity(velocity);
- ripple.setFrameRate(60f / fadeTime);
- ripple.fadeInSize(fadeTime * 1.2f);
- ripple.fadeOutIntensity(fadeTime);
- ripple.setSize(size * 0.2f);
- ripple.setArc(end, start);
- DistortionShader.addDistortion(ripple);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement