package data.scripts.weapons;

import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.CombatEntityAPI;
import com.fs.starfarer.api.combat.DamagingProjectileAPI;
import com.fs.starfarer.api.combat.OnHitEffectPlugin;
import com.fs.starfarer.api.combat.ShipAPI;
import data.scripts.IIModPlugin;
import data.scripts.hullmods.TEM_LatticeShield;
import java.awt.Color;
import org.lwjgl.util.vector.Vector2f;

public class II_HeavyPulsarOnHitEffect implements OnHitEffectPlugin {

    private static final Color EXPLOSION_COLOR = new Color(255, 150, 100, 80);

    @Override
    public void onHit(DamagingProjectileAPI projectile, CombatEntityAPI target, Vector2f point, boolean shieldHit, CombatEngineAPI engine) {
        if (target == null || point == null) {
            return;
        }
        boolean isShieldHit = shieldHit;
        if (!isShieldHit && target instanceof ShipAPI) {
            ShipAPI ship = (ShipAPI) target;
            if (IIModPlugin.templarsExists && ship.getVariant().getHullMods().contains("tem_latticeshield") && TEM_LatticeShield.shieldLevel(ship) > 0f) {
                isShieldHit = true;
            }
        }
        if (!isShieldHit) {
            engine.spawnExplosion(point, new Vector2f(target.getVelocity().x * 0.45f, target.getVelocity().y * 0.45f), EXPLOSION_COLOR, 50f, 1f);
        }
    }
}
