001package com.fs.starfarer.api.impl.combat.threat;
002
003import com.fs.starfarer.api.combat.MutableShipStatsAPI;
004import com.fs.starfarer.api.combat.ShipAPI;
005import com.fs.starfarer.api.combat.ShipCommand;
006import com.fs.starfarer.api.combat.ShipwideAIFlags.AIFlags;
007import com.fs.starfarer.api.combat.WeaponAPI;
008
009public class ExtractionProtocolSystemScript extends BaseEnergyLashActivatedSystem {
010        
011        public static float SPEED_BONUS = 100f;
012        
013        protected boolean vented = false;
014        
015        public void applyImpl(ShipAPI ship, MutableShipStatsAPI stats, String id, State state, float effectLevel) {
016                stats.getMaxSpeed().modifyFlat(id, SPEED_BONUS * effectLevel);
017                stats.getAcceleration().modifyFlat(id, 2f * SPEED_BONUS * effectLevel);
018                stats.getDeceleration().modifyFlat(id, 2f * SPEED_BONUS * effectLevel);
019                
020                //stats.getFluxDissipation().modifyMult(id, 1f + (FLUX_DISSIPATION_MULT - 1f) * effectLevel);
021                
022                //ship.getEngineController().fadeToOtherColor(this, color, new Color(0,0,0,0), effectLevel, 0.67f);
023                ship.getEngineController().extendFlame(ship.getSystem(), 0.01f * effectLevel, 0f * effectLevel, 1f * effectLevel);
024                
025                if (effectLevel <= 0f) return;
026                
027                ship.getAIFlags().setFlag(AIFlags.BACK_OFF, 1f);
028                ship.getAIFlags().setFlag(AIFlags.DO_NOT_VENT, 1f);
029                ship.getAIFlags().setFlag(AIFlags.BACK_OFF_MIN_RANGE, 10000f);
030                ship.getAIFlags().unsetFlag(AIFlags.DO_NOT_BACK_OFF);
031                
032                if (state == State.IN || state == State.ACTIVE) {
033                        vented = false;
034                        makeAllGroupsAutofireOneFrame(ship);
035                }
036                if (state == State.OUT) {
037                        if (!vented) {
038                                ship.giveCommand(ShipCommand.VENT_FLUX, null, 0);
039                                
040                                for (WeaponAPI w : ship.getAllWeapons()) {
041                                        if (w.isDecorative()) continue;
042                                        if (w.getSlot().isSystemSlot()) continue;
043                                        if (w.usesAmmo() && w.getAmmo() < w.getMaxAmmo()) {
044                                                w.setAmmo(w.getMaxAmmo());
045                                        }
046                                }
047                        }
048                }
049
050                setStandardJitter(ship, state, effectLevel);
051        }
052        
053        
054        public StatusData getStatusData(int index, State state, float effectLevel) {
055                if (effectLevel <= 0f) return null;
056                
057                if (index == 0) {
058                        return new StatusData("improved maneuverability", false);
059                } else if (index == 1) {
060                        return new StatusData("+" + (int)SPEED_BONUS + " top speed", false);
061                }
062                return null;
063        }
064
065        @Override
066        public float getCurrentUsefulnessLevel(ShipAPI overseer, ShipAPI ship) {
067                if (ship.getSystem().isActive() || ship.getSystem().isChargedown() ||
068                                ship.getSystem().isChargeup() || ship.getSystem().isCoolingDown()) {
069                        return 0f;
070                }
071                
072                float level = ship.getFluxLevel();
073                
074                float needAmmo = 0f;
075                float useAmmo = 0f;
076                for (WeaponAPI w : ship.getAllWeapons()) {
077                        if (w.isDecorative()) continue;
078                        if (w.getSlot().isSystemSlot()) continue;
079                        if (w.usesAmmo()) {
080                                float op = w.getSpec().getOrdnancePointCost(null);
081                                useAmmo += op;
082                                // the system reloads regenerating weapons, but for this don't count them
083                                if (w.getAmmo() < w.getMaxAmmo() && w.getMaxAmmo() > 0 && w.getAmmoPerSecond() > 0) {
084                                        needAmmo += (1f - (float)w.getAmmo() / (float) w.getMaxAmmo()) * op;
085                                }
086                        }
087                }
088                if (useAmmo > 0f) {
089                        level += 0.25f * needAmmo / useAmmo;
090                        if (level > 1f) level = 1f;
091                }
092                
093                
094                float threshold = 0.7f;
095                Object test = ship.getAIFlags().getCustom(AIFlags.MANEUVER_TARGET);
096                if (test instanceof ShipAPI) {
097                        ShipAPI target = (ShipAPI) test;
098                        if (target.getFluxLevel() > ship.getFluxLevel()) {
099                                threshold = 0.9f; 
100                        }
101                        //threshold = Math.max(0.7f, level + 0.05f);
102                }
103                
104                if (ship.getAIFlags().hasFlag(AIFlags.BACKING_OFF) && level > threshold) {
105                        return (level - threshold) / (1f - threshold);
106                }
107                
108                return 0f;
109        }
110        
111        
112}
113
114
115
116
117
118
119
120