协议增加:请求排行榜数据

This commit is contained in:
chen wei bo
2025-10-08 15:48:22 +08:00
parent 8b4f2d7262
commit 558b9ca240
9 changed files with 182 additions and 9 deletions
@@ -37,6 +37,7 @@ export enum DataId {
GirlUnlock = "girlUnlock", // 技师的解锁数据
GirlChat = "girlChat", // 技师的聊天数据
GirlFavorability = "girlFavorability", // 技师的好感度数据
GirlRank = "girlRank", // 技师的排行榜数据
GirlOther = "girlOther", // 技师的其他数据
Env = "env", // 环境数据
Global = "global", // 全局数据
+1 -1
View File
@@ -23,7 +23,7 @@ export class GirlChatData extends BaseData {
this.id = 0;
this.chatTotalCount = 0;
this.chatRemainCount = 0;
this.chatRecord = new Map<string, proto.cs.IChatMsg>(),
this.chatRecord = new Map<string, proto.cs.IChatMsg>();
this.chatRecordIds = [];
}
+63 -8
View File
@@ -7,6 +7,7 @@ import { GirlDetailData } from "./GirlDetailData";
import { GirlUnlockData } from "./GirlUnlockData";
import { GirlChatData } from "./GirlChatData";
import { GirlFavorabilityData } from "./GirlFavorabilityData";
import { GirlRankData } from "./GirlRankData";
import { GirlOtherData } from "./GirlOtherData";
import { DataId } from "./DataManager";
import proto from "db://assets/Scripts/proto/proto.pb.js";
@@ -37,18 +38,29 @@ const DAILY_BUCKET = "__daily__";
export class GirlData extends BaseData {
// 大分类
private _categories = new Map<string, CategoryBucket>();
// 排行榜数据
private _rankData: GirlRankData;
constructor() {
super();
this._rankData = new GirlRankData();
this._rankData.init?.(DataId.GirlRank);
}
public reset(): void {
this._categories.clear();
this._rankData.clear();
}
public clear(): void {
this._categories.clear();
this._rankData.clear();
}
public destroy(): void {
super.destroy();
this._categories = null;
this._rankData = null;
}
/** 保障 _categories 存在 */
@@ -85,10 +97,7 @@ export class GirlData extends BaseData {
}
/** 保存技师列表 */
public setGirlList(
categoryId: string,
data: proto.cs.ICSGetGirlListRes
): void {
public setGirlList(categoryId: string, data: proto.cs.ICSGetGirlListRes): void {
if (!data) return;
this.setGirlBrief(categoryId, data.girls);
this.setGirlUnlock(categoryId, data.girls);
@@ -100,10 +109,7 @@ export class GirlData extends BaseData {
}
/** 保存技师详细数据 */
public setGirlDetailData(
categoryId: string,
data: proto.cs.ICSGetGirlDetailRes
): void {
public setGirlDetailData(categoryId: string, data: proto.cs.ICSGetGirlDetailRes): void {
if (!data) return;
let details = [];
details.push(data.girl);
@@ -183,6 +189,55 @@ export class GirlData extends BaseData {
return oneData.getGrilAvatar();
}
/** --------------------------------------------------------- 技师的排行榜数据 --------------------------------------------------------- */
/** 保存 排行榜数据 */
public setGirlRank(rankType: proto.cs.EnmRankType, data: proto.cs.ICSGetRankRes): void {
if (!data) return;
let arrayData = data.girls;
// 遍历
for (const oneData of arrayData) {
let briefData = oneData.girl;
let categoryId = briefData.category;
this.mergeOneBrief(categoryId.toString(), briefData);
let theArray = [];
theArray.push(oneData);
this.setGirlUnlock(categoryId.toString(), theArray);
this.setGirlFavorability(categoryId.toString(), theArray);
this.setGirlOther(categoryId.toString(), theArray);
}
this._rankData.setRankData(rankType, arrayData);
const cats = this.ensureCategories();
logger.log("保存排行榜数据后,大分类的数据: ", cats);
}
/** 添加 排行榜数据 */
public addRankData(rankType: proto.cs.EnmRankType, data: proto.cs.ICSGetRankRes): void {
if (!data) return;
let arrayData = data.girls;
// 遍历
for (const oneData of arrayData) {
let briefData = oneData.girl;
let categoryId = briefData.category;
this.mergeOneBrief(categoryId.toString(), briefData);
let theArray = [];
theArray.push(oneData);
this.setGirlUnlock(categoryId.toString(), theArray);
this.setGirlFavorability(categoryId.toString(), theArray);
this.setGirlOther(categoryId.toString(), theArray);
}
this._rankData.addRankData(rankType, arrayData);
const cats = this.ensureCategories();
logger.log("添加排行榜数据后,大分类的数据: ", cats);
}
/** 获取排行榜技师 id,根据排行榜类型 */
public getRankIdsByType(rankType: proto.cs.EnmRankType): number[] {
if (!this._rankData) return [];
const ids = this._rankData.getRankIdsByType(rankType);
return ids;
}
/** --------------------------------------------------------- 技师的简要数据 --------------------------------------------------------- */
/**
@@ -0,0 +1,79 @@
/**
*
*/
import { BaseData } from "./BaseData";
import proto from 'db://assets/Scripts/proto/proto.pb.js';
import { logger } from "db://assets/Scripts/Main/Common/Logger";
export class GirlRankData extends BaseData {
// 技师的简要数据
rankMap: Map<number, number[]>;
constructor() {
super();
this.rankMap = new Map<number, number[]>();
}
public reset(): void {
this.rankMap.clear();
}
public clear(): void {
this.rankMap.clear();
}
public destroy(): void {
super.destroy();
this.rankMap = null;
}
/** 保存 排行榜数据 */
public setRankData(rankType: proto.cs.EnmRankType, data: proto.cs.IGirlData[]): void {
if (!data || data.length === 0) return;
// 如果该 rankType 已存在数据,先清空
if (this.rankMap.has(rankType)) {
this.rankMap.set(rankType, []);
}
// 新建 Set 去重
const idSet = new Set<number>();
for (const item of data) {
if (item && item.id != null) {
idSet.add(item.id);
}
}
this.rankMap.set(rankType, Array.from(idSet));
logger.log("保存排行榜数据:",this.rankMap);
}
/** 添加 排行榜数据 */
public addRankData(rankType: proto.cs.EnmRankType, data: proto.cs.IGirlData[]): void {
if (!data || data.length === 0) return;
// 获取旧的 ID 列表(可能为空)
const oldList = this.rankMap.get(rankType) || [];
const idSet = new Set(oldList);
// 依次追加(保持顺序 + 去重)
for (const item of data) {
if (item && item.id != null && !idSet.has(item.id)) {
idSet.add(item.id);
oldList.push(item.id);
}
}
this.rankMap.set(rankType, oldList);
logger.log("添加排行榜数据:",this.rankMap);
}
/** 获取排行榜技师 id,根据排行榜类型 */
public getRankIdsByType(rankType: proto.cs.EnmRankType): number[] {
if (!this.rankMap) return [];
const ids = this.rankMap.get(rankType);
// 返回副本,防止外部修改内部数据
return ids ? [...ids] : [];
}
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "83fd250b-6914-4c85-a39c-7c751586795f",
"files": [],
"subMetas": {},
"userData": {}
}
@@ -53,4 +53,9 @@ export class GirlService implements IGirlService {
public async reqCanChatGirlData(req: proto.cs.ICSGetLastChatListReq): Promise<ApiResponse<proto.cs.ICSGetLastChatListRes>> {
return this.impl.reqCanChatGirlData(req);
}
// 获取排行榜列表
public async reqGirlRankData(req: proto.cs.ICSGetRankReq): Promise<ApiResponse<proto.cs.ICSGetRankRes>> {
return this.impl.reqGirlRankData(req);
}
}
@@ -72,4 +72,15 @@ export class HttpGirlService implements IGirlService {
};
return this.api.call(epData, req);
}
// 获取排行榜列表
async reqGirlRankData(req: proto.cs.ICSGetRankReq): Promise<ApiResponse<proto.cs.ICSGetRankRes>> {
let epData: Endpoint<proto.cs.ICSGetRankReq, proto.cs.ICSGetRankRes> = {
path: "api/logic/getRank",
method: "POST",
codec: "json",
needsAuth: true
};
return this.api.call(epData, req);
}
}
@@ -14,4 +14,6 @@ export interface IGirlService {
reqUnlockGirlRes(req: proto.cs.ICSUnlockResourceReq): Promise<ApiResponse<proto.cs.ICSUnlockResourceRes>>;
// 获取可聊天的技师数据
reqCanChatGirlData(req: proto.cs.ICSGetLastChatListReq): Promise<ApiResponse<proto.cs.ICSGetLastChatListRes>>;
// 获取排行榜列表
reqGirlRankData(req: proto.cs.ICSGetRankReq): Promise<ApiResponse<proto.cs.ICSGetRankRes>>;
}
@@ -312,4 +312,15 @@ export class MockGirlService implements IGirlService {
};
return this.ok(res);
}
// 获取排行榜列表
async reqGirlRankData(req: proto.cs.ICSGetRankReq): Promise<ApiResponse<proto.cs.ICSGetRankRes>> {
// TODO
// 返回数据
const res: proto.cs.ICSGetRankRes = {
girls: [],
};
return this.ok(res);
}
}