获取可聊天的技师数据
This commit is contained in:
@@ -112,6 +112,23 @@ export class GirlData extends BaseData {
|
||||
logger.log("保存类别 ", categoryId, " 的详细数据: ", bucket);
|
||||
}
|
||||
|
||||
/** 保存可聊天的技师数据 */
|
||||
public setCanChatGirlData(data: proto.cs.ICSGetLastChatListRes): void {
|
||||
if (!data) return;
|
||||
let canChatList = data.LastChatList;
|
||||
// 遍历
|
||||
for (const oneData of canChatList) {
|
||||
let briefData = oneData.girl;
|
||||
let categoryId = briefData.category;
|
||||
this.mergeOneBrief(categoryId.toString(), briefData);
|
||||
this.refreshGirlUnlock(oneData);
|
||||
this.refreshGirlFavorability(oneData);
|
||||
this.refreshGirlChat(oneData);
|
||||
}
|
||||
const cats = this.ensureCategories();
|
||||
logger.log("保存可聊天的技师数据: ", cats);
|
||||
}
|
||||
|
||||
/** --------------------------------------------------------- 技师的简要数据 --------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
@@ -649,30 +666,41 @@ export class GirlData extends BaseData {
|
||||
|
||||
/** --------------------------------------------------------- 技师的解锁数据 --------------------------------------------------------- */
|
||||
|
||||
// 解析技师解锁数据,一个
|
||||
private parseOneGirlUnlock(data: proto.cs.IGirlData): GirlUnlockData | null {
|
||||
if (!data) return null;
|
||||
// 创建一个技师解锁数据
|
||||
private createOneGirlUnlock(id: number, isRelease: boolean, unlockTime: number, unlockedImageIds: number[], unlockedVideoIds: number[]): GirlUnlockData {
|
||||
let oneData = new GirlUnlockData();
|
||||
oneData.init?.(DataId.GirlUnlock);
|
||||
oneData.setId(data.id);
|
||||
oneData.setIsRelease(data.isRelease);
|
||||
if (data.images) {
|
||||
let ids = [];
|
||||
for (let one of data.images) {
|
||||
ids.push(one.resId);
|
||||
}
|
||||
oneData.setUnlockedImageIds(ids);
|
||||
oneData.setId(id);
|
||||
oneData.setIsRelease(isRelease);
|
||||
oneData.setUnlockTime(unlockTime);
|
||||
if (unlockedImageIds) {
|
||||
oneData.setUnlockedImageIds(unlockedImageIds);
|
||||
}
|
||||
if (data.videos) {
|
||||
let ids = [];
|
||||
for (let one of data.videos) {
|
||||
ids.push(one.resId);
|
||||
}
|
||||
oneData.setUnlockedVideoIds(ids);
|
||||
if (unlockedVideoIds) {
|
||||
oneData.setUnlockedVideoIds(unlockedVideoIds);
|
||||
}
|
||||
return oneData;
|
||||
}
|
||||
|
||||
// 解析技师解锁数据,一个
|
||||
private parseOneGirlUnlock(data: proto.cs.IGirlData): GirlUnlockData | null {
|
||||
if (!data) return null;
|
||||
let unlockedImageIds = [];
|
||||
if (data.images) {
|
||||
for (let one of data.images) {
|
||||
unlockedImageIds.push(one.resId);
|
||||
}
|
||||
}
|
||||
let unlockedVideoIds = [];
|
||||
if (data.videos) {
|
||||
for (let one of data.videos) {
|
||||
unlockedVideoIds.push(one.resId);
|
||||
}
|
||||
}
|
||||
let oneData = this.createOneGirlUnlock(data.id, data.isRelease, Number(data.unlockTime), unlockedImageIds, unlockedVideoIds);
|
||||
return oneData;
|
||||
}
|
||||
|
||||
/** 保存技师的解锁数据 */
|
||||
private setGirlUnlock(categoryId: string, data: proto.cs.IGirlData[]): void {
|
||||
if (!data) return;
|
||||
@@ -684,6 +712,27 @@ export class GirlData extends BaseData {
|
||||
}
|
||||
}
|
||||
|
||||
/** 刷新技师的解锁数据 */
|
||||
private refreshGirlUnlock(data: proto.cs.ILastChatData): void {
|
||||
if (!data) return;
|
||||
let briefData = data.girl;
|
||||
let categoryId = briefData.category;
|
||||
let girlId = briefData.id;
|
||||
let unlockData = this.getGrilUnlock(categoryId.toString(), girlId);
|
||||
if (unlockData) {
|
||||
// 已存在数据,刷新
|
||||
unlockData.setIsRelease(data.isRelease);
|
||||
unlockData.setUnlockTime(Number(data.unlockTime));
|
||||
} else {
|
||||
// 不存在数据,创建
|
||||
const bucket = this.ensureBucket(categoryId.toString());
|
||||
let oneData = this.createOneGirlUnlock(data.id, data.isRelease, Number(data.unlockTime), [], []);
|
||||
if (oneData) {
|
||||
bucket.unlocks.set(data.id, oneData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 取某分类 + girlId 的解锁数据 */
|
||||
private getGrilUnlock(
|
||||
categoryId: string,
|
||||
@@ -719,6 +768,20 @@ export class GirlData extends BaseData {
|
||||
oneData.setIsRelease(value);
|
||||
}
|
||||
|
||||
/** 获取 角色解锁时间,时间戳,秒 */
|
||||
public getUnlockTime(categoryId: string, girlId: number): number {
|
||||
let oneData = this.getGrilUnlock(categoryId, girlId);
|
||||
if (!oneData) return 0;
|
||||
return oneData.getUnlockTime();
|
||||
}
|
||||
|
||||
/** 保存 角色解锁时间,时间戳,秒 */
|
||||
public setUnlockTime(categoryId: string, girlId: number, value: number): void {
|
||||
let oneData = this.getGrilUnlock(categoryId, girlId);
|
||||
if (!oneData) return;
|
||||
oneData.setUnlockTime(value);
|
||||
}
|
||||
|
||||
/** 判断图片是否解锁 */
|
||||
public isImageUnlock(
|
||||
categoryId: string,
|
||||
@@ -787,14 +850,20 @@ export class GirlData extends BaseData {
|
||||
|
||||
/** --------------------------------------------------------- 技师的聊天数据 --------------------------------------------------------- */
|
||||
|
||||
// 创建一个技师聊天数据
|
||||
private createOneGirlChat(id: number, chatTotalCount: number, chatRemainCount: number): GirlChatData {
|
||||
let oneData = new GirlChatData();
|
||||
oneData.init?.(DataId.GirlChat);
|
||||
oneData.setId(id);
|
||||
oneData.setChatTotalCount(chatTotalCount);
|
||||
oneData.setChatRemainCount(chatRemainCount);
|
||||
return oneData;
|
||||
}
|
||||
|
||||
// 解析技师聊天数据,一个
|
||||
private parseOneGirlChat(data: proto.cs.IGirlData): GirlChatData | null {
|
||||
if (!data) return null;
|
||||
let oneData = new GirlChatData();
|
||||
oneData.init?.(DataId.GirlChat);
|
||||
oneData.setId(data.id);
|
||||
oneData.setChatTotalCount(data.chatTotalCount);
|
||||
oneData.setChatRemainCount(data.chatRemainCount);
|
||||
let oneData = this.createOneGirlChat(data.id, data.chatTotalCount, data.chatRemainCount);
|
||||
return oneData;
|
||||
}
|
||||
|
||||
@@ -809,6 +878,29 @@ export class GirlData extends BaseData {
|
||||
}
|
||||
}
|
||||
|
||||
/** 刷新技师的聊天数据 */
|
||||
private refreshGirlChat(data: proto.cs.ILastChatData): void {
|
||||
if (!data) return;
|
||||
let briefData = data.girl;
|
||||
let categoryId = briefData.category;
|
||||
let girlId = briefData.id;
|
||||
let chatData = this.getGrilChat(categoryId.toString(), girlId);
|
||||
if (chatData) {
|
||||
// 已存在数据,刷新
|
||||
chatData.setChatTotalCount(data.chatTotalCount);
|
||||
chatData.setChatRemainCount(data.chatRemainCount);
|
||||
chatData.setChatRecord(data.msgs);
|
||||
} else {
|
||||
// 不存在数据,创建
|
||||
const bucket = this.ensureBucket(categoryId.toString());
|
||||
let oneData = this.createOneGirlChat(data.id, data.chatTotalCount, data.chatRemainCount);
|
||||
if (oneData) {
|
||||
oneData.setChatRecord(data.msgs);
|
||||
bucket.chats.set(data.id, oneData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 取某分类 + girlId 的聊天数据 */
|
||||
private getGrilChat(categoryId: string, girlId: number): GirlChatData | null {
|
||||
const b = this.ensureCategories().get(categoryId);
|
||||
@@ -868,17 +960,9 @@ export class GirlData extends BaseData {
|
||||
|
||||
/** 是否可聊天 */
|
||||
public isCanChat(categoryId: string, girlId: number): boolean {
|
||||
// 剩余聊天次数
|
||||
let remainCount = this.getChatRemainCount(categoryId, girlId);
|
||||
if (remainCount < 0) {
|
||||
// 会员
|
||||
return true;
|
||||
} else if (remainCount === 0) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
let oneData = this.getGrilChat(categoryId, girlId);
|
||||
if (!oneData) return false;
|
||||
return oneData.isCanChat();
|
||||
}
|
||||
|
||||
/** 保存聊天记录 */
|
||||
@@ -895,6 +979,20 @@ export class GirlData extends BaseData {
|
||||
return oneData.getChatRecordIds();
|
||||
}
|
||||
|
||||
/** 获取最新的聊天记录的id */
|
||||
public getLatestChatRecordId(categoryId: string, girlId: number): number | null {
|
||||
let oneData = this.getGrilChat(categoryId, girlId);
|
||||
if (!oneData) return null;
|
||||
return oneData.getLatestChatRecordId();
|
||||
}
|
||||
|
||||
/** 获取最新的聊天记录的时间戳(毫秒) */
|
||||
public getLatestChatRecordTimestamp(categoryId: string, girlId: number): number | null {
|
||||
let oneData = this.getGrilChat(categoryId, girlId);
|
||||
if (!oneData) return null;
|
||||
return oneData.getLatestChatRecordTimestamp();
|
||||
}
|
||||
|
||||
/** 获取聊天记录,根据 id,是否是 ai 聊天数据 */
|
||||
public getChatRecordIsAi(categoryId: string, girlId: number, id: number): boolean {
|
||||
let oneData = this.getGrilChat(categoryId, girlId);
|
||||
@@ -907,27 +1005,48 @@ export class GirlData extends BaseData {
|
||||
let oneData = this.getGrilChat(categoryId, girlId);
|
||||
if (!oneData) return "";
|
||||
return oneData.getChatRecordMsg(id);
|
||||
}
|
||||
}
|
||||
|
||||
/** 获取所有可聊天的技师 id */
|
||||
public getAllCanChatGirlIds(): number[] {
|
||||
const result: number[] = [];
|
||||
const cats = this.ensureCategories();
|
||||
|
||||
for (const [categoryId, bucket] of cats.entries()) {
|
||||
for (const girlId of bucket.girlIds) {
|
||||
|
||||
|
||||
|
||||
|
||||
if (this.getIsRelease(categoryId, girlId)) {
|
||||
result.push(girlId);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 返回结果
|
||||
return result;
|
||||
}
|
||||
|
||||
/** --------------------------------------------------------- 技师的好感度数据 --------------------------------------------------------- */
|
||||
|
||||
// 解析技师好感度数据,一个
|
||||
private parseOneGirlFavorability(
|
||||
data: proto.cs.IGirlData
|
||||
): GirlFavorabilityData | null {
|
||||
if (!data) return null;
|
||||
// 创建一个技师好感度数据
|
||||
private createOneGirlFavorability(id: number, star: number): GirlFavorabilityData {
|
||||
let oneData = new GirlFavorabilityData();
|
||||
oneData.init?.(DataId.GirlFavorability);
|
||||
oneData.setId(data.id);
|
||||
oneData.setStar(data.star);
|
||||
oneData.setId(id);
|
||||
oneData.setStar(star);
|
||||
return oneData;
|
||||
}
|
||||
|
||||
// 解析技师好感度数据,一个
|
||||
private parseOneGirlFavorability(data: proto.cs.IGirlData): GirlFavorabilityData | null {
|
||||
if (!data) return null;
|
||||
let oneData = this.createOneGirlFavorability(data.id, data.star);
|
||||
return oneData;
|
||||
}
|
||||
|
||||
/** 保存技师的好感度数据 */
|
||||
private setGirlFavorability(
|
||||
categoryId: string,
|
||||
data: proto.cs.IGirlData[]
|
||||
): void {
|
||||
private setGirlFavorability(categoryId: string,data: proto.cs.IGirlData[]): void {
|
||||
if (!data) return;
|
||||
const bucket = this.ensureBucket(categoryId);
|
||||
for (const g of data) {
|
||||
@@ -937,11 +1056,28 @@ export class GirlData extends BaseData {
|
||||
}
|
||||
}
|
||||
|
||||
/** 刷新技师的好感度数据 */
|
||||
private refreshGirlFavorability(data: proto.cs.ILastChatData): void {
|
||||
if (!data) return;
|
||||
let briefData = data.girl;
|
||||
let categoryId = briefData.category;
|
||||
let girlId = briefData.id;
|
||||
let favData = this.getGrilFavorability(categoryId.toString(), girlId);
|
||||
if (favData) {
|
||||
// 已存在数据,刷新
|
||||
favData.setStar(data.star);
|
||||
} else {
|
||||
// 不存在数据,创建
|
||||
const bucket = this.ensureBucket(categoryId.toString());
|
||||
let oneData = this.createOneGirlFavorability(data.id, data.star);
|
||||
if (oneData) {
|
||||
bucket.favorability.set(data.id, oneData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 取某分类 + girlId 的好感度数据 */
|
||||
private getGrilFavorability(
|
||||
categoryId: string,
|
||||
girlId: number
|
||||
): GirlFavorabilityData | null {
|
||||
private getGrilFavorability(categoryId: string,girlId: number): GirlFavorabilityData | null {
|
||||
const b = this.ensureCategories().get(categoryId);
|
||||
if (!b) return null;
|
||||
return b.favorability.get(girlId) ?? null;
|
||||
|
||||
Reference in New Issue
Block a user