Files
novafarma/src/systems/WorkerCreaturesSystem.js
2025-12-13 00:02:38 +01:00

445 lines
13 KiB
JavaScript

/**
* WORKER CREATURES SYSTEM
* Specialized creature workers with unique abilities
*/
class WorkerCreaturesSystem {
constructor(scene) {
this.scene = scene;
this.enabled = true;
// Worker creatures
this.workers = new Map();
// Creature types
this.creatureTypes = new Map();
// Active tasks
this.activeTasks = [];
this.init();
console.log('✅ Worker Creatures System initialized');
}
init() {
this.defineCreatureTypes();
console.log('🦌 Worker creatures ready');
}
// ========== CREATURE TYPES ==========
defineCreatureTypes() {
// Donkey - Transport specialist
this.defineCreature('donkey', {
name: 'Donkey',
specialty: 'transport',
efficiency: 0.8,
abilities: ['carry_items', 'cart_transport', 'long_distance'],
carryCapacity: 50,
speed: 1.2,
tamingDifficulty: 'easy',
cost: { carrot: 10, apple: 5 }
});
// Bigfoot - Forest gathering specialist
this.defineCreature('bigfoot', {
name: 'Bigfoot',
specialty: 'gathering',
efficiency: 1.0,
abilities: ['tree_chopping', 'berry_picking', 'mushroom_finding', 'forest_navigation'],
gatherBonus: 1.5,
speed: 0.9,
tamingDifficulty: 'medium',
cost: { honey: 5, berries: 20 }
});
// Yeti - Snow biome specialist
this.defineCreature('yeti', {
name: 'Yeti',
specialty: 'snow_tasks',
efficiency: 1.2,
abilities: ['ice_mining', 'snow_clearing', 'cold_resistance', 'ice_fishing'],
coldBonus: 2.0,
speed: 0.8,
tamingDifficulty: 'hard',
cost: { frozen_meat: 10, ice_crystal: 3 }
});
// Elf - Crafting specialist
this.defineCreature('elf', {
name: 'Elf',
specialty: 'crafting',
efficiency: 1.5,
abilities: ['auto_craft', 'enchanting', 'potion_making', 'tool_repair'],
craftingSpeed: 2.0,
speed: 1.0,
tamingDifficulty: 'hard',
cost: { magic_dust: 5, golden_apple: 2 }
});
// Gnome - Mining specialist
this.defineCreature('gnome', {
name: 'Gnome',
specialty: 'mining',
efficiency: 1.3,
abilities: ['ore_detection', 'tunnel_digging', 'gem_finding', 'cave_navigation'],
miningBonus: 1.8,
speed: 0.7,
tamingDifficulty: 'medium',
cost: { gold_nugget: 5, diamond: 1 }
});
// Fairy - Plant care specialist
this.defineCreature('fairy', {
name: 'Fairy',
specialty: 'plant_care',
efficiency: 1.4,
abilities: ['instant_growth', 'disease_cure', 'crop_blessing', 'flower_magic'],
growthBonus: 2.5,
speed: 1.5,
tamingDifficulty: 'very_hard',
cost: { rainbow_flower: 3, fairy_dust: 10 }
});
// Golem - Heavy labor specialist
this.defineCreature('golem', {
name: 'Golem',
specialty: 'heavy_labor',
efficiency: 0.9,
abilities: ['boulder_moving', 'building_construction', 'land_clearing', 'defense'],
strengthBonus: 3.0,
speed: 0.5,
tamingDifficulty: 'very_hard',
cost: { stone: 100, iron: 50, magic_core: 1 }
});
// Dragon - Ultimate worker
this.defineCreature('dragon', {
name: 'Dragon',
specialty: 'all',
efficiency: 2.0,
abilities: ['flight', 'fire_breath', 'treasure_finding', 'all_tasks'],
allBonus: 2.0,
speed: 2.0,
tamingDifficulty: 'legendary',
cost: { dragon_egg: 1, legendary_meat: 10, gold: 1000 }
});
}
defineCreature(id, data) {
this.creatureTypes.set(id, {
id,
...data
});
}
// ========== TAMING ==========
canTame(creatureType) {
const creature = this.creatureTypes.get(creatureType);
if (!creature) return false;
// Check if player has required items
if (!this.scene.inventorySystem) return false;
for (const [item, amount] of Object.entries(creature.cost)) {
const has = this.scene.inventorySystem.getItemCount(item);
if (has < amount) {
console.log(`❌ Missing ${item}: ${has}/${amount}`);
return false;
}
}
return true;
}
tameCreature(creatureType, x, y) {
if (!this.canTame(creatureType)) return false;
const creatureData = this.creatureTypes.get(creatureType);
// Consume taming items
for (const [item, amount] of Object.entries(creatureData.cost)) {
this.scene.inventorySystem.removeItem(item, amount);
}
// Create worker
const worker = {
id: `worker_${creatureType}_${Date.now()}`,
type: creatureType,
name: creatureData.name,
specialty: creatureData.specialty,
efficiency: creatureData.efficiency,
abilities: creatureData.abilities,
x, y,
currentTask: null,
level: 1,
xp: 0,
loyalty: 50,
sprite: null
};
this.workers.set(worker.id, worker);
// Notify automation tier system
if (this.scene.automationTiers) {
this.scene.automationTiers.befriendCreature();
}
// Visual effect
if (this.scene.visualEnhancements) {
this.scene.visualEnhancements.createSparkleEffect(x, y);
this.scene.visualEnhancements.screenFlash(0x00ff00, 500);
}
console.log(`✅ Tamed ${creatureData.name}!`);
return worker;
}
// ========== TASK ASSIGNMENT ==========
assignTask(workerId, task) {
const worker = this.workers.get(workerId);
if (!worker) return false;
const creatureData = this.creatureTypes.get(worker.type);
// Check if creature can do this task
if (!this.canDoTask(worker, task)) {
console.log(`${worker.name} cannot do ${task.type}`);
return false;
}
// Assign task
worker.currentTask = {
...task,
startTime: Date.now(),
efficiency: this.calculateEfficiency(worker, task)
};
console.log(`📋 ${worker.name} assigned to ${task.type}`);
return true;
}
canDoTask(worker, task) {
const creatureData = this.creatureTypes.get(worker.type);
// Dragons can do everything
if (worker.type === 'dragon') return true;
// Check specialty
const taskSpecialties = {
'transport': ['donkey'],
'gather_wood': ['bigfoot'],
'gather_berries': ['bigfoot'],
'mine_ice': ['yeti'],
'ice_fishing': ['yeti'],
'craft_item': ['elf'],
'enchant_item': ['elf'],
'mine_ore': ['gnome'],
'find_gems': ['gnome'],
'water_crops': ['fairy'],
'grow_crops': ['fairy'],
'build': ['golem'],
'clear_land': ['golem']
};
const validTypes = taskSpecialties[task.type] || [];
return validTypes.includes(worker.type);
}
calculateEfficiency(worker, task) {
const creatureData = this.creatureTypes.get(worker.type);
let efficiency = creatureData.efficiency;
// Apply specialty bonuses
if (task.type.includes('gather') && creatureData.gatherBonus) {
efficiency *= creatureData.gatherBonus;
}
if (task.type.includes('mine') && creatureData.miningBonus) {
efficiency *= creatureData.miningBonus;
}
if (task.type.includes('craft') && creatureData.craftingSpeed) {
efficiency *= creatureData.craftingSpeed;
}
if (task.type.includes('grow') && creatureData.growthBonus) {
efficiency *= creatureData.growthBonus;
}
// Apply level bonus
efficiency *= (1 + worker.level * 0.1);
return efficiency;
}
// ========== TASK EXECUTION ==========
updateWorkers(delta) {
for (const worker of this.workers.values()) {
if (!worker.currentTask) continue;
const elapsed = Date.now() - worker.currentTask.startTime;
const taskTime = worker.currentTask.duration / worker.currentTask.efficiency;
if (elapsed >= taskTime) {
this.completeTask(worker);
}
}
}
completeTask(worker) {
const task = worker.currentTask;
// Execute task
this.executeTask(worker, task);
// Grant XP
this.addWorkerXP(worker, task.xp || 10);
// Increase loyalty
worker.loyalty = Math.min(100, worker.loyalty + 1);
// Clear task
worker.currentTask = null;
console.log(`${worker.name} completed ${task.type}!`);
}
executeTask(worker, task) {
switch (task.type) {
case 'transport':
this.transportItems(worker, task);
break;
case 'gather_wood':
this.gatherResource(worker, 'wood', task.amount);
break;
case 'gather_berries':
this.gatherResource(worker, 'berries', task.amount);
break;
case 'mine_ore':
this.gatherResource(worker, 'ore', task.amount);
break;
case 'craft_item':
this.craftItem(worker, task.item);
break;
case 'grow_crops':
this.growCrops(worker, task.crops);
break;
default:
console.log(`Unknown task: ${task.type}`);
}
}
transportItems(worker, task) {
// Move items from A to B
console.log(`🚚 ${worker.name} transported items`);
}
gatherResource(worker, resource, amount) {
// Add resource to inventory
if (this.scene.inventorySystem) {
const bonus = this.workers.get(worker.id).currentTask.efficiency;
const finalAmount = Math.floor(amount * bonus);
this.scene.inventorySystem.addItem(resource, finalAmount);
console.log(`📦 Gathered ${finalAmount} ${resource}`);
}
}
craftItem(worker, item) {
// Craft item
if (this.scene.inventorySystem) {
this.scene.inventorySystem.addItem(item, 1);
console.log(`🔨 Crafted ${item}`);
}
}
growCrops(worker, crops) {
// Instantly grow crops
console.log(`🌱 Grew ${crops.length} crops`);
}
// ========== LEVELING ==========
addWorkerXP(worker, amount) {
worker.xp += amount;
const xpNeeded = this.getXPForLevel(worker.level + 1);
if (worker.xp >= xpNeeded) {
this.levelUpWorker(worker);
}
}
getXPForLevel(level) {
return Math.floor(100 * Math.pow(1.5, level - 1));
}
levelUpWorker(worker) {
worker.level++;
worker.xp = 0;
console.log(`🎉 ${worker.name} leveled up to ${worker.level}!`);
// Visual effect
if (this.scene.visualEnhancements) {
this.scene.visualEnhancements.createSparkleEffect(worker.x, worker.y);
}
}
// ========== SPECIAL ABILITIES ==========
useAbility(workerId, abilityName) {
const worker = this.workers.get(workerId);
if (!worker) return false;
const creatureData = this.creatureTypes.get(worker.type);
if (!creatureData.abilities.includes(abilityName)) {
console.log(`${worker.name} doesn't have ${abilityName}`);
return false;
}
// Execute ability
switch (abilityName) {
case 'instant_growth':
this.instantGrowth(worker);
break;
case 'fire_breath':
this.fireBreath(worker);
break;
case 'treasure_finding':
this.findTreasure(worker);
break;
default:
console.log(`${worker.name} used ${abilityName}!`);
}
return true;
}
instantGrowth(worker) {
// Fairy ability - instantly grow all nearby crops
console.log('🌸 Fairy magic! All crops instantly grown!');
}
fireBreath(worker) {
// Dragon ability - clear area with fire
console.log('🔥 Dragon fire breath!');
}
findTreasure(worker) {
// Dragon ability - find hidden treasure
console.log('💎 Found treasure!');
if (this.scene.inventorySystem) {
this.scene.inventorySystem.addItem('gold', 100);
}
}
// ========== UPDATE ==========
update(delta) {
this.updateWorkers(delta);
}
destroy() {
console.log('🦌 Worker Creatures System destroyed');
}
}