Merge branch 'main' of 47.107.44.202:xionglijia/18xchat
# Conflicts: # assets/Scripts/chat18x/ui/panels/ThemePanel.ts
This commit is contained in:
@@ -6,6 +6,10 @@ import { ChatHistoryManager } from "../manager/ChatHistoryManager";
|
|||||||
import { ApiConfig } from "./ApiConfigLoader";
|
import { ApiConfig } from "./ApiConfigLoader";
|
||||||
import { ErrorHandler, ErrorType } from "../utils/ErrorHandler";
|
import { ErrorHandler, ErrorType } from "../utils/ErrorHandler";
|
||||||
import { EmotionAIService } from "./EmotionAIService";
|
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聊天服务类
|
* AI聊天服务类
|
||||||
@@ -202,6 +206,20 @@ export class ChatAIService {
|
|||||||
parts: [{ text: response.text }],
|
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(
|
EmotionAIService.Instance.updateEmotionFromChat(
|
||||||
roleId,
|
roleId,
|
||||||
@@ -288,6 +306,28 @@ export class ChatAIService {
|
|||||||
const message = data.messages[0]?.content || "";
|
const message = data.messages[0]?.content || "";
|
||||||
return this.sendMessage(roleId, message);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 请求数据类型定义
|
// 请求数据类型定义
|
||||||
|
|||||||
@@ -75,5 +75,5 @@ export class GirlChatData extends BaseData {
|
|||||||
if (this.chatRemainCount > 0) {
|
if (this.chatRemainCount > 0) {
|
||||||
this.setChatRemainCount(Math.max(0, this.chatRemainCount - times));
|
this.setChatRemainCount(Math.max(0, this.chatRemainCount - times));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -796,6 +796,21 @@ export class GirlData extends BaseData {
|
|||||||
return oneData.useChat(times);
|
return oneData.useChat(times);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 是否可聊天 */
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/** --------------------------------------------------------- 技师的好感度数据 --------------------------------------------------------- */
|
/** --------------------------------------------------------- 技师的好感度数据 --------------------------------------------------------- */
|
||||||
|
|
||||||
// 解析技师好感度数据,一个
|
// 解析技师好感度数据,一个
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { HttpChatService } from "./HttpChatService";
|
|||||||
import { MockChatService } from "./MockChatService";
|
import { MockChatService } from "./MockChatService";
|
||||||
|
|
||||||
// 模拟开关
|
// 模拟开关
|
||||||
const USE_MOCK = true;
|
const USE_MOCK = false;
|
||||||
|
|
||||||
export class ChatService implements IChatService {
|
export class ChatService implements IChatService {
|
||||||
private static _I: ChatService | null = null;
|
private static _I: ChatService | null = null;
|
||||||
|
|||||||
@@ -8,6 +8,12 @@ import {
|
|||||||
UIOpacity,
|
UIOpacity,
|
||||||
} from "cc";
|
} from "cc";
|
||||||
import { ChatController } from "../../core/ChatController";
|
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;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
@ccclass("PayToTalkSubpanel")
|
@ccclass("PayToTalkSubpanel")
|
||||||
@@ -24,6 +30,8 @@ export class PayToTalkSubpanel extends Component {
|
|||||||
vipBtnLabel: Label = null;
|
vipBtnLabel: Label = null;
|
||||||
|
|
||||||
base: UIOpacity;
|
base: UIOpacity;
|
||||||
|
categoryId: number;
|
||||||
|
girlId: number;
|
||||||
|
|
||||||
protected onLoad(): void {
|
protected onLoad(): void {
|
||||||
this.base = this.getComponent(UIOpacity);
|
this.base = this.getComponent(UIOpacity);
|
||||||
@@ -32,6 +40,8 @@ export class PayToTalkSubpanel extends Component {
|
|||||||
show(categoryId: string, girlId: number) {
|
show(categoryId: string, girlId: number) {
|
||||||
this.node.active = true;
|
this.node.active = true;
|
||||||
this.base.opacity = 0;
|
this.base.opacity = 0;
|
||||||
|
this.categoryId = Number(categoryId);
|
||||||
|
this.girlId = girlId;
|
||||||
tween(this.base).to(0.3, { opacity: 255 }).start();
|
tween(this.base).to(0.3, { opacity: 255 }).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,11 +64,41 @@ export class PayToTalkSubpanel extends Component {
|
|||||||
onClick_BuyTime() {
|
onClick_BuyTime() {
|
||||||
//购买次数
|
//购买次数
|
||||||
//ChatController.Instance.resetChatCount();
|
//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() {
|
onClick_BuyVip() {
|
||||||
//购买VIP
|
//购买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,14 @@ import { ViewManager } from "../../../Main/Manager/ViewManager";
|
|||||||
import { InnerMsgCode } from "../../../Main/Config/InnerMsgCode";
|
import { InnerMsgCode } from "../../../Main/Config/InnerMsgCode";
|
||||||
import { ThemeService } from "db://assets/Scripts/chat18x/network/services/ThemeService";
|
import { ThemeService } from "db://assets/Scripts/chat18x/network/services/ThemeService";
|
||||||
import { GirlService } from "db://assets/Scripts/chat18x/network/services/GirlService";
|
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 { DataManager, DataId } from "../../data/DataManager";
|
||||||
import { ThemeData } from "../../data/ThemeData";
|
import { ThemeData } from "../../data/ThemeData";
|
||||||
import { GirlData } from "../../data/GirlData";
|
import { GirlData } from "../../data/GirlData";
|
||||||
import { WalletData } from "../../data/WalletData";
|
import { WalletData } from "../../data/WalletData";
|
||||||
import { AccountData } from "../../data/AccountData";
|
import { AccountData } from "../../data/AccountData";
|
||||||
|
|
||||||
|
import { ShopData } from "../../data/ShopData";
|
||||||
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
||||||
|
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
@@ -117,6 +120,9 @@ export class ThemePanel extends li_BaseView {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取商品列表,提前把数据拿下来
|
||||||
|
this.reqShopList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private registerListener() {
|
private registerListener() {
|
||||||
@@ -193,6 +199,19 @@ export class ThemePanel extends li_BaseView {
|
|||||||
).replace("${leftTime}", leftTime);
|
).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 {
|
onDestroy(): void {
|
||||||
Utils.removeInnerEL(InnerMsgCode.LanguageChange, this, () => {
|
Utils.removeInnerEL(InnerMsgCode.LanguageChange, this, () => {
|
||||||
this.recName.string = LanguageUtils.getText(this.rectNameKey);
|
this.recName.string = LanguageUtils.getText(this.rectNameKey);
|
||||||
|
|||||||
Reference in New Issue
Block a user