package com.qiwu.inference.common; import com.qiwu.inference.common.utils.PersistenceUtil; import com.qiwu.inference.dto.BarrierTaskKeyDto; import com.qiwu.inference.dto.Person; import com.qiwu.inference.dto.Player; 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; @Component public class TimingAcquisition { static Logger log = LoggerFactory.getLogger(TimingAcquisition.class); /** * 关卡信息,Map> */ public volatile static Map> gateInfoMap = 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 locationMap = new ConcurrentHashMap<>(); /** * 线索配置信息 */ public volatile static Map clueMap = new ConcurrentHashMap<>(); /** * 线索类型配置信息 */ public volatile static Map clueTypeMap = new ConcurrentHashMap<>(); /** * 需求任务配置信息 */ public volatile static Map demandTaskMap = new ConcurrentHashMap<>(); /** * 性格配置信息 */ public volatile static Map dispositionMap = new ConcurrentHashMap<>(); /** * 系统配置信息 */ public volatile static Map systemConfigMap = new ConcurrentHashMap<>(); /** * 结局目标配置信息 */ public volatile static Map endGoalMap = new ConcurrentHashMap<>(); /** * 询问模块话术 */ public volatile static Map>> askSpeechMap = new ConcurrentHashMap<>(); /** * 任务模块话术 */ public volatile static Map>> taskSpeechMap = new ConcurrentHashMap<>(); /** * 查看模块话术 */ public volatile static Map>> checkSpeechMap = new ConcurrentHashMap<>(); /** * 查看模块话术 */ public volatile static Map>> barrierSpeechMap = new ConcurrentHashMap<>(); /** * 闲聊模块话术,Map<意图, List<话术配置>> */ public volatile static Map> chatSpeechMap = new ConcurrentHashMap<>(); /** * 线索成功话术,Map<线索id, List<话术配置>> */ public volatile static Map> successClueSpeechMap = new ConcurrentHashMap<>(); /** * 任务成功话术,Map<任务id, List<话术配置>> */ public volatile static Map> successTaskSpeechMap = new ConcurrentHashMap<>(); /** * 任务提示话术,Map<任务id, List<话术配置>> */ public volatile static Map> tipSpeechMap = new ConcurrentHashMap<>(); /** * 人物见面话术,Map<人物名称, List<话术配置>> */ public volatile static Map> personSpeechMap = new ConcurrentHashMap<>(); /** * 操作提示话术,Map<人物名称, List<话术配置>> */ public volatile static Map operateSpeechMap = new ConcurrentHashMap<>(); /** * 线索前因话术,Map<人物名称, List<话术配置>> */ public volatile static Map> preReasonSpeechMap = new ConcurrentHashMap<>(); /** * 通过yaml文件加载所有话术到缓存中 */ public static void speechLoading(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(); } //JSON转map对象 askSpeechMap.putAll(askSpeech); taskSpeechMap.putAll(taskSpeech); checkSpeechMap.putAll(checkSpeech); barrierSpeechMap.putAll(barrierSpeech); log.info("---------加载话术到缓存的操作完成---------"); } /** * 通过线索类型获取对应id */ public static Integer getClueTypeIdByName(String name) { for (Map.Entry entry : clueTypeMap.entrySet()) { if (name.equals(entry.getValue())) { return entry.getKey(); } } return Constants.REQ_NON; } /** * 通过场所名称获取对应id */ public static String getLocationIdByName(String name) { 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); } }