package com.qiwu.inference.common; import com.qiwu.inference.common.utils.PersistenceUtil; import com.qiwu.inference.dto.*; import com.qiwu.inference.pojo.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.PriorityBlockingQueue; @Component public class TimingAcquisition { static Logger log = LoggerFactory.getLogger(TimingAcquisition.class); /** * 关卡信息,Map<关卡编号, List> */ public volatile static Map> gateInfoMap = new ConcurrentHashMap<>(); /** * 关卡信息,Map<关卡编号, Map> */ public volatile static Map> gatePersonMap = new ConcurrentHashMap<>(); /** * 关卡攻略信息,Map<关卡编号, List<攻略任务>> */ public volatile static Map> barrierTaskKeyMap = new ConcurrentHashMap<>(); /** * 用户id跟关卡编号对应关系 */ public volatile static Map uidGateNoMap = new ConcurrentHashMap<>(); /** * 玩家信息,Map */ public volatile static Map playerMap = new ConcurrentHashMap<>(); /** * 所有在线玩家的uid数组。用于是否加载玩家数据的判断 */ public volatile static List uidList = new ArrayList<>(); /** * 系列名和关卡编号的对应关系 */ public volatile static Map> seriesGateNosMap = new ConcurrentHashMap<>(); /** * 关卡名称和关卡编号对应关系 */ public volatile static Map gateNameToNoMap = new ConcurrentHashMap<>(); /** * 玩家在系列里的用户数据,Map<系列, Map> */ public volatile static Map> seriesPlayerMap = new ConcurrentHashMap<>(); /** * 玩家在关卡里的总声望值,Map<关卡编号, Map> */ public volatile static Map> gateNoUidReputationMap = new ConcurrentHashMap<>(); /** * 系列里总声望值降序排列,Map<系列, 声望> */ public volatile static Map> seriesReputationQueueMap = new ConcurrentHashMap<>(); /** * 系列里总声望值降序排列,Map<关卡编号, 声望> */ public volatile static Map> gateNoReputationQueueMap = new ConcurrentHashMap<>(); /** * 场所配置信息,Map<系列名称, Map> */ public volatile static Map> seriesLocationMap = new ConcurrentHashMap<>(); /** * 线索配置信息,Map<系列名称, Map> */ public volatile static Map> seriesClueMap = new ConcurrentHashMap<>(); /** * 线索类型配置信息,Map<系列名称, Map> */ public volatile static Map> seriesClueTypeMap = new ConcurrentHashMap<>(); /** * 性格配置信息,Map<系列名称, Map> */ public volatile static Map> seriesDispositionMap = new ConcurrentHashMap<>(); /** * 系统配置信息,Map<系列名称, Map> */ public volatile static Map> seriesSystemConfigMap = new ConcurrentHashMap<>(); /** * 任务条件配置信息,Map<系列名称, Map> */ public volatile static Map> seriesTaskConditionMap = new ConcurrentHashMap<>(); /** * 伙伴物品配置信息,Map<系列名称, Map> */ public volatile static Map> seriesPartnerItemMap = new ConcurrentHashMap<>(); /** * 背包数量配置信息,Map<系列名称, Map<物品类型, Map<序号, BackpackNum>>> */ public volatile static Map>> seriesBackpackNumMap = new ConcurrentHashMap<>(); /** * 伙伴NPC信息,Map<系列名称, Map> */ public volatile static Map> seriesPersonMap = new ConcurrentHashMap<>(); /** * 所有系列的询问模块话术,Map<系列名称, Map<意图, List<话术配置>>> */ public volatile static Map>>> seriesAskSpeechMap = new ConcurrentHashMap<>(); /** * 关卡的询问模块话术,Map<关卡编号, Map<意图, List<话术配置>>> */ public volatile static Map>>> gateNoAskSpeechMap = new ConcurrentHashMap<>(); /** * 所有系列的任务模块话术,Map<系列名称, Map<意图, List<话术配置>>> */ public volatile static Map>>> seriesTaskSpeechMap = new ConcurrentHashMap<>(); /** * 关卡的询问模块话术,Map<关卡编号, Map<意图, List<话术配置>>> */ public volatile static Map>>> gateNoTaskSpeechMap = new ConcurrentHashMap<>(); /** * 所有系列的查看模块话术,Map<系列名称, Map<意图, List<话术配置>>> */ public volatile static Map>>> seriesCheckSpeechMap = new ConcurrentHashMap<>(); /** * 关卡的查看模块话术,Map<关卡编号, Map<意图, List<话术配置>>> */ public volatile static Map>>> gateNoCheckSpeechMap = new ConcurrentHashMap<>(); /** * 所有系列的查看模块话术,Map<系列名称, Map<意图, List<话术配置>>> */ public volatile static Map>>> seriesBarrierSpeechMap = new ConcurrentHashMap<>(); /** * 关卡的查看模块话术,Map<关卡编号, Map<意图, List<话术配置>>> */ public volatile static Map>>> gateNoBarrierSpeechMap = new ConcurrentHashMap<>(); /** * 所有系列的查看模块话术,Map<系列名称, Map<意图, List<话术配置>>> */ public volatile static Map>>> seriesPartnerItemSpeechMap = new ConcurrentHashMap<>(); /** * 关卡的查看模块话术,Map<关卡编号, Map<意图, List<话术配置>>> */ public volatile static Map>>> gateNoPartnerItemSpeechMap = new ConcurrentHashMap<>(); /** * 所有系列的闲聊模块话术,Map<系列名称, Map<意图, List<话术配置>>> */ public volatile static Map>> seriesChatSpeechMap = new ConcurrentHashMap<>(); /** * 关卡的闲聊模块话术,Map<关卡编号, Map<意图, List<话术配置>>> */ public volatile static Map>> gateNoChatSpeechMap = new ConcurrentHashMap<>(); /** * 所有系列的线索成功话术,Map<系列名称, Map<意图, List<话术配置>>> */ public volatile static Map>> seriesSuccessClueSpeechMap = new ConcurrentHashMap<>(); /** * 关卡的线索成功话术,Map<关卡编号, Map<意图, List<话术配置>>> */ public volatile static Map>> gateNoSuccessClueSpeechMap = new ConcurrentHashMap<>(); /** * 所有系列的任务成功话术,Map<系列名称, Map<意图, List<话术配置>>> */ public volatile static Map>> seriesSuccessTaskSpeechMap = new ConcurrentHashMap<>(); /** * 关卡的任务成功话术,Map<关卡编号, Map<意图, List<话术配置>>> */ public volatile static Map>> gateNoSuccessTaskSpeechMap = new ConcurrentHashMap<>(); /** * 所有系列的任务提示话术,Map<系列名称, Map<意图, List<话术配置>>> */ public volatile static Map>> seriesTipSpeechMap = new ConcurrentHashMap<>(); /** * 关卡的任务提示话术,Map<关卡编号, Map<意图, List<话术配置>>> */ public volatile static Map>> gateNoTipSpeechMap = new ConcurrentHashMap<>(); /** * 所有系列的人物见面话术,Map<系列名称, Map<意图, List<话术配置>>> */ public volatile static Map>> seriesPersonSpeechMap = new ConcurrentHashMap<>(); /** * 关卡的人物见面话术,Map<关卡编号, Map<意图, List<话术配置>>> */ public volatile static Map>> gateNoPersonSpeechMap = new ConcurrentHashMap<>(); /** * 所有系列的操作提示话术,Map<系列名称, Map<意图, 话术配置>> */ public volatile static Map> seriesOperateSpeechMap = new ConcurrentHashMap<>(); /** * 关卡的操作提示话术,Map<关卡编号, Map<意图, 话术配置>> */ public volatile static Map> gateNoOperateSpeechMap = new ConcurrentHashMap<>(); /** * 所有系列的操作提示话术,Map<系列名称, Map<意图, 话术配置>> */ public volatile static Map> seriesTaskExceptionSpeechMap = new ConcurrentHashMap<>(); /** * 关卡的任务异常话术,Map<关卡编号, Map<意图, List<话术配置>>> */ public volatile static Map> gateNoTaskExceptionSpeechMap = new ConcurrentHashMap<>(); /** * 线索前因话术,Map<人物名称, List<话术配置>> */ public volatile static Map> preReasonSpeechMap = new ConcurrentHashMap<>(); /** * 通过yaml文件加载所有话术到系列中 */ public static void speechLoading(String seriesName, String speechFilePath) { log.info("---------开始加载话术到系列中---------"); Map>> askSpeech = new HashMap<>(); Map>> taskSpeech = new HashMap<>(); Map>> checkSpeech = new HashMap<>(); Map>> barrierSpeech = new HashMap<>(); Map>> partnerItemSpeech = new HashMap<>(); try { askSpeech = PersistenceUtil.loadSpeechToMap(speechFilePath,"ask.yaml"); taskSpeech = PersistenceUtil.loadSpeechToMap(speechFilePath,"task.yaml"); checkSpeech = PersistenceUtil.loadSpeechToMap(speechFilePath,"check.yaml"); barrierSpeech = PersistenceUtil.loadSpeechToMap(speechFilePath,"barrier.yaml"); partnerItemSpeech = PersistenceUtil.loadSpeechToMap(speechFilePath,"partnerItem.yaml"); } catch (Exception e) { e.printStackTrace(); } seriesAskSpeechMap.put(seriesName, askSpeech); seriesTaskSpeechMap.put(seriesName, taskSpeech); seriesCheckSpeechMap.put(seriesName, checkSpeech); seriesBarrierSpeechMap.put(seriesName, barrierSpeech); seriesPartnerItemSpeechMap.put(seriesName, partnerItemSpeech); log.info("---------加载话术到系列的操作完成---------"); } /** * 通过yaml文件加载所有话术到关卡中 */ public static void speechLoadingToGate(String gateNo, String speechFilePath) { log.info("---------开始加载话术到关卡中---------"); Map>> askSpeech = new HashMap<>(); Map>> taskSpeech = new HashMap<>(); Map>> checkSpeech = new HashMap<>(); Map>> barrierSpeech = new HashMap<>(); try { askSpeech = PersistenceUtil.loadSpeechToMap(speechFilePath,"ask.yaml"); taskSpeech = PersistenceUtil.loadSpeechToMap(speechFilePath,"task.yaml"); checkSpeech = PersistenceUtil.loadSpeechToMap(speechFilePath,"check.yaml"); barrierSpeech = PersistenceUtil.loadSpeechToMap(speechFilePath,"barrier.yaml"); } catch (Exception e) { e.printStackTrace(); } gateNoAskSpeechMap.put(gateNo, askSpeech); gateNoTaskSpeechMap.put(gateNo, taskSpeech); gateNoCheckSpeechMap.put(gateNo, checkSpeech); gateNoBarrierSpeechMap.put(gateNo, barrierSpeech); log.info("---------加载话术到关卡的操作完成---------"); } /** * 通过线索类型获取对应id */ public static Integer getClueTypeIdByName(String uid, String name) { String seriesName = TimingAcquisition.playerMap.get(uid).getSeries(); //系列名称 Map clueTypeMap = seriesClueTypeMap.get(seriesName); for (Map.Entry entry : clueTypeMap.entrySet()) { if (name.equals(entry.getValue())) { return entry.getKey(); } } return Constants.REQ_NON; } /** * 通过场所名称获取对应id */ public static String getLocationIdByName(String uid, String name) { String seriesName = TimingAcquisition.playerMap.get(uid).getSeries(); //系列名称 Map locationMap = seriesLocationMap.get(seriesName); for (Map.Entry entry : locationMap.entrySet()) { if (name.equals(entry.getValue().getName())) { return entry.getKey(); } } return Constants.NON_STR; } /** * 通过玩家名称获取对应id */ public static Integer getPersonIdByName(String uid, String name) { Integer personId = TimingAcquisition.playerMap.get(uid).getName2IdMap().get(name); if (!StringUtils.isEmpty(personId)) { return personId; } return Constants.REQ_NON; } /** * 通过id获取玩家名称 */ public static String getNameByPersonId(String uid, Integer personId) { for (Map.Entry entry : TimingAcquisition.playerMap.get(uid).getName2IdMap().entrySet()) { if (personId.equals(entry.getValue())) { return entry.getKey(); } } return Constants.NON_STR; } /** * 获取当前正在对话的人物名称 */ public static String getTalkName(String uid) { Integer personId = TimingAcquisition.playerMap.get(uid).getPersonId(); return getNameByPersonId(uid, personId); } }