From e62de83301c2de02b4041009a900f154363f2517 Mon Sep 17 00:00:00 2001 From: Vadym Abakumov Date: Mon, 9 Mar 2026 01:18:30 +0100 Subject: [PATCH] refactor: replace decayRate with decayDuration in pet needs config Makes it easier to reason about decay timing by specifying how long each need takes to fully drain from 100 to 0 in ms instead of a rate. Also removes unused label field from PetNeedConfig. Co-Authored-By: Claude Sonnet 4.6 --- packages/types/src/pet/config.ts | 15 +++++---------- packages/types/src/pet/types.ts | 3 +-- packages/types/src/pet/utils.ts | 4 +--- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/packages/types/src/pet/config.ts b/packages/types/src/pet/config.ts index da98c0a..16eed81 100644 --- a/packages/types/src/pet/config.ts +++ b/packages/types/src/pet/config.ts @@ -27,36 +27,31 @@ export const getPetScale = (petType: PetType | 'egg'): number => { export const PET_NEEDS_CONFIG = { [PetNeed.HYGIENE]: { - label: 'Hygiene', - decayRate: 0.28, + decayDuration: 6 * 60 * 60 * 1000, urgencyMessage: 'I need a bath!', category: PetActionCategory.WASH, animation: PetAnimation.BATH, }, [PetNeed.TOILET]: { - label: 'Toilet', - decayRate: 0.56, + decayDuration: 3 * 60 * 60 * 1000, urgencyMessage: 'I need to go to the toilet!', category: PetActionCategory.CARE, animation: PetAnimation.TOILET, }, [PetNeed.HUNGER]: { - label: 'Hunger', - decayRate: 0.42, + decayDuration: 4 * 60 * 60 * 1000, urgencyMessage: "I'm hungry!", category: PetActionCategory.FEED, animation: PetAnimation.EAT, }, [PetNeed.THIRST]: { - label: 'Thirst', - decayRate: 0.83, + decayDuration: 2 * 60 * 60 * 1000, urgencyMessage: "I'm thirsty!", category: PetActionCategory.DRINK, animation: PetAnimation.DRINK, }, [PetNeed.ENERGY]: { - label: 'Energy', - decayRate: 0.33, + decayDuration: 5 * 60 * 60 * 1000, urgencyMessage: "I'm tired!", category: PetActionCategory.CARE, animation: PetAnimation.SLEEP, diff --git a/packages/types/src/pet/types.ts b/packages/types/src/pet/types.ts index 779b18d..f39c744 100644 --- a/packages/types/src/pet/types.ts +++ b/packages/types/src/pet/types.ts @@ -2,8 +2,7 @@ import { Database } from '../database'; import { PetActionCategory, PetAnimation, PetNeed, PetType } from './enums'; export interface PetNeedConfig { - label: string; - decayRate: number; + decayDuration: number; urgencyMessage: string; category: PetActionCategory; animation: PetAnimation; diff --git a/packages/types/src/pet/utils.ts b/packages/types/src/pet/utils.ts index 6fda581..e85aafd 100644 --- a/packages/types/src/pet/utils.ts +++ b/packages/types/src/pet/utils.ts @@ -2,8 +2,6 @@ import { PET_NEED_KEYS, PET_NEEDS_CONFIG } from './config'; import { PET_UPDATE_INTERVAL } from './constants'; import { PetNeeds } from './types'; -const DECAY_TIME_UNIT_MS = 60 * 1000; - export const calculateDecayedNeeds = ( needs: PetNeeds, lastUpdatedAt: Date, @@ -16,7 +14,7 @@ export const calculateDecayedNeeds = ( const updated = { ...needs }; for (const key of PET_NEED_KEYS) { - const decrease = intervals * PET_NEEDS_CONFIG[key].decayRate * (PET_UPDATE_INTERVAL / DECAY_TIME_UNIT_MS); + const decrease = (intervals * PET_UPDATE_INTERVAL * 100) / PET_NEEDS_CONFIG[key].decayDuration; updated[key] = Math.max(0, Math.min(100, needs[key] - decrease)); }