From 88b4571da5fbdde44f03d2d6a66e2604426e635f Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Sat, 10 Oct 2026 19:58:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=95=86=E5=BA=97=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages-user/data-base/src/shop/types.ts | 22 ++++++++++ packages-user/data-system/src/shop/types.ts | 45 +++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 packages-user/data-system/src/shop/types.ts diff --git a/packages-user/data-base/src/shop/types.ts b/packages-user/data-base/src/shop/types.ts index fd5153f..b4061da 100644 --- a/packages-user/data-base/src/shop/types.ts +++ b/packages-user/data-base/src/shop/types.ts @@ -7,6 +7,8 @@ export interface IShopStateSave { readonly enabled: boolean; /** 商店拥有的库存 */ readonly items: ReadonlyMap; + /** 商店道具的买入价与售出价 */ + readonly prices: ReadonlyMap; } export interface IShopState extends ISaveableContent { @@ -31,6 +33,20 @@ export interface IShopState extends ISaveableContent { */ iterateItems(): Iterable<[number, number]>; + /** + * 设置道具价格 + * @param item 道具数字或 id + * @param buy 道具买入价格 + * @param sell 道具卖出价格 + */ + setPrice(item: number | string, buy: number, sell: number): void; + + /** + * 获取道具价格 + * @param item 道具数字或 id + */ + getPrice(item: number | string): [buy: number, sell: number]; + /** * 启用该商店 */ @@ -66,6 +82,12 @@ export interface IShopManager extends ISaveableContent { */ getShop(id: string): IShopState | null; + /** + * 判断指定商店是否属于当前管理器 + * @param shop 商店 id 或其状态对象 + */ + hasShop(shop: string | IShopState): boolean; + /** * 迭代当前的所有商店,包括未启用的 */ diff --git a/packages-user/data-system/src/shop/types.ts b/packages-user/data-system/src/shop/types.ts new file mode 100644 index 0000000..1c13eda --- /dev/null +++ b/packages-user/data-system/src/shop/types.ts @@ -0,0 +1,45 @@ +import { IHeroState, IShopManager, IShopState } from '@user/data-base'; + +export interface IShopHeroAttr { + /** 勇士拥有的金币 */ + money: number; +} + +export interface IShopSystem { + /** + * 绑定商店管理器 + * @param manager 商店管理器 + */ + bindManager(manager: IShopManager): void; + + /** + * 绑定系统使用的勇士状态对象 + * @param hero 勇士状态对象 + */ + bindHero(hero: IHeroState | null): void; + + /** + * 打开指定商店,仅数据端操作,不会打开商店 UI + * @param shop 商店状态对象 + */ + openShop(shop: IShopState): void; + + /** + * 关闭当前打开的商店 + */ + closeShop(): void; + + /** + * 在当前打开的商店里面购买指定道具 + * @param item 道具数字或 id + * @param count 购买的道具数量 + */ + buyItem(item: number | string, count: number): void; + + /** + * 在当前打开的商店里面售出指定道具 + * @param item 道具数字或 id + * @param count 卖出的道具数量 + */ + sellItem(item: number | string, count: number): void; +}