Files
18xchat/assets/Scripts/chat18x/network/services/MockPlayerDataService.ts
T

29 lines
923 B
TypeScript
Raw Normal View History

2025-08-29 16:39:41 +08:00
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 {
2025-09-08 15:10:51 +08:00
private delay(ms = 160) {
return new Promise<void>(r => setTimeout(r, ms));
}
2025-08-29 16:39:41 +08:00
private ok<T>(data: T): ApiResponse<T> {
2025-09-08 15:10:51 +08:00
return ({ code: proto.cs.EnmRetCode.SUCCESS, data } as unknown) as ApiResponse<T>;
2025-08-29 16:39:41 +08:00
}
// 获取个人信息
async reqMyInfo(_req: proto.cs.ICSMyInfoReq): Promise<ApiResponse<proto.cs.ICSMyInfoRes>> {
2025-09-08 15:10:51 +08:00
// 延时
2025-08-29 16:39:41 +08:00
await this.delay();
2025-09-08 15:10:51 +08:00
const nowSeconds = Math.floor(Date.now() / 1000);
2025-08-29 16:39:41 +08:00
2025-09-08 15:10:51 +08:00
const res: proto.cs.ICSMyInfoRes = {
balance: Math.floor(Math.random() * 100000), // 随机余额
vipExpire: nowSeconds + 30 * 24 * 3600, // vip 30天后过期
};
// 返回数据
2025-08-29 16:39:41 +08:00
return this.ok(res);
}
}