package com.qiwu.inference.common.utils; import cn.hutool.poi.excel.ExcelReader; import cn.hutool.poi.excel.ExcelUtil; import com.qiwu.inference.common.Constants; import com.qiwu.inference.common.TimingAcquisition; import com.qiwu.inference.dto.*; import com.qiwu.inference.pojo.*; import org.springframework.util.StringUtils; import java.io.File; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; public class SpeechUtil { /** * 取指定范围内的随机数 * @param num1 * @param num2 * @return Integer */ public static Integer getRandomNum(Integer num1, Integer num2) { Integer min = num1 > num2 ? num2 : num1; int sub = num1 > num2 ? num1-num2 : num2-num1; sub = sub == 0 ? 1 : sub; Random random = new Random(); //random.nextInt(1)结果为0,random.nextInt(0)会报错 return random.nextInt(sub) + min; } /** * 从询问模块话术获取话术 * @param someone * @param feedText * @return String */ public static String getAskSpeech(String someone, Integer feedText) { String result = ""; List speech = TimingAcquisition.askSpeechMap.get(someone).get(feedText); Integer i = getRandomNum(0, speech.size()); result = speech.get(i); return result; } /** * 从任务模块话术获取话术 * @param someone * @param feedText * @return String */ public static String getTaskSpeech(String someone, Integer feedText) { String result = ""; List speech = TimingAcquisition.taskSpeechMap.get(someone).get(feedText); Integer i = getRandomNum(0, speech.size()); result = speech.get(i); return result; } /** * 从查看模块话术获取话术 * @param someone * @param feedText * @return String */ public static String getCheckSpeech(String someone, Integer feedText) { String result = ""; List speech = TimingAcquisition.checkSpeechMap.get(someone).get(feedText); Integer i = getRandomNum(0, speech.size()); result = speech.get(i); return result; } /** * 从查看模块话术获取话术 * @param someone * @param feedText * @return String */ public static String getBarrierSpeech(String someone, Integer feedText) { String result = ""; List speech = TimingAcquisition.barrierSpeechMap.get(someone).get(feedText); Integer i = getRandomNum(0, speech.size()); result = speech.get(i); return result; } /** * 替换话术中的一个数字 * @param one * @return String */ public static String speechReplaceNum(String text, String one) { return text.replace("【1】", one); } /** * 替换话术中的两个数字 * @param one * @param two * @return String */ public static String speechReplaceNum(String text, String one, String two) { return text.replace("【1】", one).replace("【2】", two); } /** * 替换话术中的三个数字 * @param one * @param two * @param three * @return String */ public static String speechReplaceNum(String text, String one, String two, String three) { return text.replace("【1】", one).replace("【2】", two).replace("【3】", three); } /** * 替换话术中的四个数字 * @param one * @param two * @param three * @param four * @return String */ public static String speechReplaceNum(String text, String one, String two, String three, String four) { return text.replace("【1】", one).replace("【2】", two).replace("【3】", three).replace("【4】", four); } /** * 替换话术中的五个数字 * @param one * @param two * @param three * @param four * @param five * @return String */ public static String speechReplaceNum(String text, String one, String two, String three, String four, String five) { return text.replace("【1】", one).replace("【2】", two).replace("【3】", three) .replace("【4】", four).replace("【5】", five); } /** * 替换话术中的六个数字 * @param one * @param two * @param three * @param four * @param five * @param six * @return String */ public static String speechReplaceNum(String text, String one, String two, String three, String four, String five, String six) { return text.replace("【1】", one).replace("【2】", two).replace("【3】", three) .replace("【4】", four).replace("【5】", five).replace("【6】", six); } /** * 替换话术中的七个数字 * @param one * @param two * @param three * @param four * @param five * @param six * @param seven * @return String */ public static String speechReplaceNum(String text, String one, String two, String three, String four, String five, String six, String seven) { return text.replace("【1】", one).replace("【2】", two).replace("【3】", three) .replace("【4】", four).replace("【5】", five).replace("【6】", six).replace("【7】", seven); } /** * 替换话术中的八个数字 * @param one * @param two * @param three * @param four * @param five * @param six * @param seven * @param eight * @return String */ public static String speechReplaceNum(String text, String one, String two, String three, String four, String five, String six, String seven, String eight) { return text.replace("【1】", one).replace("【2】", two).replace("【3】", three) .replace("【4】", four).replace("【5】", five).replace("【6】", six) .replace("【7】", seven).replace("【8】", eight); } /** * 替换话术中的九个数字 * @param one * @param two * @param three * @param four * @param five * @param six * @param seven * @param eight * @param nine * @return String */ public static String speechReplaceNum(String text, String one, String two, String three, String four, String five, String six, String seven, String eight, String nine) { return text.replace("【1】", one).replace("【2】", two).replace("【3】", three) .replace("【4】", four).replace("【5】", five).replace("【6】", six) .replace("【7】", seven).replace("【8】", eight).replace("【9】", nine); } /** * 替换话术中的【A】 * @param A * @return String */ public static String speechReplaceLetter(String text, String A) { return text.replace("【A】", A); } /** * 替换话术中的【A】和【B】 * @param A * @param B * @return String */ public static String speechReplaceLetter(String text, String A, String B) { return text.replace("【A】", A).replace("【B】", B); } /** * 获取线索配置表中的话术 */ public static String getSpeechFromClue(String uid, Integer taskId) { DemandTask demandTask = TimingAcquisition.demandTaskMap.get(taskId); return null; } /** * 删除话术的开头“【旁白@正常】” * @param text */ public static String deleteAsideHead(String text) { return text.replaceAll("【(.+)@(.{2,4})】", ""); } /** * 合并话术 * @param text1 * @param text2 */ public static String mergeSpeech(String text1, String text2) { text2 = deleteAsideHead(text2); return text1 + text2; } /** * 替换人物名称 * @param text * @return String */ public static String replaceHeader(String text, String name) { return text.replaceAll("【人物名称", "【" + name); } /** * 添加人物名称 * @param text * @return String */ public static String addHeader(String text, String name) { text = "【" + name + "@正常】" + text; return text; } /** * 加载闲聊话术 */ public static Map> getChatSpeechModel(String speechFilePath) { String chatPath = speechFilePath + "chat.xlsx"; ExcelReader reader = ExcelUtil.getReader(new File(chatPath)); reader.addHeaderAlias("意图反馈", "methodId"); reader.addHeaderAlias("身份", "identity"); reader.addHeaderAlias("人物名称", "personName"); reader.addHeaderAlias("性别", "gender"); reader.addHeaderAlias("年龄段", "age"); reader.addHeaderAlias("性格A", "dispositionIds"); reader.addHeaderAlias("行为", "behaviour"); reader.addHeaderAlias("任务状态", "taskStatus"); reader.addHeaderAlias("信任值", "trust"); reader.addHeaderAlias("威慑度", "deterrence"); reader.addHeaderAlias("文本内容", "answer"); reader.addHeaderAlias("通用标签", "flag"); List chatList = reader.readAll(ChatSpeech.class); reader.close(); Map> chatSpeechMap = new ConcurrentHashMap<>(); for (ChatSpeech chat : chatList) { if (StringUtils.isEmpty(chatSpeechMap.get(chat.getMethodId()))) { List chats = new ArrayList<>(); chats.add(chat); chatSpeechMap.put(chat.getMethodId(), chats); } else { chatSpeechMap.get(chat.getMethodId()).add(chat); } } return chatSpeechMap; } /** * 加载线索成功的话术 */ public static Map> getClueSpeechModel(String speechFilePath) { String clueSpeechPath = speechFilePath + "clue_success.xlsx"; ExcelReader reader = ExcelUtil.getReader(new File(clueSpeechPath)); reader.addHeaderAlias("线索ID", "clueId"); reader.addHeaderAlias("任务名称", "taskName"); reader.addHeaderAlias("身份1", "identity"); reader.addHeaderAlias("性别", "gender"); reader.addHeaderAlias("人物ID", "personId"); reader.addHeaderAlias("年龄段", "age"); reader.addHeaderAlias("性格A", "dispositionIds"); reader.addHeaderAlias("行为", "behaviour"); reader.addHeaderAlias("任务状态", "status"); reader.addHeaderAlias("线索文本", "answer"); reader.addHeaderAlias("自身线索文本", "answerSelf"); reader.addHeaderAlias("通用标签", "flag"); List clueSpeechList = reader.readAll(ClueSpeech.class); reader.close(); Map> clueSpeechMap = new ConcurrentHashMap<>(); for (ClueSpeech clueSpeech : clueSpeechList) { if (StringUtils.isEmpty(clueSpeechMap.get(clueSpeech.getClueId()))) { List clueSpeeches = new ArrayList<>(); clueSpeeches.add(clueSpeech); clueSpeechMap.put(clueSpeech.getClueId(), clueSpeeches); } else { clueSpeechMap.get(clueSpeech.getClueId()).add(clueSpeech); } } return clueSpeechMap; } /** * 加载任务成功的话术 */ public static Map> getTaskSpeechModel(String speechFilePath) { String taskSpeechPath = speechFilePath + "task_success.xlsx"; ExcelReader reader = ExcelUtil.getReader(new File(taskSpeechPath)); reader.addHeaderAlias("线索ID", "demandTaskId"); reader.addHeaderAlias("任务名称", "taskName"); reader.addHeaderAlias("身份1", "identity"); reader.addHeaderAlias("性别", "gender"); reader.addHeaderAlias("人物ID", "personId"); reader.addHeaderAlias("年龄段", "age"); reader.addHeaderAlias("性格A", "dispositionIds"); reader.addHeaderAlias("行为", "behaviour"); reader.addHeaderAlias("任务状态", "status"); reader.addHeaderAlias("进行中任务询问", "doingAsk"); reader.addHeaderAlias("进行中任务完成提醒", "doingFinishedAnswer"); reader.addHeaderAlias("未进行中任务完成提醒", "noDoingFinishedAnswer"); reader.addHeaderAlias("完成对话文本", "answer"); reader.addHeaderAlias("通用标签", "flag"); List taskSpeechList = reader.readAll(TaskSpeech.class); reader.close(); Map> taskSpeechMap = new ConcurrentHashMap<>(); for (TaskSpeech taskSpeech : taskSpeechList) { if (StringUtils.isEmpty(taskSpeechMap.get(taskSpeech.getDemandTaskId()))) { List taskSpeeches = new ArrayList<>(); taskSpeeches.add(taskSpeech); taskSpeechMap.put(taskSpeech.getDemandTaskId(), taskSpeeches); } else { taskSpeechMap.get(taskSpeech.getDemandTaskId()).add(taskSpeech); } } return taskSpeechMap; } /** * 加载人物见面成功的话术 */ public static Map> getPersonSpeechModel(String speechFilePath) { String personSpeechPath = speechFilePath + "person.xlsx"; ExcelReader reader = ExcelUtil.getReader(new File(personSpeechPath)); reader.addHeaderAlias("ID", "personId"); reader.addHeaderAlias("人物名称", "name"); reader.addHeaderAlias("人物描述", "description"); reader.addHeaderAlias("首次回复", "firstAnswer"); reader.addHeaderAlias("回复", "answer"); List personSpeechList = reader.readAll(PersonSpeech.class); reader.close(); Map> personSpeechMap = new ConcurrentHashMap<>(); for (PersonSpeech personSpeech : personSpeechList) { if (StringUtils.isEmpty(personSpeechMap.get(personSpeech.getName()))) { List personSpeeches = new ArrayList<>(); personSpeeches.add(personSpeech); personSpeechMap.put(personSpeech.getName(), personSpeeches); } else { personSpeechMap.get(personSpeech.getName()).add(personSpeech); } } return personSpeechMap; } /** * 加载任务提示的话术 */ public static Map> getTipSpeechModel(String speechFilePath) { String tipSpeechPath = speechFilePath + "tip.xlsx"; ExcelReader reader = ExcelUtil.getReader(new File(tipSpeechPath)); reader.addHeaderAlias("ID", "demandTaskId"); reader.addHeaderAlias("关于自身线索的指引", "selfClue"); reader.addHeaderAlias("关于他人线索的指引", "otherClue"); reader.addHeaderAlias("关于任务的指引", "taskClue"); List tipSpeechList = reader.readAll(TipSpeech.class); reader.close(); Map> tipSpeechMap = new ConcurrentHashMap<>(); for (TipSpeech tipSpeech : tipSpeechList) { if (StringUtils.isEmpty(tipSpeechMap.get(tipSpeech.getDemandTaskId()))) { List tipSpeeches = new ArrayList<>(); tipSpeeches.add(tipSpeech); tipSpeechMap.put(tipSpeech.getDemandTaskId(), tipSpeeches); } else { tipSpeechMap.get(tipSpeech.getDemandTaskId()).add(tipSpeech); } } return tipSpeechMap; } /** * 加载操作提示的话术 */ public static Map getOperateSpeechModel(String speechFilePath) { String operateSpeechPath = speechFilePath + "operate.xlsx"; ExcelReader reader = ExcelUtil.getReader(new File(operateSpeechPath)); reader.addHeaderAlias("ID", "id"); reader.addHeaderAlias("操作提示文本", "answer"); List operateSpeechList = reader.readAll(OperateSpeech.class); reader.close(); Map operateSpeechMap = new ConcurrentHashMap<>(); for (OperateSpeech operateSpeech : operateSpeechList) { operateSpeechMap.put(operateSpeech.getId(), operateSpeech); } return operateSpeechMap; } /** * 加载任务成功的话术 */ public static Map> getPreReasonSpeechModel(String speechFilePath) { String preReasonSpeechPath = speechFilePath + "pre_reason.xlsx"; ExcelReader reader = ExcelUtil.getReader(new File(preReasonSpeechPath)); reader.addHeaderAlias("任务ID", "demandTaskId"); reader.addHeaderAlias("线索ID", "clueId"); reader.addHeaderAlias("任务名称", "taskName"); reader.addHeaderAlias("自身身份", "identity"); reader.addHeaderAlias("对方身份", "identitySide"); reader.addHeaderAlias("性别", "gender"); reader.addHeaderAlias("人物名称", "personName"); reader.addHeaderAlias("年龄段", "age"); reader.addHeaderAlias("性格A", "dispositionIds"); reader.addHeaderAlias("关系", "relation"); reader.addHeaderAlias("行为", "behaviour"); reader.addHeaderAlias("第三方描述", "answer"); reader.addHeaderAlias("自身描述", "answerSelf"); reader.addHeaderAlias("通用标签", "flag"); List preReasonSpeechList = reader.readAll(PreReasonSpeech.class); reader.close(); Map> preReasonSpeechMap = new ConcurrentHashMap<>(); for (PreReasonSpeech preReasonSpeech : preReasonSpeechList) { if (StringUtils.isEmpty(preReasonSpeechMap.get(preReasonSpeech.getClueId()))) { List preReasonSpeeches = new ArrayList<>(); preReasonSpeeches.add(preReasonSpeech); preReasonSpeechMap.put(preReasonSpeech.getClueId(), preReasonSpeeches); } else { preReasonSpeechMap.get(preReasonSpeech.getClueId()).add(preReasonSpeech); } } return preReasonSpeechMap; } /** * 获取闲聊的话术 * @param uid * @param person * @param methodId */ public static String getChatSpeech(String uid, Person person, String methodId) { String text = ""; Map countMap = new HashMap<>(); List chatList = TimingAcquisition.chatSpeechMap.get(Integer.valueOf(methodId)); String gender = person.getGender() == 1 ? "男" : "女"; boolean flag = false; //有条件标记 int num = 0; for (int i = 0; i < chatList.size(); i++) { ChatSpeech chatSpeech = chatList.get(i); if (StringUtils.isEmpty(chatSpeech.getIdentity()) && StringUtils.isEmpty(chatSpeech.getGender()) && StringUtils.isEmpty(chatSpeech.getAge()) && StringUtils.isEmpty(chatSpeech.getDispositionIds())) { flag = true; num = i; continue; } int count = 0; //符合身份 if (!StringUtils.isEmpty(chatSpeech.getIdentity())) { if (person.getIdentityName().equals(chatSpeech.getIdentity())) { count++; } else { continue; } } //符合人物名称 if (!StringUtils.isEmpty(chatSpeech.getPersonName())) { if (person.getName().equals(chatSpeech.getPersonName())) { count++; } else { continue; } } //符合性别 if (!StringUtils.isEmpty(chatSpeech.getGender())) { if (gender.equals(chatSpeech.getGender())) { count++; } else { continue; } } //符合年龄 if (!StringUtils.isEmpty(chatSpeech.getAge())) { String[] ageRange = chatSpeech.getAge().split("\\|"); if(NumberUtil.inNumRange(person.getAge(),"["+ageRange[0]+","+ageRange[1]+"]")) { count++; } else { continue; } } //符合性格 if (!StringUtils.isEmpty(chatSpeech.getDispositionIds())) { String[] dispositionIds = chatSpeech.getDispositionIds().split("\\|"); //话术的性格要求 List dispositionIdList = Arrays.stream(dispositionIds).map(Integer::new).collect(Collectors.toList()); //对话人的性格要求 List dispositionPerson = person.getDispositions().stream().map(DispositionDto::getDispositionId).collect(Collectors.toList()); //所有性格都符合 if (PlayerUtil.checkSubset(dispositionIdList, dispositionPerson)) { count++; } else { continue; } } //符合信任值 if (!StringUtils.isEmpty(chatSpeech.getTrust())) { String[] trustRange = chatSpeech.getTrust().split("\\|"); if(NumberUtil.inNumRange(person.getTrustDegree(),"["+trustRange[0]+","+trustRange[1]+"]")) { count++; } else { continue; } } //符合威慑度 if (!StringUtils.isEmpty(chatSpeech.getDeterrence())) { String[] deterrenceRange = chatSpeech.getDeterrence().split("\\|"); if(NumberUtil.inNumRange(person.getDeterrenceDegree(),"["+deterrenceRange[0]+","+deterrenceRange[1]+"]")) { count++; } else { continue; } } countMap.put(i, count); } int max = 0; int index = 0; //找到命中次数最多的索引 for (Map.Entry entry : countMap.entrySet()) { if (entry.getValue() > max) { max = entry.getValue(); index = entry.getKey(); } } if (max == 0) { //有配置但是没有找到对应的话术 if (!flag) { //没有对应话术时,采用笼统的回复 List normalChatList = TimingAcquisition.chatSpeechMap.get(9002); for (ChatSpeech speech : normalChatList) { //符合身份 if (!StringUtils.isEmpty(speech.getIdentity())) { if (person.getIdentityName().equals(speech.getIdentity())) { //获取对应话术 text = speech.getAnswer(); break; } } } } else { //通用的话术 //获取对应话术 text = chatList.get(num).getAnswer(); } } else { //获取对应话术 text = chatList.get(index).getAnswer(); } text = text.replace("\n", ""); String[] result = text.split("\\|"); // int i = getRandomNum(0, result.length); int i = PlayerUtil.getNumByMethodId(uid, methodId, result.length); text = result[i]; //操作为9001的模糊闲聊操作,则提示相应的线索 if ("9001".equals(methodId)) { //线索提示文本 ClueDto clue = getClueTextByTypeLevel(uid, person, text); // while (StringUtils.isEmpty(clue)) { // int random = getRandomNum(0, result.length); // text = result[random]; // clue = getClueTextByTypeLevel(person, text); // } if (StringUtils.isEmpty(clue)) { for (String s : result) { text = s; clue = getClueTextByTypeLevel(uid, person, text); if (!StringUtils.isEmpty(clue)) { break; } } } String taskText = ""; String addText = ""; if (!StringUtils.isEmpty(clue)) { // if (clue.getType() == 6) { // DemandTaskDto demandTaskDto = PlayerUtil.getDemandTaskByClueId(person, clue); // ClueDto preClue = PlayerUtil.getPreClueById(person, demandTaskDto); // //获取对应话术 // if (!StringUtils.isEmpty(preClue) && !StringUtils.isEmpty(demandTaskDto)) { // preText = SpeechUtil.getPreReasonSpeech(uid, person, preClue, demandTaskDto.getDemandTaskId()); // if (!StringUtils.isEmpty(preText)) { // preText = SpeechUtil.addHeader(preText, person.getName()); // } // } // } //找到了对应的线索 addText = getSuccessClueSpeech(uid, person, clue); Integer currentId = TimingAcquisition.playerMap.get(uid).getPersonId(); // String currentName = TimingAcquisition.getNameByPersonId(uid, currentId); // if (currentId.equals(clue.getSubject()) || currentId.equals(clue.getObject())) { // addText = addText.replace("【" + currentName + "@正常" + "】", "【人物名称@正常】"); // addText = addText.replace("据说", "").replace("听说", "").replace(currentName, "我"); // addText = replaceHeader(addText, currentName); // } if (clue.getType() == 6) { //自身的任务线索 if (currentId.equals(clue.getSubject())) { //----------------是否解锁任务------------- PlayerUtil.unlockTask(uid, person, clue); Person subject = PlayerUtil.getPersonMap(uid).get(clue.getSubject()); DemandTaskDto demandTaskDto = PlayerUtil.getDemandTaskByClueId(subject, clue); Integer subjectId = person.getId(); if (!StringUtils.isEmpty(demandTaskDto)) { //判断后置任务是否已经完成 int isFinished = PlayerUtil.checkTaskStatus(uid, subjectId, demandTaskDto.getDemandTaskId()); //未完成 if (isFinished == 0) { if (demandTaskDto.getIsAuto() == 1) { String condition1 = demandTaskDto.getCondition1(); String[] taskIdTimes = condition1.split("\\|"); if ("71000".equals(taskIdTimes[0])) { Integer preTaskId = demandTaskDto.getDemandTaskId(); //后置 DemandTaskDto demandTaskPre = PlayerUtil.getDemandTaskInfo(uid, subjectId, preTaskId); //找到前置任务 if (!StringUtils.isEmpty(demandTaskPre)) { //后置任务自动完成 PlayerUtil.taskFinished(uid, subjectId, preTaskId); String preText = SpeechUtil.getSuccessTaskSpeech(uid, person, demandTaskPre); //有配置前置任务 if (!StringUtils.isEmpty(demandTaskDto.getPostTask())) { Integer postTaskId = Integer.valueOf(demandTaskDto.getPostTask());; //前置 //后置任务的主体 Integer objectId = demandTaskPre.getObject(); DemandTaskDto demandTaskPost = PlayerUtil.getDemandTaskInfo(uid, objectId, postTaskId); if (!StringUtils.isEmpty(demandTaskPost)) { //前置任务自动完成 PlayerUtil.taskFinished(uid, objectId, postTaskId); String postText = SpeechUtil.getSuccessTaskSpeech(uid, person, demandTaskPost); taskText += postText; } } taskText += preText; } } } } } } } addText = addText + taskText; } if (text.contains("<")) { int start = text.indexOf("<"); text = text.substring(0, start); } text += addText; } return text; } /** * 根据话术里的线索类型和层级过滤 */ public static ClueDto getClueTextByTypeLevel(String uid, Person person, String text) { //话术中没有配置需要返回线索提示 if (!text.contains("<")) { return null; } //配置了需要返回线索提示 int start = text.indexOf("<"); int end = text.indexOf(">"); String typeLevel = text.substring(start + 1, end); String[] typeAndLevel = typeLevel.split("&"); int type = Integer.parseInt(typeAndLevel[0]); int level = Integer.parseInt(typeAndLevel[1]); List clueList = PlayerUtil.getCluesByType(person, type, level); //过滤掉已经完成的任务对应的线索 clueList = PlayerUtil.getUndoClueList(uid, person, clueList); Integer currentId = TimingAcquisition.playerMap.get(uid).getPersonId(); List clueCopyList = new ArrayList<>(); for (ClueDto clue : clueList) { //过滤掉自身线索 if (!currentId.equals(clue.getSubject())) { if (!StringUtils.isEmpty(clue.getObject())) { if (!currentId.equals(clue.getObject())) { clueCopyList.add(clue); } } else { clueCopyList.add(clue); } } } //没有找到对应的线索 if (clueCopyList.size() == 0) { return null; } int index = RandomUtil.randomInt(clueCopyList.size()); //找到了对应的线索 return clueCopyList.get(index); } /** * 获取线索成功的话术 * @param uid * @param person * @param clue */ public static String getSuccessClueSpeech(String uid, Person person, ClueDto clue) { String text = ""; Map countMap = new HashMap<>(); Map> successClueSpeechMap = TimingAcquisition.successClueSpeechMap; List clueSpeechList = successClueSpeechMap.get(clue.getClueId()); String gender = person.getGender() == 1 ? "男" : "女"; String currentName = TimingAcquisition.getNameByPersonId(uid, TimingAcquisition.playerMap.get(uid).getPersonId()); for (int i = 1; i < clueSpeechList.size(); i++) { ClueSpeech clueSpeech = clueSpeechList.get(i); int count = 0; //符合身份 if (!StringUtils.isEmpty(clueSpeech.getIdentity())) { if (person.getIdentityName().equals(clueSpeech.getIdentity())) { count++; } else { continue; } } //符合性别 if (!StringUtils.isEmpty(clueSpeech.getGender())) { if (gender.equals(clueSpeech.getGender())) { count++; } else { continue; } } //符合年龄 if (!StringUtils.isEmpty(clueSpeech.getAge())) { String[] ageRange = clueSpeech.getAge().split("\\|"); if(NumberUtil.inNumRange(person.getAge(),"["+ageRange[0]+","+ageRange[1]+"]")) { count++; } else { continue; } } //符合性格 if (!StringUtils.isEmpty(clueSpeech.getDispositionIds())) { String[] dispositionIds = clueSpeech.getDispositionIds().split("\\|"); //话术的性格要求 List dispositionIdList = Arrays.stream(dispositionIds).map(Integer::new).collect(Collectors.toList()); //对话人的性格要求 List dispositionPerson = person.getDispositions().stream().map(DispositionDto::getDispositionId).collect(Collectors.toList()); //所有性格都符合 if (PlayerUtil.checkSubset(dispositionIdList, dispositionPerson)) { count++; } else { continue; } } countMap.put(i, count); } int max = 0; int index = 0; //找到命中次数最多的索引 for (Map.Entry entry : countMap.entrySet()) { if (entry.getValue() > max) { max = entry.getValue(); index = entry.getKey(); } } if (max == 0) { //获取对应话术 if (!person.getId().equals(clue.getSubject())) { text = clueSpeechList.get(0).getAnswer(); text = SpeechUtil.addHeader(text, currentName); } else { text = clueSpeechList.get(0).getAnswerSelf(); } } else { //获取对应话术 if (!person.getId().equals(clue.getSubject())) { text = clueSpeechList.get(index).getAnswer(); text = SpeechUtil.addHeader(text, currentName); } else { text = clueSpeechList.get(index).getAnswerSelf(); } } //话术中配置数据替换 if (text.contains("【A】")) { text = text.replace("【A】", TimingAcquisition.getNameByPersonId(uid, clue.getSubject())); } if (text.contains("【B】")) { text = text.replace("【B】", TimingAcquisition.getNameByPersonId(uid, clue.getObject())); } if (text.contains("【第三人称】")) { String call = (PlayerUtil.getPersonMap(uid).get(clue.getSubject()).getGender() == 1) ? "他" : "她"; text = text.replace("【第三人称】", call); } if (text.contains("A")) { text = text.replace("A", TimingAcquisition.getNameByPersonId(uid, clue.getSubject())); } if (text.contains("B")) { text = text.replace("B", TimingAcquisition.getNameByPersonId(uid, clue.getObject())); } String[] result = text.split("\\|"); Integer i = getRandomNum(0, result.length); text = result[i]; text = text.replace("\n", ""); return text; } /** * 获取任务成功的话术 * @param uid * @param person * @param demandTask */ public static String getSuccessTaskSpeech(String uid, Person person, DemandTaskDto demandTask) { String text = ""; Map countMap = new HashMap<>(); Map> successTaskSpeechMap = TimingAcquisition.successTaskSpeechMap; List taskSpeechList = successTaskSpeechMap.get(demandTask.getDemandTaskId()); String gender = person.getGender() == 1 ? "男" : "女"; if (StringUtils.isEmpty(taskSpeechList)) { return text; } for (int i = 1; i < taskSpeechList.size(); i++) { TaskSpeech taskSpeech = taskSpeechList.get(i); int count = 0; //符合身份 if (!StringUtils.isEmpty(taskSpeech.getIdentity())) { if (person.getIdentityName().equals(taskSpeech.getIdentity())) { count++; } else { continue; } } //符合性别 if (!StringUtils.isEmpty(taskSpeech.getGender())) { if (gender.equals(taskSpeech.getGender())) { count++; } else { continue; } } //符合年龄 if (!StringUtils.isEmpty(taskSpeech.getAge())) { String[] ageRange = taskSpeech.getAge().split("\\|"); if(NumberUtil.inNumRange(person.getAge(),"["+ageRange[0]+","+ageRange[1]+"]")) { count++; } else { continue; } } //符合性格 if (!StringUtils.isEmpty(taskSpeech.getDispositionIds())) { String[] dispositionIds = taskSpeech.getDispositionIds().split("\\|"); //话术的性格要求 List dispositionIdList = Arrays.stream(dispositionIds).map(Integer::new).collect(Collectors.toList()); //对话人的性格要求 List dispositionPerson = person.getDispositions().stream().map(DispositionDto::getDispositionId).collect(Collectors.toList()); //所有性格都符合 if (PlayerUtil.checkSubset(dispositionIdList, dispositionPerson)) { count++; } else { continue; } } countMap.put(i, count); } int max = 0; int index = 0; //找到命中次数最多的索引 for (Map.Entry entry : countMap.entrySet()) { if (entry.getValue() > max) { max = entry.getValue(); index = entry.getKey(); } } if (max == 0) { //获取对应话术 text = taskSpeechList.get(0).getAnswer(); } else { //获取对应话术 text = taskSpeechList.get(index).getAnswer(); } //话术中配置数据替换 if (text.contains("【A】")) { text = text.replace("【A】", TimingAcquisition.getNameByPersonId(uid, demandTask.getSubject())); } if (text.contains("【B】")) { text = text.replace("【B】", TimingAcquisition.getNameByPersonId(uid, demandTask.getObject())); } if (text.contains("【第三人称】")) { String call = (PlayerUtil.getPersonMap(uid).get(demandTask.getSubject()).getGender() == 1) ? "他" : "她"; text = text.replace("【第三人称】", call); } if (text.contains("【条件2】")) { if (!StringUtils.isEmpty(demandTask.getCondition2())) { text = text.replace("【条件2】", demandTask.getCondition2()); } } if (text.contains("【奖励】")) { if (!StringUtils.isEmpty(demandTask.getCompletionReward())) { if (!"0".equals(demandTask.getCompletionReward())) { PlayerUtil.addMoneyNum(uid, Integer.parseInt(demandTask.getCompletionReward())); text = text.replace("【奖励】", demandTask.getCompletionReward()); } } } if (text.contains("A")) { text = text.replace("A", TimingAcquisition.getNameByPersonId(uid, demandTask.getSubject())); } if (text.contains("B")) { text = text.replace("B", TimingAcquisition.getNameByPersonId(uid, demandTask.getObject())); } //补充信任值和威慑度增减的回复 String addText = "【旁白@正常】【1】对你的信任达到【2】,对你的畏惧达到【3】。"; addText = speechReplaceNum(addText, person.getName(), String.valueOf(person.getTrustDegree() - 50), String.valueOf(person.getDeterrenceDegree() - 50)); // if (!StringUtils.isEmpty(demandTask.getCompletionReward())) { // if (!"0".equals(demandTask.getCompletionReward())) { // addText += "你获得" + demandTask.getCompletionReward() + "文酬劳。"; // } // } text += addText; text = text.replace("\n", ""); String[] result = text.split("\\|"); Integer i = getRandomNum(0, result.length); text = result[i]; return text; } /** * 获取前后置任务成功的话术 * @param uid * @param person * @param demandTask */ public static String getPreSuccessTaskSpeech(String uid, Person person, DemandTaskDto demandTask, int level) { String text = ""; Map countMap = new HashMap<>(); Map> successTaskSpeechMap = TimingAcquisition.successTaskSpeechMap; List taskSpeechList = successTaskSpeechMap.get(demandTask.getDemandTaskId()); if (StringUtils.isEmpty(taskSpeechList)) { return text; } String gender = person.getGender() == 1 ? "男" : "女"; for (int i = 1; i < taskSpeechList.size(); i++) { TaskSpeech taskSpeech = taskSpeechList.get(i); int count = 0; //符合身份 if (!StringUtils.isEmpty(taskSpeech.getIdentity())) { if (person.getIdentityName().equals(taskSpeech.getIdentity())) { count++; } else { continue; } } //符合性别 if (!StringUtils.isEmpty(taskSpeech.getGender())) { if (gender.equals(taskSpeech.getGender())) { count++; } else { continue; } } //符合年龄 if (!StringUtils.isEmpty(taskSpeech.getAge())) { String[] ageRange = taskSpeech.getAge().split("\\|"); if(NumberUtil.inNumRange(person.getAge(),"["+ageRange[0]+","+ageRange[1]+"]")) { count++; } else { continue; } } //符合性格 if (!StringUtils.isEmpty(taskSpeech.getDispositionIds())) { String[] dispositionIds = taskSpeech.getDispositionIds().split("\\|"); //话术的性格要求 List dispositionIdList = Arrays.stream(dispositionIds).map(Integer::new).collect(Collectors.toList()); //对话人的性格要求 List dispositionPerson = person.getDispositions().stream().map(DispositionDto::getDispositionId).collect(Collectors.toList()); //所有性格都符合 if (PlayerUtil.checkSubset(dispositionIdList, dispositionPerson)) { count++; } else { continue; } } countMap.put(i, count); } int max = 0; int index = 0; //找到命中次数最多的索引 for (Map.Entry entry : countMap.entrySet()) { if (entry.getValue() > max) { max = entry.getValue(); index = entry.getKey(); } } String addText = ""; if (max == 0) { //获取对应话术 if (level == 1) { text = taskSpeechList.get(0).getDoingFinishedAnswer(); text += taskSpeechList.get(0).getAnswer(); } if (level == 2) { text = taskSpeechList.get(0).getNoDoingFinishedAnswer(); text += taskSpeechList.get(0).getAnswer(); } if (level == 3) { text = taskSpeechList.get(0).getDoingAsk(); } } else { //获取对应话术 if (level == 1) { text = taskSpeechList.get(index).getDoingFinishedAnswer(); text += taskSpeechList.get(index).getAnswer(); //补充信任值和威慑度增减的回复 addText = "【旁白@正常】【1】对你的信任达到【2】,对你的畏惧达到【3】。"; addText = speechReplaceNum(addText, person.getName(), String.valueOf(person.getTrustDegree() - 50), String.valueOf(person.getDeterrenceDegree() - 50)); if (!StringUtils.isEmpty(demandTask.getCompletionReward())) { if (!"0".equals(demandTask.getCompletionReward())) { addText += "你获得" + demandTask.getCompletionReward() + "文酬劳。"; } } } if (level == 2) { text = taskSpeechList.get(index).getNoDoingFinishedAnswer(); text += taskSpeechList.get(index).getAnswer(); //补充信任值和威慑度增减的回复 addText = "【旁白@正常】【1】对你的信任达到【2】,对你的畏惧达到【3】。"; addText = speechReplaceNum(addText, person.getName(), String.valueOf(person.getTrustDegree() - 50), String.valueOf(person.getDeterrenceDegree() - 50)); if (!StringUtils.isEmpty(demandTask.getCompletionReward())) { if (!"0".equals(demandTask.getCompletionReward())) { addText += "你获得" + demandTask.getCompletionReward() + "文酬劳。"; } } } if (level == 3) { text = taskSpeechList.get(index).getDoingAsk(); } } text = addHeader(text, person.getName()); //话术中配置数据替换 if (text.contains("【A】")) { text = text.replace("【A】", TimingAcquisition.getNameByPersonId(uid, demandTask.getSubject())); } if (text.contains("【B】")) { text = text.replace("【B】", TimingAcquisition.getNameByPersonId(uid, demandTask.getObject())); } if (text.contains("【第三人称】")) { String call = (PlayerUtil.getPersonMap(uid).get(demandTask.getSubject()).getGender() == 1) ? "他" : "她"; text = text.replace("【第三人称】", call); } if (text.contains("【条件2】")) { if (!StringUtils.isEmpty(demandTask.getCondition2())) { text = text.replace("【条件2】", demandTask.getCondition2()); } } if (text.contains("【奖励】")) { if (!StringUtils.isEmpty(demandTask.getCompletionReward())) { if (!"0".equals(demandTask.getCompletionReward())) { PlayerUtil.addMoneyNum(uid, Integer.parseInt(demandTask.getCompletionReward())); text = text.replace("【奖励】", demandTask.getCompletionReward()); } } } if (text.contains("A")) { text = text.replace("A", TimingAcquisition.getNameByPersonId(uid, demandTask.getSubject())); } if (text.contains("B")) { text = text.replace("B", TimingAcquisition.getNameByPersonId(uid, demandTask.getObject())); } text += addText; text = text.replace("\n", ""); String[] result = text.split("\\|"); Integer i = getRandomNum(0, result.length); text = result[i]; return text; } /** * 获取自身任务线索提示的话术 * @param uid * @param demandTask * @param personId * @param source */ public static String getTipSpeech(String uid, DemandTaskDto demandTask, Integer personId, int source) { String text = ""; Map> tipSpeechMap = TimingAcquisition.tipSpeechMap; List tipSpeechList = tipSpeechMap.get(demandTask.getDemandTaskId()); if (StringUtils.isEmpty(tipSpeechList)) { return text; } //当前能做的任务线索 if (source == 1) { //获取对应话术 text = tipSpeechList.get(0).getTaskClue(); } //自身能解锁任务的线索 if (source == 2) { //获取对应话术 text = tipSpeechList.get(0).getSelfClue(); } //他人能解锁任务的线索 if (source == 3) { //获取对应话术 text = tipSpeechList.get(0).getOtherClue(); } //话术中配置数据替换 if (text.contains("【A】")) { text = text.replace("【A】", TimingAcquisition.getNameByPersonId(uid, demandTask.getSubject())); } if (text.contains("【B】")) { text = text.replace("【B】", TimingAcquisition.getNameByPersonId(uid, demandTask.getObject())); } if (personId != 0) { if (text.contains("【C】")) { text = text.replace("【C】", TimingAcquisition.getNameByPersonId(uid, personId)); } } text = text.replace("\n", ""); String[] result = text.split("\\|"); Integer i = getRandomNum(0, result.length); text = result[i]; return text; } /** * 获取他人线索提示的话术 * @param uid * @param barrierTaskKey * @param personId */ public static String getTipSpeech(String uid, BarrierTaskKeyDto barrierTaskKey, Integer personId) { String text = ""; Map> tipSpeechMap = TimingAcquisition.tipSpeechMap; List tipSpeechList = tipSpeechMap.get(barrierTaskKey.getDemandTaskId()); if (StringUtils.isEmpty(tipSpeechList)) { return text; } //他人能解锁任务的线索 //获取对应话术 text = tipSpeechList.get(0).getOtherClue(); //话术中配置数据替换 if (text.contains("【A】")) { text = text.replace("【A】", TimingAcquisition.getNameByPersonId(uid, personId)); } if (personId != 0) { if (text.contains("【C】")) { text = text.replace("【C】", TimingAcquisition.getNameByPersonId(uid, barrierTaskKey.getSubject())); } } text = text.replace("\n", ""); String[] result = text.split("\\|"); Integer i = getRandomNum(0, result.length); text = result[i]; return text; } /** * 获取人物见面时的话术 */ public static String getPersonSpeech(String uid, String locationId, Integer personId) { String text = ""; String name = PlayerUtil.getPersonMap(uid).get(personId).getName(); //判断该人物是否是第一次见面 boolean isFirstMeet = PlayerUtil.isFirstMeet(uid, locationId, personId); if (isFirstMeet) { String asideText = "【旁白@正常】" + TimingAcquisition.personSpeechMap.get(name).get(0).getDescription(); String personText = "【人物名称@正常】" + TimingAcquisition.personSpeechMap.get(name).get(0).getFirstAnswer(); text = asideText + personText; } else { text = "【人物名称@正常】" + TimingAcquisition.personSpeechMap.get(name).get(0).getAnswer(); } String[] result = text.split("\\|"); Integer i = getRandomNum(0, result.length); text = result[i]; return text; } /** * 获取人物见面时的话术 */ public static String getOperateSpeech(Player player) { Integer index = player.getOperateTextNum(); Map id2NameMap = player.getId2NameMap(); Map operateSpeechMap = TimingAcquisition.operateSpeechMap; if (!StringUtils.isEmpty(operateSpeechMap.get(index))) { String text = operateSpeechMap.get(index).getAnswer(); if (text.contains("【1】")) { text = text.replace("【1】", id2NameMap.get(1)); } if (text.contains("【2】")) { text = text.replace("【2】", id2NameMap.get(2)); } if (text.contains("【3】")) { text = text.replace("【3】", id2NameMap.get(3)); } if (text.contains("【4】")) { text = text.replace("【4】", id2NameMap.get(4)); } if (text.contains("【5】")) { text = text.replace("【5】", id2NameMap.get(5)); } if (text.contains("【6】")) { text = text.replace("【6】", id2NameMap.get(6)); } if (text.contains("【7】")) { text = text.replace("【7】", id2NameMap.get(7)); } if (text.contains("【8】")) { text = text.replace("【8】", id2NameMap.get(8)); } return text; } else { return null; } } /** * 获取前后置任务成功的话术 * @param uid * @param person * @param demandTask */ public static String speechReplaceValue(String uid, String text, Person person, DemandTaskDto demandTask) { //话术中配置数据替换 if (text.contains("【A】")) { text = text.replace("【A】", TimingAcquisition.getNameByPersonId(uid, demandTask.getSubject())); } if (text.contains("【B】")) { text = text.replace("【B】", TimingAcquisition.getNameByPersonId(uid, demandTask.getObject())); } if (text.contains("【第三人称】")) { String call = (PlayerUtil.getPersonMap(uid).get(demandTask.getSubject()).getGender() == 1) ? "他" : "她"; text = text.replace("【第三人称】", call); } if (text.contains("【条件2】")) { if (!StringUtils.isEmpty(demandTask.getCondition2())) { text = text.replace("【条件2】", demandTask.getCondition2()); } } if (text.contains("【奖励】")) { if (!StringUtils.isEmpty(demandTask.getCompletionReward())) { if (!"0".equals(demandTask.getCompletionReward())) { PlayerUtil.addMoneyNum(uid, Integer.parseInt(demandTask.getCompletionReward())); text = text.replace("【奖励】", demandTask.getCompletionReward()); } } } if (text.contains("A")) { text = text.replace("A", TimingAcquisition.getNameByPersonId(uid, demandTask.getSubject())); } if (text.contains("B")) { text = text.replace("B", TimingAcquisition.getNameByPersonId(uid, demandTask.getObject())); } if (text.contains("【信任值】")) { text = text.replace("【信任值】", String.valueOf(person.getTrustDegree() - 50)); } if (text.contains("【威慑度】")) { text = text.replace("【威慑度】", String.valueOf(person.getDeterrenceDegree() - 50)); } text = text.replace("\n", ""); return text; } /** * 获取关卡的开场白 */ public static String getPrologueSpeech(String uid, String gateNo) { int size = TimingAcquisition.barrierTaskKeyMap.get(gateNo).size(); Integer demandTaskId = TimingAcquisition.barrierTaskKeyMap.get(gateNo).get(size - 1).getDemandTaskId(); Map endGoalMap = TimingAcquisition.endGoalMap; //搭档名称 String partnerName = TimingAcquisition.systemConfigMap.get("partnerName").getValue(); String text = ""; for (Map.Entry entry : endGoalMap.entrySet()) { EndGoal endGoal = entry.getValue(); List associatedTaskIds = Arrays.asList(endGoal.getAssociatedTaskId().split("\\|")); if (associatedTaskIds.contains(demandTaskId.toString())) { text = "【旁白@正常】" + endGoal.getName(); text += "【旁白@正常】" + endGoal.getDescription(); text += SpeechUtil.getAskSpeech(Constants.SPEECH_PERSON, 103101); text += SpeechUtil.getAskSpeech(Constants.SPEECH_PERSON, 103102); text = SpeechUtil.replaceHeader(text, partnerName); String location = TimingAcquisition.locationMap.get(TimingAcquisition.playerMap.get(uid).getLocation()).getName(); String name = PlayerUtil.getNameByPersonId(uid, TimingAcquisition.playerMap.get(uid).getPersonId()); text = SpeechUtil.speechReplaceNum(text, location, name); break; } } return text; } /** * 获取线索成功的话术 * @param uid * @param person * @param clue */ public static String getPreReasonSpeech(String uid, Person person, ClueDto clue, Integer demandTaskId) { String text = ""; Map countMap = new HashMap<>(); Map> preReasonSpeechMap = TimingAcquisition.preReasonSpeechMap; List preReasonSpeechList = preReasonSpeechMap.get(clue.getClueId()); //当前对话人 Integer currentId = TimingAcquisition.playerMap.get(uid).getPersonId(); if (StringUtils.isEmpty(preReasonSpeechList)) { return text; } String gender = person.getGender() == 1 ? "男" : "女"; for (int i = 0; i < preReasonSpeechList.size(); i++) { PreReasonSpeech preReasonSpeech = preReasonSpeechList.get(i); int count = 0; if (!preReasonSpeech.getDemandTaskId().equals(demandTaskId)) { continue; } //符合行为 if (!StringUtils.isEmpty(preReasonSpeech.getBehaviour())) { Integer behaviour = preReasonSpeech.getBehaviour(); List behaviourIdList = person.getBehaviours().stream().map(BehaviourDto::getBehaviourId).collect(Collectors.toList()); if(behaviourIdList.contains(behaviour)) { count++; } else { continue; } } //符合关系 if (!StringUtils.isEmpty(preReasonSpeech.getRelation())) { Integer relation = preReasonSpeech.getRelation(); List relationIdList = person.getRelations().stream().map(RelationDto::getRelationId).collect(Collectors.toList()); if(relationIdList.contains(relation)) { count++; } else { continue; } } //符合性格 if (!StringUtils.isEmpty(preReasonSpeech.getDispositionId())) { //话术的性格要求 Integer dispositionId = preReasonSpeech.getDispositionId(); //对话人的性格要求 List dispositionPerson = person.getDispositions().stream().map(DispositionDto::getDispositionId).collect(Collectors.toList()); //所有性格都符合 if (dispositionPerson.contains(dispositionId)) { count++; } else { continue; } } //符合自身身份 if (!StringUtils.isEmpty(preReasonSpeech.getIdentity())) { if (person.getIdentityId().equals(preReasonSpeech.getIdentity())) { count++; } else { continue; } } //符合对方身份 if (!StringUtils.isEmpty(preReasonSpeech.getIdentitySide())) { if (!StringUtils.isEmpty(clue.getObject())) { Integer identityIdSide = PlayerUtil.getPersonMap(uid).get(clue.getObject()).getIdentityId(); if (identityIdSide.equals(preReasonSpeech.getIdentitySide())) { count++; } else { continue; } } } //符合性别 if (!StringUtils.isEmpty(preReasonSpeech.getGender())) { if (gender.equals(preReasonSpeech.getGender())) { count++; } else { continue; } } //符合年龄 if (!StringUtils.isEmpty(preReasonSpeech.getAge())) { String[] ageRange = preReasonSpeech.getAge().split("\\|"); if(NumberUtil.inNumRange(person.getAge(),"["+ageRange[0]+","+ageRange[1]+"]")) { count++; } else { continue; } } countMap.put(i, count); } int max = 0; List indexList = new ArrayList<>(); //找到命中次数最多的索引 for (Map.Entry entry : countMap.entrySet()) { if (entry.getValue() >= max) { max = entry.getValue(); indexList.add(entry.getKey()); } } if (max == 0) { //获取对应话术 if (!currentId.equals(clue.getSubject())) { text = preReasonSpeechList.get(0).getAnswer(); } else { text = preReasonSpeechList.get(0).getAnswerSelf(); } } else { int index = 0; //命中次数最多的有多条,按优先级查找(行为 > 关系 > 性格) if (indexList.size() > 1) { //记录索引的优先级 Map indexSortMap = new HashMap<>(); //遍历所有索引,划分优先级 for (Integer i : indexList) { PreReasonSpeech preReasonSpeech = preReasonSpeechList.get(i); //配置了行为 if (!StringUtils.isEmpty(preReasonSpeech.getBehaviour())) { //配置了自身身份 if (!StringUtils.isEmpty(preReasonSpeech.getIdentity())) { indexSortMap.put(i, 1); } //配置了对方身份 if (!StringUtils.isEmpty(preReasonSpeech.getIdentitySide())) { indexSortMap.put(i, 2); } } //配置了关系 if (!StringUtils.isEmpty(preReasonSpeech.getRelation())) { //配置了自身身份 if (!StringUtils.isEmpty(preReasonSpeech.getIdentity())) { indexSortMap.put(i, 3); } //配置了对方身份 if (!StringUtils.isEmpty(preReasonSpeech.getIdentitySide())) { indexSortMap.put(i, 4); } } //配置了性格 if (!StringUtils.isEmpty(preReasonSpeech.getDispositionId())) { //配置了自身身份 if (!StringUtils.isEmpty(preReasonSpeech.getIdentity())) { indexSortMap.put(i, 5); } //配置了对方身份 if (!StringUtils.isEmpty(preReasonSpeech.getIdentitySide())) { indexSortMap.put(i, 6); } } } //找出优先级最高的索引 int min = 6; for (Map.Entry entry : indexSortMap.entrySet()) { if (entry.getValue() <= min) { min = entry.getValue(); index = entry.getKey(); } } } else { index = indexList.get(0); } //获取对应话术 if (!currentId.equals(clue.getSubject())) { text = preReasonSpeechList.get(index).getAnswer(); } else { text = preReasonSpeechList.get(index).getAnswerSelf(); } } //话术中配置数据替换 if (text.contains("【A】")) { text = text.replace("【A】", TimingAcquisition.getNameByPersonId(uid, clue.getSubject())); } if (text.contains("【B】")) { text = text.replace("【B】", TimingAcquisition.getNameByPersonId(uid, clue.getObject())); } if (text.contains("【第三人称】")) { String call = (PlayerUtil.getPersonMap(uid).get(clue.getSubject()).getGender() == 1) ? "他" : "她"; text = text.replace("【第三人称】", call); } if (text.contains("A")) { text = text.replace("A", TimingAcquisition.getNameByPersonId(uid, clue.getSubject())); } if (text.contains("B")) { text = text.replace("B", TimingAcquisition.getNameByPersonId(uid, clue.getObject())); } String[] result = text.split("\\|"); Integer i = getRandomNum(0, result.length); text = result[i]; return text; } }