558 lines
22 KiB
JavaScript
558 lines
22 KiB
JavaScript
/**
|
||
* ANIMALS & SEEDS SYSTEM
|
||
* Manages animal shop unlock, 16+ livestock types, seasonal seed shop, fruit trees, and greenhouse.
|
||
*
|
||
* Features:
|
||
* - Animal Shop Unlock: "Animal Rescue" quest, find 8 wild animals, 30-day breeding
|
||
* - 16+ Livestock: Normal + Mutant variants, Rainbow Chicken, Golden Goose
|
||
* - Seasonal Seed Shop: 100+ seed varieties across 4 seasons
|
||
* - Fruit Trees: 7 types (Cherry, Apple, Peach, etc.) + Ancient Fruit, Starfruit (legendary!)
|
||
* - Greenhouse System: Override seasonal restrictions, year-round farming
|
||
*/
|
||
class AnimalsSeedsSystem {
|
||
constructor(scene) {
|
||
this.scene = scene;
|
||
|
||
// Animal shop status
|
||
this.animalShopUnlocked = false;
|
||
this.animalRescueProgress = 0; // 0-8 animals found
|
||
|
||
// Livestock types
|
||
this.livestockTypes = {
|
||
// Normal variants
|
||
chicken: { name: 'Chicken', product: 'egg', productionTime: 1, cost: 100, rarity: 'common' },
|
||
cow: { name: 'Cow', product: 'milk', productionTime: 2, cost: 500, rarity: 'common' },
|
||
sheep: { name: 'Sheep', product: 'wool', productionTime: 3, cost: 300, rarity: 'common' },
|
||
goat: { name: 'Goat', product: 'goat_milk', productionTime: 2, cost: 400, rarity: 'common' },
|
||
pig: { name: 'Pig', product: 'truffle', productionTime: 3, cost: 600, rarity: 'common' },
|
||
rabbit: { name: 'Rabbit', product: 'rabbit_foot', productionTime: 1, cost: 200, rarity: 'common' },
|
||
duck: { name: 'Duck', product: 'duck_egg', productionTime: 1, cost: 150, rarity: 'common' },
|
||
ostrich: { name: 'Ostrich', product: 'giant_egg', productionTime: 7, cost: 1000, rarity: 'uncommon' },
|
||
|
||
// Mutant variants
|
||
mutant_chicken: { name: 'Mutant Chicken', product: 'void_egg', productionTime: 1, cost: 500, rarity: 'rare', mutation: true },
|
||
mutant_cow: { name: 'Mutant Cow', product: 'mutant_milk', productionTime: 2, cost: 2000, rarity: 'rare', mutation: true },
|
||
mutant_pig: { name: 'Mutant Pig', product: 'radioactive_truffle', productionTime: 3, cost: 2500, rarity: 'rare', mutation: true },
|
||
|
||
// Legendary variants
|
||
rainbow_chicken: { name: 'Rainbow Chicken', product: 'rainbow_egg', productionTime: 1, cost: 5000, rarity: 'legendary', special: true },
|
||
golden_goose: { name: 'Golden Goose', product: 'golden_egg', productionTime: 7, cost: 10000, rarity: 'legendary', special: true },
|
||
fairy_cow: { name: 'Fairy Cow', product: 'fairy_milk', productionTime: 2, cost: 7500, rarity: 'legendary', special: true },
|
||
phoenix_chicken: { name: 'Phoenix Chicken', product: 'phoenix_feather', productionTime: 14, cost: 15000, rarity: 'legendary', special: true },
|
||
unicorn: { name: 'Unicorn', product: 'unicorn_horn', productionTime: 30, cost: 25000, rarity: 'mythic', special: true }
|
||
};
|
||
|
||
// Player's livestock
|
||
this.playerLivestock = new Map();
|
||
|
||
// Seasonal seeds (100+ varieties!)
|
||
this.seasonalSeeds = {
|
||
spring: this.generateSpringSeeds(),
|
||
summer: this.generateSummerSeeds(),
|
||
fall: this.generateFallSeeds(),
|
||
winter: this.generateWinterSeeds()
|
||
};
|
||
|
||
// Fruit trees
|
||
this.fruitTrees = {
|
||
cherry: { name: 'Cherry Tree', fruit: 'cherry', season: 'spring', growTime: 28, production: 3, cost: 1000 },
|
||
apple: { name: 'Apple Tree', fruit: 'apple', season: 'fall', growTime: 28, production: 3, cost: 1000 },
|
||
peach: { name: 'Peach Tree', fruit: 'peach', season: 'summer', growTime: 28, production: 3, cost: 1200 },
|
||
orange: { name: 'Orange Tree', fruit: 'orange', season: 'winter', growTime: 28, production: 3, cost: 1200 },
|
||
pomegranate: { name: 'Pomegranate Tree', fruit: 'pomegranate', season: 'summer', growTime: 28, production: 2, cost: 1500 },
|
||
mango: { name: 'Mango Tree', fruit: 'mango', season: 'summer', growTime: 28, production: 2, cost: 1800 },
|
||
banana: { name: 'Banana Tree', fruit: 'banana', season: 'year_round', growTime: 28, production: 5, cost: 2000 },
|
||
ancient_fruit: { name: 'Ancient Fruit Tree', fruit: 'ancient_fruit', season: 'year_round', growTime: 56, production: 1, cost: 10000, legendary: true },
|
||
starfruit: { name: 'Starfruit Tree', fruit: 'starfruit', season: 'year_round', growTime: 84, production: 1, cost: 25000, legendary: true }
|
||
};
|
||
|
||
// Player's fruit trees
|
||
this.playerTrees = new Map();
|
||
|
||
// Greenhouse status
|
||
this.greenhousesBuilt = [];
|
||
|
||
console.log('🐄🌱 Animals & Seeds System initialized!');
|
||
}
|
||
|
||
/**
|
||
* Generate spring seeds (25 varieties)
|
||
*/
|
||
generateSpringSeeds() {
|
||
return [
|
||
{ name: 'Parsnip', growTime: 4, sellPrice: 35, cost: 20 },
|
||
{ name: 'Green Bean', growTime: 10, sellPrice: 40, cost: 60, regrow: 3 },
|
||
{ name: 'Cauliflower', growTime: 12, sellPrice: 175, cost: 80 },
|
||
{ name: 'Potato', growTime: 6, sellPrice: 80, cost: 50 },
|
||
{ name: 'Tulip', growTime: 6, sellPrice: 30, cost: 20 },
|
||
{ name: 'Kale', growTime: 6, sellPrice: 110, cost: 70 },
|
||
{ name: 'Jazz Seeds', growTime: 7, sellPrice: 50, cost: 30 },
|
||
{ name: 'Garlic', growTime: 4, sellPrice: 60, cost: 40 },
|
||
{ name: 'Rhubarb', growTime: 13, sellPrice: 220, cost: 100 },
|
||
{ name: 'Strawberry', growTime: 8, sellPrice: 120, cost: 100, regrow: 4 },
|
||
// Add 15 more varieties...
|
||
{ name: 'Spring Onion', growTime: 5, sellPrice: 45, cost: 25 },
|
||
{ name: 'Daffodil', growTime: 6, sellPrice: 35, cost: 20 },
|
||
{ name: 'Primrose', growTime: 7, sellPrice: 50, cost: 30 },
|
||
{ name: 'Wild Lettuce', growTime: 5, sellPrice: 55, cost: 35 },
|
||
{ name: 'Radish', growTime: 4, sellPrice: 40, cost: 25 },
|
||
{ name: 'Peas', growTime: 8, sellPrice: 65, cost: 45, regrow: 3 },
|
||
{ name: 'Spinach', growTime: 6, sellPrice: 50, cost: 30 },
|
||
{ name: 'Artichoke', growTime: 14, sellPrice: 200, cost: 120 },
|
||
{ name: 'Turnip', growTime: 5, sellPrice: 50, cost: 30 },
|
||
{ name: 'Carrot', growTime: 7, sellPrice: 70, cost: 45 },
|
||
{ name: 'Leek', growTime: 8, sellPrice: 80, cost: 55 },
|
||
{ name: 'Chive', growTime: 4, sellPrice: 35, cost: 20 },
|
||
{ name: 'Asparagus', growTime: 15, sellPrice: 250, cost: 150 },
|
||
{ name: 'Sweet Pea', growTime: 9, sellPrice: 90, cost: 60 },
|
||
{ name: 'Blue Jazz', growTime: 7, sellPrice: 50, cost: 30 }
|
||
];
|
||
}
|
||
|
||
/**
|
||
* Generate summer seeds (25 varieties)
|
||
*/
|
||
generateSummerSeeds() {
|
||
return [
|
||
{ name: 'Tomato', growTime: 11, sellPrice: 60, cost: 50, regrow: 4 },
|
||
{ name: 'Melon', growTime: 12, sellPrice: 250, cost: 80 },
|
||
{ name: 'Blueberry', growTime: 13, sellPrice: 50, cost: 80, regrow: 4 },
|
||
{ name: 'Hot Pepper', growTime: 5, sellPrice: 40, cost: 40, regrow: 3 },
|
||
{ name: 'Wheat', growTime: 4, sellPrice: 25, cost: 10 },
|
||
{ name: 'Radish', growTime: 6, sellPrice: 90, cost: 40 },
|
||
{ name: 'Poppy', growTime: 7, sellPrice: 140, cost: 100 },
|
||
{ name: 'Corn', growTime: 14, sellPrice: 50, cost: 150, regrow: 4 },
|
||
{ name: 'Hops', growTime: 11, sellPrice: 25, cost: 60, regrow: 1 },
|
||
{ name: 'Red Cabbage', growTime: 9, sellPrice: 260, cost: 100 },
|
||
// Add 15 more...
|
||
{ name: 'Watermelon', growTime: 12, sellPrice: 300, cost: 100 },
|
||
{ name: 'Cucumber', growTime: 8, sellPrice: 45, cost: 35, regrow: 3 },
|
||
{ name: 'Eggplant', growTime: 10, sellPrice: 80, cost: 55 },
|
||
{ name: 'Zucchini', growTime: 7, sellPrice: 55, cost: 40, regrow: 3 },
|
||
{ name: 'Bell Pepper', growTime: 9, sellPrice: 70, cost: 50 },
|
||
{ name: 'Sunflower', growTime: 8, sellPrice: 80, cost: 60 },
|
||
{ name: 'Pumpkin Seed (Summer)', growTime: 13, sellPrice: 150, cost: 90 },
|
||
{ name: 'Cantaloupe', growTime: 11, sellPrice: 200, cost: 85 },
|
||
{ name: 'Summer Squash', growTime: 6, sellPrice: 60, cost: 40 },
|
||
{ name: 'Okra', growTime: 8, sellPrice: 65, cost: 45, regrow: 3 },
|
||
{ name: 'Basil', growTime: 5, sellPrice: 40, cost: 25 },
|
||
{ name: 'Cherry Tomato', growTime: 9, sellPrice: 50, cost: 40, regrow: 3 },
|
||
{ name: 'Tomatillo', growTime: 10, sellPrice: 75, cost: 55 },
|
||
{ name: 'Lima Bean', growTime: 12, sellPrice: 90, cost: 65, regrow: 4 },
|
||
{ name: 'String Bean', growTime: 8, sellPrice: 55, cost: 40, regrow: 3 }
|
||
];
|
||
}
|
||
|
||
/**
|
||
* Generate fall seeds (25 varieties)
|
||
*/
|
||
generateFallSeeds() {
|
||
return [
|
||
{ name: 'Corn', growTime: 14, sellPrice: 50, cost: 150, regrow: 4 },
|
||
{ name: 'Pumpkin', growTime: 13, sellPrice: 320, cost: 100 },
|
||
{ name: 'Eggplant', growTime: 5, sellPrice: 60, cost: 20, regrow: 5 },
|
||
{ name: 'Bok Choy', growTime: 4, sellPrice: 80, cost: 50 },
|
||
{ name: 'Yam', growTime: 10, sellPrice: 160, cost: 60 },
|
||
{ name: 'Amaranth', growTime: 7, sellPrice: 150, cost: 70 },
|
||
{ name: 'Grape', growTime: 10, sellPrice: 80, cost: 60, regrow: 3 },
|
||
{ name: 'Artichoke', growTime: 8, sellPrice: 160, cost: 30 },
|
||
{ name: 'Cranberries', growTime: 7, sellPrice: 75, cost: 240, regrow: 5 },
|
||
{ name: 'Fairy Rose', growTime: 12, sellPrice: 290, cost: 200 },
|
||
// Add 15 more...
|
||
{ name: 'Acorn Squash', growTime: 12, sellPrice: 180, cost: 95 },
|
||
{ name: 'Butternut Squash', growTime: 14, sellPrice: 220, cost: 110 },
|
||
{ name: 'Sweet Potato', growTime: 9, sellPrice: 130, cost: 70 },
|
||
{ name: 'Carrot (Fall)', growTime: 7, sellPrice: 80, cost: 50 },
|
||
{ name: 'Beetroot', growTime: 6, sellPrice: 90, cost: 55 },
|
||
{ name: 'Broccoli', growTime: 8, sellPrice: 100, cost: 65 },
|
||
{ name: 'Brussels Sprouts', growTime: 10, sellPrice: 120, cost: 75, regrow: 4 },
|
||
{ name: 'Cauliflower (Fall)', growTime: 11, sellPrice: 180, cost: 85 },
|
||
{ name: 'Kale (Fall)', growTime: 7, sellPrice: 115, cost: 75 },
|
||
{ name: 'Leek (Fall)', growTime: 9, sellPrice: 95, cost: 60 },
|
||
{ name: 'Parsnip (Fall)', growTime: 5, sellPrice: 45, cost: 25 },
|
||
{ name: 'Spinach (Fall)', growTime: 6, sellPrice: 55, cost: 35 },
|
||
{ name: 'Turnip (Fall)', growTime: 5, sellPrice: 50, cost: 30 },
|
||
{ name: 'Sunflower (Fall)', growTime: 8, sellPrice: 85, cost: 65 },
|
||
{ name: 'Wheat (Fall)', growTime: 4, sellPrice: 30, cost: 15 }
|
||
];
|
||
}
|
||
|
||
/**
|
||
* Generate winter seeds (25 varieties - greenhouse only!)
|
||
*/
|
||
generateWinterSeeds() {
|
||
return [
|
||
{ name: 'Winter Seeds (Forage Mix)', growTime: 7, sellPrice: 30, cost: 5 },
|
||
{ name: 'Snow Yam', growTime: 7, sellPrice: 100, cost: 0, forage: true },
|
||
{ name: 'Crocus', growTime: 7, sellPrice: 60, cost: 0, forage: true },
|
||
{ name: 'Winter Root', growTime: 7, sellPrice: 70, cost: 0, forage: true },
|
||
{ name: 'Crystal Fruit', growTime: 7, sellPrice: 150, cost: 0, forage: true },
|
||
// Greenhouse-only crops
|
||
{ name: 'Ancient Seed', growTime: 28, sellPrice: 550, cost: 1000 },
|
||
{ name: 'Rare Seed', growTime: 24, sellPrice: 3000, cost: 1000 },
|
||
{ name: 'Coffee Bean', growTime: 10, sellPrice: 15, cost: 100, regrow: 2 },
|
||
{ name: 'Tea Sapling', growTime: 20, sellPrice: 500, cost: 2000 },
|
||
{ name: 'Cactus Fruit Seed', growTime: 14, sellPrice: 150, cost: 50 },
|
||
// Add 15 more...
|
||
{ name: 'Ice Lettuce', growTime: 8, sellPrice: 85, cost: 60, winterOnly: true },
|
||
{ name: 'Frost Flower', growTime: 10, sellPrice: 120, cost: 80, winterOnly: true },
|
||
{ name: 'Snow Pea', growTime: 9, sellPrice: 95, cost: 65, winterOnly: true },
|
||
{ name: 'Winter Cabbage', growTime: 12, sellPrice: 180, cost: 100, winterOnly: true },
|
||
{ name: 'Arctic Berry', growTime: 11, sellPrice: 140, cost: 90, winterOnly: true },
|
||
{ name: 'Pine Cone Crop', growTime: 14, sellPrice: 200, cost: 120, winterOnly: true },
|
||
{ name: 'Evergreen Herb', growTime: 6, sellPrice: 50, cost: 30, winterOnly: true },
|
||
{ name: 'Holly Berry', growTime: 8, sellPrice: 75, cost: 50, winterOnly: true },
|
||
{ name: 'Mistletoe', growTime: 10, sellPrice: 110, cost: 75, winterOnly: true },
|
||
{ name: 'Poinsettia', growTime: 12, sellPrice: 160, cost: 100, winterOnly: true },
|
||
{ name: 'Juniper Berry', growTime: 9, sellPrice: 90, cost: 60, winterOnly: true },
|
||
{ name: 'Ice Flower', growTime: 8, sellPrice: 80, cost: 55, winterOnly: true },
|
||
{ name: 'Glacier Melon', growTime: 15, sellPrice: 350, cost: 180, winterOnly: true },
|
||
{ name: 'Northern Lights Flower', growTime: 13, sellPrice: 250, cost: 150, winterOnly: true },
|
||
{ name: 'Permafrost Root', growTime: 7, sellPrice: 65, cost: 40, winterOnly: true }
|
||
];
|
||
}
|
||
|
||
/**
|
||
* Start Animal Rescue quest
|
||
*/
|
||
startAnimalRescueQuest() {
|
||
console.log('🚨 Quest Started: Animal Rescue!');
|
||
console.log('Find 8 wild animals to unlock the Animal Shop!');
|
||
|
||
this.scene.events.emit('quest-started', {
|
||
id: 'animal_rescue',
|
||
title: 'Animal Rescue',
|
||
description: 'Find 8 wild animals across the world',
|
||
progress: '0/8',
|
||
reward: 'Animal Shop Unlock'
|
||
});
|
||
}
|
||
|
||
/**
|
||
* Rescue a wild animal
|
||
*/
|
||
rescueAnimal(animalType, position) {
|
||
if (this.animalRescueProgress >= 8) {
|
||
console.log('ℹ️ All animals already rescued!');
|
||
return false;
|
||
}
|
||
|
||
this.animalRescueProgress++;
|
||
|
||
console.log(`🐾 Rescued ${animalType}! Progress: ${this.animalRescueProgress}/8`);
|
||
|
||
this.scene.events.emit('quest-progress', {
|
||
id: 'animal_rescue',
|
||
progress: `${this.animalRescueProgress}/8`
|
||
});
|
||
|
||
if (this.animalRescueProgress >= 8) {
|
||
this.unlockAnimalShop();
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* Unlock animal shop
|
||
*/
|
||
unlockAnimalShop() {
|
||
this.animalShopUnlocked = true;
|
||
|
||
console.log('🎉 Animal Shop UNLOCKED!');
|
||
|
||
this.scene.events.emit('notification', {
|
||
title: 'Animal Shop Unlocked!',
|
||
message: 'You can now buy livestock!',
|
||
icon: '🐄'
|
||
});
|
||
|
||
this.scene.events.emit('quest-complete', {
|
||
id: 'animal_rescue',
|
||
reward: 'Animal Shop Access'
|
||
});
|
||
}
|
||
|
||
/**
|
||
* Buy livestock from shop
|
||
*/
|
||
buyLivestock(type) {
|
||
if (!this.animalShopUnlocked) {
|
||
console.log('❌ Animal Shop not unlocked! Complete Animal Rescue quest first.');
|
||
return { success: false, message: 'Shop locked' };
|
||
}
|
||
|
||
const livestock = this.livestockTypes[type];
|
||
if (!livestock) {
|
||
console.log(`❌ Unknown livestock: ${type}`);
|
||
return { success: false, message: 'Unknown type' };
|
||
}
|
||
|
||
// Check if player has gold
|
||
if (this.scene.player && this.scene.player.gold < livestock.cost) {
|
||
return { success: false, message: `Need ${livestock.cost} gold!` };
|
||
}
|
||
|
||
// Deduct gold
|
||
if (this.scene.player) {
|
||
this.scene.player.gold -= livestock.cost;
|
||
}
|
||
|
||
// Create livestock
|
||
const livestockId = this.createLivestock(type);
|
||
|
||
console.log(`🐄 Bought ${livestock.name} for ${livestock.cost} gold!`);
|
||
|
||
return { success: true, livestockId: livestockId };
|
||
}
|
||
|
||
/**
|
||
* Create livestock
|
||
*/
|
||
createLivestock(type) {
|
||
const livestockData = this.livestockTypes[type];
|
||
const livestockId = `${type}_${Date.now()}`;
|
||
|
||
const animal = {
|
||
id: livestockId,
|
||
type: type,
|
||
name: livestockData.name,
|
||
product: livestockData.product,
|
||
productionTime: livestockData.productionTime,
|
||
daysSinceProduction: 0,
|
||
happiness: 100,
|
||
health: 100,
|
||
age: 0,
|
||
breeding: false,
|
||
breedingDaysLeft: 0
|
||
};
|
||
|
||
this.playerLivestock.set(livestockId, animal);
|
||
|
||
return livestockId;
|
||
}
|
||
|
||
/**
|
||
* Update livestock (called daily)
|
||
*/
|
||
updateLivestock() {
|
||
this.playerLivestock.forEach((animal, id) => {
|
||
animal.age++;
|
||
animal.daysSinceProduction++;
|
||
|
||
// Produce item
|
||
if (animal.daysSinceProduction >= animal.productionTime) {
|
||
this.produceAnimalProduct(id);
|
||
animal.daysSinceProduction = 0;
|
||
}
|
||
|
||
// Breeding countdown
|
||
if (animal.breeding) {
|
||
animal.breedingDaysLeft--;
|
||
if (animal.breedingDaysLeft <= 0) {
|
||
this.birthAnimal(id);
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
/**
|
||
* Produce animal product
|
||
*/
|
||
produceAnimalProduct(livestockId) {
|
||
const animal = this.playerLivestock.get(livestockId);
|
||
if (!animal) return;
|
||
|
||
const product = animal.product;
|
||
|
||
console.log(`🥚 ${animal.name} produced ${product}!`);
|
||
|
||
// Add to inventory
|
||
if (this.scene.inventorySystem) {
|
||
this.scene.inventorySystem.addItem(product, 1);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Breed two animals (30 days)
|
||
*/
|
||
breedAnimals(animal1Id, animal2Id) {
|
||
const animal1 = this.playerLivestock.get(animal1Id);
|
||
const animal2 = this.playerLivestock.get(animal2Id);
|
||
|
||
if (!animal1 || !animal2) {
|
||
return { success: false, message: 'Animal not found' };
|
||
}
|
||
|
||
if (animal1.type !== animal2.type) {
|
||
return { success: false, message: 'Animals must be same type!' };
|
||
}
|
||
|
||
if (animal1.breeding || animal2.breeding) {
|
||
return { success: false, message: 'Animal already breeding!' };
|
||
}
|
||
|
||
// Start breeding
|
||
animal1.breeding = true;
|
||
animal1.breedingDaysLeft = 30;
|
||
|
||
console.log(`💕 Breeding ${animal1.name}! Baby in 30 days!`);
|
||
|
||
return { success: true, daysRemaining: 30 };
|
||
}
|
||
|
||
/**
|
||
* Birth new animal
|
||
*/
|
||
birthAnimal(parentId) {
|
||
const parent = this.playerLivestock.get(parentId);
|
||
if (!parent) return;
|
||
|
||
parent.breeding = false;
|
||
|
||
const newLivestockId = this.createLivestock(parent.type);
|
||
|
||
console.log(`🐣 ${parent.name} had a baby!`);
|
||
|
||
this.scene.events.emit('notification', {
|
||
title: 'Baby Born!',
|
||
message: `New ${parent.name} baby!`,
|
||
icon: '🐣'
|
||
});
|
||
}
|
||
|
||
/**
|
||
* Plant fruit tree
|
||
*/
|
||
plantTree(treeType, position) {
|
||
const treeData = this.fruitTrees[treeType];
|
||
if (!treeData) {
|
||
console.log(`❌ Unknown tree type: ${treeType}`);
|
||
return null;
|
||
}
|
||
|
||
// Check if player has gold
|
||
if (this.scene.player && this.scene.player.gold < treeData.cost) {
|
||
return { success: false, message: `Need ${treeData.cost} gold!` };
|
||
}
|
||
|
||
// Deduct gold
|
||
if (this.scene.player) {
|
||
this.scene.player.gold -= treeData.cost;
|
||
}
|
||
|
||
const treeId = `tree_${treeType}_${Date.now()}`;
|
||
const tree = {
|
||
id: treeId,
|
||
type: treeType,
|
||
name: treeData.name,
|
||
fruit: treeData.fruit,
|
||
season: treeData.season,
|
||
production: treeData.production,
|
||
position: position,
|
||
growthDays: 0,
|
||
growTime: treeData.growTime,
|
||
mature: false
|
||
};
|
||
|
||
this.playerTrees.set(treeId, tree);
|
||
|
||
console.log(`🌳 Planted ${treeData.name}! Mature in ${treeData.growTime} days.`);
|
||
|
||
return { success: true, treeId: treeId };
|
||
}
|
||
|
||
/**
|
||
* Update trees (called daily)
|
||
*/
|
||
updateTrees(currentSeason) {
|
||
this.playerTrees.forEach((tree, id) => {
|
||
if (!tree.mature) {
|
||
tree.growthDays++;
|
||
if (tree.growthDays >= tree.growTime) {
|
||
tree.mature = true;
|
||
console.log(`🌳 ${tree.name} is now mature!`);
|
||
}
|
||
} else {
|
||
// Produce fruit if in season or year-round
|
||
if (tree.season === 'year_round' || tree.season === currentSeason) {
|
||
this.produceFruit(id);
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
/**
|
||
* Produce fruit from tree
|
||
*/
|
||
produceFruit(treeId) {
|
||
const tree = this.playerTrees.get(treeId);
|
||
if (!tree || !tree.mature) return;
|
||
|
||
const amount = tree.production;
|
||
|
||
console.log(`🍎 ${tree.name} produced ${amount} ${tree.fruit}!`);
|
||
|
||
// Add to inventory
|
||
if (this.scene.inventorySystem) {
|
||
this.scene.inventorySystem.addItem(tree.fruit, amount);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Build greenhouse
|
||
*/
|
||
buildGreenhouse(position) {
|
||
const greenhouseId = `greenhouse_${Date.now()}`;
|
||
const greenhouse = {
|
||
id: greenhouseId,
|
||
position: position,
|
||
capacity: 100, // 100 crops max
|
||
active: true
|
||
};
|
||
|
||
this.greenhousesBuilt.push(greenhouse);
|
||
|
||
console.log('🏡 Greenhouse built! Year-round farming enabled!');
|
||
|
||
this.scene.events.emit('notification', {
|
||
title: 'Greenhouse Built!',
|
||
message: 'You can now grow crops all year long!',
|
||
icon: '🏡'
|
||
});
|
||
|
||
return greenhouseId;
|
||
}
|
||
|
||
/**
|
||
* Check if crop can grow (season or greenhouse)
|
||
*/
|
||
canPlantSeed(seedName, currentSeason) {
|
||
// Find seed in all seasons
|
||
let seedData = null;
|
||
let seedSeason = null;
|
||
|
||
Object.keys(this.seasonalSeeds).forEach(season => {
|
||
const found = this.seasonalSeeds[season].find(s => s.name === seedName);
|
||
if (found) {
|
||
seedData = found;
|
||
seedSeason = season;
|
||
}
|
||
});
|
||
|
||
if (!seedData) return { canPlant: false, reason: 'Unknown seed' };
|
||
|
||
// Check if correct season
|
||
if (seedSeason === currentSeason) {
|
||
return { canPlant: true, reason: 'In season' };
|
||
}
|
||
|
||
// Check if greenhouse available
|
||
if (this.greenhousesBuilt.length > 0) {
|
||
return { canPlant: true, reason: 'Greenhouse available' };
|
||
}
|
||
|
||
return { canPlant: false, reason: `Wrong season (needs ${seedSeason})` };
|
||
}
|
||
}
|