From 2ad64bbca71d12df328c8e86eb429c8da108ff6c Mon Sep 17 00:00:00 2001 From: filemon Date: Wed, 25 Mar 2026 11:33:05 -0300 Subject: [PATCH] Filter egg-only items from companion interaction system Since companions can only be baby or adult (not egg), egg-only items like Shell Repair Kit should never appear in the companion flow. Changes: - Update resolveItemsForAction to use centralized canUseItemForStage - Add item-stage validation in useBlobbiItemUse mutation - Egg-only items are now filtered at both display and use layers The filtering is now enforced by: 1. resolveItemsForAction - items won't appear in hanging items menu 2. useBlobbiItemUse - validation prevents use even if somehow displayed --- .../companion/interaction/useBlobbiItemUse.ts | 8 +++++ .../interaction/useCompanionActionMenu.ts | 29 ++++++++++++------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/blobbi/companion/interaction/useBlobbiItemUse.ts b/src/blobbi/companion/interaction/useBlobbiItemUse.ts index 0d69e7ff..24bba331 100644 --- a/src/blobbi/companion/interaction/useBlobbiItemUse.ts +++ b/src/blobbi/companion/interaction/useBlobbiItemUse.ts @@ -43,6 +43,7 @@ import { applyItemEffects, decrementStorageItem, canUseAction, + canUseItemForStage, getStageRestrictionMessage, clampStat, applyStat, @@ -243,6 +244,13 @@ export function useBlobbiItemUse(options: UseBlobbiItemUseOptions = {}): UseBlob throw new Error('Item not found in catalog'); } + // Validate item can be used by this companion's stage + // This catches egg-only items (like Shell Repair Kit) being used by baby/adult companions + const itemUsability = canUseItemForStage(itemId, companion.stage); + if (!itemUsability.canUse) { + throw new Error(itemUsability.reason ?? 'This item cannot be used by this companion'); + } + // Validate item exists in storage with sufficient quantity const storageItem = profile.storage.find(s => s.itemId === itemId); if (!storageItem || storageItem.quantity <= 0) { diff --git a/src/blobbi/companion/interaction/useCompanionActionMenu.ts b/src/blobbi/companion/interaction/useCompanionActionMenu.ts index 4d6619f4..568530ae 100644 --- a/src/blobbi/companion/interaction/useCompanionActionMenu.ts +++ b/src/blobbi/companion/interaction/useCompanionActionMenu.ts @@ -20,6 +20,7 @@ import { useLocation } from 'react-router-dom'; import { useBlobbonautProfile } from '@/hooks/useBlobbonautProfile'; import { getShopItemById } from '@/blobbi/shop/lib/blobbi-shop-items'; import type { StorageItem } from '@/lib/blobbi'; +import { canUseItemForStage } from '@/blobbi/actions/lib/blobbi-action-utils'; import type { CompanionMenuAction, @@ -68,6 +69,15 @@ interface UseCompanionActionMenuResult { /** * Resolve inventory items for a specific action/category. + * + * Uses the centralized `canUseItemForStage` function to ensure consistent + * stage-based filtering across all UIs: + * - Egg-only items (like Shell Repair Kit) are excluded for baby/adult companions + * - Baby/adult-only items (food, toys) are excluded for eggs + * - Items without relevant effects are excluded + * + * Since companions can only be baby or adult (not egg), this effectively + * filters out all egg-only items from the companion interaction system. */ function resolveItemsForAction( storage: StorageItem[], @@ -88,16 +98,15 @@ function resolveItemsForAction( if (!shopItem) continue; if (shopItem.type !== category) continue; - // Stage-specific filtering - if (stage === 'egg') { - // Eggs can only use certain items - if (category === 'food' || category === 'toy') { - continue; // Eggs can't eat or play with toys - } - // For medicine, check if it has health effect - if (category === 'medicine' && !shopItem.effect?.health) { - continue; - } + // Use centralized stage-based filtering + // This handles: + // - Shell Repair Kit: only for eggs (excluded for baby/adult companions) + // - Food/Toys: only for baby/adult (excluded for eggs) + // - Medicine: must have health effect + // - Hygiene: must have hygiene or happiness effect + const usability = canUseItemForStage(storageItem.itemId, stage); + if (!usability.canUse) { + continue; } items.push({