/**
 * Galaxy Strike Online - Game Data
 * Static game data, constants, and configuration
 */

// Game configuration
const GAME_CONFIG = {
    version: '1.0.0',
    name: 'Galaxy Strike Online',
    maxLevel: 100,
    saveInterval: 30000, // 30 seconds
    notificationDuration: 3000,
    maxNotifications: 5
};

// Player defaults
const PLAYER_DEFAULTS = {
    level: 1,
    experience: 0,
    skillPoints: 0,
    credits: 1000,
    gems: 10,
    health: 100,
    maxHealth: 100,
    energy: 100,
    maxEnergy: 100,
    attack: 10,
    defense: 5,
    speed: 10,
    criticalChance: 0.05,
    criticalDamage: 1.5
};

// Experience requirements
const EXPERIENCE_TABLE = [];
for (let i = 1; i <= 100; i++) {
    EXPERIENCE_TABLE[i] = Math.floor(100 * Math.pow(1.5, i - 1));
}

// Item rarities with colors and multipliers
const ITEM_RARITIES = {
    common: {
        name: 'Common',
        color: '#888888',
        multiplier: 1.0,
        dropChance: 0.60
    },
    uncommon: {
        name: 'Uncommon',
        color: '#00ff00',
        multiplier: 1.2,
        dropChance: 0.25
    },
    rare: {
        name: 'Rare',
        color: '#0088ff',
        multiplier: 1.5,
        dropChance: 0.10
    },
    epic: {
        name: 'Epic',
        color: '#8833ff',
        multiplier: 2.0,
        dropChance: 0.04
    },
    legendary: {
        name: 'Legendary',
        color: '#ff8800',
        multiplier: 3.0,
        dropChance: 0.01
    }
};

// Enemy types and stats
const ENEMY_TEMPLATES = {
    space_pirate: {
        name: 'Space Pirate',
        health: 25,
        attack: 10,
        defense: 3,
        speed: 8,
        experience: 15,
        credits: 12,
        rarity: 'common'
    },
    alien_guardian: {
        name: 'Alien Guardian',
        health: 50,
        attack: 8,
        defense: 5,
        speed: 6,
        experience: 25,
        credits: 15,
        rarity: 'common'
    },
    mining_drone: {
        name: 'Mining Drone',
        health: 20,
        attack: 8,
        defense: 3,
        speed: 5,
        experience: 12,
        credits: 8,
        rarity: 'common'
    },
    security_drone: {
        name: 'Security Drone',
        health: 35,
        attack: 14,
        defense: 4,
        speed: 10,
        experience: 22,
        credits: 15,
        rarity: 'uncommon'
    },
    pirate_captain: {
        name: 'Pirate Captain',
        health: 40,
        attack: 15,
        defense: 6,
        speed: 12,
        experience: 30,
        credits: 20,
        rarity: 'uncommon'
    },
    crystal_golem: {
        name: 'Crystal Golem',
        health: 80,
        attack: 6,
        defense: 10,
        speed: 4,
        experience: 35,
        credits: 25,
        rarity: 'rare'
    },
    corrupted_ai: {
        name: 'Corrupted AI',
        health: 60,
        attack: 20,
        defense: 2,
        speed: 15,
        experience: 40,
        credits: 30,
        rarity: 'rare'
    },
    energy_being: {
        name: 'Energy Being',
        health: 55,
        attack: 22,
        defense: 3,
        speed: 18,
        experience: 45,
        credits: 35,
        rarity: 'epic'
    },
    quantum_entity: {
        name: 'Quantum Entity',
        health: 70,
        attack: 35,
        defense: 5,
        speed: 20,
        experience: 60,
        credits: 50,
        rarity: 'legendary'
    }
};

// Dungeon configurations
const DUNGEON_CONFIGS = {
    alien_ruins: {
        name: 'Alien Ruins',
        description: 'Ancient alien structures filled with mysterious technology',
        difficulty: 'medium',
        minLevel: 3,
        roomCount: [5, 8],
        enemyTypes: ['alien_guardian', 'ancient_drone', 'crystal_golem'],
        rewardMultiplier: 1.2,
        energyCost: 20
    },
    pirate_lair: {
        name: 'Pirate Lair',
        description: 'Dangerous pirate hideouts with valuable loot',
        difficulty: 'easy',
        minLevel: 1,
        roomCount: [4, 6],
        enemyTypes: ['space_pirate', 'pirate_captain', 'defense_turret'],
        rewardMultiplier: 1.0,
        energyCost: 15
    },
    corrupted_vault: {
        name: 'Corrupted AI Vault',
        description: 'Malfunctioning AI facilities with corrupted security',
        difficulty: 'hard',
        minLevel: 5,
        roomCount: [6, 9],
        enemyTypes: ['security_drone', 'corrupted_ai', 'virus_program'],
        rewardMultiplier: 1.5,
        energyCost: 25
    },
    asteroid_mine: {
        name: 'Asteroid Mine',
        description: 'Abandoned mining facilities in asteroid fields',
        difficulty: 'easy',
        minLevel: 2,
        roomCount: [4, 7],
        enemyTypes: ['mining_drone', 'rock_creature', 'explosive_asteroid'],
        rewardMultiplier: 0.8,
        energyCost: 10
    },
    nebula_anomaly: {
        name: 'Nebula Anomaly',
        description: 'Strange energy anomalies in deep space',
        difficulty: 'extreme',
        minLevel: 8,
        roomCount: [7, 10],
        enemyTypes: ['energy_being', 'phase_shifter', 'quantum_entity'],
        rewardMultiplier: 2.0,
        energyCost: 30
    }
};

