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;
import com.fs.starfarer.api.impl.campaign.ids.Factions;
import com.fs.starfarer.api.impl.campaign.ids.Personalities;
import com.fs.starfarer.api.util.Misc;

public class CHM_sindrian extends BaseHullMod {
    public static String bigidentifier = "ERROR";
    public static String bigidentifier2 = "ERROR";
    public static float bigidentifier21 = 0f;
    public static String bigidentifier3 = "ERROR";
    public static float bigidentifier31 = 0f;
    public static boolean bigidentifier3shield = false;
    public static final float WEAPON_HITPOINTS_BONUS = 25f;
    public static final float SHIELD_DAMAGE_REDUCTION = 7f;
    public static final float TURRET_SPEED_BONUS = 20f;
    public static final float TURRET_SPEED_BONUS2 = 5f;
    public static final float MANEUVER_BONUS = 20f;
    public static final float MANEUVER_BONUS2 = 5f;
    public static final float DAMAGE_TO_SHIELDS_BONUS = 5f;
    public static final float WEAPON_DAMAGE = 3f;
    public static MutableShipStatsAPI stat;
	
	//@Override
	//public void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id) {
            //stats.getCRLossPerSecondPercent().modifyMult(id, 1f - DEGRADE_REDUCTION_PERCENT / 100f);
            	//}

	//	stats.getDynamic().getStat(Stats.REPLACEMENT_RATE_INCREASE_MULT).modifyPercent(id, RATE_INCREASE_MODIFIER);
    
