package com.qiwu.inference.common.utils; import cn.hutool.poi.excel.ExcelReader; import cn.hutool.poi.excel.ExcelUtil; 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("人物ID", "personId"); reader.addHeaderAlias("性别", "gender"); reader.addHeaderAlias("年龄段", "age"); reader.addHeaderAlias("性格A", "dispositionIds"); reader.addHeaderAlias("行为", "behaviour"); reader.addHeaderAlias("任务状态", "taskStatus"); reader.addHeaderAlias("关系", "degree"); 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; } /** * 获取闲聊的话术 * @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.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; } } 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(); } return text; } /** * 获取线索成功的话术 * @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 ? "男" : "女"; 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(); } else { text = clueSpeechList.get(0).getAnswerSelf(); } } else { //获取对应话术 if (!person.getId().equals(clue.getSubject())) { text = clueSpeechList.get(index).getAnswer(); } 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 = (TimingAcquisition.playerMap.get(uid).getPersonMap().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())); } 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 ? "男" : "女"; 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 = (TimingAcquisition.playerMap.get(uid).getPersonMap().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()), String.valueOf(person.getDeterrenceDegree())); // if (!StringUtils.isEmpty(demandTask.getCompletionReward())) { // if (!"0".equals(demandTask.getCompletionReward())) { // addText += "你获得" + demandTask.getCompletionReward() + "文酬劳。"; // } // } text += addText; text = text.replace("\n", ""); 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()); 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()), String.valueOf(person.getDeterrenceDegree())); 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()), String.valueOf(person.getDeterrenceDegree())); 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 = (TimingAcquisition.playerMap.get(uid).getPersonMap().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", ""); 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 (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", ""); 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()); //他人能解锁任务的线索 //获取对应话术 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", ""); return text; } /** * 获取人物见面时的话术 */ public static String getPersonSpeech(String uid, String locationId, Integer personId) { String text = ""; String name = TimingAcquisition.playerMap.get(uid).getPersonMap().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(); } return text; } }