// Skill definitions
const SKILL_DEFINITIONS = {
    combat: {
        weapons_mastery: {
            name: 'Weapons Mastery',
            description: 'Increases weapon damage and critical chance',
            maxLevel: 10,
            experiencePerLevel: 100,
            effects: {
                attack: 2,
                criticalChance: 0.01
            },
            icon: 'fa-sword'
        },
        shield_techniques: {
            name: 'Shield Techniques',
            description: 'Improves defense and energy efficiency',
            maxLevel: 10,
            experiencePerLevel: 100,
            effects: {
                defense: 2,
                maxEnergy: 5
            },
            icon: 'fa-shield-alt'
        },
        piloting: {
            name: 'Piloting',
            description: 'Enhances speed and evasion',
            maxLevel: 10,
            experiencePerLevel: 100,
            effects: {
                speed: 2,
                criticalChance: 0.005
            },
            icon: 'fa-rocket'
        }
    },
    science: {
        energy_manipulation: {
            name: 'Energy Manipulation',
            description: 'Better energy control and regeneration',
            maxLevel: 10,
            experiencePerLevel: 100,
            effects: {
                maxEnergy: 10,
                energyRegeneration: 0.1
            },
            icon: 'fa-bolt'
        },
        alien_technology: {
            name: 'Alien Technology',
            description: 'Understanding and using alien artifacts',
            maxLevel: 10,
            experiencePerLevel: 150,
            effects: {
                findRarity: 0.05,
                itemValue: 0.1
            },
            icon: 'fa-atom'
        }
    },
    crafting: {
        weapon_crafting: {
            name: 'Weapon Crafting',
            description: 'Create and upgrade weapons',
            maxLevel: 10,
            experiencePerLevel: 100,
            effects: {
                craftingBonus: 0.1,
                weaponStats: 0.05
            },
            icon: 'fa-hammer'
        },
        armor_forging: {
            name: 'Armor Forging',
            description: 'Forge protective armor and shields',
            maxLevel: 10,
            experiencePerLevel: 100,
            effects: {
                craftingBonus: 0.1,
                armorStats: 0.05
            },
            icon: 'fa-anvil'
        }
    }
};

// Shop items
const SHOP_ITEMS = {
    ships: [
        {
            id: 'fighter_mk1',
            name: 'Fighter Mk. I',
            type: 'ship',
            rarity: 'common',
            price: 5000,
            currency: 'credits',
            description: 'Fast and agile fighter ship',
            stats: { attack: 15, speed: 20, defense: 8 }
        },
        {
            id: 'cruiser_mk1',
            name: 'Cruiser Mk. I',
            type: 'ship',
            rarity: 'uncommon',
            price: 15000,
            currency: 'credits',
            description: 'Well-balanced cruiser for combat',
            stats: { attack: 20, speed: 10, defense: 15 }
        }
    ],
    upgrades: [
        {
            id: 'weapon_upgrade_1',
            name: 'Weapon Upgrade I',
            type: 'upgrade',
            rarity: 'common',
            price: 500,
            currency: 'credits',
            description: 'Increases weapon damage by 10%',
            effect: { attackMultiplier: 1.1 }
        },
        {
            id: 'shield_upgrade_1',
            name: 'Shield Upgrade I',
            type: 'upgrade',
            rarity: 'common',
            price: 400,
            currency: 'credits',
            description: 'Increases defense by 5 points',
            effect: { defense: 5 }
        }
    ],
    cosmetics: [
        {
            id: 'blue_paint',
            name: 'Blue Paint Job',
            type: 'cosmetic',
            rarity: 'common',
            price: 100,
            currency: 'gems',
            description: 'Custom blue paint for your ship'
        },
        {
            id: 'golden_trim',
            name: 'Golden Trim',
            type: 'cosmetic',
            rarity: 'rare',
            price: 500,
            currency: 'gems',
            description: 'Luxurious golden trim for your ship'
        }
    ],
    consumables: [
        {
            id: 'mega_health_kit',
            name: 'Mega Health Kit',
            type: 'consumable',
            rarity: 'uncommon',
            price: 50,
            currency: 'credits',
            description: 'Restores full health',
            effect: { heal: 999 }
        },
        {
            id: 'energy_boost',
            name: 'Energy Boost',
            type: 'consumable',
            rarity: 'common',
            price: 25,
            currency: 'credits',
            description: 'Restores 50 energy',
            effect: { energy: 50 }
        }
    ]
};

