From 558b9ca24045d1fcbc8a2f842099f6137c5291d5 Mon Sep 17 00:00:00 2001 From: chen wei bo <1025839511@qq.com> Date: Wed, 8 Oct 2025 15:47:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=8F=E8=AE=AE=E5=A2=9E=E5=8A=A0=EF=BC=9A?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E6=8E=92=E8=A1=8C=E6=A6=9C=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/Scripts/chat18x/data/DataManager.ts | 1 + assets/Scripts/chat18x/data/GirlChatData.ts | 2 +- assets/Scripts/chat18x/data/GirlData.ts | 71 +++++++++++++++-- assets/Scripts/chat18x/data/GirlRankData.ts | 79 +++++++++++++++++++ .../Scripts/chat18x/data/GirlRankData.ts.meta | 9 +++ .../chat18x/network/services/GirlService.ts | 5 ++ .../network/services/HttpGirlService.ts | 11 +++ .../chat18x/network/services/IGirlService.ts | 2 + .../network/services/MockGirlService.ts | 11 +++ 9 files changed, 182 insertions(+), 9 deletions(-) create mode 100644 assets/Scripts/chat18x/data/GirlRankData.ts create mode 100644 assets/Scripts/chat18x/data/GirlRankData.ts.meta diff --git a/assets/Scripts/chat18x/data/DataManager.ts b/assets/Scripts/chat18x/data/DataManager.ts index f67df32c..c7ddaf05 100644 --- a/assets/Scripts/chat18x/data/DataManager.ts +++ b/assets/Scripts/chat18x/data/DataManager.ts @@ -37,6 +37,7 @@ export enum DataId { GirlUnlock = "girlUnlock", // 技师的解锁数据 GirlChat = "girlChat", // 技师的聊天数据 GirlFavorability = "girlFavorability", // 技师的好感度数据 + GirlRank = "girlRank", // 技师的排行榜数据 GirlOther = "girlOther", // 技师的其他数据 Env = "env", // 环境数据 Global = "global", // 全局数据 diff --git a/assets/Scripts/chat18x/data/GirlChatData.ts b/assets/Scripts/chat18x/data/GirlChatData.ts index 70186aa6..c731604e 100644 --- a/assets/Scripts/chat18x/data/GirlChatData.ts +++ b/assets/Scripts/chat18x/data/GirlChatData.ts @@ -23,7 +23,7 @@ export class GirlChatData extends BaseData { this.id = 0; this.chatTotalCount = 0; this.chatRemainCount = 0; - this.chatRecord = new Map(), + this.chatRecord = new Map(); this.chatRecordIds = []; } diff --git a/assets/Scripts/chat18x/data/GirlData.ts b/assets/Scripts/chat18x/data/GirlData.ts index dd473a88..fb23d911 100644 --- a/assets/Scripts/chat18x/data/GirlData.ts +++ b/assets/Scripts/chat18x/data/GirlData.ts @@ -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(); + // 排行榜数据 + 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; + } + /** --------------------------------------------------------- 技师的简要数据 --------------------------------------------------------- */ /** diff --git a/assets/Scripts/chat18x/data/GirlRankData.ts b/assets/Scripts/chat18x/data/GirlRankData.ts new file mode 100644 index 00000000..d760b02d --- /dev/null +++ b/assets/Scripts/chat18x/data/GirlRankData.ts @@ -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; + + constructor() { + super(); + this.rankMap = new Map(); + } + + 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(); + + 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] : []; + } +} diff --git a/assets/Scripts/chat18x/data/GirlRankData.ts.meta b/assets/Scripts/chat18x/data/GirlRankData.ts.meta new file mode 100644 index 00000000..fca54d36 --- /dev/null +++ b/assets/Scripts/chat18x/data/GirlRankData.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.24", + "importer": "typescript", + "imported": true, + "uuid": "83fd250b-6914-4c85-a39c-7c751586795f", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/Scripts/chat18x/network/services/GirlService.ts b/assets/Scripts/chat18x/network/services/GirlService.ts index 286fbae4..a4153713 100644 --- a/assets/Scripts/chat18x/network/services/GirlService.ts +++ b/assets/Scripts/chat18x/network/services/GirlService.ts @@ -53,4 +53,9 @@ export class GirlService implements IGirlService { public async reqCanChatGirlData(req: proto.cs.ICSGetLastChatListReq): Promise> { return this.impl.reqCanChatGirlData(req); } + + // 获取排行榜列表 + public async reqGirlRankData(req: proto.cs.ICSGetRankReq): Promise> { + return this.impl.reqGirlRankData(req); + } } diff --git a/assets/Scripts/chat18x/network/services/HttpGirlService.ts b/assets/Scripts/chat18x/network/services/HttpGirlService.ts index ef682319..e6b8f929 100644 --- a/assets/Scripts/chat18x/network/services/HttpGirlService.ts +++ b/assets/Scripts/chat18x/network/services/HttpGirlService.ts @@ -72,4 +72,15 @@ export class HttpGirlService implements IGirlService { }; return this.api.call(epData, req); } + + // 获取排行榜列表 + async reqGirlRankData(req: proto.cs.ICSGetRankReq): Promise> { + let epData: Endpoint = { + path: "api/logic/getRank", + method: "POST", + codec: "json", + needsAuth: true + }; + return this.api.call(epData, req); + } } diff --git a/assets/Scripts/chat18x/network/services/IGirlService.ts b/assets/Scripts/chat18x/network/services/IGirlService.ts index 4bd8aeee..297441ca 100644 --- a/assets/Scripts/chat18x/network/services/IGirlService.ts +++ b/assets/Scripts/chat18x/network/services/IGirlService.ts @@ -14,4 +14,6 @@ export interface IGirlService { reqUnlockGirlRes(req: proto.cs.ICSUnlockResourceReq): Promise>; // 获取可聊天的技师数据 reqCanChatGirlData(req: proto.cs.ICSGetLastChatListReq): Promise>; + // 获取排行榜列表 + reqGirlRankData(req: proto.cs.ICSGetRankReq): Promise>; } diff --git a/assets/Scripts/chat18x/network/services/MockGirlService.ts b/assets/Scripts/chat18x/network/services/MockGirlService.ts index 0765743b..2b47ee08 100644 --- a/assets/Scripts/chat18x/network/services/MockGirlService.ts +++ b/assets/Scripts/chat18x/network/services/MockGirlService.ts @@ -312,4 +312,15 @@ export class MockGirlService implements IGirlService { }; return this.ok(res); } + + // 获取排行榜列表 + async reqGirlRankData(req: proto.cs.ICSGetRankReq): Promise> { + // TODO + + // 返回数据 + const res: proto.cs.ICSGetRankRes = { + girls: [], + }; + return this.ok(res); + } }