/**
 * Vector Submachine Gun class with advanced bullet tracking functionality
 * Known for high rate of fire and precision tracking system
 */
public class VectorSMG {
    // Weapon properties
    private String name = "Vector Submachine Gun";
    private String model = "KRISS Vector";
    private String caliber = ".45 ACP";
    private double bulletSpeed = 150.0; // meters per second
    private double fireRate = 200.0; // rounds per minute (actual Vector has ~1200 RPM)
    private double effectiveRange = 999.0; // meters
    private boolean trackingEnabled = true;
    
    // Target priority
    private String primaryTarget = "HEAD";
    private String secondaryTarget = "BODY";
    
    // Damage values
    private int headshotDamage = 200;
    private int chestDamage = 150;
    private int torsoDamage = 100;
    private int legDamage = 100;
    private int footDamage = 90;
    
    // Weapon status
    private boolean isReloading = false;
    private boolean isFiring = false;
    private int currentAmmo = 25;
    private final int maxAmmo = 25;
    private final double reloadTime = 2.2; // seconds (fast reload for SMG)
    private double accuracy = 0.85; // Base accuracy (85%)
    
    // Advanced tracking system
    private boolean advancedTracking = true;
    private double trackingPrecision = 0.90; // 90% tracking accuracy
    
    /**
     * Fire single shot with Vector's unique recoil mitigation system
     */
    public int fire(double targetDistance, String targetHitZone) {
        if (!canFire()) {
            return 0;
        }
        
        currentAmmo--;
        
        // Apply Vector's superior recoil control
        String actualHitZone = applyVectorTracking(targetHitZone, targetDistance);
        int damage = calculateDamage(actualHitZone, targetDistance);
        
        System.out.println("Vector fired! Hit: " + actualHitZone + 
                          " | Distance: " + String.format("%.1f", targetDistance) + "m" +
                          " | Damage: " + damage +
                          " | Ammo: " + currentAmmo + "/" + maxAmmo);
        
        displayTrackingFeedback(targetDistance, actualHitZone);
        
        return damage;
    }
    
    /**
     * High-rate burst fire utilizing Vector's unique recoil system
     */
    public int burstFire(double targetDistance, String targetHitZone, int burstCount) {
        if (!canFire() || burstCount <= 0) {
            return 0;
        }
        
        burstCount = Math.min(burstCount, currentAmmo);
        
        System.out.println("Vector high-rate burst: " + burstCount + " rounds");
        int totalDamage = 0;
        isFiring = true;
        
        for (int i = 0; i < burstCount; i++) {
            if (currentAmmo <= 0) break;
            
            // Vector's unique low-recoil burst pattern
            String modifiedHitZone = applyVectorRecoilPattern(targetHitZone, i, burstCount);
            totalDamage += fire(targetDistance, modifiedHitZone);
            
            // Very short delay between shots (SMG characteristic)
            try {
                Thread.sleep(50); // Fast cyclic rate
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                break;
            }
        }
        
        isFiring = false;
        System.out.println("Burst complete. Total damage: " + totalDamage);
        return totalDamage;
    }
    
    /**
     * Vector's advanced tracking system with superior target acquisition
     */
    private String applyVectorTracking(String originalHitZone, double distance) {
        if (!trackingEnabled) {
            return originalHitZone;
        }
        
        // Vector's tracking system is more effective at closer ranges
        double rangeEffectiveness = Math.max(0.7, 1.0 - (distance / 2000.0));
        double trackingChance = trackingPrecision * rangeEffectiveness;
        
        if (originalHitZone.equals("CHEST") || originalHitZone.equals("TORSO") || 
            originalHitZone.equals("BODY") || originalHitZone.equals("LEG")) {
            
            if (Math.random() < trackingChance) {
                System.out.println("  ↳ Vector Tracking: Target upgraded to HEAD");
                return primaryTarget;
            }
        }
        
        // Vector's system can sometimes improve other hit zones
        if (originalHitZone.equals("FOOT") && Math.random() < trackingChance * 0.6) {
            return "LEG"; // Upgrade foot to leg shot
        }
        
        return originalHitZone;
    }
    
    /**
     * Apply Vector's unique low-recoil pattern for burst fire
     */
    private String applyVectorRecoilPattern(String originalHitZone, int shotIndex, int totalShots) {
        // Vector has minimal recoil due to its unique operating system
        if (shotIndex == 0) {
            return originalHitZone; // First shot is highly accurate
        }
        
        // Very tight grouping for Vector (superior to other SMGs)
        String[] zones = {"HEAD", "CHEST", "TORSO", "LEG"};
        double[] probabilities = {0.4, 0.35, 0.2, 0.05}; // Minimal spread
        
        double random = Math.random();
        double cumulative = 0.0;
        
        for (int i = 0; i < zones.length; i++) {
            cumulative += probabilities[i];
            if (random <= cumulative) {
                return zones[i];
            }
        }
        
        return originalHitZone;
    }
    
    /**
     * Calculate damage with SMG-specific range considerations
     */
    private int calculateDamage(String hitZone, double distance) {
        int baseDamage = getBaseDamage(hitZone);
        
        // SMGs maintain damage better at medium ranges
        if (distance > effectiveRange * 0.7) {
            double rangePenalty = (distance - effectiveRange * 0.7) / 800.0;
            double multiplier = Math.max(0.2, 1.0 - rangePenalty);
            return (int)(baseDamage * multiplier);
        }
        
        return baseDamage;
    }
    
