package com.qiwu.inference.common.utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.TypeReference; import com.qiwu.inference.common.Constants; import com.qiwu.inference.common.TimingAcquisition; import com.qiwu.inference.common.api.CommonResult; import com.qiwu.inference.dto.*; import com.qiwu.inference.dto.request.OperationRequest; import com.qiwu.inference.dto.response.CallResponse; import com.qiwu.inference.dto.response.ResultResponse; import com.qiwu.inference.dto.response.ResultVarsResponse; import com.qiwu.inference.factory.RemoteCallFactory; import com.qiwu.inference.pojo.Location; import com.qiwu.inference.pojo.PartnerItem; import com.qiwu.inference.service.remote.impl.RemoteGardenImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; import java.io.*; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.PriorityBlockingQueue; @Component public class PlayerUtil { static Logger log = LoggerFactory.getLogger(PlayerUtil.class); public static String expireTime; @Value("${expireTime}") public void setExpireTime(String expireTime) { PlayerUtil.expireTime = expireTime; } public static String dataFilePath; @Value("${dataFilePath}") public void setDataFilePath(String dataFilePath) { PlayerUtil.dataFilePath = dataFilePath; } private static RemoteGardenImpl remoteGardenService; @Autowired public void setRemoteGardenService(RemoteGardenImpl remoteGardenService) { PlayerUtil.remoteGardenService = remoteGardenService; } private static RedisUtil redisUtil; @Autowired public void setRedisUtil(RedisUtil redisUtil) { PlayerUtil.redisUtil = redisUtil; } /** * 通过玩家当前关卡拿到NPC数据 */ public static Map getPersonMap(String uid) { String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); return TimingAcquisition.gatePersonMap.get(gateNo); } /** * 通过玩家当前关卡拿到指定NPC数据 */ public static Person getPerson(String uid, Integer personId) { String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); 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 uid * @param demandTask * @param subject * @return */ public static boolean checkThreshold(String uid, DemandTaskDto demandTask, PersonInfoDto subject){ boolean flag = false; boolean trustFlag = false; boolean deterrenceFlag = false; List allowTask = Arrays.asList(-2, -1, 0, 2, 5); Map demandTaskSwitchMap = TimingAcquisition.playerMap.get(uid).getPersonInfoMap().get(subject.getId()).getDemandTaskSwitchMap(); //1.任务无需解锁或者任务已解锁 if (allowTask.contains(demandTaskSwitchMap.get(demandTask.getDemandTaskId()))) { //2.配置了任务条件id if (demandTask.getConditionTaskId() != 0) { //2.1已完成配置的任务条件id if (checkTaskFinished(uid, demandTask.getConditionTaskId()) == 1) { //配置了时间阈值 if (!StringUtils.isEmpty(demandTask.getTimeThreshold())) { //时间阈值有范围 if (!"0|0".equals(demandTask.getTimeThreshold()) && !"0".equals(demandTask.getTimeThreshold())) { int initTime = TimingAcquisition.playerMap.get(uid).getInitTime(); String[] timeThresholds = demandTask.getTimeThreshold().split("\\|"); boolean timeFlag = NumberUtil.inNumRange(initTime,"["+timeThresholds[0]+","+timeThresholds[1]+"]"); //满足阈值条件 if (timeFlag) { //3.满足阈值 if(demandTask.getTrustStart() >=0 && demandTask.getTrustEnd() > 0) { trustFlag = NumberUtil.inNumRange(subject.getTrustDegree(),"["+demandTask.getTrustStart()+","+demandTask.getTrustEnd()+"]"); } if(demandTask.getDeterrenceStart() >= 0 && demandTask.getDeterrenceEnd() > 0) { deterrenceFlag = NumberUtil.inNumRange(subject.getDeterrenceDegree(),"["+demandTask.getDeterrenceStart()+","+demandTask.getDeterrenceEnd()+"]"); } } } else { //时间阈值没有配置范围 //3.满足阈值 if(demandTask.getTrustStart() >=0 && demandTask.getTrustEnd() > 0) { trustFlag = NumberUtil.inNumRange(subject.getTrustDegree(),"["+demandTask.getTrustStart()+","+demandTask.getTrustEnd()+"]"); } if(demandTask.getDeterrenceStart() >= 0 && demandTask.getDeterrenceEnd() > 0) { deterrenceFlag = NumberUtil.inNumRange(subject.getDeterrenceDegree(),"["+demandTask.getDeterrenceStart()+","+demandTask.getDeterrenceEnd()+"]"); } } } else { //没有配置时间阈值 //3.满足阈值 if(demandTask.getTrustStart() >=0 && demandTask.getTrustEnd() > 0) { trustFlag = NumberUtil.inNumRange(subject.getTrustDegree(),"["+demandTask.getTrustStart()+","+demandTask.getTrustEnd()+"]"); } if(demandTask.getDeterrenceStart() >= 0 && demandTask.getDeterrenceEnd() > 0) { deterrenceFlag = NumberUtil.inNumRange(subject.getDeterrenceDegree(),"["+demandTask.getDeterrenceStart()+","+demandTask.getDeterrenceEnd()+"]"); } } } } else { //没有配置任务条件id //配置了时间阈值 if (!StringUtils.isEmpty(demandTask.getTimeThreshold())) { if (!"0|0".equals(demandTask.getTimeThreshold()) && !"0".equals(demandTask.getTimeThreshold())) { int initTime = TimingAcquisition.playerMap.get(uid).getInitTime(); String[] timeThresholds = demandTask.getTimeThreshold().split("\\|"); boolean timeFlag = NumberUtil.inNumRange(initTime, "[" + timeThresholds[0] + "," + timeThresholds[1] + "]"); //满足阈值条件 if (timeFlag) { //3.满足阈值 if (demandTask.getTrustStart() >= 0 && demandTask.getTrustEnd() > 0) { trustFlag = NumberUtil.inNumRange(subject.getTrustDegree(), "[" + demandTask.getTrustStart() + "," + demandTask.getTrustEnd() + "]"); } if (demandTask.getDeterrenceStart() >= 0 && demandTask.getDeterrenceEnd() > 0) { deterrenceFlag = NumberUtil.inNumRange(subject.getDeterrenceDegree(), "[" + demandTask.getDeterrenceStart() + "," + demandTask.getDeterrenceEnd() + "]"); } } } else { //时间阈值没有配置范围 //3.满足阈值 if(demandTask.getTrustStart() >=0 && demandTask.getTrustEnd() > 0) { trustFlag = NumberUtil.inNumRange(subject.getTrustDegree(),"["+demandTask.getTrustStart()+","+demandTask.getTrustEnd()+"]"); } if(demandTask.getDeterrenceStart() >= 0 && demandTask.getDeterrenceEnd() > 0) { deterrenceFlag = NumberUtil.inNumRange(subject.getDeterrenceDegree(),"["+demandTask.getDeterrenceStart()+","+demandTask.getDeterrenceEnd()+"]"); } } } else { //没有配置时间阈值 //3.满足阈值 if(demandTask.getTrustStart() >=0 && demandTask.getTrustEnd() > 0) { trustFlag = NumberUtil.inNumRange(subject.getTrustDegree(),"["+demandTask.getTrustStart()+","+demandTask.getTrustEnd()+"]"); } if(demandTask.getDeterrenceStart() >= 0 && demandTask.getDeterrenceEnd() > 0) { deterrenceFlag = NumberUtil.inNumRange(subject.getDeterrenceDegree(),"["+demandTask.getDeterrenceStart()+","+demandTask.getDeterrenceEnd()+"]"); } } } flag = trustFlag || deterrenceFlag; } return flag; } /** * 判断是否符合阈值需求,不判断是否解锁 * @param demandTask * @param subject * @return */ public static boolean checkThresholdNoSwitch(DemandTaskDto demandTask, PersonInfoDto subject){ boolean flag = false; //任务无需解锁或者任务已解锁 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; } /** * 判断是否符合阈值需求 * @param person * @param clueList * @return */ public static List checkThresholdTalk(PersonInfoDto 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; } /** * 获取玩家关卡中人物所在的所有场所 */ 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(); String seriesName = TimingAcquisition.playerMap.get(uid).getSeries(); //系列名称 Map locationMap = TimingAcquisition.playerMap.get(uid).getLocationMap(); for (Map.Entry entry : locationMap.entrySet()) { //场所未隐藏 if (!Constants.IS_HIDDEN.equals(entry.getValue().getIsHidden())) { text.append(TimingAcquisition.seriesLocationMap.get(seriesName).get(entry.getKey()).getName()).append("、"); } } if (text.length() != 0) { text.deleteCharAt(text.length() - 1); } return text.toString(); } /** * 获取玩家关卡中已知的所有场所 */ public static List getLocationIdsByUid(String uid) { List locationList = new ArrayList<>(); Map locationMap = TimingAcquisition.playerMap.get(uid).getLocationMap(); for (Map.Entry entry : locationMap.entrySet()) { //场所未隐藏 if (!Constants.IS_HIDDEN.equals(entry.getValue().getIsHidden())) { locationList.add(entry.getKey()); } } return locationList; } /** * 通过场所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); //记录线索信息 ClueInfoDto clueInfo = new ClueInfoDto(); clueInfo.setId(clue.getId()); clueInfo.setClueId(clue.getClueId()); clueInfo.setSubject(clue.getSubject()); clueInfo.setObject(clue.getObject()); clueInfo.setType(clue.getType()); //玩家还没有收集此人的线索 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(clueInfo); 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(clueInfo); clueListMap.put(clueTypeId, clueList); clueMap.get(personId).putAll(clueListMap); return; } //玩家还没有收集到这条线索 List clues = clueMap.get(personId).get(clueTypeId); boolean have = false; for (ClueInfoDto 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(clueInfo); } } /** * 记录玩家已获得线索 */ 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(String uid, List clueList, String type) { List result = new ArrayList<>(); String seriesName = TimingAcquisition.playerMap.get(uid).getSeries(); //系列名称 for (ClueDto clueDto : clueList) { //关联的性格id Integer associatedId = TimingAcquisition.seriesClueMap.get(seriesName).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.seriesDispositionMap.get(seriesName).get(associatedId).getType())) { result.add(clueDto); } } else { if (type.equals(TimingAcquisition.seriesDispositionMap.get(seriesName).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 = getPerson(uid, 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, PersonInfoDto person, ClueDto clue) { Map demandTaskSwitchMap = person.getDemandTaskSwitchMap(); String postTaskId = null; //本人身上该任务解锁 for (Map.Entry entry: demandTaskSwitchMap.entrySet()) { DemandTaskDto demandTask = getDemandTaskById(uid, person.getId(), entry.getKey()); if (!StringUtils.isEmpty(demandTask)) { if (demandTask.getClueId() == clue.getClueId() && demandTask.getType() == clue.getType()) { //需解锁任务 if (entry.getValue() == 1) { entry.setValue(2); postTaskId = demandTask.getPostTask(); //有相同任务id的也解锁 for (Map.Entry e : demandTaskSwitchMap.entrySet()) { if (e.getKey() == demandTask.getDemandTaskId()) { e.setValue(2); } } } } } } int objectId = clue.getSubject(); if (person.getId() == clue.getSubject()) { objectId = clue.getObject(); } //线索主体为当前对话人时,解锁对应的任务 if (person.getId().equals(clue.getSubject())) { //解锁后置任务 if (!StringUtils.isEmpty(postTaskId)) { //线索对应任务解锁 Map demandTaskSwitchObjectMap = TimingAcquisition.playerMap.get(uid).getPersonInfoMap().get(objectId).getDemandTaskSwitchMap(); //客体身上该任务解锁 for (Map.Entry entry: demandTaskSwitchObjectMap.entrySet()) { DemandTaskDto demandTask = getDemandTaskById(uid, person.getId(), entry.getKey()); if (!StringUtils.isEmpty(demandTask)) { if (demandTask.getDemandTaskId() == Integer.parseInt(postTaskId)) { //需解锁任务 if (entry.getValue() == 1) { entry.setValue(2); } } } } } } else { //线索对应他人的任务解锁 Map demandTaskSwitchObjectMap = TimingAcquisition.playerMap.get(uid).getPersonInfoMap().get(objectId).getDemandTaskSwitchMap(); //客体身上该任务解锁 for (Map.Entry entry: demandTaskSwitchObjectMap.entrySet()) { DemandTaskDto demandTask = getDemandTaskById(uid, person.getId(), entry.getKey()); if (!StringUtils.isEmpty(demandTask)) { if (demandTask.getClueId() == clue.getClueId()) { //需解锁任务 if (entry.getValue() == 1) { entry.setValue(2); } } } } } } /** * 根据线索找到对应任务,判断任务是否需要解锁,需要则改为解锁状态 */ public static void unlockTask(String uid, ClueDto clue) { Map personInfoMap = TimingAcquisition.playerMap.get(uid).getPersonInfoMap(); for (Map.Entry entry : personInfoMap.entrySet()) { Person person = getPerson(uid, entry.getKey()); DemandTaskDto demandTask = getDemandTaskByClueId(person, clue.getClueId()); if (!StringUtils.isEmpty(demandTask)) { Integer clueSwitch = entry.getValue().getDemandTaskSwitchMap().get(demandTask.getDemandTaskId()); //需解锁任务 if (clueSwitch == 1) { clueSwitch = 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 = getPerson(uid, talkPersonId).getTrustDegree(); //威慑度 Integer deterrenceDegree = getPerson(uid, 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(PersonInfoDto 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); //初始化推理游戏人物 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(uid, locationPersonMap, player.getSeries()); player.setLocationMap(locationMap); //玩家当前关卡已经消耗的货币值 // double currency = player.getCurrency(); // //玩家系列汇总的货币值 // int money = TimingAcquisition.seriesPlayerMap.get(player.getSeries()).get(uid).getMoney(); // player.setCurrency((double) money + currency); 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(String uid, Map> locationPersonMap, String seriesName) { Map locationInfoMap = new HashMap<>(); Map locationMap = TimingAcquisition.seriesLocationMap.get(seriesName); //遍历所有场所,找到所有已知和必现场所 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("0"); } } /** * 查找有前置任务的任务 * @param uid * @param personIdList */ public static List getDemandTaskHavePre(String uid, List personIdList) { List postTaskStatusList = new ArrayList<>(); //所有人物 Map personMap = getPersonMap(uid); List allowTask = Arrays.asList(-1, 0, 2, 5); //遍历所有人物 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) { PersonInfoDto personInfo = TimingAcquisition.playerMap.get(uid).getPersonInfoMap().get(personId); //判断是否符合阈值需求 boolean conditionFlag = checkThreshold(uid, demandTask, personInfo); //满足阈值条件 if (conditionFlag) { //该任务有前置任务,则为后置任务 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 (demandTask.getIsAuto() == 1) { Map demandTaskSwitchMap = personInfo.getDemandTaskSwitchMap(); if (allowTask.contains(demandTaskSwitchMap.get(demandTask.getDemandTaskId()))) { //存在任务 if (StringUtils.isEmpty(taskStatusMap.get(demandTask.getDemandTaskId()))) { //判断任务是否完成 int flag = checkTaskStatus(uid, personId, demandTask.getDemandTaskId()); //未完成 if (flag == 0) { TaskStatusDto taskStatus = new TaskStatusDto(); if (!StringUtils.isEmpty(demandTask.getPostTask())) { //判断前置任务是否已经完成 Integer postTaskId = Integer.valueOf(demandTask.getPostTask()); //前置任务的完成情况 int finished = checkTaskStatus(uid, demandTask.getObject(), postTaskId); taskStatus.setTaskId(postTaskId); taskStatus.setStatus(finished); } else { taskStatus.setTaskId(0); taskStatus.setStatus(0); } 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 = getPerson(uid, personId).getDemandTasks(); PostTaskDto postTask = new PostTaskDto(); postTask.setPersonId(personId); //保存前后置任务对应关系的map Map taskStatusMap = new HashMap<>(); List allowTask = Arrays.asList(-1, 0, 2, 5); //判断任务是否有前置任务 for (DemandTaskDto demandTask : demandTasks) { PersonInfoDto personInfo = TimingAcquisition.playerMap.get(uid).getPersonInfoMap().get(personId); //判断是否符合阈值需求 boolean conditionFlag = checkThreshold(uid, demandTask, personInfo); //满足阈值条件 if (conditionFlag) { //该任务有前置任务,则为后置任务 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 (demandTask.getIsAuto() == 1) { Map demandTaskSwitchMap = personInfo.getDemandTaskSwitchMap(); if (allowTask.contains(demandTaskSwitchMap.get(demandTask.getDemandTaskId()))) { //存在任务 if (StringUtils.isEmpty(taskStatusMap.get(demandTask.getDemandTaskId()))) { //判断任务是否完成 int flag = checkTaskStatus(uid, personId, demandTask.getDemandTaskId()); //未完成 if (flag == 0) { TaskStatusDto taskStatus = new TaskStatusDto(); if (!StringUtils.isEmpty(demandTask.getPostTask())) { //判断前置任务是否已经完成 Integer postTaskId = Integer.valueOf(demandTask.getPostTask()); //前置任务的完成情况 int finished = checkTaskStatus(uid, demandTask.getObject(), postTaskId); taskStatus.setTaskId(postTaskId); taskStatus.setStatus(finished); } else { taskStatus.setTaskId(0); taskStatus.setStatus(0); } 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; } /** * 判断任务是否已经完成,0-未完成,1-已完成 * @param uid * @param taskId */ public static int checkTaskFinished(String uid, Integer taskId) { Map> taskStatusMap = TimingAcquisition.playerMap.get(uid).getTaskMap(); for (Map.Entry> entry : taskStatusMap.entrySet()) { if (!StringUtils.isEmpty(entry.getValue().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<>(); //允许选择的任务类型 List allowTask = Arrays.asList(-2, -1, 0, 2, 5); //遍历每个任务 for (PostTaskDto postTask : postTaskList) { Map taskStatusMap = postTask.getTaskStatusMap(); PersonInfoDto talk = TimingAcquisition.playerMap.get(uid).getPersonInfoMap().get(postTask.getPersonId()); for (Map.Entry entry : taskStatusMap.entrySet()) { Integer postTaskId = entry.getKey(); //后置任务id TaskStatusDto taskStatus = entry.getValue(); //前置任务id及其状态 //通过人物的后置任务id找到任务信息 DemandTaskDto demandTask = getDemandTaskInfo(uid, postTask.getPersonId(), postTaskId); //是前后置任务 if (!StringUtils.isEmpty(taskStatus)) { //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); //1.前置任务已完成且是自己发布 } else { postTaskRecord.setLevel(2); //2.前置任务已完成且不是自己发布 } return postTaskRecord; } } } //前置任务为自动触发的 // if (taskStatus.getStatus() == 0 && taskStatus.getTaskId() != 0) { // DemandTaskDto demandTaskPre = getDemandTaskInfo(uid, postTask.getPersonId(), taskStatus.getTaskId()); // if (!StringUtils.isEmpty(demandTaskPre)) { // //前置任务为自动触发 // if (demandTaskPre.getIsAuto() == 1) { // //前置任务已启动或能直接执行 // int clueSwitch = talk.getDemandTaskSwitchMap().get(demandTaskPre.getDemandTaskId()); // if (allowTask.contains(clueSwitch)) { // String[] condition1 = demandTaskPre.getCondition1().split("\\|"); // PostTaskRecordDto postTaskRecordCopy = new PostTaskRecordDto(); // postTaskRecordCopy.setPersonId(demandTaskPre.getSubject()); // postTaskRecordCopy.setPostTaskId(taskStatus.getTaskId()); //后置任务 // postTaskRecordCopy.setPreTaskId(0); //前置任务 // postTaskRecordCopy.setStatus(taskStatus.getStatus()); // //任务是否为71000自动完成 // if ("71000".equals(condition1[0])) { // postTaskRecordCopy.setLevel(3); //3.任务为自动触发完成 // } else { // //任务为本人发布 // boolean selfSign = checkTaskSelf(uid, postTask.getPersonId(), demandTask.getClueId()); // if (!selfSign) { // postTaskRecordCopy.setLevel(4); //4.任务为自动发布 // } else { // postTaskRecordCopy.setLevel(5); //5.任务为本人发布 // } // } // postTaskRecordList.add(postTaskRecordCopy); // } // } // } // } } //2.任务自动触发的情况 if (!StringUtils.isEmpty(demandTask)) { //任务是自动触发 if (demandTask.getIsAuto() == 1) { //判断是否达到阈值 boolean flag = checkThresholdNoSwitch(demandTask, talk); if (flag) { //任务已启动或能直接执行 int clueSwitch = talk.getDemandTaskSwitchMap().get(demandTask.getDemandTaskId()); if (allowTask.contains(clueSwitch)) { 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); //3.任务为自动触发完成 } else { //任务为本人发布 boolean selfSign = checkTaskSelf(uid, postTask.getPersonId(), demandTask.getClueId()); if (!selfSign) { postTaskRecordCopy.setLevel(4); //4.任务为自动发布 } else { postTaskRecordCopy.setLevel(5); //5.任务为本人发布 } } postTaskRecordList.add(postTaskRecordCopy); } else { //主要任务(后置任务)还未解锁 //主要任务有配置前置任务 if (!StringUtils.isEmpty(demandTask.getPostTask())) { 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); //3.任务为自动触发完成 } else { //任务为本人发布 boolean selfSign = checkTaskSelf(uid, postTask.getPersonId(), demandTask.getClueId()); if (!selfSign) { postTaskRecordCopy.setLevel(4); //4.任务为自动发布 } else { postTaskRecordCopy.setLevel(5); //5.任务为本人发布 } } 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); //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 = getPerson(uid, 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 (ClueInfoDto 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 = SpeechUtil.getSuccessClueOtherSpeech(uid, PlayerUtil.getPersonMap(uid).get(subjectId), clue); 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()) { String text = SpeechUtil.getTipSpeech(uid, demandTask, 0, 1); String[] condition1 = demandTask.getCondition1().split("\\|"); //排除自动触发、70043、71000和没有配置任务文本的情况 if (!StringUtils.isEmpty(text) && demandTask.getIsAuto() != 1 && !"70043".equals(condition1[0]) && !"71000".equals(condition1[0])) { //记录本轮的任务数据,用于下轮的二次回复 String unique = uid + player.getGateNo(); ReplyDto reply = new ReplyDto(); reply.setSubjectId(person.getId()); reply.setDemandTaskId(demandTask.getDemandTaskId()); reply.setType(2); //直接操作提醒 CacheUtil.put(unique, reply, Long.parseLong(expireTime)); } return text; } } } 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()) { String text = SpeechUtil.getTipSpeech(uid, demandTask, 0, 2); String[] condition1 = demandTask.getCondition1().split("\\|"); //排除自动触发、70043、71000和没有配置任务文本的情况 if (!StringUtils.isEmpty(text) && demandTask.getIsAuto() != 1 && !"70043".equals(condition1[0]) && !"71000".equals(condition1[0])) { //记录本轮的任务数据,用于下轮的二次回复 String unique = uid + player.getGateNo(); ReplyDto reply = new ReplyDto(); reply.setSubjectId(person.getId()); reply.setDemandTaskId(demandTask.getDemandTaskId()); reply.setType(4); //自身线索提示 CacheUtil.put(unique, reply, Long.parseLong(expireTime)); } return text; } } } } } } 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); //记录本轮的任务数据,用于下轮的二次回复 String unique = uid + player.getGateNo(); ReplyDto reply = new ReplyDto(); reply.setSubjectId(barrierTaskKey.getSubject()); reply.setObjectId(person.getId()); reply.setDemandTaskId(demandTask.getDemandTaskId()); reply.setType(1); //闲聊 CacheUtil.put(unique, reply, Long.parseLong(expireTime)); return SpeechUtil.getTipSpeech(uid, barrierTaskKey, person.getId()); } } } count++; } } } if (count > 0) { //获取对应话术 return SpeechUtil.getAskSpeech(uid, 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 currency = TimingAcquisition.playerMap.get(uid).getCurrency().intValue(); String seriesName = TimingAcquisition.playerMap.get(uid).getSeries(); int money = TimingAcquisition.seriesPlayerMap.get(seriesName).get(uid).getMoney(); if (money > num) { TimingAcquisition.seriesPlayerMap.get(seriesName).get(uid).setMoney(money - num); //累计当前关卡已消耗货币数量 // TimingAcquisition.playerMap.get(uid).setCurrency((double) (currency + num)); } else { TimingAcquisition.seriesPlayerMap.get(seriesName).get(uid).setMoney(0); //累计当前关卡已消耗货币数量 // TimingAcquisition.playerMap.get(uid).setCurrency((double) (currency + currency)); } } /** * 增加玩家的货币 * @param uid * @param num */ public static void addMoneyNum(String uid, int num) { String seriesName = TimingAcquisition.playerMap.get(uid).getSeries(); int money = TimingAcquisition.seriesPlayerMap.get(seriesName).get(uid).getMoney(); TimingAcquisition.seriesPlayerMap.get(seriesName).get(uid).setMoney(money + num); //累计当前关卡已消耗货币数量 // int currency = TimingAcquisition.playerMap.get(uid).getCurrency().intValue(); // TimingAcquisition.playerMap.get(uid).setCurrency((double) (currency - 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 player * @param num */ public static void updateInitTime(Player player, int num) { if (num != 0) { //初始时间值 int initTime = player.getInitTime(); int result = initTime - num; if (result <= 0) { player.setInitTime(0); } else { player.setInitTime(result); } } } /** * 更新生命状态 */ public static void updateLifeState(PersonInfoDto personInfo, int lifeState) { if (lifeState != 0) { if (personInfo.getLifeState() != lifeState) { personInfo.setLifeState(lifeState); } } } /** * 任务完成,数据更新 * @param uid * @param subjectId * @param demandTaskId */ public static void taskFinished(String uid, Integer subjectId, Integer demandTaskId) { Player player = TimingAcquisition.playerMap.get(uid); //已完成任务的map Map map = player.getTaskMap().get(subjectId); DemandTaskDto demandTask = getDemandTaskInfo(uid, subjectId, demandTaskId); //任务存在 if (!StringUtils.isEmpty(demandTask)) { int num = 0; if (!StringUtils.isEmpty(map.get(demandTaskId))) { num = map.get(demandTaskId); } //1.任务完成 map.put(demandTaskId, num + 1); //2.更新信任值和威慑度 addThreshold(player.getPersonInfoMap().get(subjectId), demandTask); String cost = demandTask.getCost(); if (!StringUtils.isEmpty(cost)) { String[] costs = cost.split("\\|"); int value = Integer.parseInt(costs[0]); //3.扣除货币 if (value > 0) { updateMoneyNum(uid, value); } } String completionReward = demandTask.getCompletionReward(); //4.发放奖励 if (!StringUtils.isEmpty(completionReward)) { int reward = Integer.parseInt(completionReward); addMoneyNum(uid, reward); } //5.增加声望值 updateReputation(player, demandTask.getReputation()); //6.更新时间值 updateInitTime(player, demandTask.getCostTime()); //7.更新生命状态 updateLifeState(player.getPersonInfoMap().get(subjectId), demandTask.getLifeState()); } } /** * 自动触发的任务自动完成 * @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()); PersonInfoDto talk = TimingAcquisition.playerMap.get(uid).getPersonInfoMap().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(uid, demandTaskDto, talk); 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; } /** * 通过关卡名称找到对应的系列名称 * @param gateName */ public static String getSeriesNameByGateName(String gateName) { String gateNo = TimingAcquisition.gateNameToNoMap.get(gateName); Map> seriesGateNosMap = TimingAcquisition.seriesGateNosMap; for (Map.Entry> entry : seriesGateNosMap.entrySet()) { List gateNoList = entry.getValue(); if (gateNoList.contains(gateNo)) { return entry.getKey(); } } return null; } /** * 更新关卡排行榜 * @param player * @param reputation */ public static void updateGateNoReputation(Player player, ReputationDto reputation) { String uid = player.getUid(); String gateNo = player.getGateNo(); //关卡编号 Map> gateNoUidReputationMap = TimingAcquisition.gateNoUidReputationMap; Map> gateNoReputationQueueMap = TimingAcquisition.gateNoReputationQueueMap; //关卡中已存在用户 if (!StringUtils.isEmpty(gateNoUidReputationMap.get(gateNo))) { ReputationDto reputationOld = gateNoUidReputationMap.get(gateNo).get(uid); //关卡中有该用户的声望 if (!StringUtils.isEmpty(reputationOld)) { //该用户的声望已更新 if (!reputation.equals(reputationOld)) { //更新关卡中该用户的声望 gateNoUidReputationMap.get(gateNo).put(uid, reputation); //更新关卡排行榜中用户的旧声望 gateNoReputationQueueMap.get(gateNo).add(reputation); gateNoReputationQueueMap.get(gateNo).remove(reputationOld); } } else { //新增关卡中该用户的声望 gateNoUidReputationMap.get(gateNo).put(uid, reputation); //新增关卡排行榜中用户的声望 gateNoReputationQueueMap.get(gateNo).add(reputation); } } else { //新增关卡和声望 Map reputationMap = new HashMap<>(); reputationMap.put(uid, reputation); gateNoUidReputationMap.put(gateNo, reputationMap); //新增关卡排行榜 PriorityBlockingQueue gateNoReputationQueue = new PriorityBlockingQueue<>(); gateNoReputationQueue.add(reputation); gateNoReputationQueueMap.put(gateNo, gateNoReputationQueue); } } /** * 更新系列排行榜 * @param uid * @param seriesName * @param reputation */ public static void updateSeriesReputation(String uid, String seriesName, ReputationDto reputation) { Map> seriesPlayerMap = TimingAcquisition.seriesPlayerMap; Map> seriesReputationQueueMap = TimingAcquisition.seriesReputationQueueMap; //不存在该系列 if (StringUtils.isEmpty(seriesReputationQueueMap.get(seriesName))) { PlayerSeriesDto playerSeries = new PlayerSeriesDto(); ReputationDto totalReputation = new ReputationDto(); totalReputation.setUid(uid); totalReputation.setReputation(reputation.getReputation()); playerSeries.setTotalReputation(totalReputation); //新增系列排行榜 PriorityBlockingQueue seriesReputationQueue = new PriorityBlockingQueue<>(); seriesReputationQueue.add(reputation); seriesReputationQueueMap.put(seriesName, seriesReputationQueue); } else { //该系列不存在该用户 ReputationDto reputationOld = seriesPlayerMap.get(seriesName).get(uid).getTotalReputation(); //累计声望值 reputation.setReputation(reputation.getReputation() + reputationOld.getReputation()); //更新系列中该用户 seriesPlayerMap.get(seriesName).get(uid).setTotalReputation(reputation); //更新系列排行榜中用户的旧声望 seriesReputationQueueMap.get(seriesName).add(reputation); seriesReputationQueueMap.get(seriesName).remove(reputationOld); } } /** * 任务按优先级自动完成任务或自动触发 * @param uid * @param postTaskRecord */ public static ResultVarsResponse taskDoByLevel(String uid, PostTaskRecordDto postTaskRecord) { ResultVarsResponse resultVarsResponse = new ResultVarsResponse(); ResultResponse resultResponse = new ResultResponse(); Player player = TimingAcquisition.playerMap.get(uid); Integer subjectId = postTaskRecord.getPersonId(); String text = ""; //前置任务已完成 if (postTaskRecord.getLevel() == 1 || postTaskRecord.getLevel() == 2) { DemandTaskDto demandTask = getDemandTaskById(uid, subjectId, postTaskRecord.getPostTaskId()); if (!StringUtils.isEmpty(demandTask)) { //任务自动完成 taskFinished(uid, subjectId, postTaskRecord.getPostTaskId()); if (postTaskRecord.getLevel() == 1) { //获取对应话术 text = SpeechUtil.getPreSuccessTaskSpeech(uid, getPerson(uid, subjectId), demandTask, 1); resultResponse.set反馈ID(400106); } if (postTaskRecord.getLevel() == 2) { //获取对应话术 text = SpeechUtil.getPreSuccessTaskSpeech(uid, getPerson(uid, subjectId), demandTask, 2); resultResponse.set反馈ID(400107); } //记录本轮的任务数据,用于下轮的二次回复 String unique = uid + player.getGateNo(); ReplyDto reply = new ReplyDto(); reply.setSubjectId(subjectId); reply.setDemandTaskId(postTaskRecord.getPostTaskId()); reply.setType(2); //直接操作提醒 String[] condition = demandTask.getCondition1().split("\\|"); //任务会掉落物或人 if ("72000".equals(condition[0])) { Map dropMap = ConfigDataUtil.getDropItems(uid, demandTask.getDropItems()); if (dropMap.isEmpty()) { text = ""; } else { reply.setIdNumMap(dropMap); } } CacheUtil.put(unique, reply, Long.parseLong(expireTime)); //任务链下一个任务的对应回复 CommonResult result = PlayerUtil.getNextTaskAnswer(uid, subjectId, demandTask.getDemandTaskId()); if (!StringUtils.isEmpty(result.getMessage())) { text += result.getMessage(); //任务链下一任务启动 PlayerUtil.startTaskOnNext(uid, demandTask.getDemandTaskId()); DemandTaskDto nextDemandTask = result.getData(); //存在任务链下一个 if (!StringUtils.isEmpty(nextDemandTask)) { //返回下一个任务对应的后台附加返回给bot端 String[] condition1 = nextDemandTask.getCondition1().split("\\|"); Integer methodId = TimingAcquisition.seriesTaskConditionMap.get(player.getSeries()).get(Integer.valueOf(condition1[0])).getMethodId(); resultResponse.set后台附加返回(methodId.toString()); } } //任务为最终任务,或者时间值到1或以下,通关 if (demandTask.getTaskLabel() == 3 || player.getInitTime() <= 1 || text.contains(Constants.END_TEXT)) { //数据更新与结算 PlayerUtil.clearanceUpdate(uid); } resultResponse.set反馈文本(text); resultVarsResponse.setVars(resultResponse); return resultVarsResponse; } } //任务为自动触发且自动完成 if (postTaskRecord.getLevel() == 3) { Integer preTaskId = postTaskRecord.getPreTaskId(); //前置 Integer postTaskId = postTaskRecord.getPostTaskId();; //后置 DemandTaskDto demandTaskPost = getDemandTaskInfo(uid, subjectId, postTaskId); //找到后置任务 if (!StringUtils.isEmpty(demandTaskPost)) { ClueDto clue = getClueById(uid, subjectId, demandTaskPost.getClueId()); if (!StringUtils.isEmpty(clue)) { //任务线索文本 // text = SpeechUtil.getSuccessClueSpeech(uid, getPerson(uid, subjectId), clue); //任务启动文本 text = SpeechUtil.getPreSuccessTaskSpeech(uid, getPerson(uid, subjectId), demandTaskPost, 4); } //后置任务自动完成 taskFinished(uid, subjectId, postTaskId); String postText = SpeechUtil.getSuccessTaskSpeech(uid, getPerson(uid, subjectId), demandTaskPost); //有配置前置任务 if (preTaskId != 0) { //后置任务的客体 Integer objectId = demandTaskPost.getObject(); DemandTaskDto demandTaskPre = getDemandTaskInfo(uid, objectId, preTaskId); if (!StringUtils.isEmpty(demandTaskPre)) { //前置任务自动完成 taskFinished(uid, objectId, preTaskId); String preText = SpeechUtil.getSuccessTaskSpeech(uid, getPerson(uid, objectId), demandTaskPre); text += preText; } } text += postText; //任务链下一个任务的对应回复 CommonResult result = PlayerUtil.getNextTaskAnswer(uid, subjectId, postTaskId); if (!StringUtils.isEmpty(result.getMessage())) { text += result.getMessage(); //任务链下一任务启动 PlayerUtil.startTaskOnNext(uid, postTaskId); DemandTaskDto nextDemandTask = result.getData(); //存在任务链下一个 if (!StringUtils.isEmpty(nextDemandTask)) { //返回下一个任务对应的后台附加返回给bot端 String[] condition = nextDemandTask.getCondition1().split("\\|"); Integer methodId = TimingAcquisition.seriesTaskConditionMap.get(player.getSeries()).get(Integer.valueOf(condition[0])).getMethodId(); resultResponse.set后台附加返回(methodId.toString()); } } //任务为最终任务,或者时间值到1或以下,通关 if (demandTaskPost.getTaskLabel() == 3 || player.getInitTime() <= 1 || text.contains(Constants.END_TEXT)) { //数据更新与结算 PlayerUtil.clearanceUpdate(uid); } } resultResponse.set反馈ID(400108); resultResponse.set反馈文本(text); resultVarsResponse.setVars(resultResponse); return resultVarsResponse; } //任务为自动触发仅提供线索 if (postTaskRecord.getLevel() == 4) { List allowTask = Arrays.asList(-1, 0, 2); Integer postTaskId = postTaskRecord.getPostTaskId();; //后置 //找到后置任务 DemandTaskDto demandTaskPost = getDemandTaskInfo(uid, subjectId, postTaskId); //存在后置任务 if (!StringUtils.isEmpty(demandTaskPost)) { Map demandTaskSwitchMap = player.getPersonInfoMap().get(subjectId).getDemandTaskSwitchMap(); //后置任务解锁 if (allowTask.contains(demandTaskSwitchMap.get(postTaskId))) { demandTaskSwitchMap.put(postTaskId, 5); } ClueDto clue = getClueById(uid, subjectId, demandTaskPost.getClueId()); if (!StringUtils.isEmpty(clue)) { //----------------记录线索-------------- recordClue(uid, player.getPersonId(), subjectId, clue.getType(), clue); //----------------是否解锁任务------------- // PlayerUtil.unlockTask(uid, player.getPersonMap().get(subjectId), clue); //前置任务解锁 if (postTaskRecord.getPreTaskId() != 0) { Map demandTaskSwitchPreMap = player.getPersonInfoMap().get(demandTaskPost.getObject()).getDemandTaskSwitchMap(); DemandTaskDto demandTaskPre = getDemandTaskInfo(uid, demandTaskPost.getObject(), postTaskRecord.getPreTaskId()); if (!StringUtils.isEmpty(demandTaskPre)) { if (demandTaskSwitchPreMap.get(postTaskRecord.getPreTaskId()) == 1) { demandTaskSwitchPreMap.put(postTaskRecord.getPreTaskId(), 2); } else { if (allowTask.contains(demandTaskSwitchPreMap.get(postTaskRecord.getPreTaskId()))) { demandTaskSwitchPreMap.put(postTaskRecord.getPreTaskId(), 5); } } } } //任务线索 // text = SpeechUtil.getSuccessClueSpeech(uid, getPerson(uid, subjectId), clue); //任务启动文本 text = SpeechUtil.getPreSuccessTaskSpeech(uid, getPerson(uid, subjectId), demandTaskPost, 4); String[] condition = demandTaskPost.getCondition1().split("\\|"); //记录本轮的任务数据,用于下轮的二次回复 String unique = uid + player.getGateNo(); ReplyDto reply = new ReplyDto(); reply.setSubjectId(subjectId); reply.setDemandTaskId(postTaskRecord.getPostTaskId()); reply.setType(2); //直接操作提醒 //任务会掉落物或人 if ("72000".equals(condition[0])) { Map dropMap = ConfigDataUtil.getDropItems(uid, demandTaskPost.getDropItems()); if (dropMap.isEmpty()) { text = ""; } else { reply.setIdNumMap(dropMap); } } CacheUtil.put(unique, reply, Long.parseLong(expireTime)); //返回任务对应的后台附加返回给bot端 Integer methodId = TimingAcquisition.seriesTaskConditionMap.get(player.getSeries()).get(Integer.valueOf(condition[0])).getMethodId(); resultResponse.set后台附加返回(methodId.toString()); } } resultResponse.set反馈ID(400109); resultResponse.set反馈文本(text); resultVarsResponse.setVars(resultResponse); return resultVarsResponse; } //任务是本人发布的 if (postTaskRecord.getLevel() == 5) { //获取对应的后置任务 DemandTaskDto demandTask = getDemandTaskById(uid, subjectId, postTaskRecord.getPostTaskId()); if (!StringUtils.isEmpty(demandTask)) { text = SpeechUtil.getPreSuccessTaskSpeech(uid, getPerson(uid, subjectId), demandTask, 3); String[] condition1 = demandTask.getCondition1().split("\\|"); if (!"70043".equals(condition1[0]) && !"71000".equals(condition1[0])) { //记录本轮的任务数据,用于下轮的二次回复 String unique = uid + player.getGateNo(); ReplyDto reply = new ReplyDto(); reply.setSubjectId(subjectId); reply.setDemandTaskId(postTaskRecord.getPostTaskId()); reply.setType(3); //执行任务 //任务会掉落物或人 if ("72000".equals(condition1[0])) { Map dropMap = ConfigDataUtil.getDropItems(uid, demandTask.getDropItems()); if (dropMap.isEmpty()) { text = ""; } else { reply.setIdNumMap(dropMap); } } CacheUtil.put(unique, reply, Long.parseLong(expireTime)); //返回对应的后台附加返回给bot端 String[] condition = demandTask.getCondition1().split("\\|"); Integer methodId = TimingAcquisition.seriesTaskConditionMap.get(player.getSeries()).get(Integer.valueOf(condition[0])).getMethodId(); resultResponse.set后台附加返回(methodId.toString()); } } resultResponse.set反馈ID(400110); resultResponse.set反馈文本(text); resultVarsResponse.setVars(resultResponse); return resultVarsResponse; } resultResponse.set反馈ID(400111); resultResponse.set反馈文本(text); resultVarsResponse.setVars(resultResponse); return resultVarsResponse; } /** * 判断任务是否为某主任务的副任务,同时满足对应主任务的任务条件id为“71001”。返回人物id和主任务的id */ public static Map checkTaskIsSub(String uid, Integer personId, Integer demandTaskId) { Map personIdTaskIdMap = new HashMap<>(); String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //关卡编号 Map personMap = TimingAcquisition.gatePersonMap.get(gateNo); //遍历所有关卡人物 for (Map.Entry entry : personMap.entrySet()) { //该人物身上挂的任务 List demandTaskList = getPerson(uid, entry.getKey()).getDemandTasks(); //判断该任务是否为前置任务的主任务 for (DemandTaskDto demandTask : demandTaskList) { //有前置任务 if (!StringUtils.isEmpty(demandTask.getPostTask())) { if (demandTask.getPostTask().equals(demandTaskId.toString()) && personId == demandTask.getObject()) { int result; //存在主任务,但不是“71001”,不自动完成 String[] condition1 = demandTask.getCondition1().split("\\|"); if ("71001".equals(condition1[0])) { result = demandTask.getDemandTaskId(); personIdTaskIdMap.put(entry.getKey(), result); } break; } } } } return personIdTaskIdMap; } /** * 找到对应时间范围内的所有任务 * @param uid * @param personId */ public static List getDemandTaskIdsByInitTime(String uid, Integer personId) { List result = new ArrayList<>(); //玩家的剩余时间 int initTime = TimingAcquisition.playerMap.get(uid).getInitTime(); List demandTaskList = getPerson(uid, personId).getDemandTasks(); for (DemandTaskDto demandTask : demandTaskList) { //配置了时间阈值 if (!StringUtils.isEmpty(demandTask.getTimeThreshold())) { if (!"0|0".equals(demandTask.getTimeThreshold()) && !"0".equals(demandTask.getTimeThreshold())) { String[] timeThresholds = demandTask.getTimeThreshold().split("\\|"); boolean timeFlag = NumberUtil.inNumRange(initTime,"["+timeThresholds[0]+","+timeThresholds[1]+"]"); if (timeFlag) { result.add(demandTask.getDemandTaskId()); } } } } return result; } /** * 找到任务所在任务链的下个任务id。任务可以在不同NPC的身上 * @param uid * @param taskId */ public static Map> getNextTaskIdByTask(String uid, Integer taskId) { Map> result = new HashMap<>(); String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //关卡编号 Map personMap = TimingAcquisition.gatePersonMap.get(gateNo); for (Map.Entry entry : personMap.entrySet()) { List nextTaskIds = new ArrayList<>(); List demandTaskList = getPerson(uid, entry.getKey()).getDemandTasks(); for (DemandTaskDto demandTask : demandTaskList) { //配置了开启任务条件id if (!StringUtils.isEmpty(demandTask.getConditionTaskId())) { if (demandTask.getConditionTaskId() == taskId) { nextTaskIds.add(demandTask.getDemandTaskId()); } } } if (nextTaskIds.size() != 0) { result.put(entry.getKey(), nextTaskIds); } } return result; } /** * 找到NPC身上指定任务的任务链 * @param uid * @param personId * @param taskId */ public static List getNextTaskOnPerson(String uid, Integer personId, Integer taskId) { List result = new ArrayList<>(); int taskIdTmp = taskId; List demandTaskList = getPerson(uid, personId).getDemandTasks(); for (DemandTaskDto demandTask : demandTaskList) { //配置了开启任务条件id if (!StringUtils.isEmpty(demandTask.getConditionTaskId())) { if (demandTask.getConditionTaskId() == taskIdTmp) { taskIdTmp = demandTask.getDemandTaskId(); result.add(taskIdTmp); } } } return result; } /** * 找到NPC身上的任务链,某任务id的下一个任务对应的返回 * @param uid * @param personId * @param taskId */ public static CommonResult getNextTaskAnswer(String uid, Integer personId, Integer taskId) { StringBuilder text = new StringBuilder(); DemandTaskDto result = null; //任务NPC PersonInfoDto subject = TimingAcquisition.playerMap.get(uid).getPersonInfoMap().get(personId); //找到NPC身上该任务id的任务链 List nextTaskIdList = getNextTaskOnPerson(uid, personId, taskId); int taskIdTmp = taskId; for (Integer nextId : nextTaskIdList) { DemandTaskDto demandTask = getDemandTaskInfo(uid, personId, nextId); if (StringUtils.isEmpty(demandTask)) { continue; } //没有配置开启任务条件id if (StringUtils.isEmpty(demandTask.getConditionTaskId())) { continue; } //配置了开启任务条件id if (demandTask.getConditionTaskId() != taskIdTmp || demandTask.getIsAuto() != 1) { continue; } //配置了开启任务条件id //判断是否符合阈值需求 boolean flag = checkThreshold(uid, demandTask, subject); //不符合阈值需求 if (!flag) { continue; } String[] condition1 = demandTask.getCondition1().split("\\|"); if ("71000".equals(condition1[0])) { //任务自动完成 taskFinished(uid, personId, demandTask.getDemandTaskId()); //可以重复扣钱 if (!StringUtils.isEmpty(demandTask.getCost())) { String[] costList = demandTask.getCost().split("\\|"); int value = Integer.parseInt(costList[0]); int costFlag = Integer.parseInt(costList[1]); if (costFlag == 0) { //扣除货币 if (value > 0) { PlayerUtil.updateMoneyNum(uid, value); } } } //返回任务完成文本 text.append(SpeechUtil.getPreSuccessTaskSpeech(uid, getPerson(uid, personId), demandTask, 4)); //返回任务完成文本 text.append(SpeechUtil.getSuccessTaskSpeech(uid, getPerson(uid, personId), demandTask)); } else { //返回任务启动文本 text.append(SpeechUtil.getPreSuccessTaskSpeech(uid, getPerson(uid, personId), demandTask, 4)); if (!StringUtils.isEmpty(demandTask.getPostTask())) { Map> taskMap = TimingAcquisition.playerMap.get(uid).getTaskMap(); //2.符合阈值需求,判断是否完成副任务 if (!taskMap.containsKey(demandTask.getObject())) { continue; } Map objectMap = taskMap.get(demandTask.getObject()); if (!objectMap.containsKey(Integer.valueOf(demandTask.getPostTask()))) { continue; } } result = demandTask; //记录本轮的任务数据,用于下轮的二次回复 String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); String unique = uid + gateNo; ReplyDto reply = new ReplyDto(); reply.setSubjectId(personId); reply.setDemandTaskId(demandTask.getDemandTaskId()); reply.setType(2); //直接操作提醒 //任务会掉落物或人 if ("72000".equals(condition1[0])) { Map dropMap = ConfigDataUtil.getDropItems(uid, demandTask.getDropItems()); if (dropMap.isEmpty()) { text = new StringBuilder(); } else { reply.setIdNumMap(dropMap); } } CacheUtil.put(unique, reply, Long.parseLong(expireTime)); break; } taskIdTmp = demandTask.getDemandTaskId(); } return CommonResult.success(result, text.toString()); } /** * 启动任务链的下一任务 */ public static void startTaskOnNext(String uid, Integer taskId) { Map> nextTaskIdList = getNextTaskIdByTask(uid, taskId); Player player = TimingAcquisition.playerMap.get(uid); if (nextTaskIdList.size() != 0) { Map personInfoMap = player.getPersonInfoMap(); for (Map.Entry> entry : nextTaskIdList.entrySet()) { Map demandTaskSwitchMap = personInfoMap.get(entry.getKey()).getDemandTaskSwitchMap(); for (Integer next : entry.getValue()) { //任务解锁 if (demandTaskSwitchMap.get(next) == 1) { demandTaskSwitchMap.put(next, 2); } else { demandTaskSwitchMap.put(next, 5); } //找到后置任务 DemandTaskDto demandTaskPost = getDemandTaskInfo(uid, entry.getKey(), next); if (!StringUtils.isEmpty(demandTaskPost)) { ClueDto clue = getClueById(uid, demandTaskPost.getSubject(), demandTaskPost.getClueId()); if (!StringUtils.isEmpty(clue)) { //----------------记录线索-------------- recordClue(uid, player.getPersonId(), demandTaskPost.getSubject(), clue.getType(), clue); } //前置任务解锁 if (!StringUtils.isEmpty(demandTaskPost.getPostTask())) { DemandTaskDto demandTaskPre = getDemandTaskInfo(uid, demandTaskPost.getObject(), Integer.valueOf(demandTaskPost.getPostTask())); if (!StringUtils.isEmpty(demandTaskPre)) { Map demandTaskSwitchPreMap = personInfoMap.get(demandTaskPre.getSubject()).getDemandTaskSwitchMap(); if (demandTaskSwitchPreMap.get(demandTaskPre.getDemandTaskId()) == 1) { demandTaskSwitchPreMap.put(demandTaskPre.getDemandTaskId(), 2); } else { demandTaskSwitchPreMap.put(demandTaskPre.getDemandTaskId(), 5); } ClueDto cluePre = getClueById(uid, demandTaskPre.getSubject(), demandTaskPre.getClueId()); if (!StringUtils.isEmpty(cluePre)) { //----------------记录线索-------------- recordClue(uid, player.getPersonId(), demandTaskPre.getSubject(), cluePre.getType(), cluePre); } } } } } } } } /** * 更新任务的线索开关即任务状态 * @param uid * @param personId * @param taskId * @param status */ public static void updateTaskStatus(String uid, Integer personId, Integer taskId, Integer status) { Map demandTaskSwitchMap = TimingAcquisition.playerMap.get(uid).getPersonInfoMap(). get(personId).getDemandTaskSwitchMap(); demandTaskSwitchMap.put(taskId, status); } /** * 开始游戏时,找到进行中任务的对应提示 * @param uid * @param personId */ public static String getDoingTaskAnswer(String uid, Integer personId) { String result = ""; Map demandTaskSwitchMap = TimingAcquisition.playerMap.get(uid).getPersonInfoMap(). get(personId).getDemandTaskSwitchMap(); for (Map.Entry entry : demandTaskSwitchMap.entrySet()) { if (entry.getValue() == 5) { int finishFlag = checkTaskStatus(uid, personId, entry.getKey()); if (finishFlag == 0) { //任务启动文本 DemandTaskDto demandTask = getDemandTaskById(uid, personId, entry.getKey()); result = SpeechUtil.getPreSuccessTaskSpeech(uid, getPerson(uid, personId), demandTask, 4); } } } return result; } /** * 初始化系列中玩家的汇总数据 */ public static void initSeriesPlayer(String uid, String seriesName) { ReputationDto reputation = new ReputationDto(); reputation.setUid(uid); Map> seriesPlayerMap = TimingAcquisition.seriesPlayerMap; //不存在该系列 if (StringUtils.isEmpty(seriesPlayerMap.get(seriesName))) { //新增系列和声望 Map playerSeriesDtoMap = new HashMap<>(); PlayerSeriesDto playerSeries = new PlayerSeriesDto(); playerSeries.setTotalReputation(reputation); //初始货币值 String initMoney = TimingAcquisition.seriesSystemConfigMap.get(seriesName).get("init_money").getValue(); if (StringUtils.isEmpty(initMoney)) { //远程获取货币数量进行同步 CallResponse callMoney = remoteGardenService.getMoney(uid); initMoney = callMoney.getData(); //获取物品进行同步 CallResponse callItems = remoteGardenService.getItems(uid); List itemList = JSON.parseObject(callItems.getData(), new TypeReference>(){}); Map partnerItemMap = ConfigDataUtil.getItemMap(uid, itemList); playerSeries.setPartnerItemMap(partnerItemMap); } playerSeries.setMoney(Integer.parseInt(initMoney)); playerSeriesDtoMap.put(uid, playerSeries); seriesPlayerMap.put(seriesName, playerSeriesDtoMap); } else { //不存在该用户 if (StringUtils.isEmpty(seriesPlayerMap.get(seriesName).get(uid))) { //新增系列中该用户 PlayerSeriesDto playerSeries = new PlayerSeriesDto(); playerSeries.setTotalReputation(reputation); //初始货币值 String initMoney = TimingAcquisition.seriesSystemConfigMap.get(seriesName).get("init_money").getValue(); if (StringUtils.isEmpty(initMoney)) { //远程获取货币数量进行同步 CallResponse callMoney = remoteGardenService.getMoney(uid); initMoney = callMoney.getData(); //获取物品进行同步 CallResponse callItems = remoteGardenService.getItems(uid); List itemList = JSON.parseObject(callItems.getData(), new TypeReference>(){}); Map partnerItemMap = ConfigDataUtil.getItemMap(uid, itemList); playerSeries.setPartnerItemMap(partnerItemMap); } playerSeries.setMoney(Integer.parseInt(initMoney)); seriesPlayerMap.get(seriesName).put(uid, playerSeries); } } } /** * NPC加入伙伴队列 * @param uid * @param partnerId */ public static void joinPartner(String uid, Integer partnerId) { //系列名称 String seriesName = TimingAcquisition.playerMap.get(uid).getSeries(); PartnerItemDto partners = TimingAcquisition.seriesPlayerMap.get(seriesName).get(uid).getPartnerItemMap().get(Constants.ITEM_PARTNER); Map partnerMap = partners.getItemInfoMap(); ItemNumDto partnerNum = new ItemNumDto(); partnerNum.setId(partnerId); partnerNum.setTimes(TimingAcquisition.seriesPartnerItemMap.get(seriesName).get(partnerId).getHelpTimes()); partnerMap.put(partnerId, partnerNum); } /** * 过滤掉系列中已有的伙伴NPC */ public static List filterPerson(String uid, List personList) { List result = new ArrayList<>(); //已有该玩家 if (StringUtils.isEmpty(TimingAcquisition.playerMap.get(uid))) { return personList; } //系列名称 String seriesName = TimingAcquisition.playerMap.get(uid).getSeries(); Map partnerInfoMap = TimingAcquisition.seriesPlayerMap.get(seriesName).get(uid).getPartnerItemMap(). get(Constants.ITEM_PARTNER).getItemInfoMap(); //该系列已有伙伴 if (partnerInfoMap.size() == 0) { return personList; } List joinPersonIdList = new ArrayList<>(); Map partnerMap = TimingAcquisition.seriesPartnerItemMap.get(seriesName); for (Map.Entry entry : partnerInfoMap.entrySet()) { joinPersonIdList.add(partnerMap.get(entry.getKey()).getId()); } for (Person person : personList) { //伙伴已在NPC中 if (joinPersonIdList.contains(person.getPersonId())) { continue; } result.add(person); } return result; } /** * 获取已有伙伴信息 */ public static ItemNumDto getPartnerNumById(String uid, Integer partnerId) { Player player = TimingAcquisition.playerMap.get(uid); Map partnerNumMap = TimingAcquisition.seriesPlayerMap.get(player.getSeries()).get(uid). getPartnerItemMap().get(Constants.ITEM_PARTNER).getItemInfoMap(); for (Map.Entry entry : partnerNumMap.entrySet()) { if (partnerId.equals(entry.getKey())) { return entry.getValue(); } } return null; } /** * 获取已有物品信息 */ public static ItemNumDto getItemNumById(String uid, Integer itemId) { Player player = TimingAcquisition.playerMap.get(uid); Map itemNumMap = TimingAcquisition.seriesPlayerMap.get(player.getSeries()).get(uid). getPartnerItemMap().get(Constants.ITEM_PARTNER).getItemInfoMap(); for (Map.Entry entry : itemNumMap.entrySet()) { if (itemId.equals(entry.getKey())) { return entry.getValue(); } } return null; } /** * 删除指定物品 */ public static boolean removePartnerItemById(String uid, Integer partnerItemId) { String seriesName = TimingAcquisition.playerMap.get(uid).getSeries(); //伙伴物品配置数据 PartnerItem partnerItem = TimingAcquisition.seriesPartnerItemMap.get(seriesName).get(partnerItemId); int type = partnerItem.getType(); //系列的玩家汇总数据 Map partnerItemMap = TimingAcquisition.seriesPlayerMap.get(seriesName).get(uid).getPartnerItemMap(); //没有伙伴或物品的类型,不用删除 if (StringUtils.isEmpty(partnerItemMap.get(type))) { return true; } Map itemInfoMap = partnerItemMap.get(type).getItemInfoMap(); //没有没有该物品 if (StringUtils.isEmpty(itemInfoMap.get(partnerItemId))) { return true; } //删除伙伴或物品 itemInfoMap.remove(partnerItemId); return true; } /** * 通关完成后,数据更新并结算 */ public static void clearanceUpdate(String uid) { log.info(uid + "成功通关,开始更新数据"); Player player = TimingAcquisition.playerMap.get(uid); //系列名称 String seriesName = player.getSeries(); //最终任务完成 player.setFinished(1); //通过次数累计1次 int clearanceNum = TimingAcquisition.seriesPlayerMap.get(seriesName).get(uid).getClearanceNum(); TimingAcquisition.seriesPlayerMap.get(seriesName).get(uid).setClearanceNum(clearanceNum + 1); //更新货币数量 // int totalMoney = TimingAcquisition.seriesPlayerMap.get(seriesName).get(uid).getMoney(); // Double money = player.getCurrency(); // TimingAcquisition.seriesPlayerMap.get(seriesName).get(uid).setMoney(totalMoney + money.intValue()); //更新系列和关卡中玩家的排名 ReputationDto reputationDto = new ReputationDto(); reputationDto.setUid(player.getUid()); reputationDto.setReputation(player.getReputation()); //更新关卡排行榜 updateGateNoReputation(player, reputationDto); //更新系列排行榜 updateSeriesReputation(uid, seriesName, reputationDto); //判断伙伴人数上限和背包上限是否更新 updateSeriesPlayerMax(uid); //持久化玩家数据 String seriesPlayerStr = JSON.toJSONString(TimingAcquisition.seriesPlayerMap); PersistenceUtil.saveDataToFile(dataFilePath, "seriesPlayer", seriesPlayerStr); log.info(uid + "通关后更新数据完成"); try { //-----------存入redis缓存中------------- redisUtil.setStr(seriesName + "::"+ uid, JSON.toJSONString(TimingAcquisition.seriesPlayerMap.get(seriesName).get(uid))); RemoteCallFactory.getInstance().updateItems(uid, "gardenSys"); } catch (IOException e) { e.printStackTrace(); } } /** * 更新伙伴人数上限和背包上限 */ public static void updateSeriesPlayerMax(String uid) { //系列名称 String seriesName = TimingAcquisition.playerMap.get(uid).getSeries(); //下一声望对应的伙伴数量上限 int nextPartnerNumMax = ConfigDataUtil.getPartnerNumMax(uid); if (nextPartnerNumMax > 0) { TimingAcquisition.seriesPlayerMap.get(seriesName).get(uid).getPartnerItemMap().get(Constants.ITEM_PARTNER).setMax(nextPartnerNumMax); } //下一声望对应的背包道具数量上限 int nextItemNumMax = ConfigDataUtil.getItemNumMax(uid); if (nextItemNumMax > 0) { TimingAcquisition.seriesPlayerMap.get(seriesName).get(uid).getPartnerItemMap().get(Constants.ITEM_PROPS).setMax(nextItemNumMax); } } /** * 获取副任务对应主任务的主体名称 */ public static String getSubjectNameByPreTaskId(String uid, Integer personId, Integer preTaskId) { String gateNo = TimingAcquisition.playerMap.get(uid).getGateNo(); //关卡编号 Map personMap = TimingAcquisition.gatePersonMap.get(gateNo); //遍历所有关卡人物 for (Map.Entry entry : personMap.entrySet()) { //过滤本人 if (personId.equals(entry.getKey())) { continue; } //该人物身上挂的任务 List demandTaskList = getPerson(uid, entry.getKey()).getDemandTasks(); //判断该任务是否为前置任务的主任务 for (DemandTaskDto demandTask : demandTaskList) { //有前置任务 if (!StringUtils.isEmpty(demandTask.getPostTask())) { if (demandTask.getPostTask().equals(preTaskId.toString()) && personId == demandTask.getObject()) { return getNameByPersonId(uid, demandTask.getSubject()); } } } } return ""; } /** * 玩家下线 */ public static void offLine(String uid) { Player player = TimingAcquisition.playerMap.get(uid); //更新玩家为离线状态 player.setStatus(Constants.OFFLINE); //修改下线时间 player.setOfflineTime(DateUtil.getCurrentTime()); //创建玩家数据路径 String path = MD5Util.changeToPath(uid, player.getSeries()); //--------------持久化该玩家信息--------------- PersistenceUtil.saveDataToFile(path, player.getGateNo(), JSON.toJSONString(player)); //-----------------清除该玩家的数据缓存----------------- TimingAcquisition.playerMap.remove(uid); //--------------持久化该玩家系列汇总的数据--------------- String dataPath = MD5Util.changeToDataPath(uid, player.getSeries()); PersistenceUtil.saveDataToFile(dataPath, uid, JSON.toJSONString(TimingAcquisition.seriesPlayerMap.get(player.getSeries()).get(uid))); //-----------------清除该玩家系列汇总的数据----------------- TimingAcquisition.seriesPlayerMap.get(player.getSeries()).remove(uid); } /** * NPC死亡的判断。-1:死亡,其他值表示活着 */ public static int checkPersonLife(String uid, String operateName, OperationRequest operationReq) { Integer personId = operationReq.getSubjectId(); String locationId = operationReq.getLocationId(); Player player = TimingAcquisition.playerMap.get(uid); //去找人的操作 if ("关卡操作".equals(operateName)) { String methodId = operationReq.getMethodId(); List moveOperateList = Arrays.asList("4001", "4002"); //找人 if (moveOperateList.contains(methodId)) { //根据人名找 if (!StringUtils.isEmpty(personId)) { if (player.getPersonInfoMap().get(personId).getLifeState() == 1) { String personName = player.getId2NameMap().get(personId); log.info(operationReq.getUid() + "对话的" + personName + "已经死亡"); return -1; } } //根据场所找 if (!StringUtils.isEmpty(locationId)) { //找到场所里的人 List personIdList = getPersonsByLocationId(uid, locationId); List pidIdList = new ArrayList<>(); if (!StringUtils.isEmpty(personIdList)) { for (Integer pid : personIdList) { if (player.getPersonInfoMap().get(pid).getLifeState() != 1) { pidIdList.add(pid); } } if (pidIdList.size() == 0) { String personName = player.getId2NameMap().get(personId); log.info(operationReq.getUid() + "对话的" + personName + "已经死亡"); return -1; } else { return 0; } } } } } Integer currentId = player.getPersonId(); if (player.getPersonInfoMap().get(currentId).getLifeState() == 1) { String personName = player.getId2NameMap().get(currentId); log.info(operationReq.getUid() + "对话的" + personName + "已经死亡"); return -1; } return 0; } }