mirror of
https://github.com/motajs/template.git
synced 2026-10-11 15:10:17 +08:00
feat: 商店系统
This commit is contained in:
parent
3a6269be60
commit
88b4571da5
@ -7,6 +7,8 @@ export interface IShopStateSave {
|
||||
readonly enabled: boolean;
|
||||
/** 商店拥有的库存 */
|
||||
readonly items: ReadonlyMap<number, number>;
|
||||
/** 商店道具的买入价与售出价 */
|
||||
readonly prices: ReadonlyMap<number, [buy: number, sell: number]>;
|
||||
}
|
||||
|
||||
export interface IShopState extends ISaveableContent<IShopStateSave> {
|
||||
@ -31,6 +33,20 @@ export interface IShopState extends ISaveableContent<IShopStateSave> {
|
||||
*/
|
||||
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<IShopManagerSave> {
|
||||
*/
|
||||
getShop(id: string): IShopState | null;
|
||||
|
||||
/**
|
||||
* 判断指定商店是否属于当前管理器
|
||||
* @param shop 商店 id 或其状态对象
|
||||
*/
|
||||
hasShop(shop: string | IShopState): boolean;
|
||||
|
||||
/**
|
||||
* 迭代当前的所有商店,包括未启用的
|
||||
*/
|
||||
|
||||
45
packages-user/data-system/src/shop/types.ts
Normal file
45
packages-user/data-system/src/shop/types.ts
Normal file
@ -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<IShopHeroAttr> | 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;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user