package com.qiwu.inference.common.utils; import com.qiwu.inference.common.Constants; import com.qiwu.inference.common.TimingAcquisition; import com.qiwu.inference.dto.*; import com.qiwu.inference.pojo.Location; import org.springframework.util.StringUtils; import java.io.*; import java.util.*; import java.util.concurrent.ConcurrentHashMap; public class PlayerUtil { /** * 通过玩家当前关卡拿到NPC数据 */ public static Map getPersonMap(String uid) { String gateNo = TimingAcquisition.uidGateNoMap.get(uid); return TimingAcquisition.gatePersonMap.get(gateNo); } /** * 通过玩家当前关卡拿到指定NPC数据 */ public static Person getPerson(String uid, Integer personId) { String gateNo = TimingAcquisition.uidGateNoMap.get(uid); return TimingAcquisition.gatePersonMap.get(gateNo).get(personId); } /** * 通过角色身份找到对应的人物名称 * @param name */ public static String getName(String uid, String name) { Map personMap = getPersonMap(uid); for (Map.Entry entry : personMap.entrySet()) { Person person = entry.getValue(); //name为身份或人物名称 if (person.getIdentityName().equals(name) || person.getName().equals(name)) { return person.getName(); } } return name; } /** * 查询符合条件的线索 * @param current * @param subject * @param type * @return */ public static List findClues(Person current,Person subject,Integer type){ List result = new ArrayList<>(); if(!StringUtils.isEmpty(current)){ List clueList =current.getClues(); for (int i= 0;i checkThreshold(Person person, List clueList){ List result = new ArrayList<>(); for (int i= 0;i= clue.getTrustDegree()||person.getDeterrenceDegree() >= clue.getThreaten()){ flag = true; } if(flag){ //符合阈值要求 result.add(clue); } } return result; } /** * 判断是否符合阈值需求 * @param demandTask * @param subject * @return */ public static boolean checkThreshold(DemandTaskDto demandTask, Person subject){ boolean flag = false; //任务无需解锁或者任务已解锁 if (demandTask.getClueSwitch() == 0 || demandTask.getClueSwitch() == 2) { if(demandTask.getTrustStart() >=0 && demandTask.getTrustEnd() > 0) { if(NumberUtil.inNumRange(subject.getTrustDegree(),"["+demandTask.getTrustStart()+","+demandTask.getTrustEnd()+"]")) { flag = true; } } if(demandTask.getDeterrenceStart() >= 0 && demandTask.getDeterrenceEnd() > 0) { if(NumberUtil.inNumRange(subject.getDeterrenceDegree(),"["+demandTask.getDeterrenceStart()+","+demandTask.getDeterrenceEnd()+"]")) { flag = true; } } } return flag; } /** * 获取玩家关卡中人物所在的所有场所 */ public static List getLocationByUid(String uid) { List locationList = new ArrayList<>(); Map personMap = getPersonMap(uid); for (Map.Entry entry : personMap.entrySet()) { Person person = entry.getValue(); if (!StringUtils.isEmpty(person.getLocation())) { locationList.add(person.getLocation()); } } return locationList; } /** * 通过人物id获取人物名称 */ public static String getNameByPersonId(String uid, Integer id) { Map name2IdMap = TimingAcquisition.playerMap.get(uid).getName2IdMap(); for (Map.Entry entry : name2IdMap.entrySet()) { if (entry.getValue().equals(id)) { return entry.getKey(); } } return null; } /** * 获取玩家已知的场所 */ public static String getLocations(String uid) { StringBuilder text = new StringBuilder(); Map locationMap = TimingAcquisition.playerMap.get(uid).getLocationMap(); for (Map.Entry entry : locationMap.entrySet()) { if (!"1".equals(entry.getValue().getIsHidden())) { text.append(TimingAcquisition.locationMap.get(entry.getKey()).getName()).append("、"); } } if (text.length() != 0) { text.deleteCharAt(text.length() - 1); } return text.toString(); } /** * 通过场所id找到场所的所有人物 */ public static List getPersonsByLocationId(String uid, String locationId) { List personIdList = null; Map locationMap = TimingAcquisition.playerMap.get(uid).getLocationMap(); if (!StringUtils.isEmpty(locationMap.get(locationId))) { Map personIdMap = locationMap.get(locationId).getPersonInfoMap(); if (personIdMap.size() != 0) { personIdList = new ArrayList<>(personIdMap.keySet()); } } return personIdList; } /** * 通过指定人物找到所有满足关系线索阈值的人物 */ public static List getRelativePersonIds(String uid, Integer personId) { List personIdList = new ArrayList<>(); Map personMap = getPersonMap(uid); //指定人物拥有的关系 List relations = personMap.get(personId).getRelations(); List clues = personMap.get(personId).getClues(); //信任值 Integer trustDegree = personMap.get(personId).getTrustDegree(); //威慑度 Integer deterrenceDegree = personMap.get(personId).getDeterrenceDegree(); int max = trustDegree; //遍历所有关系 for (RelationDto relation : relations) { //关系类型为“交情”和“亲缘” if (relation.getType() == 1 || relation.getType() == 2) { //遍历所有线索 for (ClueDto clue : clues) { if (Constants.RELATION_TYPE.equals(clue.getType())) { //判断是否符合阈值需求 if(trustDegree >= clue.getTrustDegree() || deterrenceDegree >= clue.getThreaten()){ personIdList.add(relation.getObject()); break; } } } } } return personIdList; } /** * 记录玩家已获得线索 */ public static void recordClue(String uid, Integer sourceId, Integer personId, Integer clueTypeId, ClueDto clue) { Map>> clueMap = TimingAcquisition.playerMap.get(uid).getClueMap(); Map> clueListMap = new ConcurrentHashMap<>(); List clueList = new ArrayList<>(); //线索来源的人物id List sourceIdList = new ArrayList<>(); sourceIdList.add(sourceId); //玩家还没有收集此人的线索 if (StringUtils.isEmpty(clueMap.get(personId))) { Map> clueSourceMap = new ConcurrentHashMap<>(); clueSourceMap.put(clue.getClueId(), sourceIdList); TimingAcquisition.playerMap.get(uid).getPersonInfoMap().get(personId).setClueSourceMap(clueSourceMap); clueList.add(clue); clueListMap.put(clueTypeId, clueList); clueMap.put(personId, clueListMap); return; } //玩家还没有收集到此人这类的线索 if (StringUtils.isEmpty(clueMap.get(personId).get(clueTypeId))) { Map> clueSourceMap = new ConcurrentHashMap<>(); clueSourceMap.put(clue.getClueId(), sourceIdList); TimingAcquisition.playerMap.get(uid).getPersonInfoMap().get(personId).setClueSourceMap(clueSourceMap); clueList.add(clue); clueListMap.put(clueTypeId, clueList); clueMap.get(personId).putAll(clueListMap); return; } //玩家还没有收集到这条线索 List clues = clueMap.get(personId).get(clueTypeId); boolean have = false; for (ClueDto c : clues) { if (c.getClueId() == clue.getClueId()) { List sourceIds = TimingAcquisition.playerMap.get(uid).getPersonInfoMap().get(personId).getClueSourceMap().get(c.getClueId()); //找到了同样的线索,则新增来源 //不为同一个人 if (!sourceIds.contains(sourceId)) { sourceIds.add(sourceId); } have = true; break; } } //没有找到则新增一条线索 if (!have) { TimingAcquisition.playerMap.get(uid).getPersonInfoMap().get(personId).getClueSourceMap().put(clue.getClueId(), sourceIdList); clues.add(clue); } } /** * 记录玩家已获得线索 */ public static void recordClue(String uid, Integer personId) { Map>> clueMap = TimingAcquisition.playerMap.get(uid).getClueMap(); //玩家见过这个人 if (!StringUtils.isEmpty(clueMap.get(personId))) { return; } clueMap.put(personId, null); } /** * 判断线索是否为指定性格类型的线索 * @param clueList * @param type */ public static List checkClueType(List clueList, String type) { List result = new ArrayList<>(); for (ClueDto clueDto : clueList) { //关联的性格id Integer associatedId = TimingAcquisition.clueMap.get(clueDto.getClueId()).getAssociatedId(); if ("1".equals(type) || "3".equals(type)) { List typeList = new ArrayList<>(); typeList.add("1"); typeList.add("3"); if (typeList.contains(TimingAcquisition.dispositionMap.get(associatedId).getType())) { result.add(clueDto); } } else { if (type.equals(TimingAcquisition.dispositionMap.get(associatedId).getType())) { result.add(clueDto); } } } return result; } /** * 找到人物对应线索类型,且符合任务目的线索 * @param current * @param subject * @param taskTarget 1 信任度提升 2 信任度降低 3 威慑度提升 4 威慑度降低 */ public static List getCluesByType(Person current, Person subject, Integer taskTarget) { List result = new ArrayList<>(); List clueList = current.getClues(); //找到玩家能达到目的任务的线索 for (ClueDto clue : clueList) { //线索为任务类型 if (clue.getSubject() == subject.getId() && clue.getType() == 6) { //通过线索id找主体对象身上的任务 DemandTaskDto demandTask = getDemandTaskByClueId(subject, clue.getClueId()); if (!StringUtils.isEmpty(demandTask)) { //增加信任值 if (taskTarget == 1) { int trustDegree = demandTask.getTrustDegree(); if (!StringUtils.isEmpty(trustDegree) && trustDegree > 0) { result.add(clue); } } //降低信任值 if (taskTarget == 2) { int trustDegree = demandTask.getTrustDegree(); if (!StringUtils.isEmpty(trustDegree) && trustDegree < 0) { result.add(clue); } } //提升威慑度 if (taskTarget == 3) { int deterrenceDegree = demandTask.getDeterrenceDegree(); if (!StringUtils.isEmpty(deterrenceDegree) && deterrenceDegree > 0) { result.add(clue); } } //降低威慑度 if (taskTarget == 4) { int deterrenceDegree = demandTask.getDeterrenceDegree(); if (!StringUtils.isEmpty(deterrenceDegree) && deterrenceDegree < 0) { result.add(clue); } } } } } return result; } /** * 找到人物对应任务的线索 * @param uid * @param personId */ public static List getClueByTypeAndTaskId(String uid, Integer personId, String taskId) { List result = new ArrayList<>(); Integer currentId = TimingAcquisition.playerMap.get(uid).getPersonId(); Person current = getPersonMap(uid).get(currentId); if(!StringUtils.isEmpty(current)){ //通过任务条件id找到玩家需求任务集合 List demandTaskList = findDemandsByTaskId(current, personId, taskId); for (DemandTaskDto demandTask : demandTaskList) { //找到对应的任务线索 Integer clueId = demandTask.getClueId(); //找到对应线索 ClueDto clue = getClueById(uid, personId, clueId); if (!StringUtils.isEmpty(clue)) { result.add(clue); } } } return result; } /** * 找到当前NPC身上,关于指定人物对应任务条件id的线索 * @param uid * @param subjectId * @param conditionTaskId */ public static List getClueByConditionTaskId(String uid, Integer subjectId, String conditionTaskId) { List result = new ArrayList<>(); Integer currentId = TimingAcquisition.playerMap.get(uid).getPersonId(); Person current = getPersonMap(uid).get(currentId); Person subject = getPersonMap(uid).get(subjectId); if(!StringUtils.isEmpty(current)){ //通过任务条件id找到玩家需求任务集合 List demandTaskList = findDemandsByTaskId(subject, subjectId, conditionTaskId); for (DemandTaskDto demandTask : demandTaskList) { //找到对应的任务线索id Integer clueId = demandTask.getClueId(); //找到对应线索 ClueDto clue = getClueById(uid, currentId, clueId); if (!StringUtils.isEmpty(clue)) { result.add(clue); } } } return result; } /** * 找到对应类型且达到阈值的线索 */ public static List getCluesByType(Person person, int clueType, int infoLevel) { List result = new ArrayList<>(); List clueList = person.getClues(); if (clueType == 0) { for (ClueDto clue : clueList) { //线索大于等于指定层级 if (clue.getInfoLevel() >= infoLevel) { if (person.getTrustDegree() >= clue.getTrustDegree() || person.getDeterrenceDegree() >= clue.getThreaten()) { result.add(clue); } } } } else { for (ClueDto clue : clueList) { //为指定类型 if (clue.getType() == clueType) { //线索大于等于指定层级 if (clue.getInfoLevel() >= infoLevel) { if (person.getTrustDegree() >= clue.getTrustDegree() || person.getDeterrenceDegree() >= clue.getThreaten()) { result.add(clue); } } } } } return result; } /** * 查询符合条件的任务 * @param person * @param taskTarget 1 信任度提升 2 信任度降低 3 威慑度提升 4 威慑度降低 * @return */ private static List findTasks(Person person, Integer taskTarget){ List result = new ArrayList<>(); if(!StringUtils.isEmpty(person)){ List demandTaskList = person.getDemandTasks(); for (DemandTaskDto demandTask : demandTaskList) { if (demandTask.getType() == 6) { if (taskTarget == 1) { if (Objects.equals(demandTask.getSubject(), person.getId())) { int trustDegree = demandTask.getTrustDegree(); if (!StringUtils.isEmpty(trustDegree) && trustDegree > 0) { result.add(demandTask); } } } else if (taskTarget == 2) { if (Objects.equals(demandTask.getSubject(), person.getId())) { int trustDegree = demandTask.getTrustDegree(); if (!StringUtils.isEmpty(trustDegree) && trustDegree < 0) { result.add(demandTask); } } } else if (taskTarget == 3) { if (Objects.equals(demandTask.getSubject(), person.getId())) { int deterrenceDegree = demandTask.getDeterrenceDegree(); if (!StringUtils.isEmpty(deterrenceDegree) && deterrenceDegree > 0) { result.add(demandTask); } } } else if (taskTarget == 4) { if (Objects.equals(demandTask.getSubject(), person.getId())) { int deterrenceDegree = demandTask.getDeterrenceDegree(); if (!StringUtils.isEmpty(deterrenceDegree) && deterrenceDegree < 0) { result.add(demandTask); } } } } } } return result; } /** * 通过任务条件id找到对应的需求任务id */ public static List findDemandsByTaskId(Person person, Integer personId, String taskConditionId) { List result = new ArrayList<>(); List demandTaskList = person.getDemandTasks(); for (DemandTaskDto demandTask : demandTaskList) { String condition1 = demandTask.getCondition1(); String[] taskIdTimes = condition1.split("\\|"); if (taskConditionId.equals(taskIdTimes[0]) && demandTask.getType() == 6) { if (demandTask.getObject() != 0) { if (personId == demandTask.getObject()) { result.add(demandTask); } } else { if (personId == demandTask.getSubject()) { result.add(demandTask); } } } } return result; } /** * 通过线索id找到对应线索 * @param person * @param clueId */ public static ClueDto getClueById(Person person, Integer clueId, Integer type) { List clueList = person.getClues(); for (ClueDto clue : clueList) { if (clueId.equals(clue.getClueId()) && type.equals(clue.getType())) { return clue; } } return null; } /** * 通过线索id找到对应线索 * @param uid * @param personId * @param clueId */ public static ClueDto getClueById(String uid, Integer personId, Integer clueId) { List clueList = getPersonMap(uid).get(personId).getClues(); for (ClueDto clue : clueList) { if (clueId.equals(clue.getClueId())) { return clue; } } return null; } /** * 通过线索id在主体身上找到对应线索 * @param person * @param demandTaskDto */ public static ClueDto getPreClueById(Person person, DemandTaskDto demandTaskDto) { List demandTaskList = person.getDemandTasks(); List clueList = new ArrayList<>(); if (!StringUtils.isEmpty(demandTaskDto)) { for (DemandTaskDto demandTask : demandTaskList) { if (demandTask.getDemandTaskId() == demandTaskDto.getDemandTaskId() && demandTask.getSubject() == demandTaskDto.getSubject()) { ClueDto clue = getClueById(person, demandTask.getClueId(), demandTask.getType()); if (!StringUtils.isEmpty(clue)) { clueList.add(clue); } } } } if (clueList.size() > 1) { for (ClueDto clue : clueList) { if (clue.getType() != 6) { return clue; } } } if (clueList.size() == 1) { return clueList.get(0); } return null; } /** * 通过线索id找到需求任务 */ public static DemandTaskDto getDemandTaskByClueId(Person person, ClueDto clue) { List demandTaskList = person.getDemandTasks(); for (DemandTaskDto demandTask : demandTaskList) { if (clue.getClueId() == demandTask.getClueId() && clue.getSubject() == demandTask.getSubject()) { return demandTask; } } return null; } /** * 通过线索id找到需求任务 */ public static DemandTaskDto getDemandTaskByClueId(Person person, Integer clueId) { List demandTaskList = person.getDemandTasks(); for (DemandTaskDto demandTask : demandTaskList) { if (clueId.equals(demandTask.getClueId())) { return demandTask; } } return null; } /** * 查询符合条件的任务 * @param demandTaskList * @param clue * @return */ private static DemandTaskDto findTasks(List demandTaskList, ClueDto clue) { DemandTaskDto result = null; for (DemandTaskDto demandTask : demandTaskList) { if (Objects.equals(demandTask.getClueId(), clue.getClueId()) && Objects.equals(demandTask.getType(), clue.getType())) { result = demandTask; break; } } if (!StringUtils.isEmpty(result)) { for (DemandTaskDto demandTask:demandTaskList) { if (demandTask.getDemandTaskId() == result.getDemandTaskId() && demandTask.getType() == 6 && result.getSubject() == demandTask.getSubject()) { return demandTask; } } } return null; } /** * 通过任务id找到对应的任务 */ public static DemandTaskDto getDemandTaskById(String uid, Integer personId, Integer taskId) { List demandTaskList = getPersonMap(uid).get(personId).getDemandTasks(); for (DemandTaskDto demandTask:demandTaskList) { if (demandTask.getDemandTaskId() == taskId && demandTask.getType() == 6 && demandTask.getSubject() == personId) { return demandTask; } } return null; } /** * 根据线索找到对应任务,判断任务是否需要解锁,需要则改为解锁状态 */ public static void unlockTask(String uid, Person person, ClueDto clue) { List demandTaskList = person.getDemandTasks(); String postTaskId = null; //本人身上该任务解锁 for (DemandTaskDto demandTask : demandTaskList) { if (demandTask.getClueId() == clue.getClueId() && demandTask.getType() == clue.getType()) { //需解锁任务 if (demandTask.getClueSwitch() == 1) { demandTask.setClueSwitch(2); postTaskId = demandTask.getPostTask(); for (DemandTaskDto task : demandTaskList) { if (task.getDemandTaskId() == demandTask.getDemandTaskId()) { task.setClueSwitch(2); } } } } } int objectId = clue.getSubject(); if (person.getId() == clue.getSubject()) { objectId = clue.getObject(); } //线索主体为当前对话人时,解锁对应的任务 if (person.getId().equals(clue.getSubject())) { //解锁后置任务 if (!StringUtils.isEmpty(postTaskId)) { //线索对应任务解锁 List demandTaskObjectList = getPersonMap(uid).get(objectId).getDemandTasks(); //客体身上该任务解锁 for (DemandTaskDto demandTask : demandTaskObjectList) { if (demandTask.getDemandTaskId() == Integer.parseInt(postTaskId)) { //需解锁任务 if (demandTask.getClueSwitch() == 1) { demandTask.setClueSwitch(2); } } } } } else { //线索对应他人的任务解锁 List demandTaskObjectList = getPersonMap(uid).get(objectId).getDemandTasks(); //客体身上该任务解锁 for (DemandTaskDto demandTask : demandTaskObjectList) { if (demandTask.getClueId() == clue.getClueId()) { //需解锁任务 if (demandTask.getClueSwitch() == 1) { demandTask.setClueSwitch(2); } } } } } /** * 根据线索找到对应任务,判断任务是否需要解锁,需要则改为解锁状态 */ public static void unlockTask(String uid, ClueDto clue) { Map personMap = getPersonMap(uid); for (Map.Entry entry : personMap.entrySet()) { Person person = entry.getValue(); DemandTaskDto demandTask = getDemandTaskByClueId(person, clue.getClueId()); if (!StringUtils.isEmpty(demandTask)) { //需解锁任务 if (demandTask.getClueSwitch() == 1) { demandTask.setClueSwitch(2); } } } } /** * 判断线索是否符合阈值需求 * @param uid * @param clueList * @return */ public static List checkTaskThreshold(String uid, List clueList){ List result = new ArrayList<>(); Integer talkPersonId = TimingAcquisition.playerMap.get(uid).getPersonId(); //信任值 Integer trustDegree = getPersonMap(uid).get(talkPersonId).getTrustDegree(); //威慑度 Integer deterrenceDegree = getPersonMap(uid).get(talkPersonId).getDeterrenceDegree(); for (ClueDto clue : clueList) { if (trustDegree >= clue.getTrustDegree() || deterrenceDegree >= clue.getThreaten()) { result.add(clue); } } return result; } /** * 查找任务目的为对应类型线索 * @param person * @param clueList * @param taskTarget 1 信任度提升 2 信任度降低 3 威慑度提升 4 威慑度降低 */ public static List getCluesIsType(Person person, List clueList, Integer taskTarget) { List result = new ArrayList<>(); for (ClueDto clue : clueList) { DemandTaskDto demandTask = getDemandTaskByClueId(person, clue.getClueId()); if (!StringUtils.isEmpty(demandTask)) { if (taskTarget == 1) { if (Objects.equals(demandTask.getSubject(), person.getId())) { int trustDegree = demandTask.getTrustDegree(); if (!StringUtils.isEmpty(trustDegree) && trustDegree > 0) { result.add(clue); } } } else if (taskTarget == 2) { if (Objects.equals(demandTask.getSubject(), person.getId())) { int trustDegree = demandTask.getTrustDegree(); if (!StringUtils.isEmpty(trustDegree) && trustDegree < 0) { result.add(clue); } } } else if (taskTarget == 3) { if (Objects.equals(demandTask.getSubject(), person.getId())) { int deterrenceDegree = demandTask.getDeterrenceDegree(); if (!StringUtils.isEmpty(deterrenceDegree) && deterrenceDegree > 0) { result.add(clue); } } } else if (taskTarget == 4) { if (Objects.equals(demandTask.getSubject(), person.getId())) { int deterrenceDegree = demandTask.getDeterrenceDegree(); if (!StringUtils.isEmpty(deterrenceDegree) && deterrenceDegree < 0) { result.add(clue); } } } } } return result; } /** * 判断是否符合阈值需求 * @param trustCondition * @param deterrenceCondition * @param subject * @return */ public static boolean checkThreshold(String trustCondition,String deterrenceCondition,Person subject){ boolean flag = false; if(!StringUtils.isEmpty(trustCondition)){ String[] trustConditions = trustCondition.split("\\|"); if(NumberUtil.inNumRange(subject.getTrustDegree(),"["+trustConditions[0]+","+trustConditions[1]+"]")) { flag = true; } } if(!StringUtils.isEmpty(deterrenceCondition)) { String[] deterrenceConditions = deterrenceCondition.split("\\|"); if(NumberUtil.inNumRange(subject.getDeterrenceDegree(),"["+deterrenceConditions[0]+","+deterrenceConditions[1]+"]")) { flag = true; } } return flag; } /** * 新增阈值 * @param subject * @param demandTask */ public static void addThreshold(Person subject, DemandTaskDto demandTask) { if(demandTask.getTrustDegree() != 0) { if(subject.getTrustDegree() <= 100) { if((subject.getTrustDegree() + demandTask.getTrustDegree() ) > 100) { subject.setTrustDegree(100); } else { subject.setTrustDegree(Math.max((subject.getTrustDegree() + demandTask.getTrustDegree()), 0)); } } } if(demandTask.getDeterrenceDegree() != 0) { if(subject.getDeterrenceDegree() <= 100) { if((subject.getDeterrenceDegree() + demandTask.getDeterrenceDegree()) > 100){ subject.setDeterrenceDegree(100); } else { subject.setDeterrenceDegree(Math.max((subject.getDeterrenceDegree() + demandTask.getDeterrenceDegree()), 0)); } } } } /** * 玩家重置关卡 */ public static void resetPlayer(String uid) { Player player = TimingAcquisition.playerMap.get(uid); player.setClueMap(new HashMap<>()); player.setTaskMap(new HashMap<>()); player.setCurrency(0.0); player.setPoint(0); //初始化推理游戏人物 List personsCopy = TimingAcquisition.gateInfoMap.get(player.getGateNo()); //深拷贝list List personCopyList = PlayerUtil.deepCopyList(personsCopy); Map> taskMap = new HashMap<>(); Map personInfoMap = new HashMap<>(); Map name2IdMap = new HashMap<>(); Map id2NameMap = new HashMap<>(); for (Person person : personCopyList) { taskMap.put(person.getId(), new HashMap<>()); name2IdMap.put(person.getName(), person.getId()); id2NameMap.put(person.getId(), person.getName()); //NPC相关数据 PersonInfoDto personInfo = new PersonInfoDto(); Map> clueSourceMap = new ConcurrentHashMap<>(); Map demandTaskSwitchMap = new ConcurrentHashMap<>(); personInfo.setId(person.getId()); List clueList = person.getClues(); for (ClueDto clue : clueList) { clueSourceMap.put(clue.getClueId(), new ArrayList<>()); } List demandTaskList = person.getDemandTasks(); for (DemandTaskDto demandTask : demandTaskList) { demandTaskSwitchMap.put(demandTask.getDemandTaskId(), demandTask.getClueSwitch()); } personInfo.setClueSourceMap(clueSourceMap); personInfo.setDemandTaskSwitchMap(demandTaskSwitchMap); personInfoMap.put(person.getId(), personInfo); } player.setTaskMap(taskMap); player.setPersonInfoMap(personInfoMap); player.setName2IdMap(name2IdMap); player.setId2NameMap(id2NameMap); //给玩家分配场所和对话人物 Map> locationPersonMap = new HashMap<>(); Map personMap = getPersonMap(uid); for (Map.Entry entry : personMap.entrySet()) { Person person = entry.getValue(); if (!StringUtils.isEmpty(person.getLocation())) { //没有当前场所 if (StringUtils.isEmpty(locationPersonMap.get(person.getLocation()))) { List personList = new ArrayList<>(); personList.add(entry.getKey()); locationPersonMap.put(person.getLocation(), personList); } //有当前场所,但是没有这个人 List persons = locationPersonMap.get(person.getLocation()); if (!persons.contains(entry.getKey())) { persons.add(entry.getKey()); } } } List locationList = new ArrayList<>(locationPersonMap.keySet()); int index = RandomUtil.randomInt(locationList.size()); String locationId = locationList.get(index); player.setLocation(locationId); //随机分配人物 List personList = locationPersonMap.get(locationId); int num = RandomUtil.randomInt(personList.size()); player.setPersonId(personList.get(num)); //生成场所表,包含场所隐藏状态和必现场所 Map locationMap = PlayerUtil.makeLocationMap(locationPersonMap); player.setLocationMap(locationMap); player.setCurrency(3000.0); player.setPoint(0); player.setClueMap(new HashMap<>()); player.setFinishedTaskNum(0); player.setTipFlag(false); player.setOperateTextNum(1); player.setAskAndNumMap(new HashMap<>()); player.setFinished(0); } /** * 玩家放弃关卡 */ public static void playerGiveUp(String uid) { Player player = TimingAcquisition.playerMap.get(uid); player.setClueMap(new HashMap<>()); player.setTaskMap(new HashMap<>()); player.setCurrency(0.0); player.setPoint(0); } /** * 判断数组A是否为数组B的子集 */ public static boolean checkSubset(List listA, List listB) { for (Integer a : listA) { if (!listB.contains(a)) { return false; } } return true; } /** * 生成场所表 * @param locationPersonMap */ public static Map makeLocationMap(Map> locationPersonMap) { Map locationInfoMap = new HashMap<>(); Map locationMap = TimingAcquisition.locationMap; //遍历所有场所,找到所有已知和必现场所 for (Map.Entry entry : locationMap.entrySet()) { LocationInfoDto locationInfo = new LocationInfoDto(); String locationId = entry.getKey(); List personIdList = locationPersonMap.get(locationId); //该场所已有玩家 if (!StringUtils.isEmpty(personIdList)) { Map personInfoMap = new HashMap<>(); for (Integer personId : personIdList) { personInfoMap.put(personId, 0); } String isHidden = entry.getValue().getIsHidden(); locationInfo.setIsHidden(isHidden); locationInfo.setPersonInfoMap(personInfoMap); locationInfoMap.put(entry.getKey(), locationInfo); } else { //该场所为必现场所 if ("1".equals(entry.getValue().getIsAppear())) { String isHidden = entry.getValue().getIsHidden(); locationInfo.setIsHidden(isHidden); locationInfoMap.put(entry.getKey(), locationInfo); } } } return locationInfoMap; } /** * 判断玩家是否获得了对应人物的场所线索 * @param clueMap * @param personId */ public static boolean checkLocationClue(Map>> clueMap, Integer personId) { Map> personClueMap = clueMap.get(personId); //有这个人的线索 if (!StringUtils.isEmpty(personClueMap)) { List clueList = personClueMap.get(2); //有这个人场所线索 return !StringUtils.isEmpty(clueList); } return false; } /** * 判断玩家是否已经见过某个人 * @param locationMap * @param personId */ public static boolean checkHaveMeet(Map locationMap, String locationId, Integer personId) { //指定场所已有的人物见面次数 Map personInfoMap = locationMap.get(locationId).getPersonInfoMap(); if (!StringUtils.isEmpty(personInfoMap.get(personId))) { int meetTimes = personInfoMap.get(personId); if (meetTimes > 0) { return true; } } return false; } /** * 解锁场所 * @param locationMap * @param locationId */ public static void unlockLocation(Map locationMap, String locationId) { //场所未解锁 String isHidden = locationMap.get(locationId).getIsHidden(); if ("1".equals(isHidden)) { locationMap.get(locationId).setIsHidden("1"); } } /** * 查找有前置任务的任务 * @param uid * @param personIdList */ public static List getDemandTaskHavePre(String uid, List personIdList) { List postTaskStatusList = new ArrayList<>(); //所有人物 Map personMap = getPersonMap(uid); //遍历所有人物 for (Integer personId : personIdList) { //该人物身上挂的任务 List demandTasks = personMap.get(personId).getDemandTasks(); PostTaskDto postTask = new PostTaskDto(); postTask.setPersonId(personId); Map taskStatusMap = new HashMap<>(); //判断任务是否有前置任务 for (DemandTaskDto demandTask : demandTasks) { //该任务有前置任务,则为后置任务 if (!StringUtils.isEmpty(demandTask.getPostTask())) { //判断后置任务是否已经完成 int flag = checkTaskStatus(uid, personId, demandTask.getDemandTaskId()); //未完成 if (flag == 0) { TaskStatusDto taskStatus = new TaskStatusDto(); //判断前置任务是否已经完成 Integer postTaskId = Integer.valueOf(demandTask.getPostTask()); int finished = checkTaskStatus(uid, demandTask.getObject(), postTaskId); taskStatus.setTaskId(postTaskId); taskStatus.setStatus(finished); taskStatusMap.put(demandTask.getDemandTaskId(), taskStatus); } } } if (taskStatusMap.size() != 0) { postTask.setTaskStatusMap(taskStatusMap); postTaskStatusList.add(postTask); } } return postTaskStatusList; } /** * 查找单个人有前置任务的任务 * @param uid * @param personId */ public static List getDemandTaskHavePre(String uid, Integer personId) { List postTaskStatusList = new ArrayList<>(); //该人物身上挂的任务 List demandTasks = getPersonMap(uid).get(personId).getDemandTasks(); PostTaskDto postTask = new PostTaskDto(); postTask.setPersonId(personId); Map taskStatusMap = new HashMap<>(); //判断任务是否有前置任务 for (DemandTaskDto demandTask : demandTasks) { //该任务有前置任务,则为后置任务 if (!StringUtils.isEmpty(demandTask.getPostTask())) { //判断后置任务是否已经完成 int flag = checkTaskStatus(uid, personId, demandTask.getDemandTaskId()); //未完成 if (flag == 0) { TaskStatusDto taskStatus = new TaskStatusDto(); //判断前置任务是否已经完成 Integer postTaskId = Integer.valueOf(demandTask.getPostTask()); int finished = checkTaskStatus(uid, demandTask.getObject(), postTaskId); taskStatus.setTaskId(postTaskId); taskStatus.setStatus(finished); taskStatusMap.put(demandTask.getDemandTaskId(), taskStatus); } } } if (taskStatusMap.size() != 0) { postTask.setTaskStatusMap(taskStatusMap); postTaskStatusList.add(postTask); } return postTaskStatusList; } /** * 判断任务是否已经完成,0-未完成,1-已完成 * @param uid * @param personId * @param taskId */ public static int checkTaskStatus(String uid, Integer personId, Integer taskId) { Map taskStatusMap = TimingAcquisition.playerMap.get(uid).getTaskMap().get(personId); if (!StringUtils.isEmpty(taskStatusMap.get(taskId))) { return 1; } return 0; } /** * 后置任务的提示按优先级查找 * @param uid * @param postTaskList */ public static PostTaskRecordDto getPostTask(String uid, List postTaskList) { PostTaskRecordDto postTaskRecord = new PostTaskRecordDto(); List postTaskRecordList = new ArrayList<>(); Integer currentId = TimingAcquisition.playerMap.get(uid).getPersonId(); Person current = getPersonMap(uid).get(currentId); //遍历每个人 for (PostTaskDto postTask : postTaskList) { Map taskStatusMap = postTask.getTaskStatusMap(); for (Map.Entry entry : taskStatusMap.entrySet()) { Integer postTaskId = entry.getKey(); //后置任务 TaskStatusDto taskStatus = entry.getValue(); //通过人物的任务id找到任务信息 DemandTaskDto demandTask = getDemandTaskInfo(uid, postTask.getPersonId(), postTaskId); //1.有前置任务已完成 if (taskStatus.getStatus() == 1) { if (!StringUtils.isEmpty(demandTask)) { String[] condition1 = demandTask.getCondition1().split("\\|"); //任务条件为“70043” if ("70043".equals(condition1[0])) { postTaskRecord.setPersonId(postTask.getPersonId()); postTaskRecord.setPostTaskId(postTaskId); postTaskRecord.setPreTaskId(taskStatus.getTaskId()); //前置任务 postTaskRecord.setStatus(taskStatus.getStatus()); boolean flag = checkTaskSelf(uid, postTask.getPersonId(), demandTask.getClueId()); if (flag) { postTaskRecord.setLevel(1); //前置任务已完成且是自己发布 } else { postTaskRecord.setLevel(2); //前置任务已完成且不是自己发布 } return postTaskRecord; } } } //2.任务为自动触发 if (!StringUtils.isEmpty(demandTask)) { //任务已解锁或者无需解锁 if (demandTask.getClueSwitch() != 1) { //判断是否达到阈值 boolean flag = PlayerUtil.checkThreshold(demandTask, current); if (flag) { //任务是不是自动触发 if (demandTask.getIsAuto() == 1) { String[] condition1 = demandTask.getCondition1().split("\\|"); PostTaskRecordDto postTaskRecordCopy = new PostTaskRecordDto(); postTaskRecordCopy.setPersonId(postTask.getPersonId()); postTaskRecordCopy.setPostTaskId(postTaskId); postTaskRecordCopy.setPreTaskId(taskStatus.getTaskId()); postTaskRecordCopy.setStatus(taskStatus.getStatus()); //任务是否为71000自动完成 if ("71000".equals(condition1[0])) { postTaskRecordCopy.setLevel(3); //任务为自动触发完成 } else { postTaskRecordCopy.setLevel(4); //任务为自动发布 } postTaskRecordList.add(postTaskRecordCopy); } } } } //3.前置任务为本人发布 if (!StringUtils.isEmpty(demandTask)) { boolean flag = checkTaskSelf(uid, postTask.getPersonId(), demandTask.getClueId()); if (flag) { PostTaskRecordDto postTaskRecordCopy = new PostTaskRecordDto(); postTaskRecordCopy.setPersonId(postTask.getPersonId()); postTaskRecordCopy.setPostTaskId(postTaskId); postTaskRecordCopy.setPreTaskId(taskStatus.getTaskId()); postTaskRecordCopy.setStatus(taskStatus.getStatus()); postTaskRecordCopy.setLevel(5); //任务为本人发布 postTaskRecordList.add(postTaskRecordCopy); } } } } //找到优先级最高的任务 if (postTaskRecordList.size() != 0) { int min = 5; int index = 0; for (int i = 0; i < postTaskRecordList.size(); i++) { if (postTaskRecordList.get(i).getLevel() <= min) { min = postTaskRecordList.get(i).getLevel(); index = i; } } return postTaskRecordList.get(index); } return null; } /** * 通过人物的任务id找到任务信息 * @param uid * @param personId * @param taskId */ public static DemandTaskDto getDemandTaskInfo(String uid, Integer personId, Integer taskId) { List demandTasks = getPersonMap(uid).get(personId).getDemandTasks(); for (DemandTaskDto demandTask : demandTasks) { if (demandTask.getDemandTaskId() == taskId) { return demandTask; } } return null; } /** * 验证任务是否为本人发布 * @param uid * @param personId * @param clueId */ public static boolean checkTaskSelf(String uid, Integer personId, Integer clueId) { Map>> clueMap = TimingAcquisition.playerMap.get(uid).getClueMap(); //有收集到线索 if (clueMap.size() != 0) { //有收集到这个人的线索 Map> clueTypeMap = clueMap.get(personId); if (!StringUtils.isEmpty(clueTypeMap)) { for (Map.Entry> entry : clueTypeMap.entrySet()) { List clueList = entry.getValue(); for (ClueDto clue : clueList) { List sourceIdList = TimingAcquisition.playerMap.get(uid).getPersonInfoMap().get(personId).getClueSourceMap().get(clue.getClueId()); if (clue.getClueId() == clueId && sourceIdList.contains(personId)) { return true; } } } } } return false; } /** * 根据玩家任务进度,给玩家提供建议 * @param uid */ public static String getClueFromTaskKey(String uid) { String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //攻略任务 List barrierTaskKeyList = TimingAcquisition.barrierTaskKeyMap.get(gateNo); //玩家已完成的任务 Map> taskMap = TimingAcquisition.playerMap.get(uid).getTaskMap(); for (BarrierTaskKeyDto barrierTaskKey : barrierTaskKeyList) { Map taskStatusMap = taskMap.get(barrierTaskKey.getSubject()); //有完成的任务 if (!StringUtils.isEmpty(taskStatusMap)) { //该任务已经完成,查找下一个 if (StringUtils.isEmpty(taskStatusMap.get(barrierTaskKey.getDemandTaskId()))) { Integer clueId = barrierTaskKey.getClueId(); Integer subjectId = barrierTaskKey.getSubject(); ClueDto clue = getClueById(uid, subjectId, clueId); if (!StringUtils.isEmpty(clue)) { String text = TimingAcquisition.clueMap.get(clueId).getClueTemplate(); return text + "这条线索可能对你比较重要。"; } } } } return null; } /** * 找到白名单内该人的任务中已解锁或无需解锁的任务对应的提示 * @param uid * @param person */ public static String getTipInChat(String uid, Person person) { List demandTaskList = person.getDemandTasks(); Player player = TimingAcquisition.playerMap.get(uid); String gateNo = player.getGateNo(); //攻略任务(白名单) List barrierTaskKeyList = TimingAcquisition.barrierTaskKeyMap.get(gateNo); int count = 0; //统计已完成次数 //信任值 Integer trustDegree = person.getTrustDegree(); //威慑度 Integer deterrenceDegree = person.getDeterrenceDegree(); for (DemandTaskDto demandTask : demandTaskList) { //判断这个任务是否在白名单内 for (BarrierTaskKeyDto barrierTaskKey : barrierTaskKeyList) { //任务在白名单中 if (barrierTaskKey.getId().equals(demandTask.getId())) { //该任务已解锁或无需解锁 if (demandTask.getClueSwitch() != 1) { //任务是否已经完成 int taskStatus = checkTaskStatus(uid, person.getId(), demandTask.getDemandTaskId()); //未完成 if (taskStatus == 0) { if (trustDegree >= demandTask.getTrustStart() || deterrenceDegree >= demandTask.getDeterrenceStart()) { return SpeechUtil.getTipSpeech(uid, demandTask, 0, 1); } } } else { //任务需要解锁,找到能解锁任务的线索 //能解锁任务的线索在哪个人身上 List personIdList = getPersonIdByClueId(uid, demandTask.getClueId(), demandTask.getSubject()); //线索挂在NPC本人身上 if (personIdList.contains(person.getId())) { ClueDto clue = getClueById(uid, person.getId(), demandTask.getClueId()); if (!StringUtils.isEmpty(clue)) { //该任务已解锁或无需解锁 if (demandTask.getClueSwitch() != 1) { //任务是否已经完成 int taskStatus = checkTaskStatus(uid, person.getId(), demandTask.getDemandTaskId()); //未完成 if (taskStatus == 0) { if (trustDegree >= clue.getTrustDegree() || deterrenceDegree >= clue.getThreaten()) { return SpeechUtil.getTipSpeech(uid, demandTask, 0, 2); } } } } } } count++; } } } //该NPC身上有其他人的线索且在白名单 List clueList = person.getClues(); for (BarrierTaskKeyDto barrierTaskKey : barrierTaskKeyList) { List clueIdList = getClueByTaskId(getPersonMap(uid).get(barrierTaskKey.getSubject()), barrierTaskKey.getDemandTaskId()); DemandTaskDto demandTask = getDemandTaskInfo(uid, barrierTaskKey.getSubject(), barrierTaskKey.getDemandTaskId()); for (ClueDto clue : clueList) { //排除当前对话人的线索 if (clueIdList.contains(clue.getClueId()) && clue.getSubject() == barrierTaskKey.getSubject() && player.getPersonId() != clue.getSubject()) { //任务是否已经完成 // int taskStatus = checkTaskStatus(uid, barrierTaskKey.getSubject(), barrierTaskKey.getDemandTaskId()); //任务是否已经解锁 if (!StringUtils.isEmpty(demandTask)) { //未解锁 if (demandTask.getClueSwitch() == 1) { if (trustDegree >= clue.getTrustDegree() || deterrenceDegree >= clue.getThreaten()) { //----------------记录线索-------------- recordClue(uid, person.getId(), barrierTaskKey.getSubject(), clue.getType(), clue); return SpeechUtil.getTipSpeech(uid, barrierTaskKey, person.getId()); } } } count++; } } } if (count > 0) { //获取对应话术 return SpeechUtil.getAskSpeech(Constants.SPEECH_PERSON, 103201); } return "算了吧,估计这个人问不出什么东西来。我们去问问其他人吧。"; } /** * 通过线索id找到挂线索的人物 * @param uid * @param clueId * @param subjectId */ public static List getPersonIdByClueId(String uid, Integer clueId, Integer subjectId) { List personIdList = new ArrayList<>(); Map personMap = getPersonMap(uid); for (Map.Entry entry : personMap.entrySet()) { Person person = entry.getValue(); List clueList = person.getClues(); for (ClueDto clue : clueList) { if (clueId.equals(clue.getClueId()) && subjectId.equals(clue.getSubject())) { if (!personIdList.contains(entry.getKey())) { personIdList.add(entry.getKey()); } } } } return personIdList; } /** * 找到NPC身上的某个任务对应的所有线索 * @param person * @param demandTaskId */ public static List getClueByTaskId(Person person, Integer demandTaskId) { List clueIdList = new ArrayList<>(); List demandTaskList = person.getDemandTasks(); for (DemandTaskDto demandTask : demandTaskList) { if (demandTask.getDemandTaskId() == demandTaskId && demandTask.getSubject() == person.getId()) { clueIdList.add(demandTask.getClueId()); } } return clueIdList; } /** * 判断该人物是否是第一次见面 * @param uid * @param locationId * @param personId */ public static boolean isFirstMeet(String uid, String locationId, Integer personId) { Map personInfoMap = TimingAcquisition.playerMap.get(uid).getLocationMap().get(locationId).getPersonInfoMap(); int times = personInfoMap.get(personId); return times == 0; } /** * 更新玩家跟人物的见面次数 * @param uid * @param locationId * @param personId */ public static void updateMeetTimes(String uid, String locationId, Integer personId) { Map personInfoMap = TimingAcquisition.playerMap.get(uid).getLocationMap().get(locationId).getPersonInfoMap(); int times = personInfoMap.get(personId) + 1; personInfoMap.put(personId, times); } /** * 扣除玩家的货币 * @param uid * @param num */ public static void updateMoneyNum(String uid, int num) { int money = TimingAcquisition.playerMap.get(uid).getCurrency().intValue(); if (money > num) { TimingAcquisition.playerMap.get(uid).setCurrency((double) (money - num)); } else { TimingAcquisition.playerMap.get(uid).setCurrency((double) (0)); } } /** * 增加玩家的货币 * @param uid * @param num */ public static void addMoneyNum(String uid, int num) { int money = TimingAcquisition.playerMap.get(uid).getCurrency().intValue(); TimingAcquisition.playerMap.get(uid).setCurrency((double) (money + num)); } /** * 深拷贝list */ public static List deepCopyList(List src) { List dest = null; try { ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(byteOut); out.writeObject(src); ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray()); ObjectInputStream in = new ObjectInputStream(byteIn); dest = (List) in.readObject(); } catch (ClassNotFoundException | IOException e) { e.printStackTrace(); } return dest; } /** * 过滤到已经完成任务对应的线索 * @param uid * @param person * @param clueList */ public static List getUndoClueList(String uid, Person person, List clueList) { List result = new ArrayList<>(); for (ClueDto clue : clueList) { DemandTaskDto demandTask = getDemandTaskByClueId(person, clue.getClueId()); if (!StringUtils.isEmpty(demandTask)) { int taskStatus = checkTaskStatus(uid, person.getId(), demandTask.getDemandTaskId()); if (taskStatus == 1) { continue; } } result.add(clue); } return result; } /** * 取出询问操作的方法编号对应的线索序号 */ public static int getNumByMethodId(String uid, String methodId, int size) { Map askAndNumMap = TimingAcquisition.playerMap.get(uid).getAskAndNumMap(); int result = 0; //还没有对用询问操作方法编号的序号 if (StringUtils.isEmpty(askAndNumMap.get(methodId))) { askAndNumMap.put(methodId, 0); } else { result = askAndNumMap.get(methodId); if (result >= size - 1) { result = 0; } else { result += 1; } askAndNumMap.put(methodId, result); } return result; } /** * 更新声望值 * @param player * @param num */ public static void updateReputation(Player player, int num) { //声望值 int fame = player.getReputation(); int result = fame + num; if (result <= 0) { player.setReputation(0); } else { player.setReputation(result); } } /** * 任务完成,数据更新 * @param uid * @param subjectId * @param demandTaskId */ public static void taskFinished(String uid, Integer subjectId, Integer demandTaskId) { Player player = TimingAcquisition.playerMap.get(uid); //已完成任务 Map map = player.getTaskMap().get(subjectId); DemandTaskDto demandTask = getDemandTaskInfo(uid, subjectId, demandTaskId); //3.信任阈值提升 if (!StringUtils.isEmpty(demandTask)) { int num = 0; if (!StringUtils.isEmpty(map.get(demandTaskId))) { num = map.get(demandTaskId); } //前置任务完成 map.put(demandTaskId, num + 1); //更新威慑度 addThreshold(getPersonMap(uid).get(subjectId), demandTask); String condition2 = demandTask.getCondition2(); if (!StringUtils.isEmpty(condition2)) { int value = Integer.parseInt(condition2); //扣除货币 if (value > 0) { updateMoneyNum(uid, value); } } String completionReward = demandTask.getCompletionReward(); //发放奖励 if (!StringUtils.isEmpty(completionReward)) { int reward = Integer.parseInt(completionReward); addMoneyNum(uid, reward); } } } /** * 自动触发的任务自动完成 * @param uid * @param person * @param clue */ public static String taskAutoFinish(String uid, Person person, ClueDto clue) { String result = ""; String taskText = ""; if (!StringUtils.isEmpty(clue)) { //线索类型为任务线索 if (clue.getType() == 6) { Person subject = getPersonMap(uid).get(clue.getSubject()); DemandTaskDto demandTaskDto = PlayerUtil.getDemandTaskByClueId(subject, clue); Integer subjectId = person.getId(); if (!StringUtils.isEmpty(demandTaskDto)) { //判断任务是否已经完成 int isFinished = PlayerUtil.checkTaskStatus(uid, subjectId, demandTaskDto.getDemandTaskId()); //未完成 if (isFinished == 0) { if (demandTaskDto.getIsAuto() == 1) { String condition1 = demandTaskDto.getCondition1(); String[] taskIdTimes = condition1.split("\\|"); //自动完成 if ("71000".equals(taskIdTimes[0])) { //达到阈值 boolean flag = checkThreshold(demandTaskDto, subject); if (flag) { Integer preTaskId = demandTaskDto.getDemandTaskId(); //后置 DemandTaskDto demandTaskPre = getDemandTaskInfo(uid, subjectId, preTaskId); //找到后置任务 if (!StringUtils.isEmpty(demandTaskPre)) { //后置任务自动完成 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 = getDemandTaskInfo(uid, objectId, postTaskId); if (!StringUtils.isEmpty(demandTaskPost)) { //前置任务自动完成 taskFinished(uid, objectId, postTaskId); String postText = SpeechUtil.getSuccessTaskSpeech(uid, person, demandTaskPost); taskText += postText; } } taskText += preText; } } } } } } } result = result + taskText; } return result; } }