From 7140ae69879a4b7f7445c9c7a77dbb027e781e01 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Sat, 10 Oct 2026 19:35:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=95=86=E5=BA=97=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages-user/data-base/src/shop/types.ts | 95 +++++++++++++++++++++++ packages-user/data-state/src/common.ts | 11 +++ src/content/core.jsonc | 12 ++- 3 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 packages-user/data-base/src/shop/types.ts diff --git a/packages-user/data-base/src/shop/types.ts b/packages-user/data-base/src/shop/types.ts new file mode 100644 index 0000000..fd5153f --- /dev/null +++ b/packages-user/data-base/src/shop/types.ts @@ -0,0 +1,95 @@ +import { ISaveableContent } from '@user/data-common'; + +export interface IShopStateSave { + /** 商店 id */ + readonly id: string; + /** 当前商店是否已启用 */ + readonly enabled: boolean; + /** 商店拥有的库存 */ + readonly items: ReadonlyMap; +} + +export interface IShopState extends ISaveableContent { + /** 当前商店是否已经启用 */ + readonly enabled: boolean; + + /** + * 向此商店添加或减少道具库存,会与原本的库存叠加 + * @param token 道具数字或 id + * @param count 添加或减少的道具数量,正数表示添加,负数表示减少 + */ + addItem(token: number | string, count: number): void; + + /** + * 获取指定道具的库存数量,不存在道具则返回 -1 + * @param token 道具数字或 id + */ + getCount(token: number | string): number; + + /** + * 迭代商店拥有的所有道具 + */ + iterateItems(): Iterable<[number, number]>; + + /** + * 启用该商店 + */ + enable(): void; + + /** + * 禁用该商店 + */ + disable(): void; +} + +export interface IShopManagerSave { + /** 商店状态列表 */ + readonly list: IShopStateSave[]; +} + +export interface IShopManager extends ISaveableContent { + /** + * 添加新的商店 + * @param shop 商店状态对象 + */ + addShop(shop: IShopState): void; + + /** + * 移除已有商店 + * @param shop 商店 id 或其状态对象 + */ + removeShop(shop: string | IShopState): void; + + /** + * 根据商店 id 获取其状态对象 + * @param id 商店 id + */ + getShop(id: string): IShopState | null; + + /** + * 迭代当前的所有商店,包括未启用的 + */ + iterateShops(): Iterable<[string, IShopState]>; + + /** + * 迭代当前所有已启用的商店 + */ + iterateEnabledShops(): Iterable<[string, IShopState]>; + + /** + * 迭代当前所有未启用的商店 + */ + iterateDisabledShops(): Iterable<[string, IShopState]>; + + /** + * 启用指定商店 + * @param shop 商店 id 或其状态对象 + */ + enableShop(shop: string | IShopState): void; + + /** + * 禁用指定商店 + * @param shop 商店 id 或其状态对象 + */ + disableShop(shop: string | IShopState): void; +} diff --git a/packages-user/data-state/src/common.ts b/packages-user/data-state/src/common.ts index 8e0c724..e165261 100644 --- a/packages-user/data-state/src/common.ts +++ b/packages-user/data-state/src/common.ts @@ -44,11 +44,22 @@ export interface ICoreStateHeroInitConfig { readonly attribute: Readonly; } +export interface ICoreStateShopInitConfig { + /** 该商店的 id */ + readonly id: string; + /** 初始状态下该商店是否启用 */ + readonly enabled: boolean; + /** 商店初始状态下拥有的库存 */ + readonly items: [number, number][]; +} + export interface ICoreStateInitConfig { /** 初始事件 id,游戏开始时将在执行完毕此事件后正式开始 */ readonly startEvent: string; /** 勇士初始状态,包含起始位置、初始属性等 */ readonly hero: ICoreStateHeroInitConfig; + /** 商店初始状态 */ + readonly shop: ICoreStateShopInitConfig[]; } export interface ICoreStateFlagConfig { diff --git a/src/content/core.jsonc b/src/content/core.jsonc index 432e6ae..d77e4af 100644 --- a/src/content/core.jsonc +++ b/src/content/core.jsonc @@ -38,7 +38,17 @@ "money": 0, "exp": 0 } - } + }, + "shop": [ + { + "id": "test-shop", + "enabled": false, + "items": [ + [100, 2], + [101, 3] + ] + } + ] }, "flag": { "flyNearStair": false,