narejeno
This commit is contained in:
454
src/systems/AutomationTierSystem.js
Normal file
454
src/systems/AutomationTierSystem.js
Normal file
@@ -0,0 +1,454 @@
|
||||
/**
|
||||
* FARM AUTOMATION TIERS SYSTEM
|
||||
* Progressive automation from manual labor to AI-driven farm
|
||||
*/
|
||||
class AutomationTierSystem {
|
||||
constructor(scene) {
|
||||
this.scene = scene;
|
||||
this.enabled = true;
|
||||
|
||||
// Current tier
|
||||
this.currentTier = 1;
|
||||
|
||||
// Tier definitions
|
||||
this.tiers = {
|
||||
1: {
|
||||
name: 'Manual Labor',
|
||||
description: 'Player does everything',
|
||||
efficiency: 1.0,
|
||||
automation: 0,
|
||||
unlockRequirement: null,
|
||||
features: ['manual_farming', 'manual_crafting', 'manual_building']
|
||||
},
|
||||
2: {
|
||||
name: 'Zombie Workers',
|
||||
description: 'Basic automation with zombie workers',
|
||||
efficiency: 0.5,
|
||||
automation: 0.3,
|
||||
unlockRequirement: { type: 'tame_zombies', count: 5 },
|
||||
features: ['zombie_workers', 'simple_tasks', 'task_queue']
|
||||
},
|
||||
3: {
|
||||
name: 'Creature Helpers',
|
||||
description: 'Specialized automation with creatures',
|
||||
efficiency: 0.75,
|
||||
automation: 0.6,
|
||||
unlockRequirement: { type: 'befriend_creatures', count: 10 },
|
||||
features: ['creature_workers', 'complex_tasks', 'crafting_automation', 'sorting']
|
||||
},
|
||||
4: {
|
||||
name: 'Mechanical Automation',
|
||||
description: 'Full automation with machines',
|
||||
efficiency: 1.0,
|
||||
automation: 0.9,
|
||||
unlockRequirement: { type: 'build_all_automation', buildings: ['auto_planter', 'auto_harvester', 'irrigation', 'conveyor', 'silo', 'sorter'] },
|
||||
features: ['24_7_operation', 'no_management', 'full_automation']
|
||||
},
|
||||
5: {
|
||||
name: 'AI Farm',
|
||||
description: 'Self-sustaining AI-driven farm',
|
||||
efficiency: 1.5,
|
||||
automation: 1.0,
|
||||
unlockRequirement: { type: 'complete_quest', quest: 'singularity' },
|
||||
features: ['self_optimizing', 'resource_balancing', 'profit_collection', 'ai_decisions']
|
||||
}
|
||||
};
|
||||
|
||||
// Tier progress
|
||||
this.tierProgress = {
|
||||
zombiesTamed: 0,
|
||||
creaturesBefriended: 0,
|
||||
automationBuildings: [],
|
||||
questsCompleted: []
|
||||
};
|
||||
|
||||
// AI Farm settings (Tier 5)
|
||||
this.aiSettings = {
|
||||
optimizationInterval: 60000, // 1 minute
|
||||
resourceBalanceThreshold: 0.8,
|
||||
profitCollectionInterval: 300000, // 5 minutes
|
||||
lastOptimization: 0,
|
||||
lastProfitCollection: 0
|
||||
};
|
||||
|
||||
this.loadProgress();
|
||||
this.init();
|
||||
|
||||
console.log('✅ Automation Tier System initialized');
|
||||
}
|
||||
|
||||
init() {
|
||||
console.log(`🤖 Current Tier: ${this.currentTier} - ${this.tiers[this.currentTier].name}`);
|
||||
}
|
||||
|
||||
// ========== TIER MANAGEMENT ==========
|
||||
|
||||
checkTierUnlock(tier) {
|
||||
const tierData = this.tiers[tier];
|
||||
if (!tierData || !tierData.unlockRequirement) return false;
|
||||
|
||||
const req = tierData.unlockRequirement;
|
||||
|
||||
switch (req.type) {
|
||||
case 'tame_zombies':
|
||||
return this.tierProgress.zombiesTamed >= req.count;
|
||||
|
||||
case 'befriend_creatures':
|
||||
return this.tierProgress.creaturesBefriended >= req.count;
|
||||
|
||||
case 'build_all_automation':
|
||||
return req.buildings.every(b =>
|
||||
this.tierProgress.automationBuildings.includes(b)
|
||||
);
|
||||
|
||||
case 'complete_quest':
|
||||
return this.tierProgress.questsCompleted.includes(req.quest);
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
upgradeTier() {
|
||||
const nextTier = this.currentTier + 1;
|
||||
|
||||
if (nextTier > 5) {
|
||||
console.log('❌ Already at max tier!');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.checkTierUnlock(nextTier)) {
|
||||
console.log(`❌ Requirements not met for Tier ${nextTier}`);
|
||||
this.showTierRequirements(nextTier);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Upgrade!
|
||||
this.currentTier = nextTier;
|
||||
this.applyTierBonuses();
|
||||
|
||||
// Visual effect
|
||||
if (this.scene.visualEnhancements) {
|
||||
const player = this.scene.player;
|
||||
if (player) {
|
||||
const pos = player.getPosition();
|
||||
this.scene.visualEnhancements.createSparkleEffect(pos.x, pos.y);
|
||||
this.scene.visualEnhancements.screenFlash(0x00ff00, 500);
|
||||
}
|
||||
}
|
||||
|
||||
// Achievement
|
||||
if (this.scene.uiGraphics) {
|
||||
if (this.currentTier === 5) {
|
||||
this.scene.uiGraphics.unlockAchievement('ai_farm_master');
|
||||
}
|
||||
}
|
||||
|
||||
this.saveProgress();
|
||||
console.log(`🎉 Upgraded to Tier ${this.currentTier}: ${this.tiers[this.currentTier].name}!`);
|
||||
return true;
|
||||
}
|
||||
|
||||
showTierRequirements(tier) {
|
||||
const tierData = this.tiers[tier];
|
||||
const req = tierData.unlockRequirement;
|
||||
|
||||
console.log(`📋 Requirements for ${tierData.name}:`);
|
||||
|
||||
switch (req.type) {
|
||||
case 'tame_zombies':
|
||||
console.log(` - Tame ${req.count} zombies (${this.tierProgress.zombiesTamed}/${req.count})`);
|
||||
break;
|
||||
|
||||
case 'befriend_creatures':
|
||||
console.log(` - Befriend ${req.count} creatures (${this.tierProgress.creaturesBefriended}/${req.count})`);
|
||||
break;
|
||||
|
||||
case 'build_all_automation':
|
||||
console.log(` - Build all automation buildings:`);
|
||||
req.buildings.forEach(b => {
|
||||
const built = this.tierProgress.automationBuildings.includes(b);
|
||||
console.log(` ${built ? '✅' : '❌'} ${b}`);
|
||||
});
|
||||
break;
|
||||
|
||||
case 'complete_quest':
|
||||
console.log(` - Complete quest: "${req.quest}"`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
applyTierBonuses() {
|
||||
const tier = this.tiers[this.currentTier];
|
||||
|
||||
// Apply efficiency to all workers
|
||||
if (this.scene.farmAutomation) {
|
||||
for (const worker of this.scene.farmAutomation.zombieWorkers) {
|
||||
worker.efficiency = tier.efficiency;
|
||||
}
|
||||
for (const worker of this.scene.farmAutomation.creatureWorkers) {
|
||||
worker.efficiency = tier.efficiency;
|
||||
}
|
||||
}
|
||||
|
||||
// Enable features
|
||||
this.enableTierFeatures(tier.features);
|
||||
}
|
||||
|
||||
enableTierFeatures(features) {
|
||||
for (const feature of features) {
|
||||
switch (feature) {
|
||||
case '24_7_operation':
|
||||
this.enable24_7Operation();
|
||||
break;
|
||||
|
||||
case 'no_management':
|
||||
this.enableNoManagement();
|
||||
break;
|
||||
|
||||
case 'self_optimizing':
|
||||
this.enableSelfOptimizing();
|
||||
break;
|
||||
|
||||
case 'resource_balancing':
|
||||
this.enableResourceBalancing();
|
||||
break;
|
||||
|
||||
case 'ai_decisions':
|
||||
this.enableAIDecisions();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ========== TIER 2: ZOMBIE WORKERS ==========
|
||||
|
||||
tameZombie() {
|
||||
this.tierProgress.zombiesTamed++;
|
||||
this.checkAutoUpgrade();
|
||||
this.saveProgress();
|
||||
console.log(`🧟 Zombie tamed! (${this.tierProgress.zombiesTamed}/5)`);
|
||||
}
|
||||
|
||||
// ========== TIER 3: CREATURE HELPERS ==========
|
||||
|
||||
befriendCreature() {
|
||||
this.tierProgress.creaturesBefriended++;
|
||||
this.checkAutoUpgrade();
|
||||
this.saveProgress();
|
||||
console.log(`🦌 Creature befriended! (${this.tierProgress.creaturesBefriended}/10)`);
|
||||
}
|
||||
|
||||
// ========== TIER 4: MECHANICAL AUTOMATION ==========
|
||||
|
||||
buildAutomationBuilding(buildingType) {
|
||||
if (!this.tierProgress.automationBuildings.includes(buildingType)) {
|
||||
this.tierProgress.automationBuildings.push(buildingType);
|
||||
this.checkAutoUpgrade();
|
||||
this.saveProgress();
|
||||
console.log(`🏭 Built ${buildingType}! (${this.tierProgress.automationBuildings.length}/6)`);
|
||||
}
|
||||
}
|
||||
|
||||
enable24_7Operation() {
|
||||
// Buildings work 24/7 without stopping
|
||||
if (this.scene.farmAutomation) {
|
||||
for (const building of this.scene.farmAutomation.automationBuildings.values()) {
|
||||
building.alwaysActive = true;
|
||||
}
|
||||
}
|
||||
console.log('⚡ 24/7 operation enabled!');
|
||||
}
|
||||
|
||||
enableNoManagement() {
|
||||
// Workers don't need food/rest
|
||||
if (this.scene.farmAutomation) {
|
||||
for (const worker of [...this.scene.farmAutomation.zombieWorkers, ...this.scene.farmAutomation.creatureWorkers]) {
|
||||
worker.needsManagement = false;
|
||||
worker.hunger = 100;
|
||||
worker.fatigue = 0;
|
||||
}
|
||||
}
|
||||
console.log('🤖 No management needed!');
|
||||
}
|
||||
|
||||
// ========== TIER 5: AI FARM ==========
|
||||
|
||||
completeQuest(questId) {
|
||||
if (!this.tierProgress.questsCompleted.includes(questId)) {
|
||||
this.tierProgress.questsCompleted.push(questId);
|
||||
this.checkAutoUpgrade();
|
||||
this.saveProgress();
|
||||
console.log(`✅ Quest completed: ${questId}`);
|
||||
}
|
||||
}
|
||||
|
||||
enableSelfOptimizing() {
|
||||
console.log('🧠 Self-optimizing AI enabled!');
|
||||
}
|
||||
|
||||
enableResourceBalancing() {
|
||||
console.log('⚖️ Automatic resource balancing enabled!');
|
||||
}
|
||||
|
||||
enableAIDecisions() {
|
||||
console.log('🤖 AI decision-making enabled!');
|
||||
}
|
||||
|
||||
optimizeFarm() {
|
||||
if (this.currentTier < 5) return;
|
||||
|
||||
// AI analyzes farm and makes decisions
|
||||
const decisions = [];
|
||||
|
||||
// Check resource levels
|
||||
if (this.scene.inventorySystem) {
|
||||
const resources = this.scene.inventorySystem.items;
|
||||
|
||||
// Low on seeds? Plant more
|
||||
if (resources.wheat_seeds < 10) {
|
||||
decisions.push({ action: 'plant_wheat', priority: 'high' });
|
||||
}
|
||||
|
||||
// Too much wood? Craft tools
|
||||
if (resources.wood > 100) {
|
||||
decisions.push({ action: 'craft_tools', priority: 'medium' });
|
||||
}
|
||||
|
||||
// Low on food? Harvest crops
|
||||
if (resources.wheat < 20) {
|
||||
decisions.push({ action: 'harvest_crops', priority: 'high' });
|
||||
}
|
||||
}
|
||||
|
||||
// Execute decisions
|
||||
for (const decision of decisions) {
|
||||
this.executeAIDecision(decision);
|
||||
}
|
||||
|
||||
this.aiSettings.lastOptimization = Date.now();
|
||||
}
|
||||
|
||||
executeAIDecision(decision) {
|
||||
console.log(`🤖 AI Decision: ${decision.action} (${decision.priority} priority)`);
|
||||
|
||||
// Add task to automation queue
|
||||
if (this.scene.farmAutomation) {
|
||||
this.scene.farmAutomation.addToTaskQueue({
|
||||
type: decision.action,
|
||||
priority: decision.priority === 'high' ? 3 : decision.priority === 'medium' ? 2 : 1
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
balanceResources() {
|
||||
if (this.currentTier < 5) return;
|
||||
|
||||
// AI balances resources automatically
|
||||
// Convert excess resources to needed ones
|
||||
|
||||
console.log('⚖️ Balancing resources...');
|
||||
|
||||
this.aiSettings.lastProfitCollection = Date.now();
|
||||
}
|
||||
|
||||
collectProfits() {
|
||||
if (this.currentTier < 5) return;
|
||||
|
||||
// Collect all profits from automation
|
||||
let totalProfit = 0;
|
||||
|
||||
if (this.scene.farmAutomation) {
|
||||
// Calculate profits from all automated systems
|
||||
totalProfit += this.scene.farmAutomation.zombieWorkers.length * 10;
|
||||
totalProfit += this.scene.farmAutomation.creatureWorkers.length * 20;
|
||||
totalProfit += this.scene.farmAutomation.automationBuildings.size * 50;
|
||||
}
|
||||
|
||||
if (this.scene.inventorySystem) {
|
||||
this.scene.inventorySystem.gold += totalProfit;
|
||||
}
|
||||
|
||||
console.log(`💰 Collected ${totalProfit} gold from automation!`);
|
||||
}
|
||||
|
||||
// ========== AUTO-UPGRADE ==========
|
||||
|
||||
checkAutoUpgrade() {
|
||||
const nextTier = this.currentTier + 1;
|
||||
if (nextTier <= 5 && this.checkTierUnlock(nextTier)) {
|
||||
this.upgradeTier();
|
||||
}
|
||||
}
|
||||
|
||||
// ========== UPDATE ==========
|
||||
|
||||
update(delta) {
|
||||
if (this.currentTier < 5) return;
|
||||
|
||||
const now = Date.now();
|
||||
|
||||
// Self-optimization
|
||||
if (now - this.aiSettings.lastOptimization > this.aiSettings.optimizationInterval) {
|
||||
this.optimizeFarm();
|
||||
}
|
||||
|
||||
// Profit collection
|
||||
if (now - this.aiSettings.lastProfitCollection > this.aiSettings.profitCollectionInterval) {
|
||||
this.collectProfits();
|
||||
this.balanceResources();
|
||||
}
|
||||
}
|
||||
|
||||
// ========== GETTERS ==========
|
||||
|
||||
getTierInfo() {
|
||||
return {
|
||||
current: this.currentTier,
|
||||
name: this.tiers[this.currentTier].name,
|
||||
description: this.tiers[this.currentTier].description,
|
||||
efficiency: this.tiers[this.currentTier].efficiency,
|
||||
automation: this.tiers[this.currentTier].automation,
|
||||
features: this.tiers[this.currentTier].features
|
||||
};
|
||||
}
|
||||
|
||||
getProgress() {
|
||||
return {
|
||||
zombiesTamed: this.tierProgress.zombiesTamed,
|
||||
creaturesBefriended: this.tierProgress.creaturesBefriended,
|
||||
automationBuildings: this.tierProgress.automationBuildings.length,
|
||||
questsCompleted: this.tierProgress.questsCompleted.length
|
||||
};
|
||||
}
|
||||
|
||||
// ========== PERSISTENCE ==========
|
||||
|
||||
saveProgress() {
|
||||
const data = {
|
||||
currentTier: this.currentTier,
|
||||
tierProgress: this.tierProgress
|
||||
};
|
||||
|
||||
localStorage.setItem('novafarma_automation_tiers', JSON.stringify(data));
|
||||
}
|
||||
|
||||
loadProgress() {
|
||||
const saved = localStorage.getItem('novafarma_automation_tiers');
|
||||
if (saved) {
|
||||
try {
|
||||
const data = JSON.parse(saved);
|
||||
this.currentTier = data.currentTier || 1;
|
||||
this.tierProgress = data.tierProgress || this.tierProgress;
|
||||
console.log('✅ Automation tier progress loaded');
|
||||
} catch (error) {
|
||||
console.error('Failed to load tier progress:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.saveProgress();
|
||||
console.log('🤖 Automation Tier System destroyed');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user