Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions packages/types/src/pet/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions packages/types/src/pet/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions packages/types/src/pet/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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));
}

Expand Down