    @Override
    public void applyEffectsAfterShipCreation(ShipAPI ship, String id) {
                if (!Factions.DIKTAT.equals(Misc.getCommissionFactionId())) {
                    ship.getVariant().removeMod("CHM_sindrian");
           }
                if (ship.getVariant().hasHullMod("CHM_commission")) {
                    ship.getVariant().removeMod("CHM_commission");
                }
                if (ship.getCaptain() != null) {
                    stat = ship.getMutableStats();
                    if (ship.getCaptain().isDefault()) {
                        bigidentifier = "Lion's Whisker";
                        bigidentifier2 = "Turret Turn Rate";
                        bigidentifier21 = TURRET_SPEED_BONUS2;
                        bigidentifier3shield = false;
                        bigidentifier3 = "Maneuverability";
                        bigidentifier31 = MANEUVER_BONUS2;
                        stat.getWeaponTurnRateBonus().modifyPercent(id, TURRET_SPEED_BONUS2);
                        stat.getBeamWeaponTurnRateBonus().modifyPercent(id, TURRET_SPEED_BONUS2);
                        stat.getAcceleration().modifyPercent(id, MANEUVER_BONUS2 * 2f);
                        stat.getDeceleration().modifyPercent(id, MANEUVER_BONUS2);
                        stat.getTurnAcceleration().modifyPercent(id, MANEUVER_BONUS2 * 2f);
                        stat.getMaxTurnRate().modifyPercent(id, MANEUVER_BONUS2);
                        return;
                    }
                    String personality = Misc.lcFirst(ship.getCaptain().getPersonalityAPI().getId());
                    if (personality.equals(Personalities.TIMID)) {
                        bigidentifier = "Lion's Tail";
                        bigidentifier2 = "Weapon Hitpoints";
                        bigidentifier21 = WEAPON_HITPOINTS_BONUS;
                        bigidentifier3shield = true;
                        bigidentifier3 = "Damage Received by Shield";
                        bigidentifier31 = SHIELD_DAMAGE_REDUCTION;
                        stat.getWeaponHealthBonus().modifyPercent(id, WEAPON_HITPOINTS_BONUS);
                        stat.getShieldDamageTakenMult().modifyMult(id, 1f - SHIELD_DAMAGE_REDUCTION / 100f);
                    }
                    else if (personality.equals(Personalities.CAUTIOUS)) {
                        bigidentifier = "Lion's Eye";
                        bigidentifier2 = "Maneuverability";
                        bigidentifier21 = MANEUVER_BONUS;
                        bigidentifier3shield = false;
                        bigidentifier3 = "Weapon Hitpoints";
                        bigidentifier31 = WEAPON_HITPOINTS_BONUS;
                        stat.getAcceleration().modifyPercent(id, MANEUVER_BONUS * 2f);
                        stat.getDeceleration().modifyPercent(id, MANEUVER_BONUS);
                        stat.getTurnAcceleration().modifyPercent(id, MANEUVER_BONUS * 2f);
                        stat.getMaxTurnRate().modifyPercent(id, MANEUVER_BONUS);
                        stat.getWeaponHealthBonus().modifyPercent(id, WEAPON_HITPOINTS_BONUS);
                    }
                    else if (personality.equals(Personalities.STEADY)) {
                        bigidentifier = "Lion's Mane";
                        bigidentifier2 = "Turret Turn Rate";
                        bigidentifier21 = TURRET_SPEED_BONUS;
                        bigidentifier3shield = false;
                        bigidentifier3 = "Maneuverability";
                        bigidentifier31 = MANEUVER_BONUS;
                        stat.getWeaponTurnRateBonus().modifyPercent(id, TURRET_SPEED_BONUS);
                        stat.getBeamWeaponTurnRateBonus().modifyPercent(id, TURRET_SPEED_BONUS);
                        stat.getAcceleration().modifyPercent(id, MANEUVER_BONUS * 2f);
                        stat.getDeceleration().modifyPercent(id, MANEUVER_BONUS);
                        stat.getTurnAcceleration().modifyPercent(id, MANEUVER_BONUS * 2f);
                        stat.getMaxTurnRate().modifyPercent(id, MANEUVER_BONUS);
                    }
                    else if (personality.equals(Personalities.AGGRESSIVE)) {
                        bigidentifier = "Lion's Claws";
                        bigidentifier2 = "Turret Turn Rate";
                        bigidentifier21 = TURRET_SPEED_BONUS;
                        bigidentifier3shield = false;
                        bigidentifier3 = "Damage to Shields";
                        bigidentifier31 = DAMAGE_TO_SHIELDS_BONUS;
                        stat.getWeaponTurnRateBonus().modifyPercent(id, TURRET_SPEED_BONUS2);
                        stat.getBeamWeaponTurnRateBonus().modifyPercent(id, TURRET_SPEED_BONUS2);
                        stat.getDamageToTargetShieldsMult().modifyPercent(id, DAMAGE_TO_SHIELDS_BONUS);
                    }
                    else if (personality.equals(Personalities.RECKLESS)) {
                        bigidentifier = "Lion's Bite";
                        bigidentifier2 = "Damage to Shields";
                        bigidentifier21 = DAMAGE_TO_SHIELDS_BONUS;
                        bigidentifier3shield = false;
                        bigidentifier3 = "Ballistic and Energy Weapon Damage";
                        bigidentifier31 = WEAPON_DAMAGE;
                        stat.getDamageToTargetShieldsMult().modifyPercent(id, DAMAGE_TO_SHIELDS_BONUS);
                        stat.getBallisticWeaponDamageMult().modifyPercent(id, WEAPON_DAMAGE);
			stat.getEnergyWeaponDamageMult().modifyPercent(id, WEAPON_DAMAGE);
                    }
                }
            }
      @Override
	public String getDescriptionParam(int index, HullSize hullSize) {
		if (index == 0) return bigidentifier;
                if (index == 1) return "" + (int) bigidentifier21 + "%";
                if (index == 2) return bigidentifier2;
                if (index == 3 && bigidentifier3shield == true) return "-";
                if (index == 3 && bigidentifier3shield == false) return "";
                if (index == 4) return "" + (int) bigidentifier31 + "%";
                if (index == 5) return bigidentifier3;
		return null;
	}
}
