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
This commit is contained in:
filemon
2026-03-25 11:33:05 -03:00
parent 247b94f3b3
commit 2ad64bbca7
2 changed files with 27 additions and 10 deletions
@@ -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) {
@@ -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({