// Starter equipment for new players
const STARTER_EQUIPMENT = {
    starter_blaster: {
        id: 'starter_blaster',
        name: 'Common Blaster',
        type: 'weapon',
        rarity: 'common',
        description: 'A reliable basic blaster for new pilots',
        stats: { attack: 5, criticalChance: 0.02 },
        equipable: true,
        slot: 'weapon',
        value: 100,
        stackable: false
    },
    basic_armor: {
        id: 'basic_armor',
        name: 'Basic Armor',
        type: 'armor',
        rarity: 'common',
        description: 'Standard issue armor for basic protection',
        stats: { defense: 3, health: 10 },
        equipable: true,
        slot: 'armor',
        value: 150,
        stackable: false
    }
};

// Achievement definitions
const ACHIEVEMENTS = {
    first_victory: {
        name: 'First Victory',
        description: 'Win your first dungeon',
        requirement: { dungeonsCompleted: 1 },
        reward: { gems: 10, experience: 100 },
        icon: 'fa-trophy'
    },
    dungeon_master: {
        name: 'Dungeon Master',
        description: 'Complete 50 dungeons',
        requirement: { dungeonsCompleted: 50 },
        reward: { gems: 100, experience: 1000 },
        icon: 'fa-dungeon'
    },
    level_master: {
        name: 'Level Master',
        description: 'Reach level 50',
        requirement: { level: 50 },
        reward: { gems: 200, experience: 5000 },
        icon: 'fa-level-up-alt'
    },
    wealthy_commander: {
        name: 'Wealthy Commander',
        description: 'Accumulate 1,000,000 credits',
        requirement: { credits: 1000000 },
        reward: { gems: 150, experience: 2000 },
        icon: 'fa-coins'
    },
    skill_expert: {
        name: 'Skill Expert',
        description: 'Max out any skill',
        requirement: { maxSkillLevel: 10 },
        reward: { gems: 75, experience: 1500 },
        icon: 'fa-graduation-cap'
    }
};

// Game messages and notifications
const GAME_MESSAGES = {
    welcome: 'Welcome to Galaxy Strike Online, Commander!',
    levelUp: 'Level Up! You are now level {level}!',
    questCompleted: 'Quest completed: {questName}!',
    dungeonCompleted: 'Dungeon completed! Time: {time}',
    achievementUnlocked: 'Achievement Unlocked: {achievementName}!',
    insufficientCredits: 'Not enough credits!',
    insufficientGems: 'Not enough gems!',
    insufficientEnergy: 'Not enough energy!',
    inventoryFull: 'Inventory is full!',
    skillPointsAvailable: 'You have {points} skill points available!',
    dailyReward: 'Daily reward claimed! Day {day}',
    offlineRewards: 'Welcome back! You were offline for {time}'
};

// Utility functions
const GameUtils = {
    // Get random item from array
    getRandomItem(array) {
        return array[Math.floor(Math.random() * array.length)];
    },
    
    // Get random integer between min and max (inclusive)
    getRandomInt(min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    },
    
    // Get random float between min and max
    getRandomFloat(min, max) {
        return Math.random() * (max - min) + min;
    },
    
    // Check if chance succeeds
    checkChance(chance) {
        return Math.random() < chance;
    },
    
    // Format large numbers with suffixes
    formatNumber(num) {
        if (num >= 1000000) return (num / 1000000).toFixed(1) + 'M';
        if (num >= 1000) return (num / 1000).toFixed(1) + 'K';
        return Math.floor(num).toString();
    },
    
    // Format time in milliseconds to readable string
    formatTime(milliseconds) {
        const seconds = Math.floor(milliseconds / 1000);
        const minutes = Math.floor(seconds / 60);
        const hours = Math.floor(minutes / 60);
        const days = Math.floor(hours / 24);
        
        if (days > 0) return `${days}d ${hours % 24}h`;
        if (hours > 0) return `${hours}h ${minutes % 60}m`;
        if (minutes > 0) return `${minutes}m ${seconds % 60}s`;
        return `${seconds}s`;
    },
    
    // Calculate experience needed for level
    getExperienceForLevel(level) {
        return EXPERIENCE_TABLE[level] || 0;
    },
    
    // Get item rarity by chance
    getItemRarity() {
        const roll = Math.random();
        let cumulative = 0;
        
        for (const [rarity, data] of Object.entries(ITEM_RARITIES)) {
            cumulative += data.dropChance;
            if (roll <= cumulative) {
                return rarity;
            }
        }
        
        return 'common';
    },
    
    // Deep clone object
    deepClone(obj) {
        return JSON.parse(JSON.stringify(obj));
    },
    
    // Generate unique ID
    generateId() {
        return Date.now().toString() + Math.random().toString(36).substr(2, 9);
    }
};

// Export for use in other modules
if (typeof module !== 'undefined' && module.exports) {
    module.exports = {
        GAME_CONFIG,
        PLAYER_DEFAULTS,
        EXPERIENCE_TABLE,
        ITEM_RARITIES,
        ENEMY_TEMPLATES,
        DUNGEON_CONFIGS,
        SKILL_DEFINITIONS,
        SHOP_ITEMS,
        ACHIEVEMENTS,
        GAME_MESSAGES,
        GameUtils
    };
}
