2025-09-08 22:59:32 +08:00
|
|
|
/**
|
|
|
|
|
* 全局数据
|
|
|
|
|
*/
|
|
|
|
|
import { BaseData } from "./BaseData";
|
2025-09-19 18:20:10 +08:00
|
|
|
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
2025-09-08 22:59:32 +08:00
|
|
|
|
|
|
|
|
export class GlobalData extends BaseData {
|
2025-09-12 11:29:11 +08:00
|
|
|
// api键
|
|
|
|
|
private _apiKey: string = "";
|
|
|
|
|
// 情绪判断机器人api
|
|
|
|
|
private _emotionApiKey: string = "";
|
|
|
|
|
// ai模型
|
|
|
|
|
private _model: string = "";
|
|
|
|
|
// Temperature
|
|
|
|
|
private _temperature: number = 0;
|
|
|
|
|
// 单次聊天最大token
|
|
|
|
|
private _maxTokens: number = 0;
|
|
|
|
|
// 超时时间(微秒)
|
|
|
|
|
private _timeout: number = 0;
|
|
|
|
|
// 单个角色免费聊天次数
|
|
|
|
|
private _freeChatTimes: number = 0;
|
|
|
|
|
// 单次对话增长好感度
|
|
|
|
|
private _onceChatAddScore: number = 0;
|
|
|
|
|
// 好感度等级兑换比例
|
|
|
|
|
private _scoreExchangeStarLevel: number = 0;
|
|
|
|
|
// 游戏名
|
|
|
|
|
private _gameName: string = "";
|
|
|
|
|
// 情绪评分机器人system_prompt,需拼接角色prompt
|
2025-09-19 23:25:41 +08:00
|
|
|
private _emotionBasePrompt: string = "";
|
2025-09-12 11:29:11 +08:00
|
|
|
// ai机器人基础规则
|
2025-09-19 18:20:10 +08:00
|
|
|
private _girlBasePrompt: string = "";
|
2025-09-08 22:59:32 +08:00
|
|
|
|
|
|
|
|
public reset(): void {
|
2025-09-12 11:29:11 +08:00
|
|
|
this._apiKey = "";
|
|
|
|
|
this._emotionApiKey = "";
|
|
|
|
|
this._model = "";
|
|
|
|
|
this._temperature = 0;
|
|
|
|
|
this._maxTokens = 0;
|
|
|
|
|
this._timeout = 0;
|
|
|
|
|
this._freeChatTimes = 0;
|
|
|
|
|
this._onceChatAddScore = 0;
|
|
|
|
|
this._scoreExchangeStarLevel = 0;
|
|
|
|
|
this._gameName = "";
|
2025-09-19 18:20:10 +08:00
|
|
|
this._emotionBasePrompt = "";
|
2025-09-19 23:25:41 +08:00
|
|
|
this._girlBasePrompt = "";
|
2025-09-08 22:59:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public clear(): void {
|
2025-09-12 11:29:11 +08:00
|
|
|
this._apiKey = "";
|
|
|
|
|
this._emotionApiKey = "";
|
|
|
|
|
this._model = "";
|
|
|
|
|
this._temperature = 0;
|
|
|
|
|
this._maxTokens = 0;
|
|
|
|
|
this._timeout = 0;
|
|
|
|
|
this._freeChatTimes = 0;
|
|
|
|
|
this._onceChatAddScore = 0;
|
|
|
|
|
this._scoreExchangeStarLevel = 0;
|
|
|
|
|
this._gameName = "";
|
2025-09-19 18:20:10 +08:00
|
|
|
this._emotionBasePrompt = "";
|
2025-09-19 23:25:41 +08:00
|
|
|
this._girlBasePrompt = "";
|
2025-09-08 22:59:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public destroy(): void {
|
|
|
|
|
super.destroy();
|
2025-09-12 11:29:11 +08:00
|
|
|
this._apiKey = null;
|
|
|
|
|
this._emotionApiKey = null;
|
|
|
|
|
this._model = null;
|
|
|
|
|
this._temperature = null;
|
|
|
|
|
this._maxTokens = null;
|
|
|
|
|
this._timeout = null;
|
|
|
|
|
this._freeChatTimes = null;
|
|
|
|
|
this._onceChatAddScore = null;
|
|
|
|
|
this._scoreExchangeStarLevel = null;
|
|
|
|
|
this._gameName = null;
|
2025-09-19 18:20:10 +08:00
|
|
|
this._emotionBasePrompt = null;
|
2025-09-19 23:25:41 +08:00
|
|
|
this._girlBasePrompt = null;
|
2025-09-08 22:59:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 设置全局数据 */
|
2025-09-12 11:29:11 +08:00
|
|
|
public set globals(data: proto.cs.ICSGetResConfigRes) {
|
|
|
|
|
const parsed = JSON.parse(data.data);
|
|
|
|
|
if (Array.isArray(parsed) && parsed.length > 0) {
|
|
|
|
|
const obj = parsed[0];
|
|
|
|
|
this._apiKey = obj.ApiKey;
|
|
|
|
|
this._emotionApiKey = obj.emotionApiKey;
|
|
|
|
|
this._model = obj.Model;
|
|
|
|
|
this._temperature = obj.Temperature;
|
|
|
|
|
this._maxTokens = obj.MaxTokens;
|
|
|
|
|
this._timeout = obj.Timeout;
|
|
|
|
|
this._freeChatTimes = obj.FreeChatTimes;
|
|
|
|
|
this._onceChatAddScore = obj.OnceChatAddScore;
|
|
|
|
|
this._scoreExchangeStarLevel = obj.ScoreExchangeStarLevel;
|
|
|
|
|
this._gameName = obj.GameName;
|
2025-09-19 18:20:10 +08:00
|
|
|
this._emotionBasePrompt = obj.EmotionBasePrompt;
|
2025-09-19 23:25:41 +08:00
|
|
|
this._girlBasePrompt = obj.girlBasePrompt;
|
2025-09-19 18:20:10 +08:00
|
|
|
}
|
2025-09-08 22:59:32 +08:00
|
|
|
}
|
2025-09-12 11:29:11 +08:00
|
|
|
|
|
|
|
|
/** 获取api键 */
|
|
|
|
|
public getApiKey(): string {
|
|
|
|
|
return this._apiKey;
|
2025-09-19 18:20:10 +08:00
|
|
|
}
|
2025-09-12 11:29:11 +08:00
|
|
|
|
|
|
|
|
/** 获取情绪判断机器人api */
|
|
|
|
|
public getEmotionApiKey(): string {
|
|
|
|
|
return this._emotionApiKey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 获取ai模型 */
|
|
|
|
|
public getModel(): string {
|
|
|
|
|
return this._model;
|
2025-09-19 18:20:10 +08:00
|
|
|
}
|
2025-09-12 11:29:11 +08:00
|
|
|
|
|
|
|
|
/** Temperature */
|
|
|
|
|
public getTemperature(): number {
|
|
|
|
|
return this._temperature;
|
2025-09-19 18:20:10 +08:00
|
|
|
}
|
2025-09-12 11:29:11 +08:00
|
|
|
|
|
|
|
|
/** 单次聊天最大token */
|
|
|
|
|
public getMaxTokens(): number {
|
|
|
|
|
return this._maxTokens;
|
2025-09-19 18:20:10 +08:00
|
|
|
}
|
2025-09-12 11:29:11 +08:00
|
|
|
|
|
|
|
|
/** 超时时间(微秒) */
|
|
|
|
|
public getTimeout(): number {
|
|
|
|
|
return this._timeout;
|
2025-09-19 18:20:10 +08:00
|
|
|
}
|
2025-09-12 11:29:11 +08:00
|
|
|
|
|
|
|
|
/** 单个角色免费聊天次数 */
|
|
|
|
|
public getFreeChatTimes(): number {
|
|
|
|
|
return this._freeChatTimes;
|
2025-09-19 18:20:10 +08:00
|
|
|
}
|
2025-09-12 11:29:11 +08:00
|
|
|
|
|
|
|
|
/** 单次对话增长好感度 */
|
|
|
|
|
public getOnceChatAddScore(): number {
|
|
|
|
|
return this._onceChatAddScore;
|
2025-09-19 18:20:10 +08:00
|
|
|
}
|
2025-09-12 11:29:11 +08:00
|
|
|
|
|
|
|
|
/** 好感度等级兑换比例 */
|
|
|
|
|
public getScoreExchangeStarLevel(): number {
|
|
|
|
|
return this._scoreExchangeStarLevel;
|
2025-09-19 18:20:10 +08:00
|
|
|
}
|
2025-09-12 11:29:11 +08:00
|
|
|
|
|
|
|
|
/** 游戏名 */
|
|
|
|
|
public getGameName(): string {
|
|
|
|
|
return this._gameName;
|
2025-09-19 18:20:10 +08:00
|
|
|
}
|
2025-09-12 11:29:11 +08:00
|
|
|
|
|
|
|
|
/** 情绪评分机器人system_prompt,需拼接角色prompt */
|
2025-09-19 23:25:41 +08:00
|
|
|
public getEmotionBasePrompt(): string {
|
|
|
|
|
return this._emotionBasePrompt;
|
2025-09-19 18:20:10 +08:00
|
|
|
}
|
2025-09-12 11:29:11 +08:00
|
|
|
|
|
|
|
|
/** ai机器人基础规则 */
|
|
|
|
|
public getGirlBasePrompt(): string {
|
|
|
|
|
return this._girlBasePrompt;
|
2025-09-19 18:20:10 +08:00
|
|
|
}
|
2025-09-08 22:59:32 +08:00
|
|
|
}
|