协议调试:聊天
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 请求数据类型定义
|
||||
|
||||
@@ -6,7 +6,7 @@ import { HttpChatService } from "./HttpChatService";
|
||||
import { MockChatService } from "./MockChatService";
|
||||
|
||||
// 模拟开关
|
||||
const USE_MOCK = true;
|
||||
const USE_MOCK = false;
|
||||
|
||||
export class ChatService implements IChatService {
|
||||
private static _I: ChatService | null = null;
|
||||
|
||||
@@ -8,6 +8,12 @@ import {
|
||||
UIOpacity,
|
||||
} from "cc";
|
||||
import { ChatController } from "../../core/ChatController";
|
||||
import { ShopService } from "db://assets/Scripts/chat18x/network/services/ShopService";
|
||||
import { DataManager, DataId } from "../../data/DataManager";
|
||||
import { WalletData } from "../../data/WalletData";
|
||||
import { ShopData } from "../../data/ShopData";
|
||||
import { GirlData } from "../../data/GirlData";
|
||||
import proto from 'db://assets/Scripts/proto/proto.pb.js';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("PayToTalkSubpanel")
|
||||
@@ -24,6 +30,8 @@ export class PayToTalkSubpanel extends Component {
|
||||
vipBtnLabel: Label = null;
|
||||
|
||||
base: UIOpacity;
|
||||
categoryId: number;
|
||||
girlId: number;
|
||||
|
||||
protected onLoad(): void {
|
||||
this.base = this.getComponent(UIOpacity);
|
||||
@@ -32,6 +40,8 @@ export class PayToTalkSubpanel extends Component {
|
||||
show(categoryId: string, girlId: number) {
|
||||
this.node.active = true;
|
||||
this.base.opacity = 0;
|
||||
this.categoryId = Number(categoryId);
|
||||
this.girlId = girlId;
|
||||
tween(this.base).to(0.3, { opacity: 255 }).start();
|
||||
}
|
||||
|
||||
@@ -54,11 +64,41 @@ export class PayToTalkSubpanel extends Component {
|
||||
onClick_BuyTime() {
|
||||
//购买次数
|
||||
//ChatController.Instance.resetChatCount();
|
||||
this.hide();
|
||||
const shopData = DataManager.I.getDataById<ShopData>(DataId.Shop);
|
||||
const chatIds = shopData.getChatIds();
|
||||
console.log("聊天商品Id: ", chatIds);
|
||||
if (chatIds.length > 0) {
|
||||
this.reqBuyGood(chatIds[0], this.girlId);
|
||||
}
|
||||
}
|
||||
|
||||
onClick_BuyVip() {
|
||||
//购买VIP
|
||||
console.log("购买vip,未实现功能");
|
||||
console.log("购买vip");
|
||||
const shopData = DataManager.I.getDataById<ShopData>(DataId.Shop);
|
||||
const memberId = shopData.get7DayMemberId();
|
||||
this.reqBuyGood(memberId, this.girlId);
|
||||
}
|
||||
|
||||
// 使用余额购买商品
|
||||
async reqBuyGood(goodId: number, girlId: number) {
|
||||
// 请求购买商品
|
||||
const reqData = {
|
||||
goodId: goodId,
|
||||
girlId: girlId,
|
||||
};
|
||||
let res = await ShopService.I.reqBuyGood(reqData);
|
||||
console.log("请求使用余额购买商品的响应数据:", res);
|
||||
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
|
||||
const resData = res.data;
|
||||
// 保存数据
|
||||
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
||||
girlData.setChatRemainCount(this.categoryId.toString(), girlId, resData.chatRemainCount);
|
||||
const walletData = DataManager.I.getDataById<WalletData>(DataId.Wallet);
|
||||
walletData.balance = Number(resData.balance);
|
||||
walletData.vipExpire = Number(resData.vipExpire);
|
||||
// 刷新界面
|
||||
this.hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,13 @@ import { ViewManager } from "../../../Main/Manager/ViewManager";
|
||||
import { InnerMsgCode } from "../../../Main/Config/InnerMsgCode";
|
||||
import { ThemeService } from "db://assets/Scripts/chat18x/network/services/ThemeService";
|
||||
import { GirlService } from "db://assets/Scripts/chat18x/network/services/GirlService";
|
||||
import { ShopService } from "db://assets/Scripts/chat18x/network/services/ShopService";
|
||||
import { DataManager, DataId } from "../../data/DataManager";
|
||||
import { ThemeData } from "../../data/ThemeData";
|
||||
import { GirlData } from "../../data/GirlData";
|
||||
import { WalletData } from "../../data/WalletData";
|
||||
import { AccountData } from "../../data/AccountData";
|
||||
import { ShopData } from "../../data/ShopData";
|
||||
import proto from 'db://assets/Scripts/proto/proto.pb.js';
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
@@ -121,6 +123,9 @@ export class ThemePanel extends li_BaseView {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// 获取商品列表,提前把数据拿下来
|
||||
this.reqShopList();
|
||||
}
|
||||
|
||||
private registerListener() {
|
||||
@@ -175,6 +180,21 @@ export class ThemePanel extends li_BaseView {
|
||||
).replace("${leftTime}", leftTime);
|
||||
}
|
||||
|
||||
// 获取商品列表
|
||||
async reqShopList() {
|
||||
// 请求购买商品
|
||||
const reqData = {
|
||||
|
||||
};
|
||||
let res = await ShopService.I.reqShopList(reqData);
|
||||
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
|
||||
const resData = res.data;
|
||||
// 保存数据
|
||||
const shopData = DataManager.I.getDataById<ShopData>(DataId.Shop);
|
||||
shopData.goods = res.data;
|
||||
}
|
||||
}
|
||||
|
||||
onDestroy(): void {
|
||||
Utils.removeInnerEL(InnerMsgCode.LanguageChange, this, () => {
|
||||
this.recName.string = LanguageUtils.getText(this.rectNameKey);
|
||||
|
||||
+1
-1
Submodule proto_cs updated: f055100cf0...9ec1d4f077
Reference in New Issue
Block a user