协议调试:聊天
This commit is contained in:
@@ -6,6 +6,10 @@ import { ChatHistoryManager } from "../manager/ChatHistoryManager";
|
||||
import { ApiConfig } from "./ApiConfigLoader";
|
||||
import { ErrorHandler, ErrorType } from "../utils/ErrorHandler";
|
||||
import { EmotionAIService } from "./EmotionAIService";
|
||||
import { ChatService } from "db://assets/Scripts/chat18x/network/services/ChatService";
|
||||
import { DataManager, DataId } from "../data/DataManager";
|
||||
import { GirlData } from "../data/GirlData";
|
||||
import proto from 'db://assets/Scripts/proto/proto.pb.js';
|
||||
|
||||
/**
|
||||
* AI聊天服务类
|
||||
@@ -202,6 +206,20 @@ export class ChatAIService {
|
||||
parts: [{ text: response.text }],
|
||||
});
|
||||
|
||||
// 上报聊天数据到服务器
|
||||
let msgList: proto.cs.IChatMsg[] = [];
|
||||
let userData = {
|
||||
isAi: false,
|
||||
msg: message,
|
||||
};
|
||||
msgList.push(userData);
|
||||
let aiData = {
|
||||
isAi: true,
|
||||
msg: response.text,
|
||||
};
|
||||
msgList.push(aiData);
|
||||
this.reqChatMsg(roleId, msgList);
|
||||
|
||||
// 异步更新情绪状态(非阻塞)
|
||||
EmotionAIService.Instance.updateEmotionFromChat(
|
||||
roleId,
|
||||
@@ -288,6 +306,28 @@ export class ChatAIService {
|
||||
const message = data.messages[0]?.content || "";
|
||||
return this.sendMessage(roleId, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上报聊天数据到服务器
|
||||
*/
|
||||
async reqChatMsg(girlId: number, msgList: proto.cs.IChatMsg[]) {
|
||||
// 请求购买商品
|
||||
const reqData = {
|
||||
girlId,
|
||||
ChatMsg: msgList,
|
||||
};
|
||||
console.log("请求上报聊天数据的请求数据:", reqData);
|
||||
let res = await ChatService.I.reqChatMsg(reqData);
|
||||
console.log("请求上报聊天数据的响应数据:", res);
|
||||
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
|
||||
const resData = res.data;
|
||||
// 保存数据
|
||||
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
||||
const category = girlData.getGrilCategoryById(girlId);
|
||||
girlData.setChatTotalCount(category.toString(), girlId, resData.chatTotalCount);
|
||||
girlData.setChatRemainCount(category.toString(), girlId, resData.chatRemainCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 请求数据类型定义
|
||||
|
||||
Reference in New Issue
Block a user