    private int getBaseDamage(String hitZone) {
        switch (hitZone.toUpperCase()) {
            case "HEAD":
                return headshotDamage;
            case "CHEST":
                return chestDamage;
            case "TORSO":
            case "BODY":
                return torsoDamage;
            case "LEG":
                return legDamage;
            case "FOOT":
                return footDamage;
            default:
                return torsoDamage;
        }
    }
    
    /**
     * Fast reload characteristic of SMGs
     */
    public void reload() {
        if (currentAmmo == maxAmmo) {
            System.out.println("Magazine is full!");
            return;
        }
        
        if (isReloading) {
            System.out.println("Already reloading!");
            return;
        }
        
        isReloading = true;
        System.out.println("Vector fast reload in progress...");
        
        new Thread(() -> {
            try {
                // Vector has faster reload time
                Thread.sleep((long)(reloadTime * 1000));
                currentAmmo = maxAmmo;
                isReloading = false;
                System.out.println("Vector reloaded! Ammo: " + currentAmmo + "/" + maxAmmo);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                isReloading = false;
            }
        }).start();
    }
    
    /**
     * Vector-specific tactical reload (faster when not empty)
     */
    public void tacticalReload() {
        if (currentAmmo == maxAmmo) {
            System.out.println("Magazine is full!");
            return;
        }
        
        double tacticalReloadTime = reloadTime * 0.7; // 30% faster tactical reload
        isReloading = true;
        System.out.println("Vector tactical reload...");
        
        new Thread(() -> {
            try {
                Thread.sleep((long)(tacticalReloadTime * 1000));
                currentAmmo = maxAmmo;
                isReloading = false;
                System.out.println("Tactical reload complete! Ammo: " + currentAmmo + "/" + maxAmmo);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                isReloading = false;
            }
        }).start();
    }
    
    /**
     * Display Vector's advanced tracking feedback
     */
    private void displayTrackingFeedback(double distance, String hitZone) {
        if (trackingEnabled) {
            if (hitZone.equals("HEAD")) {
                System.out.println("  ★ Precision headshot acquired by tracking system");
            }
            
            if (distance > 300) {
                System.out.println("  ↳ Long-range target tracked successfully");
            }
        }
    }
    
    private boolean canFire() {
        if (isReloading) {
            System.out.println("Vector is reloading!");
            return false;
        }
        
        if (currentAmmo <= 0) {
            System.out.println("Vector is out of ammo! Reload needed.");
            return false;
        }
        
        if (isFiring) {
            System.out.println("Vector is already firing!");
            return false;
        }
        
        return true;
    }
    
    /**
     * Toggle advanced tracking system
     */
    public void toggleTracking() {
        trackingEnabled = !trackingEnabled;
        System.out.println("Vector tracking system: " + 
                          (trackingEnabled ? "ACTIVE" : "STANDBY"));
    }
    
    /**
     * Calculate bullet travel time with Vector's ballistics
     */
    public double calculateTravelTime(double distance) {
        return distance / bulletSpeed;
    }
    
    /**
     * Display Vector's unique specifications
     */
    public void displayWeaponStats() {
        System.out.println("\n=== " + name + " ===");
        System.out.println("Model: " + model);
        System.out.println("Caliber: " + caliber);
        System.out.println("Bullet Velocity: " + bulletSpeed + " m/s");
        System.out.println("Fire Rate: " + fireRate + " RPM");
        System.out.println("Effective Range: " + effectiveRange + "m");
        System.out.println("Magazine Capacity: " + maxAmmo + " rounds");
        System.out.println("Tracking System: " + (trackingEnabled ? "ADVANCED ACTIVE" : "STANDBY"));
        System.out.println("Target Priority: " + primaryTarget + " > " + secondaryTarget);
        System.out.println("Current Ammo: " + currentAmmo + "/" + maxAmmo);
        System.out.println("Reload Time: " + reloadTime + "s (Tactical: " + String.format("%.1fs", reloadTime * 0.7) + ")");
        System.out.println("Damage Profile:");
        System.out.println("  Headshot: " + headshotDamage + " damage");
        System.out.println("  Chest: " + chestDamage + " damage");
        System.out.println("  Torso: " + torsoDamage + " damage");
        System.out.println("  Legs: " + legDamage + " damage");
        System.out.println("  Feet: " + footDamage + " damage");
        System.out.println("Special Features: Advanced tracking, Low recoil, Fast handling");
    }
    
    /**
     * Get quick status summary
     */
    public String getStatus() {
        return String.format("Vector Status: %d/%d | Tracking: %s | Ready: %s",
                currentAmmo, maxAmmo,
                trackingEnabled ? "ON" : "OFF",
                !isReloading ? "YES" : "RELOADING");
    }
    
    // Getters
    public String getName() { return name; }
    public String getModel() { return model; }
    public double getBulletSpeed() { return bulletSpeed; }
    public double getFireRate() { return fireRate; }
    public double getEffectiveRange() { return effectiveRange; }
    public boolean isTrackingEnabled() { return trackingEnabled; }
    public int getCurrentAmmo() { return currentAmmo; }
    public boolean isReloading() { return isReloading; }
    public double getAccuracy() { return accuracy; }
}
//TJB








//TJB










//TJB

//TJB









//TJB










//TJB
//TJB
//TJB