Commit 0e55d03e by 周君强

1.推理项目第二版

parent d4c7ebca
......@@ -8,12 +8,14 @@
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="InferenceGame" />
<module name="InferenceGame-0.0.2" />
</profile>
</annotationProcessing>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="InferenceGame" options="-parameters" />
<module name="InferenceGame-0.0.2" options="-parameters" />
</option>
</component>
</project>
\ No newline at end of file
......@@ -2,6 +2,7 @@ package com.qiwu.inference.common;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.qiwu.inference.common.utils.CacheUtil;
import com.qiwu.inference.common.utils.PersistenceUtil;
import com.qiwu.inference.common.utils.SpeechUtil;
import com.qiwu.inference.dao.*;
......@@ -25,6 +26,8 @@ import java.util.concurrent.ConcurrentHashMap;
public class InitSysServlet implements InitializingBean {
Logger log = LoggerFactory.getLogger(InitSysServlet.class);
@Value("${offlineTime}")
private String offlineTime;
@Value("${userFilePath}")
private String userFilePath;
@Value("${configFilePath}")
......@@ -69,29 +72,6 @@ public class InitSysServlet implements InitializingBean {
log.info("关卡攻略数据缓存完成");
}
//--------------------------加载玩家数据----------------------
log.info("开始加载玩家数据");
//从yml配置文件中取出存放玩家数据的地址
File file = new File(userFilePath);
File[] files = file.listFiles();
if (files == null) {
log.info("路径" + userFilePath+ "下没有文件");
return;
}
Map<String, Player> playerMap = new ConcurrentHashMap<>();
for (File f : files) {
if (f.isFile()) {
String s = PersistenceUtil.getDataFromFile(String.valueOf(f));
//JSON转map对象
Player player = JSON.parseObject(s, new TypeReference<Player>(){});
String fileName = f.getName().replace(".json", "");
playerMap.put(fileName, player);
TimingAcquisition.playerMap.putAll(playerMap);
}
}
log.info("玩家数据缓存完成");
//--------------------加载话术-----------------
TimingAcquisition.speechLoading(speechFilePath);
//--------------------加载闲聊话术的excel表----------------
......@@ -124,6 +104,18 @@ public class InitSysServlet implements InitializingBean {
TimingAcquisition.personSpeechMap.putAll(personSpeechMap);
log.info("人物见面话术加载完成");
//--------------------加载操作提示话术的excel表----------------
log.info("加载操作提示话术");
Map<Integer, OperateSpeech> operateSpeechMap = SpeechUtil.getOperateSpeechModel(speechFilePath);
TimingAcquisition.operateSpeechMap.putAll(operateSpeechMap);
log.info("操作提示话术加载完成");
//--------------------加载线索前因话术的excel表----------------
// log.info("加载线索前因话术");
// Map<Integer, List<PreReasonSpeech>> preReasonSpeechMap = SpeechUtil.getPreReasonSpeechModel(speechFilePath);
// TimingAcquisition.preReasonSpeechMap.putAll(preReasonSpeechMap);
// log.info("线索前因话术加载完成");
//-----------------缓存场所信息------------------
Map<String, Location> locationMap = new ConcurrentHashMap<>();
......@@ -180,12 +172,38 @@ public class InitSysServlet implements InitializingBean {
log.info("系统配置信息缓存完成");
//-----------------缓存结局目标配置信息------------------
Map<Integer, EndGoal> endGoalMap = new ConcurrentHashMap<>();
List<EndGoal> endGoalList = endGoalMapper.findAll();
for (EndGoal endGoal : endGoalList) {
endGoalMap.put(endGoal.getId(), endGoal);
// Map<Integer, EndGoal> endGoalMap = new ConcurrentHashMap<>();
// List<EndGoal> endGoalList = endGoalMapper.findAll();
// for (EndGoal endGoal : endGoalList) {
// endGoalMap.put(endGoal.getId(), endGoal);
// }
// TimingAcquisition.endGoalMap.putAll(endGoalMap);
// log.info("结局目标配置信息缓存完成");
//--------------------------加载玩家数据----------------------
log.info("开始加载玩家数据");
//从yml配置文件中取出存放玩家数据的地址
File file = new File(userFilePath);
File[] files = file.listFiles();
if (files == null) {
log.info("路径" + userFilePath+ "下没有文件");
return;
}
TimingAcquisition.endGoalMap.putAll(endGoalMap);
log.info("结局目标配置信息缓存完成");
// Map<String, Player> playerMap = new ConcurrentHashMap<>();
for (File f : files) {
if (f.isFile()) {
// String s = PersistenceUtil.getDataFromFile(String.valueOf(f));
//JSON转map对象
// Player player = JSON.parseObject(s, new TypeReference<Player>(){});
String fileName = f.getName().replace(".json", "");
// playerMap.put(fileName, player);
// TimingAcquisition.playerMap.putAll(playerMap);
TimingAcquisition.uidList.add(fileName); //保存所有玩家的uid
//该玩家以唯一标识加入全局缓存,用于玩家离线判断
String uniqueUid = fileName + "%#%online%#%";
CacheUtil.put(uniqueUid, "", Long.parseLong(offlineTime));
}
}
log.info("玩家数据缓存完成");
}
}
......@@ -33,6 +33,10 @@ public class TimingAcquisition {
* 玩家信息,Map<sid, Player>
*/
public volatile static Map<String, Player> playerMap = new ConcurrentHashMap<>();
/**
* 所有在线玩家的uid数组。用于是否加载玩家数据的判断
*/
public volatile static List<String> uidList = new ArrayList<>();
/**
* 场所配置信息
......@@ -99,6 +103,14 @@ public class TimingAcquisition {
* 人物见面话术,Map<人物名称, List<话术配置>>
*/
public volatile static Map<String, List<PersonSpeech>> personSpeechMap = new ConcurrentHashMap<>();
/**
* 操作提示话术,Map<人物名称, List<话术配置>>
*/
public volatile static Map<Integer, OperateSpeech> operateSpeechMap = new ConcurrentHashMap<>();
/**
* 线索前因话术,Map<人物名称, List<话术配置>>
*/
public volatile static Map<Integer, List<PreReasonSpeech>> preReasonSpeechMap = new ConcurrentHashMap<>();
/**
* 通过yaml文件加载所有话术到缓存中
......
......@@ -9,6 +9,7 @@ import com.qiwu.inference.dto.Player;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
......@@ -20,8 +21,12 @@ import java.util.concurrent.TimeUnit;
@EnableAsync
@Component
public class ExpireThread implements Runnable{
//动态词组更新秘钥
public static String userFilePath;
@Value("${userFilePath}")
private String userFilePath;
public void setUserFilePath(String userFilePath) {
ExpireThread.userFilePath = userFilePath;
}
@Override
public void run() {
......@@ -49,15 +54,16 @@ public class ExpireThread implements Runnable{
if (key.contains("%#%online%#%")) {
String uid = key.replace("%#%online%#%", "");
Player player = TimingAcquisition.playerMap.get(uid);
//更新玩家为离线状态
player.setStatus(Constants.OFFLINE);
//修改下线时间
player.setOfflineTime(DateUtil.getCurrentTime());
//--------------持久化该园丁信息---------------
Map<String, Player> playerMap = new ConcurrentHashMap<>();
playerMap.put(uid, TimingAcquisition.playerMap.get(uid));
String playerStr = JSON.toJSONString(playerMap);
PersistenceUtil.saveDataToFile(userFilePath, uid, playerStr);
if (!StringUtils.isEmpty(player)) {
//更新玩家为离线状态
player.setStatus(Constants.OFFLINE);
//修改下线时间
player.setOfflineTime(DateUtil.getCurrentTime());
//--------------持久化该园丁信息---------------
PersistenceUtil.saveDataToFile(userFilePath, uid, JSON.toJSONString(player));
//-----------------清除该玩家的数据缓存-----------------
TimingAcquisition.playerMap.remove(uid);
}
}
//清除过期缓存
CacheGlobal.concurrentMap.remove(key);
......
......@@ -22,7 +22,7 @@ public class CacheUtil {
MyCache myCache = CacheGlobal.concurrentMap.get(key);
myCache.setHitCount(myCache.getHitCount() + 1);
myCache.setLastTime(System.currentTimeMillis());
myCache.setExpireTime(System.currentTimeMillis());
myCache.setExpireTime(expire);
myCache.setValue(value);
} else {
MyCache myCache = new MyCache();
......
......@@ -90,10 +90,13 @@ public class DataTrimUtil {
"]";
//需要给玩家提示任务线索
// if (TimingAcquisition.playerMap.get(uid).isTipFlag()) {
// //搭档名称
// String partnerName = TimingAcquisition.systemConfigMap.get("partnerName").getValue();
// String addText = PlayerUtil.getClueFromTaskKey(uid);
// addText = SpeechUtil.addHeader(addText, partnerName);
// if (!StringUtils.isEmpty(addText)) {
// TimingAcquisition.playerMap.get(uid).setTipFlag(false);
// data.getVars().set反馈文本(data.getVars().get反馈文本() + "【寒烟@正常】" + addText);
// data.getVars().set反馈文本(data.getVars().get反馈文本() + addText);
// }
// }
log.info(feedContent);
......
......@@ -102,6 +102,35 @@ public class PersistenceUtil {
}
/**
* 读取json文件数据
* @param path json文件路径
* @param fileName
* @return 字符串
*/
public static String readJson(String path, String fileName) {
String jsonPath = path + fileName;
File jsonFile = new File(jsonPath);
try {
FileReader fileReader = new FileReader(jsonFile);
BufferedReader reader = new BufferedReader(fileReader);
StringBuilder sb = new StringBuilder();
while (true) {
int ch = reader.read();
if (ch != -1) {
sb.append((char) ch);
} else {
break;
}
}
fileReader.close();
reader.close();
return sb.toString();
} catch (IOException e) {
return "";
}
}
/**
* 将话术转成map格式
* @param
* @return Map<String, Map<String, List<String>>>
......@@ -117,4 +146,36 @@ public class PersistenceUtil {
}
return speechMap;
}
/**
* 读取玩家json文件的数据
* @param path json文件路径
* @param uid
* @return 字符串
*/
public static String loadPlayerData(String path, String uid) {
BufferedReader reader = null;
String fileName = uid + ".json";
String lastStr = "";
try {
FileInputStream fileInputStream = new FileInputStream(path + fileName);
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
reader = new BufferedReader(inputStreamReader);
String stringTmp = null;
while ((stringTmp = reader.readLine()) != null) {
lastStr += stringTmp;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return lastStr;
}
}
......@@ -3,8 +3,11 @@ package com.qiwu.inference.controller;
import com.qiwu.inference.common.Constants;
import com.qiwu.inference.common.TimingAcquisition;
import com.qiwu.inference.common.api.CommonResult;
import com.qiwu.inference.common.cache.CacheGlobal;
import com.qiwu.inference.common.utils.CacheUtil;
import com.qiwu.inference.common.utils.DataTrimUtil;
import com.qiwu.inference.common.utils.RequestConversionUtil;
import com.qiwu.inference.dto.ReplyDto;
import com.qiwu.inference.dto.request.CommonRequest;
import com.qiwu.inference.dto.request.OperationRequest;
import com.qiwu.inference.dto.response.ResultResponse;
......@@ -59,10 +62,18 @@ public class CommonController {
CommonResult<ResultVarsResponse> result = null;
String uid = commonRequest.getUid();
boolean login = false;
//玩家第一次登录
if (StringUtils.isEmpty(TimingAcquisition.playerMap.get(uid))) {
loginService.login(uid);
login = true;
//玩家已经存在
if (TimingAcquisition.uidList.contains(uid)) {
//玩家已经下线,重新加载
if (StringUtils.isEmpty(TimingAcquisition.playerMap.get(uid))) {
loginService.loadPlayerData(uid);
}
} else {
//玩家第一次登录
if (StringUtils.isEmpty(TimingAcquisition.playerMap.get(uid))) {
loginService.login(uid);
login = true;
}
}
//请求参数转换
OperationRequest operationReq = RequestConversionUtil.request2Operation(commonRequest);
......@@ -86,7 +97,7 @@ public class CommonController {
if ("闲聊".equals(operateName)) {
int chatTimes = TimingAcquisition.playerMap.get(uid).getChatTimes();
int times = Integer.parseInt(TimingAcquisition.systemConfigMap.get("chatTimes").getValue());
if (chatTimes > times) {
if (chatTimes >= times - 1) {
TimingAcquisition.playerMap.get(uid).setChatTimes(0);
} else {
TimingAcquisition.playerMap.get(uid).setChatTimes(TimingAcquisition.playerMap.get(uid).getChatTimes() + 1);
......@@ -94,6 +105,15 @@ public class CommonController {
} else {
TimingAcquisition.playerMap.get(uid).setChatTimes(0);
}
//判断上一轮玩家任务数据是否清空
if (!"二次回复".equals(operateName)) {
String unique = uid + TimingAcquisition.playerMap.get(uid).getGateNo();
ReplyDto reply = (ReplyDto) CacheUtil.get(unique);
if (!StringUtils.isEmpty(reply)) {
//清除任务数据
CacheGlobal.concurrentMap.remove(unique);
}
}
switch (operateName) {
case "开始游戏":
result = loginService.startGame(operationReq);
......@@ -107,6 +127,9 @@ public class CommonController {
case "查看操作":
result = checkService.check(operationReq);
break;
case "二次回复":
result = checkService.secondAnswer(operationReq);
break;
case "关卡操作":
result = barrierService.operate(operationReq);
break;
......
......@@ -19,7 +19,7 @@ public class BehaviourDto implements Serializable {
/**
* 行为名称
*/
private String name;
// private String name;
/**
* 行为id
*/
......@@ -27,7 +27,7 @@ public class BehaviourDto implements Serializable {
/**
* 行为描述
*/
private String description;
// private String description;
/**
* 主体
*/
......@@ -35,7 +35,7 @@ public class BehaviourDto implements Serializable {
/**
* 主体名称
*/
private String subjectName;
// private String subjectName;
/**
* 客体
*/
......@@ -43,6 +43,6 @@ public class BehaviourDto implements Serializable {
/**
* 客体名称
*/
private String objectName;
// private String objectName;
}
......@@ -38,7 +38,7 @@ public class ClueDto implements Serializable {
/**
* 描述
*/
private String description;
// private String description;
/**
* 类型: 1:身份 2:场所 3:性格爱好 4:行为 5:关系 6:任务 9: 关键线索
*/
......@@ -54,7 +54,7 @@ public class ClueDto implements Serializable {
/**
* 线索模板
*/
private String clueTemplate;
// private String clueTemplate;
/**
* 信任度
......
......@@ -31,7 +31,7 @@ public class DemandTaskDto implements Serializable {
/**
* 描述
*/
private String description;
// private String description;
/**
* 主体
......@@ -102,7 +102,7 @@ public class DemandTaskDto implements Serializable {
/**
* 完成反馈
*/
private String completionFeedback;
// private String completionFeedback;
/**
* 有效次数
*/
......@@ -124,10 +124,20 @@ public class DemandTaskDto implements Serializable {
private int infoLevel;
/**
* 任务标签 1普通任务 2关键任务 3目标任
* 任务标签 1普通任务 2关键任务 3目标任务
*/
private int taskLabel;
/**
* 自动触发: 0-不自动触发,1-自动触发
*/
private int isAuto;
/**
* 声望值
*/
private int reputation;
@Override
......
......@@ -27,11 +27,11 @@ public class DispositionDto implements Serializable {
/**
* 性格名称
*/
private String name;
// private String name;
/**
* 性格描述
*/
private String description;
// private String description;
/**
* 类型
*/
......
......@@ -68,6 +68,10 @@ public class Player {
* 人物的姓名和编号转换 map
*/
private Map<String,Integer> name2IdMap = new HashMap<>();
/**
* 人物的编号和姓名转换 map
*/
private Map<Integer, String> id2NameMap = new HashMap<>();
/**
* 当前关卡的货币
......@@ -127,6 +131,21 @@ public class Player {
*/
private int chatTimes = 0;
/**
* 记录玩家操作提示的序号
*/
private int operateTextNum = 1;
/**
* 记录玩家询问操作的每个操作对应线索的序号
*/
private Map<String, Integer> askAndNumMap = new HashMap<>();
/**
* 声望值
*/
private int reputation = 0;
// public Player(){
// //初始化推理游戏人物
// List<String> keys = new ArrayList<>(TimingAcquisition.gateInfoMap.keySet());
......
......@@ -11,7 +11,7 @@ public class PostTaskDto {
*/
private Integer personId;
/**
* 后置任务的前置任务完成情况: Map<后置任务id, Map<前置任务id, 完成状态>>
* 后置任务的前置任务完成情况: Map<后置任务id, 对象{前置任务id, 前置任务完成状态}>
*/
Map<Integer, TaskStatusDto> taskStatusMap;
}
......@@ -20,12 +20,12 @@ public class RelationDto implements Serializable {
/**
* 关系名称
*/
private String name;
// private String name;
/**
* 关系描述
*/
private String description;
// private String description;
/**
* 类型
......
package com.qiwu.inference.dto;
import lombok.Data;
@Data
public class ReplyDto {
/**
* 主体id
*/
private Integer subjectId;
/**
* 客体id
*/
private Integer objectId;
/**
* 任务id
*/
private Integer demandTaskId;
/**
* 响应方式:1-闲聊,2-发布任务,3-执行任务
*/
private int type;
/**
* 序号,按顺序去对应话术
*/
private int num = 0;
}
......@@ -15,8 +15,8 @@ public class ChatSpeech implements Serializable {
@ApiModelProperty("身份")
private String identity;
@ApiModelProperty("人物ID")
private Integer personId;
@ApiModelProperty("人物名称")
private String personName;
@ApiModelProperty("性别")
private String gender;
......@@ -33,8 +33,11 @@ public class ChatSpeech implements Serializable {
@ApiModelProperty("任务状态")
private String taskStatus;
@ApiModelProperty("关系")
private String degree;
@ApiModelProperty("信任值")
private String trust;
@ApiModelProperty("威慑度")
private String deterrence;
@ApiModelProperty("文本内容")
private String answer;
......
package com.qiwu.inference.pojo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@Data
public class OperateSpeech implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("ID")
private Integer id;
@ApiModelProperty("操作提示文本")
private String answer;
}
package com.qiwu.inference.pojo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@Data
public class PreReasonSpeech implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("线索ID")
private Integer demandTaskId;
@ApiModelProperty("任务ID")
private Integer clueId;
@ApiModelProperty("任务名称")
private String taskName;
@ApiModelProperty("自身身份")
private Integer identity;
@ApiModelProperty("对方身份")
private Integer identitySide;
@ApiModelProperty("性别")
private String gender;
@ApiModelProperty("人物名称")
private Integer personName;
@ApiModelProperty("年龄段")
private String age;
@ApiModelProperty("性格A")
private Integer dispositionId;
@ApiModelProperty("关系")
private Integer relation;
@ApiModelProperty("行为")
private Integer behaviour;
@ApiModelProperty("第三方描述")
private String answer;
@ApiModelProperty("自身描述")
private String answerSelf;
@ApiModelProperty("通用标签")
private Integer flag;
}
......@@ -48,6 +48,9 @@ public class TaskSpeech implements Serializable {
@ApiModelProperty("完成对话文本")
private String answer;
@ApiModelProperty("任务操作提醒文本")
private String replyAnswer;
@ApiModelProperty("通用标签")
private Integer flag;
}
......@@ -36,19 +36,32 @@ public class ChatServiceImpl implements ChatService {
Player player = TimingAcquisition.playerMap.get(uid);
//对话人的信息
Person current = player.getPersonMap().get(player.getPersonId());
//搭档名称
String partnerName = TimingAcquisition.systemConfigMap.get("partnerName").getValue();
//获取对应话术
String text = SpeechUtil.getChatSpeech(uid, current, methodId);
text = SpeechUtil.addHeader(text, current.getName());
//闲聊连续对话次数超过指定次数,任务白名单中有该人已解锁或无需解锁的任务则进行提示
int chatTimes = Integer.parseInt(TimingAcquisition.systemConfigMap.get("chatTimes").getValue());
if (player.getChatTimes() >= chatTimes) {
if (player.getChatTimes() >= chatTimes - 1) {
//找到白名单内该人的任务中已解锁或无需解锁的任务
String addText = PlayerUtil.getTipInChat(uid, current);
if (!StringUtils.isEmpty(addText)) {
addText = "【寒烟@正常】" + addText;
addText = SpeechUtil.addHeader(addText, partnerName);
text += addText;
}
}
//每轮的第一次进行操作提示
if (player.getChatTimes() == 0) {
//找到操作的提示
String operateText = SpeechUtil.getOperateSpeech(player);
if (!StringUtils.isEmpty(operateText)) {
operateText = SpeechUtil.addHeader(operateText, partnerName);
text += operateText;
}
//更新玩家操作提示的序号
player.setOperateTextNum(player.getOperateTextNum() + 1);
}
resultResponse.set反馈ID(600101);
resultResponse.set反馈文本(text);
resultVarsResponse.setVars(resultResponse);
......
......@@ -6,4 +6,6 @@ import com.qiwu.inference.dto.response.ResultVarsResponse;
public interface CheckService {
CommonResult<ResultVarsResponse> check(OperationRequest operationReq);
CommonResult<ResultVarsResponse> secondAnswer(OperationRequest operationReq);
}
......@@ -52,6 +52,8 @@ public class CommonService {
case "1028":
case "1029":
return playerService.askPrompt(request);
case "1030":
return playerService.askFinalClue(request);
case "2001":
case "2003":
case "2002":
......@@ -93,6 +95,7 @@ public class CommonService {
case "2039":
case "2040":
case "2041":
case "2042":
case "2101":
case "2102":
case "2104":
......@@ -100,6 +103,13 @@ public class CommonService {
case "2107":
case "2108":
case "2109":
case "2043":
case "204301":
case "204302":
case "204303":
case "204304":
case "204305":
case "2044":
return playerService.performTask(request);
}
return null;
......
......@@ -9,4 +9,6 @@ public interface LoginService {
CommonResult<ResultVarsResponse> login(String uid);
CommonResult<ResultVarsResponse> startGame(OperationRequest operationReq);
CommonResult<ResultVarsResponse> loadPlayerData(String uid);
}
......@@ -2,6 +2,7 @@ package com.qiwu.inference.service.login.impl;
import cn.hutool.core.lang.UUID;
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;
......@@ -22,6 +23,8 @@ import java.util.concurrent.ConcurrentHashMap;
@Service
public class LoginServiceImpl implements LoginService {
@Value("${offlineTime}")
private String offlineTime;
//从yml配置文件中取出对话过期时间
@Value("${expireTime}")
private String expireTime;
......@@ -49,14 +52,17 @@ public class LoginServiceImpl implements LoginService {
Map<Integer,Map<Integer,Integer>> taskMapCopy = new HashMap<>();
Map<Integer,Person> personMapCopy = new HashMap<>();
Map<String,Integer> name2IdMapCopy = new HashMap<>();
Map<Integer, String> id2NameMapCopy = new HashMap<>();
for (Person person : personCopyList) {
taskMapCopy.put(person.getId(), new HashMap<>());
personMapCopy.put(person.getId(), person);
name2IdMapCopy.put(person.getName(), person.getId());
id2NameMapCopy.put(person.getId(), person.getName());
}
player.setTaskMap(taskMapCopy);
player.setPersonMap(personMapCopy);
player.setName2IdMap(name2IdMapCopy);
player.setId2NameMap(id2NameMapCopy);
//给玩家分配场所和对话人物
Map<String, List<Integer>> locationPersonMap = new HashMap<>();
Map<Integer, Person> personMap = player.getPersonMap();
......@@ -95,6 +101,12 @@ public class LoginServiceImpl implements LoginService {
PersistenceUtil.saveDataToFile(userFilePath, uid, playerStr);
sidGateNoMap.put(uid, player.getGateNo());
TimingAcquisition.uidGateNoMap.putAll(sidGateNoMap);
//保存所有玩家的uid
TimingAcquisition.uidList.add(uid);
//该玩家以唯一标识加入全局缓存,用于玩家离线判断
String uniqueUid = uid + "%#%online%#%";
CacheUtil.put(uniqueUid, "", Long.parseLong(offlineTime));
resultResponse.set反馈ID(100000);
resultResponse.set反馈文本("登录成功");
......@@ -108,7 +120,6 @@ public class LoginServiceImpl implements LoginService {
ResultResponse resultResponse = new ResultResponse();
String uid = operationReq.getUid();
String text = "";
Player player = TimingAcquisition.playerMap.get(uid);
//数据重置
if (player.getFinished() == 1) {
......@@ -122,15 +133,17 @@ public class LoginServiceImpl implements LoginService {
Map<Integer,Map<Integer,Integer>> taskMapCopy = new HashMap<>();
Map<Integer,Person> personMapCopy = new HashMap<>();
Map<String,Integer> name2IdMapCopy = new HashMap<>();
Map<Integer, String> id2NameMapCopy = new HashMap<>();
for (Person person : personCopyList) {
taskMapCopy.put(person.getId(), new HashMap<>());
personMapCopy.put(person.getId(), person);
name2IdMapCopy.put(person.getName(), person.getId());
id2NameMapCopy.put(person.getId(), person.getName());
}
player.setTaskMap(taskMapCopy);
player.setPersonMap(personMapCopy);
player.setName2IdMap(name2IdMapCopy);
player.setCurrency(3000.0);
player.setId2NameMap(id2NameMapCopy);
//给玩家分配场所和对话人物
Map<String, List<Integer>> locationPersonMap = new HashMap<>();
Map<Integer, Person> personMap = player.getPersonMap();
......@@ -161,29 +174,42 @@ public class LoginServiceImpl implements LoginService {
//生成场所表,包含场所隐藏状态和必现场所
Map<String, LocationInfoDto> locationMap = PlayerUtil.makeLocationMap(locationPersonMap);
player.setLocationMap(locationMap);
player.setCurrency(3000.0);
player.setPoint(0);
player.setClueMap(new HashMap<>());
player.setFinishedTaskNum(0);
player.setTipFlag(false);
player.setOperateTextNum(1);
player.setAskAndNumMap(new HashMap<>());
player.setFinished(0);
}
//关卡编号
String gateNo = player.getGateNo();
int size = TimingAcquisition.barrierTaskKeyMap.get(gateNo).size();
Integer demandTaskId = TimingAcquisition.barrierTaskKeyMap.get(gateNo).get(size - 1).getDemandTaskId();
Map<Integer, EndGoal> endGoalMap = TimingAcquisition.endGoalMap;
for (Map.Entry<Integer, EndGoal> entry : endGoalMap.entrySet()) {
EndGoal endGoal = entry.getValue();
List<String> associatedTaskIds = Arrays.asList(endGoal.getAssociatedTaskId().split("\\|"));
if (associatedTaskIds.contains(demandTaskId.toString())) {
text = "【旁白@正常】" + endGoal.getName();
text += "【旁白@正常】" + endGoal.getDescription();
text += SpeechUtil.getAskSpeech(Constants.SPEECH_PERSON, 103001);
text += SpeechUtil.getAskSpeech(Constants.SPEECH_PERSON, 103002);
String location = TimingAcquisition.locationMap.get(TimingAcquisition.playerMap.get(uid).getLocation()).getName();
String name = PlayerUtil.getNameByPersonId(uid, TimingAcquisition.playerMap.get(uid).getPersonId());
text = SpeechUtil.speechReplaceNum(text, location, name);
break;
}
}
//获取开场白话术
String text = SpeechUtil.getPrologueSpeech(uid, gateNo);
resultResponse.set反馈ID(100009);
resultResponse.set反馈文本(text);
resultVarsResponse.setVars(resultResponse);
return CommonResult.success(resultVarsResponse);
}
@Override
public CommonResult<ResultVarsResponse> loadPlayerData(String uid) {
ResultVarsResponse resultVarsResponse = new ResultVarsResponse();
ResultResponse resultResponse = new ResultResponse();
String playStr = PersistenceUtil.loadPlayerData(userFilePath, uid);
Player player = JSON.parseObject(playStr, new TypeReference<Player>(){});
player.setOnlineTime(DateUtil.getCurrentTime());
player.setStatus(Constants.ONLINE);
TimingAcquisition.playerMap.put(uid, player);
//该玩家以唯一标识加入全局缓存,用于玩家离线判断
String uniqueUid = uid + "%#%online%#%";
CacheUtil.put(uniqueUid, "", Long.parseLong(offlineTime));
resultResponse.set反馈ID(100010);
resultResponse.set反馈文本(uid + "的数据加载完成");
resultVarsResponse.setVars(resultResponse);
return CommonResult.success(resultVarsResponse);
}
}
......@@ -54,6 +54,13 @@ public interface PlayerService {
public CommonResult<ResultVarsResponse> askPrompt(OperationRequest request);
/**
* 询问最终线索
* @param request
* @return
*/
public CommonResult<ResultVarsResponse> askFinalClue(OperationRequest request);
/**
* 执行任务
* @param request
* @return
......
This source diff could not be displayed because it is too large. You can view the blob instead.
server:
port: 60019
serlvet:
context-type:/inference
#设置当前服务名
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/inference_brick?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
username: root
password: dgKNTmt2iLHNjEQajkDEZkq8
type: com.alibaba.druid.pool.DruidDataSource
druid:
initial-size: 5
min-idle: 5
max-active: 20
max-wait: 60000
#配置间隔多久才进行一次检测,检测需要关闭的空闲连接
time-between-eviction-runs-millis: 20000
#配置一个连接在池中最小生存的时间
min-evictable-idle-time-millis: 300000
#对话过期时间
expireTime: 180000
#玩家无操作时长,默认下线
offlineTime: 180000
speechFilePath: /home/jiaoyou/projects/inferenceBrick/speech/
configFilePath: /home/jiaoyou/projects/inferenceBrick/config/
userFilePath: /home/jiaoyou/projects/inferenceBrick/user/
server:
port: 60020
serlvet:
context-type:/inference
#设置当前服务名
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/inference_reflection?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
username: root
password: dgKNTmt2iLHNjEQajkDEZkq8
type: com.alibaba.druid.pool.DruidDataSource
druid:
initial-size: 5
min-idle: 5
max-active: 20
max-wait: 60000
#配置间隔多久才进行一次检测,检测需要关闭的空闲连接
time-between-eviction-runs-millis: 20000
#配置一个连接在池中最小生存的时间
min-evictable-idle-time-millis: 300000
#对话过期时间
expireTime: 180000
#玩家无操作时长,默认下线
offlineTime: 180000
speechFilePath: /home/jiaoyou/projects/inferenceReflection/speech/
configFilePath: /home/jiaoyou/projects/inferenceReflection/config/
userFilePath: /home/jiaoyou/projects/inferenceReflection/user/
......@@ -7,7 +7,7 @@ server:
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/inference_game?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
url: jdbc:mysql://localhost:3306/inference_reflection?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
username: root
password: dgKNTmt2iLHNjEQajkDEZkq8
type: com.alibaba.druid.pool.DruidDataSource
......
spring:
profiles:
active: pro
\ No newline at end of file
active: dev
\ No newline at end of file
......@@ -10,7 +10,7 @@ aside:
400103:
- 【旁白@正常】不知道您说的这个地方在哪呢。
400104:
- 【旁白@正常】这个地方没有你要找的人。
- 【旁白@正常】没有这个地方,换其他地方试试吧,您可以说:我可以去哪里。
400105:
- 【旁白@正常】你想要去哪里呢?目前已知场所有:【1】。
#4002: 开启对话
......
......@@ -31,7 +31,7 @@ aside:
300501:
- 【旁白@正常】您当前已知线索【1】条,请问想要查看关于人物的线索还是不同类型的线索呢?
30050101:
- 【旁白@正常】您当前还没有获得任何线索,我能给您提供点建议。
- 您当前还没有获得任何线索,我能给您提供点建议。
300502:
- 【旁白@正常】当前已知人物【1】名:【2】,想要知道哪个人物的相关线索呢?说出他的名称即可。
30050201:
......@@ -39,7 +39,7 @@ aside:
300503:
- 【旁白@正常】当前已知【1】,想要知晓哪个类型线索呢?
30050301:
- 【旁白@正常】您当前还没有收集到线索,我能给您提供点建议。
- 您当前还没有收集到线索,我能给您提供点建议。
300504:
- 【旁白@正常】【1】已知线索【2】条,其中【3】,想要了解【1】的哪种线索呢?
30050401:
......@@ -62,17 +62,25 @@ aside:
- 【旁白@正常】您想看什么类型的线索呢?
30050605:
- 【旁白@正常】没有这种类型的线索哦。
30050606:
- 【旁白@正常】【1】的【2】线索共【3】条,第【4】条:【5】
30050607:
- 【旁白@正常】【1】的【2】线索共【3】条,第【4】条:【5】要重新查看吗?
#3006: 询问谁和谁有某个关系
300601:
- 【旁白@正常】您当前排名积分为:【1】。
#3007: 询问某人的模糊处理操作
3007:
- 【寒烟@正常】那我们下次再说吧。
- 【寒烟@正常】嗯嗯,我们下次再说这件事。
#3101: 询问某人的模糊处理操作
310101:
- 【寒烟@正常】您还没告诉要看谁的呢。
- 【人物名称@正常】您还没告诉要看谁的呢。
310102:
- 【寒烟@正常】没有您说的这个人哦。
- 【人物名称@正常】没有您说的这个人哦。
310103:
- 【寒烟@正常】【1】,年龄【2】,性别【3】,身份【4】,其他信息不详。
- 【人物名称@正常】【1】,年龄【2】,性别【3】,身份【4】,其他信息不详。
310104:
- 【寒烟@正常】【1】,年龄【2】,性别【3】,身份【4】,【5】对你的信任度为:【6】、威慑度为:【7】。
- 【人物名称@正常】【1】,年龄【2】,性别【3】,身份【4】,【5】对你的信任度为:【6】、威慑度为:【7】。
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment