package com.qiwu.inference.common.utils; import cn.hutool.poi.excel.ExcelReader; import cn.hutool.poi.excel.ExcelUtil; import com.opencsv.CSVReader; import com.opencsv.CSVReaderBuilder; 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.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; import java.io.*; import java.nio.charset.Charset; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; @Component public class SpeechUtil { public static String expireTime; @Value("${expireTime}") public void setExpireTime(String expireTime) { SpeechUtil.expireTime = expireTime; } /** * 取指定范围内的随机数 * @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 uid * @param someone * @param feedText * @return String */ public static String getAskSpeech(String uid, String someone, Integer feedText) { String result = ""; List speech; String series = TimingAcquisition.playerMap.get(uid).getSeries(); //系列 String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //关卡编号 Map>> askSpeechMap = TimingAcquisition.gateNoAskSpeechMap.get(gateNo); if (!StringUtils.isEmpty(askSpeechMap)) { speech = askSpeechMap.get(someone).get(feedText); } else { speech = TimingAcquisition.seriesAskSpeechMap.get(series).get(someone).get(feedText); } Integer i = getRandomNum(0, speech.size()); result = speech.get(i); return result; } /** * 从任务模块话术获取话术 * @param uid * @param someone * @param feedText * @return String */ public static String getTaskSpeech(String uid, String someone, Integer feedText) { String result = ""; List speech; String series = TimingAcquisition.playerMap.get(uid).getSeries(); //系列 String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //关卡编号 Map>> askSpeechMap = TimingAcquisition.gateNoTaskSpeechMap.get(gateNo); if (!StringUtils.isEmpty(askSpeechMap)) { speech = askSpeechMap.get(someone).get(feedText); } else { speech = TimingAcquisition.seriesTaskSpeechMap.get(series).get(someone).get(feedText); } Integer i = getRandomNum(0, speech.size()); result = speech.get(i); return result; } /** * 从查看模块话术获取话术 * @param uid * @param someone * @param feedText * @return String */ public static String getCheckSpeech(String uid, String someone, Integer feedText) { String result = ""; List speech; String series = TimingAcquisition.playerMap.get(uid).getSeries(); //系列 String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //关卡编号 Map>> askSpeechMap = TimingAcquisition.gateNoCheckSpeechMap.get(gateNo); if (!StringUtils.isEmpty(askSpeechMap)) { speech = askSpeechMap.get(someone).get(feedText); } else { speech = TimingAcquisition.seriesCheckSpeechMap.get(series).get(someone).get(feedText); } Integer i = getRandomNum(0, speech.size()); result = speech.get(i); return result; } /** * 从查看模块话术获取话术 * @param uid * @param someone * @param feedText * @return String */ public static String getBarrierSpeech(String uid, String someone, Integer feedText) { String result = ""; List speech; String series = TimingAcquisition.playerMap.get(uid).getSeries(); //系列 String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //关卡编号 Map>> askSpeechMap = TimingAcquisition.gateNoBarrierSpeechMap.get(gateNo); if (!StringUtils.isEmpty(askSpeechMap)) { speech = askSpeechMap.get(someone).get(feedText); } else { speech = TimingAcquisition.seriesBarrierSpeechMap.get(series).get(someone).get(feedText); } Integer i = getRandomNum(0, speech.size()); result = speech.get(i); return result; } /** * 从查看模块话术获取话术 * @param uid * @param someone * @param feedText * @return String */ public static String getPartnerItemSpeech(String uid, String someone, Integer feedText) { String result = ""; List speech; String series = TimingAcquisition.playerMap.get(uid).getSeries(); //系列 String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //关卡编号 Map>> askSpeechMap = TimingAcquisition.gateNoPartnerItemSpeechMap.get(gateNo); if (!StringUtils.isEmpty(askSpeechMap)) { speech = askSpeechMap.get(someone).get(feedText); } else { speech = TimingAcquisition.seriesPartnerItemSpeechMap.get(series).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) { if (text.contains("【A】")) { text = text.replaceAll("【A】", name);; } if (text.contains("【A")) { text = text.replaceAll("【A", "【" + name);; } if (text.contains("【人物名称")) { text = text.replaceAll("【人物名称", "【" + name);; } return text; } /** * 添加人物名称 * @param text * @return String */ public static String addHeader(String text, String name) { text = "【" + name + "@正常】" + text; return text; } /** * 加载闲聊话术 */ public static Map> getChatSpeechModel(String speechFilePath) throws IOException { String chatPath = speechFilePath + "chat.csv"; CsvUtil csvUtil = new CsvUtil<>(); List chatList = csvUtil.read(chatPath, ChatSpeech.class); 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.csv"; CsvUtil csvUtil = new CsvUtil<>(); List clueSpeechList = csvUtil.read(clueSpeechPath, ClueSpeech.class); 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.csv"; CsvUtil csvUtil = new CsvUtil<>(); List taskSpeechList = csvUtil.read(taskSpeechPath, TaskSpeech.class); 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.csv"; CsvUtil csvUtil = new CsvUtil<>(); List personSpeechList = csvUtil.read(personSpeechPath, PersonSpeech.class); 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.csv"; CsvUtil csvUtil = new CsvUtil<>(); List tipSpeechList = csvUtil.read(tipSpeechPath, TipSpeech.class); 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.csv"; CsvUtil csvUtil = new CsvUtil<>(); List operateSpeechList = csvUtil.read(operateSpeechPath, OperateSpeech.class); Map operateSpeechMap = new ConcurrentHashMap<>(); for (OperateSpeech operateSpeech : operateSpeechList) { operateSpeechMap.put(operateSpeech.getId(), operateSpeech); } return operateSpeechMap; } /** * 加载任务异常的话术 */ public static Map getTaskExceptionSpeechModel(String speechFilePath) { String taskExceptionSpeechPath = speechFilePath + "task_exception.csv"; CsvUtil csvUtil = new CsvUtil<>(); List taskExceptionSpeechList = csvUtil.read(taskExceptionSpeechPath, TaskExceptionSpeech.class); Map taskExceptionSpeechMap = new ConcurrentHashMap<>(); for (TaskExceptionSpeech taskExceptionSpeech : taskExceptionSpeechList) { taskExceptionSpeechMap.put(taskExceptionSpeech.getId(), taskExceptionSpeech); } return taskExceptionSpeechMap; } /** * 加载原因的话术 */ public static Map> getPreReasonSpeechModel(String speechFilePath) { String preReasonSpeechPath = speechFilePath + "pre_reason.csv"; CsvUtil csvUtil = new CsvUtil<>(); List preReasonSpeechList = csvUtil.read(preReasonSpeechPath, PreReasonSpeech.class); 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 = new ArrayList<>(); String series = TimingAcquisition.playerMap.get(uid).getSeries(); //系列 String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //关卡编号 Map> chatSpeechMap = TimingAcquisition.gateNoChatSpeechMap.get(gateNo); if (!StringUtils.isEmpty(chatSpeechMap)) { chatList = chatSpeechMap.get(Integer.valueOf(methodId)); } else { chatList = TimingAcquisition.seriesChatSpeechMap.get(series).get(Integer.valueOf(methodId)); } String gender = person.getGender() == 1 ? "男" : "女"; //当前对话人 PersonInfoDto talk = TimingAcquisition.playerMap.get(uid).getPersonInfoMap().get(person.getId()); 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(talk.getTrustDegree(),"["+trustRange[0]+","+trustRange[1]+"]")) { count++; } else { continue; } } //符合威慑度 if (!StringUtils.isEmpty(chatSpeech.getDeterrence())) { String[] deterrenceRange = chatSpeech.getDeterrence().split("\\|"); if(NumberUtil.inNumRange(talk.getDeterrenceDegree(),"["+deterrenceRange[0]+","+deterrenceRange[1]+"]")) { count++; } else { continue; } } //符合时间范围 if (!StringUtils.isEmpty(chatSpeech.getTime())) { String[] timeRange = chatSpeech.getTime().split("\\|"); if(NumberUtil.inNumRange(TimingAcquisition.playerMap.get(uid).getInitTime(),"["+timeRange[0]+","+timeRange[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 = new ArrayList<>(); if (!StringUtils.isEmpty(chatSpeechMap)) { normalChatList = chatSpeechMap.get(9002); } else { normalChatList = TimingAcquisition.seriesChatSpeechMap.get(series).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)) { String textCopy = null; for (String s : result) { textCopy = s; clue = getClueTextByTypeLevel(uid, person, textCopy); if (!StringUtils.isEmpty(clue)) { text = textCopy; 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())) { Person subject = PlayerUtil.getPersonMap(uid).get(clue.getSubject()); DemandTaskDto demandTaskDto = PlayerUtil.getDemandTaskByClueId(subject, clue); Integer subjectId = person.getId(); //----------------是否解锁任务------------- PlayerUtil.unlockTask(uid, TimingAcquisition.playerMap.get(uid).getPersonInfoMap().get(subjectId), clue); 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; //任务为最终任务,或者时间值到1或以下,通关 if (demandTaskDto.getTaskLabel() == 3 || TimingAcquisition.playerMap.get(uid).getInitTime() <= 1 || text.contains(Constants.END_TEXT)) { //数据更新与结算 PlayerUtil.clearanceUpdate(uid); } } } } } } } } 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<>(); List clueSpeechList; String series = TimingAcquisition.playerMap.get(uid).getSeries(); //系列 String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //关卡编号 Map> clueSpeechMap = TimingAcquisition.gateNoSuccessClueSpeechMap.get(gateNo); if (!StringUtils.isEmpty(clueSpeechMap)) { clueSpeechList = clueSpeechMap.get(clue.getClueId()); } else { clueSpeechList = TimingAcquisition.seriesSuccessClueSpeechMap.get(series).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", ""); //如果没有指定说话人,则默认当前对话人 if (!text.contains("@正常】")) { text = addHeader(text, person.getName()); } return text; } /** * 获取线索成功的话术 * @param uid * @param person * @param clue */ public static String getSuccessClueOtherSpeech(String uid, Person person, ClueDto clue) { String text = ""; Map countMap = new HashMap<>(); List clueSpeechList; String series = TimingAcquisition.playerMap.get(uid).getSeries(); //系列 String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //关卡编号 Map> clueSpeechMap = TimingAcquisition.gateNoSuccessClueSpeechMap.get(gateNo); if (!StringUtils.isEmpty(clueSpeechMap)) { clueSpeechList = clueSpeechMap.get(clue.getClueId()); } else { clueSpeechList = TimingAcquisition.seriesSuccessClueSpeechMap.get(series).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) { //获取对应话术 text = clueSpeechList.get(0).getAnswer(); } else { //获取对应话术 text = clueSpeechList.get(index).getAnswer(); } //话术中配置数据替换 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", ""); //如果没有指定说话人,则默认当前对话人 if (!text.contains("@正常】")) { text = addHeader(text, person.getName()); } return text; } /** * 获取线索成功的话术 * @param uid * @param person * @param clue */ public static String getClueWithPreSpeech(String uid, Person person, ClueDto clue) { String text = ""; Map countMap = new HashMap<>(); List clueSpeechList; String series = TimingAcquisition.playerMap.get(uid).getSeries(); //系列 String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //关卡编号 Map> clueSpeechMap = TimingAcquisition.gateNoSuccessClueSpeechMap.get(gateNo); if (!StringUtils.isEmpty(clueSpeechMap)) { clueSpeechList = clueSpeechMap.get(clue.getClueId()); } else { clueSpeechList = TimingAcquisition.seriesSuccessClueSpeechMap.get(series).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<>(); List taskSpeechList; String series = TimingAcquisition.playerMap.get(uid).getSeries(); //系列 String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //关卡编号 Map> taskSpeechMap = TimingAcquisition.gateNoSuccessTaskSpeechMap.get(gateNo); if (!StringUtils.isEmpty(taskSpeechMap)) { taskSpeechList = taskSpeechMap.get(demandTask.getDemandTaskId()); } else { taskSpeechList = TimingAcquisition.seriesSuccessTaskSpeechMap.get(series).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.getCost())) { String[] cost = demandTask.getCost().split("\\|"); text = text.replace("【条件2】", cost[0]); } } 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("【消费货币】")) { if (!StringUtils.isEmpty(demandTask.getCost())) { String[] cost = demandTask.getCost().split("\\|"); text = text.replace("【消费货币】", cost[0]); } } 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())); } int trustDegree = TimingAcquisition.playerMap.get(uid).getPersonInfoMap().get(person.getId()).getTrustDegree(); int deterrenceDegree = TimingAcquisition.playerMap.get(uid).getPersonInfoMap().get(person.getId()).getDeterrenceDegree(); if (text.contains("【好感度】")) { text = text.replace("【好感度】", String.valueOf(trustDegree - 50)); } if (text.contains("【威慑度】")) { text = text.replace("【威慑度】", String.valueOf(deterrenceDegree - 50)); } if (text.contains("【S】")) { text = text.replace("【S】", PlayerUtil.getSubjectNameByPreTaskId(uid, demandTask.getSubject(), demandTask.getDemandTaskId())); } if (text.contains("【S@正常】")) { String name = "【" + PlayerUtil.getSubjectNameByPreTaskId(uid, demandTask.getSubject(), demandTask.getDemandTaskId()) + "@正常】"; text = text.replace("【S@正常】", name); } //补充信任值和威慑度增减的回复 // String addText = "【旁白@正常】【1】对你的信任达到【2】,对你的畏惧达到【3】。"; // addText = speechReplaceNum(addText, person.getName(), String.valueOf(trustDegree - 50), String.valueOf(deterrenceDegree - 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 getSuccessTaskReplySpeech(String uid, Person person, DemandTaskDto demandTask, ReplyDto reply) { String text = ""; Map countMap = new HashMap<>(); List taskSpeechList; String series = TimingAcquisition.playerMap.get(uid).getSeries(); //系列 String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //关卡编号 Map> taskSpeechMap = TimingAcquisition.gateNoSuccessTaskSpeechMap.get(gateNo); if (!StringUtils.isEmpty(taskSpeechMap)) { taskSpeechList = taskSpeechMap.get(demandTask.getDemandTaskId()); } else { taskSpeechList = TimingAcquisition.seriesSuccessTaskSpeechMap.get(series).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).getReplyAnswer(); } else { //获取对应话术 text = taskSpeechList.get(index).getReplyAnswer(); } //话术中配置数据替换 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("【消费货币】")) { if (!StringUtils.isEmpty(demandTask.getCost())) { String[] cost = demandTask.getCost().split("\\|"); text = text.replace("【消费货币】", cost[0]); } } 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("【消费货币】")) { if (!StringUtils.isEmpty(demandTask.getCost())) { String[] cost = demandTask.getCost().split("\\|"); text = text.replace("【消费货币】", cost[0]); } } 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("【S】")) { text = text.replace("【S】", PlayerUtil.getSubjectNameByPreTaskId(uid, demandTask.getSubject(), demandTask.getDemandTaskId())); } if (text.contains("【S@正常】")) { String name = "【" + PlayerUtil.getSubjectNameByPreTaskId(uid, demandTask.getSubject(), demandTask.getDemandTaskId()) + "@正常】"; text = text.replace("【S@正常】", name); } text = text.replace("\n", ""); String[] result = text.split("\\|"); int num = reply.getNum(); text = result[num]; if (num < result.length - 1) { reply.setNum(num + 1); } else { reply.setNum(result.length - 1); } String unique = uid + gateNo; //用户uid和关卡编号组成唯一标识 //保存上轮数据 CacheUtil.put(unique, reply, Long.parseLong(expireTime)); return text; } /** * 获取前后置任务成功的话术。level: 1-是进行中任务完成提醒;2-未进行中任务完成提醒;3-进行中任务询问.其中1和2会加上完成对话文本; * 4-是任务启动文本;5-是任务中断或关闭文本 * @param uid * @param person * @param demandTask */ public static String getPreSuccessTaskSpeech(String uid, Person person, DemandTaskDto demandTask, int level) { String text = ""; Map countMap = new HashMap<>(); List taskSpeechList; String series = TimingAcquisition.playerMap.get(uid).getSeries(); //系列 String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //关卡编号 Map> taskSpeechMap = TimingAcquisition.gateNoSuccessTaskSpeechMap.get(gateNo); if (!StringUtils.isEmpty(taskSpeechMap)) { taskSpeechList = taskSpeechMap.get(demandTask.getDemandTaskId()); } else { taskSpeechList = TimingAcquisition.seriesSuccessTaskSpeechMap.get(series).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(); } if (level == 4) { text = taskSpeechList.get(0).getStartAnswer(); } if (level == 5) { text = taskSpeechList.get(0).getCloseAnswer(); } } else { //获取对应话术 if (level == 1) { text = taskSpeechList.get(index).getDoingFinishedAnswer(); text += taskSpeechList.get(index).getAnswer(); } if (level == 2) { text = taskSpeechList.get(index).getNoDoingFinishedAnswer(); text += taskSpeechList.get(index).getAnswer(); } if (level == 3) { text = taskSpeechList.get(index).getDoingAsk(); } if (level == 4) { text = taskSpeechList.get(index).getStartAnswer(); } if (level == 5) { text = taskSpeechList.get(index).getCloseAnswer(); } } int trustDegree = TimingAcquisition.playerMap.get(uid).getPersonInfoMap().get(person.getId()).getTrustDegree(); int deterrenceDegree = TimingAcquisition.playerMap.get(uid).getPersonInfoMap().get(person.getId()).getDeterrenceDegree(); if (text.contains("【好感度】")) { text = text.replace("【好感度】", String.valueOf(trustDegree - 50)); } if (text.contains("【威慑度】")) { text = text.replace("【威慑度】", String.valueOf(deterrenceDegree - 50)); } if (level == 1) { // if (!StringUtils.isEmpty(taskSpeechList.get(index).getDoingFinishedAnswer())) { // text = addHeader(text, person.getName()); // } //补充信任值和威慑度增减的回复 // addText = "【旁白@正常】【1】对你的信任达到【2】,对你的畏惧达到【3】。"; // addText = speechReplaceNum(addText, person.getName(), String.valueOf(trustDegree - 50), String.valueOf(deterrenceDegree - 50)); if (!StringUtils.isEmpty(demandTask.getCompletionReward())) { if (!"0".equals(demandTask.getCompletionReward())) { addText += "你获得" + demandTask.getCompletionReward() + "文酬劳。"; } } text += addText; } if (level == 2) { // if (!StringUtils.isEmpty(taskSpeechList.get(index).getNoDoingFinishedAnswer())) { // text = addHeader(text, person.getName()); // } //补充信任值和威慑度增减的回复 // addText = "【旁白@正常】【1】对你的信任达到【2】,对你的畏惧达到【3】。"; // addText = speechReplaceNum(addText, person.getName(), String.valueOf(trustDegree - 50), String.valueOf(deterrenceDegree - 50)); if (!StringUtils.isEmpty(demandTask.getCompletionReward())) { if (!"0".equals(demandTask.getCompletionReward())) { addText += "你获得" + demandTask.getCompletionReward() + "文酬劳。"; } } text += addText; } if (level == 3) { // if (!StringUtils.isEmpty(taskSpeechList.get(index).getDoingAsk())) { // text = addHeader(text, person.getName()); // } } // if (level == 4) { // if (!StringUtils.isEmpty(taskSpeechList.get(index).getStartAnswer())) { // text = addHeader(text, person.getName()); // } // } // if (level == 5) { // if (!StringUtils.isEmpty(taskSpeechList.get(index).getCloseAnswer())) { // 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.getCost())) { String[] cost = demandTask.getCost().split("\\|"); text = text.replace("【条件2】", cost[0]); } } 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("【消费货币】")) { if (!StringUtils.isEmpty(demandTask.getCost())) { String[] cost = demandTask.getCost().split("\\|"); text = text.replace("【消费货币】", cost[0]); } } 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("【S】")) { text = text.replace("【S】", PlayerUtil.getSubjectNameByPreTaskId(uid, demandTask.getSubject(), demandTask.getDemandTaskId())); } if (text.contains("【S@正常】")) { String name = "【" + PlayerUtil.getSubjectNameByPreTaskId(uid, demandTask.getSubject(), demandTask.getDemandTaskId()) + "@正常】"; text = text.replace("【S@正常】", name); } text = text.replace("\n", ""); return text; } /** * 获取自身任务线索提示的话术 * @param uid * @param demandTask * @param personId * @param source */ public static String getTipSpeech(String uid, DemandTaskDto demandTask, Integer personId, int source) { String text = ""; List tipSpeechList; String series = TimingAcquisition.playerMap.get(uid).getSeries(); //系列 String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //关卡编号 Map> tipSpeechMap = TimingAcquisition.gateNoTipSpeechMap.get(gateNo); if (!StringUtils.isEmpty(tipSpeechMap)) { tipSpeechList = tipSpeechMap.get(demandTask.getDemandTaskId()); } else { tipSpeechList = TimingAcquisition.seriesTipSpeechMap.get(series).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("【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)); } 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; } /** * 获取自身任务线索提示的话术,用于二次回复。source指代线索类型 * @param uid * @param demandTask * @param personId * @param source */ public static String getTipReplySpeech(String uid, DemandTaskDto demandTask, Integer personId, int source, ReplyDto reply) { String text = ""; List tipSpeechList; String series = TimingAcquisition.playerMap.get(uid).getSeries(); //系列 String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //关卡编号 Map> tipSpeechMap = TimingAcquisition.gateNoTipSpeechMap.get(gateNo); if (!StringUtils.isEmpty(tipSpeechMap)) { tipSpeechList = tipSpeechMap.get(demandTask.getDemandTaskId()); } else { tipSpeechList = TimingAcquisition.seriesTipSpeechMap.get(series).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("【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)); } if (text.contains("【C@正常】")) { text = text.replace("【C@正常】", "【" + TimingAcquisition.getNameByPersonId(uid, personId) + "@正常】"); } } text = text.replace("\n", ""); String[] result = text.split("\\|"); int num = reply.getNum(); text = result[num]; if (num < result.length - 1) { reply.setNum(num + 1); } else { reply.setNum(result.length - 1); } String unique = uid + gateNo; //用户uid和关卡编号组成唯一标识 //保存上轮数据 CacheUtil.put(unique, reply, Long.parseLong(expireTime)); return text; } /** * 获取他人线索提示的话术 * @param uid * @param barrierTaskKey * @param personId */ public static String getTipSpeech(String uid, BarrierTaskKeyDto barrierTaskKey, Integer personId) { String text = ""; List tipSpeechList; String series = TimingAcquisition.playerMap.get(uid).getSeries(); //系列 String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //关卡编号 Map> tipSpeechMap = TimingAcquisition.gateNoTipSpeechMap.get(gateNo); if (!StringUtils.isEmpty(tipSpeechMap)) { tipSpeechList = tipSpeechMap.get(barrierTaskKey.getDemandTaskId()); } else { tipSpeechList = TimingAcquisition.seriesTipSpeechMap.get(series).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 (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())); } 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; } /** * 获取人物见面时的话术 */ public static String getPersonSpeech(String uid, String locationId, Integer personId) { String text = ""; String name = PlayerUtil.getPersonMap(uid).get(personId).getName(); List personSpeechList; String series = TimingAcquisition.playerMap.get(uid).getSeries(); //系列 String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //关卡编号 Map> personSpeechMap = TimingAcquisition.gateNoPersonSpeechMap.get(gateNo); if (!StringUtils.isEmpty(personSpeechMap)) { personSpeechList = personSpeechMap.get(name); } else { personSpeechList = TimingAcquisition.seriesPersonSpeechMap.get(series).get(name); } //判断该人物是否是第一次见面 boolean isFirstMeet = PlayerUtil.isFirstMeet(uid, locationId, personId); if (isFirstMeet) { String asideText = StringUtils.isEmpty(personSpeechList.get(0).getDescription()) ? "" : ("【旁白@正常】" + personSpeechList.get(0).getDescription()); String personText = StringUtils.isEmpty(personSpeechList.get(0).getFirstAnswer()) ? "" : ("【人物名称@正常】" + personSpeechList.get(0).getFirstAnswer()); text = asideText + personText; } else { text = "【人物名称@正常】" + personSpeechList.get(0).getAnswer(); } String[] result = text.split("\\|"); Integer i = getRandomNum(0, result.length); text = result[i]; return text; } /** * 获取人物见面时的话术 */ public static String getPersonFirstSpeech(String uid, String locationId, Integer personId) { String text = ""; String name = PlayerUtil.getPersonMap(uid).get(personId).getName(); List personSpeechList; String series = TimingAcquisition.playerMap.get(uid).getSeries(); //系列 String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //关卡编号 Map> personSpeechMap = TimingAcquisition.gateNoPersonSpeechMap.get(gateNo); if (!StringUtils.isEmpty(personSpeechMap)) { personSpeechList = personSpeechMap.get(name); } else { personSpeechList = TimingAcquisition.seriesPersonSpeechMap.get(series).get(name); } //判断该人物是否是第一次见面 boolean isFirstMeet = PlayerUtil.isFirstMeet(uid, locationId, personId); if (isFirstMeet) { if (!StringUtils.isEmpty(personSpeechList.get(0).getDescription())) { text = "【旁白@正常】" + personSpeechList.get(0).getDescription(); String personText = "【" + name + "@正常】" + personSpeechList.get(0).getFirstAnswer(); text += personText; } } else { text = ""; } 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(); String series = player.getSeries(); //系列 String gateNo = player.getGateNo(); //关卡编号 Map operateSpeechMap = TimingAcquisition.gateNoOperateSpeechMap.get(gateNo); if (StringUtils.isEmpty(operateSpeechMap)) { operateSpeechMap = TimingAcquisition.seriesOperateSpeechMap.get(series); } 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.getCost())) { String[] cost = demandTask.getCost().split("\\|"); text = text.replace("【条件2】", cost[0]); } } 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("【信任值】")) { int trustDegree = TimingAcquisition.playerMap.get(uid).getPersonInfoMap().get(person.getId()).getTrustDegree(); text = text.replace("【信任值】", String.valueOf(trustDegree - 50)); } if (text.contains("【威慑度】")) { int deterrenceDegree = TimingAcquisition.playerMap.get(uid).getPersonInfoMap().get(person.getId()).getDeterrenceDegree(); text = text.replace("【威慑度】", String.valueOf(deterrenceDegree - 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(); String text = PlayerUtil.getDoingTaskAnswer(uid, TimingAcquisition.playerMap.get(uid).getPersonId()); if (StringUtils.isEmpty(text)) { String seriesName = TimingAcquisition.playerMap.get(uid).getSeries(); //系列名称 //搭档名称 String partnerName = TimingAcquisition.seriesSystemConfigMap.get(seriesName).get("partnerName").getValue(); text = SpeechUtil.getAskSpeech(uid, Constants.SPEECH_PERSON, 103102); text = SpeechUtil.replaceHeader(text, partnerName); String location = TimingAcquisition.seriesLocationMap.get(seriesName).get(TimingAcquisition.playerMap.get(uid).getLocation()).getName(); String name = PlayerUtil.getNameByPersonId(uid, TimingAcquisition.playerMap.get(uid).getPersonId()); text = SpeechUtil.speechReplaceNum(text, location, name); //人物见面时的回复 text += SpeechUtil.getPersonSpeech(uid, TimingAcquisition.playerMap.get(uid).getLocation(), TimingAcquisition.playerMap.get(uid).getPersonId()); text = SpeechUtil.replaceHeader(text, name); //开场白 // Map endGoalMap = TimingAcquisition.endGoalMap; // 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; } /** * 获取任务异常反馈的话术 */ public static String getTaskExceptionSpeech(String uid, DemandTaskDto demandTask, String num) { String text = ""; String series = TimingAcquisition.playerMap.get(uid).getSeries(); //系列 String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //关卡编号 String[] condition1 = demandTask.getCondition1().split("\\|"); Integer feedBackId = Integer.valueOf(condition1[0] + num); Map taskExceptionSpeechMap = TimingAcquisition.gateNoTaskExceptionSpeechMap.get(gateNo); if (!StringUtils.isEmpty(taskExceptionSpeechMap)) { text = taskExceptionSpeechMap.get(feedBackId).getAnswer(); } else { text = TimingAcquisition.seriesTaskExceptionSpeechMap.get(series).get(feedBackId).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("【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.getCost())) { String[] cost = demandTask.getCost().split("\\|"); text = text.replace("【条件2】", cost[0]); } } if (text.contains("【消费货币】")) { if (!StringUtils.isEmpty(demandTask.getCost())) { String[] cost = demandTask.getCost().split("\\|"); text = text.replace("【消费货币】", cost[0]); } } return text; } /** * 获取任务异常反馈的话术 */ public static String getTaskExceptionSpeech(String uid, String conditionTaskId, String num) { String text = ""; String series = TimingAcquisition.playerMap.get(uid).getSeries(); //系列 String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //关卡编号 Integer feedBackId = Integer.valueOf(conditionTaskId + num); Map taskExceptionSpeechMap = TimingAcquisition.gateNoTaskExceptionSpeechMap.get(gateNo); if (!StringUtils.isEmpty(taskExceptionSpeechMap)) { text = taskExceptionSpeechMap.get(feedBackId).getAnswer(); } else { text = TimingAcquisition.seriesTaskExceptionSpeechMap.get(series).get(feedBackId).getAnswer(); } return text; } /** * 获取任务异常反馈的话术 */ public static String getTaskExceptionSpeech(String uid, String feedBackId) { String text = ""; String series = TimingAcquisition.playerMap.get(uid).getSeries(); //系列 String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //关卡编号 Map taskExceptionSpeechMap = TimingAcquisition.gateNoTaskExceptionSpeechMap.get(gateNo); if (!StringUtils.isEmpty(taskExceptionSpeechMap)) { text = taskExceptionSpeechMap.get(Integer.valueOf(feedBackId)).getAnswer(); } else { text = TimingAcquisition.seriesTaskExceptionSpeechMap.get(series).get(Integer.valueOf(feedBackId)).getAnswer(); } 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; } }