001package com.fs.starfarer.api.impl.combat.threat;
002
003import java.awt.Color;
004
005import com.fs.starfarer.api.combat.MutableShipStatsAPI;
006import com.fs.starfarer.api.combat.ShipAPI;
007import com.fs.starfarer.api.combat.ShipwideAIFlags.AIFlags;
008import com.fs.starfarer.api.util.Misc;
009
010public class DisplacerGlowScript extends BaseEnergyLashActivatedSystem {
011        
012        public void applyImpl(ShipAPI ship, MutableShipStatsAPI stats, String id, State state, float effectLevel) {
013                if (state != State.IDLE && state != State.OUT) return;
014                
015                float ammo = ship.getSystem().getAmmo();
016                float maxAmmo = ship.getSystem().getMaxAmmo();
017                
018                if (ammo <= 0 && (state == State.IDLE || state == State.OUT)) return;
019                
020                if (ship.isHulk()) return;
021                
022                //float jitterLevel = effectLevel;
023                float jitterLevel = ammo / maxAmmo;
024                jitterLevel = 0.5f + 0.5f * jitterLevel;
025                if (state == State.OUT) {
026                        jitterLevel *= jitterLevel;
027                }
028//              float maxRangeBonus = 50f;
029//              float jitterRangeBonus = jitterLevel * maxRangeBonus;
030                
031                Color base = VoltaicDischargeOnFireEffect.EMP_FRINGE_COLOR;
032                Color underColor = Misc.setAlpha(base, 255);
033                Color overColor = Misc.setAlpha(base, 255);;
034                ship.setJitterUnder(this, underColor, jitterLevel, 7, 4f, 4f);
035                ship.setJitter(this, overColor, jitterLevel, 2, 0f, 4f);
036                
037                ship.setJitterShields(false);
038                ship.setCircularJitter(true);
039        }
040
041        @Override
042        public void hitWithEnergyLash(ShipAPI overseer, ShipAPI ship) {
043                if (ship.getSystem() == null) return;
044                
045                ship.getSystem().setAmmo(ship.getSystem().getMaxAmmo());
046        }
047
048        @Override
049        public float getCurrentUsefulnessLevel(ShipAPI overseer, ShipAPI ship) {
050                float ammo = ship.getSystem().getAmmo();
051                float maxAmmo = ship.getSystem().getMaxAmmo();
052                if (ammo >= maxAmmo) return 0f;
053                
054                if (maxAmmo < 1) maxAmmo = 1f;
055                float f = ammo / maxAmmo;
056                
057                float mult = 0.5f;
058                if (ship.getAIFlags().hasFlag(AIFlags.BACKING_OFF) || 
059                                ship.getAIFlags().hasFlag(AIFlags.NEEDS_HELP)) {
060                        mult += 0.5f;
061                }
062                
063                float fluxFactor = Math.min(0.25f, ship.getFluxLevel() * 0.25f);
064                
065                return fluxFactor + 0.75f * (1f - f) * mult;
066        }
067}
068
069
070
071
072
073
074
075