From d7d3999401ad5b6997639a793be7321228e31999 Mon Sep 17 00:00:00 2001 From: Ryan Lanny Jenkins Date: Sun, 25 May 2025 11:29:31 -0500 Subject: [PATCH] Add perennial plants, starting with olives. --- src/constants/index.ts | 29 ++++++++++++++++++++++++++++- src/store/useGameStore.ts | 16 ++++++++++++++-- src/types/index.ts | 3 +++ 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/constants/index.ts b/src/constants/index.ts index b7b02d3..258d3e5 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -22,6 +22,7 @@ export const CROPS: CropDefinitions = { yield: 1, yieldType: 'celery', fertilityDepletion: 0.1, + seedType: 'celery_seed', }, corn: { id: 'corn', @@ -31,6 +32,19 @@ export const CROPS: CropDefinitions = { yield: 5, yieldType: 'corn', fertilityDepletion: 0.3, + seedType: 'corn_seed', + }, + olive: { + id: 'olive', + name: 'Olive Tree', + growthTicks: 200, + waterPerTick: 1 / 50, + yield: 5, + yieldType: 'olive', + fertilityDepletion: 0.1, + seedType: 'olive', // Uses olives as seeds + isPerennial: true, + regrowthProgress: 150, // Resets to 150 ticks after harvest }, } @@ -101,5 +115,18 @@ export const MARKET_ITEMS: Record = { buyPrice: null, sellPrice: 5, }, - corn: { id: 'corn', name: 'Corn', emoji: '🌽', buyPrice: null, sellPrice: 8 }, + corn: { + id: 'corn', + name: 'Corn', + emoji: '🌽', + buyPrice: null, + sellPrice: 8, + }, + olive: { + id: 'olive', + name: 'Olive', + emoji: '🫒', + buyPrice: 15, + sellPrice: null, + }, } diff --git a/src/store/useGameStore.ts b/src/store/useGameStore.ts index 3ff46fe..f17cb0f 100644 --- a/src/store/useGameStore.ts +++ b/src/store/useGameStore.ts @@ -144,7 +144,8 @@ export const useGameStore = create< const plot = plots[row][col] if (plot.intended && !plot.current) { - const seedId = `${plot.intended}_seed` + const crop = CROPS[plot.intended] + const seedId = crop.seedType if (inventory[seedId] && inventory[seedId] > 0) { set( @@ -207,7 +208,18 @@ export const useGameStore = create< set( produce((state) => { - state.plots[row][col].current = undefined + if (crop.isPerennial) { + // For perennial crops, reset progress instead of clearing + state.plots[row][col].current = { + cropId: plot.current!.cropId, + progress: crop.regrowthProgress!, + mature: false, + } + } else { + // For regular crops, clear the plot + state.plots[row][col].current = undefined + } + state.inventory[yieldItem] = (state.inventory[yieldItem] || 0) + yieldAmount state.plots[row][col].fertility = Math.max( diff --git a/src/types/index.ts b/src/types/index.ts index f8ce71a..3c8e243 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -6,6 +6,9 @@ export interface Crop { yield: number yieldType: string fertilityDepletion: number + seedType: string + isPerennial?: boolean + regrowthProgress?: number } export interface CropDefinitions {