29 lines
923 B
TypeScript
29 lines
923 B
TypeScript
import type { ApiResponse } from "../client/types";
|
|
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
|
import type { IPlayerDataService } from "./IPlayerDataService";
|
|
|
|
export class MockPlayerDataService implements IPlayerDataService {
|
|
private delay(ms = 160) {
|
|
return new Promise<void>(r => setTimeout(r, ms));
|
|
}
|
|
|
|
private ok<T>(data: T): ApiResponse<T> {
|
|
return ({ code: proto.cs.EnmRetCode.SUCCESS, data } as unknown) as ApiResponse<T>;
|
|
}
|
|
|
|
// 获取个人信息
|
|
async reqMyInfo(_req: proto.cs.ICSMyInfoReq): Promise<ApiResponse<proto.cs.ICSMyInfoRes>> {
|
|
// 延时
|
|
await this.delay();
|
|
|
|
const nowSeconds = Math.floor(Date.now() / 1000);
|
|
|
|
const res: proto.cs.ICSMyInfoRes = {
|
|
balance: Math.floor(Math.random() * 100000), // 随机余额
|
|
vipExpire: nowSeconds + 30 * 24 * 3600, // vip 30天后过期
|
|
};
|
|
// 返回数据
|
|
return this.ok(res);
|
|
}
|
|
}
|