package data.scripts.hullmods;

import com.fs.starfarer.api.combat.BaseHullMod;
import com.fs.starfarer.api.combat.MutableShipStatsAPI;
import com.fs.starfarer.api.combat.ShipAPI;
import com.fs.starfarer.api.combat.ShipAPI.HullSize;

public class SWP_GunneryControlAI extends BaseHullMod {

    public static final float AUTOAIM_BONUS = 50f;
    public static final float RECOIL_BONUS = 35f;
    public static final float SHOT_SPEED_BONUS = 35f;

    @Override
    public void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id) {
        stats.getAutofireAimAccuracy().modifyFlat(id, AUTOAIM_BONUS * 0.01f);
        stats.getMaxRecoilMult().modifyMult(id, 1f - (RECOIL_BONUS * 0.01f));
        stats.getRecoilPerShotMult().modifyMult(id, 1f - (RECOIL_BONUS * 0.01f));
        stats.getRecoilDecayMult().modifyMult(id, 1f - (RECOIL_BONUS * 0.01f));
        stats.getProjectileSpeedMult().modifyPercent(id, SHOT_SPEED_BONUS);
    }

    @Override
    public String getDescriptionParam(int index, HullSize hullSize) {
        if (index == 0) {
            return "" + (int) RECOIL_BONUS + "%";
        }
        if (index == 1) {
            return "" + (int) SHOT_SPEED_BONUS + "%";
        }
        return null;
    }

    @Override
    public String getUnapplicableReason(ShipAPI ship) {
        if (ship.getVariant().getHullMods().contains("ii_targeting_package")) {
            return "Incompatible with Imperial Targeting Package";
        }

        return null;
    }

    @Override
    public boolean isApplicableToShip(ShipAPI ship) {
        return !ship.getVariant().hasHullMod("ii_fire_control");
    }
}
