Commit d4c7ebca by 周君强

1.推理项目第一版

parent 7d2055fe
......@@ -117,6 +117,11 @@
<artifactId>hutool-all</artifactId>
<version>5.8.8</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
</dependencies>
<properties>
......
package com.qiwu.inference;
import com.qiwu.inference.common.TimingAcquisition;
import com.qiwu.inference.common.cache.ExpireThread;
import com.qiwu.inference.common.cache.TaskTipsThread;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
......@@ -10,5 +11,11 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
public class InferenceApplication {
public static void main(String[] args) {
SpringApplication.run(InferenceApplication.class, args);
ExpireThread expireThread = new ExpireThread();
Thread thread = new Thread(expireThread);
thread.start();
// TaskTipsThread taskTipsThread = new TaskTipsThread();
// Thread taskThread = new Thread(taskTipsThread);
// taskThread.start();
}
}
......@@ -3,7 +3,9 @@ package com.qiwu.inference.common;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.qiwu.inference.common.utils.PersistenceUtil;
import com.qiwu.inference.common.utils.SpeechUtil;
import com.qiwu.inference.dao.*;
import com.qiwu.inference.dto.BarrierTaskKeyDto;
import com.qiwu.inference.dto.Person;
import com.qiwu.inference.dto.Player;
import com.qiwu.inference.pojo.*;
......@@ -40,6 +42,8 @@ public class InitSysServlet implements InitializingBean {
private DemandTaskMapper demandTaskMapper;
@Autowired
private DispositionMapper dispositionMapper;
@Autowired
private EndGoalMapper endGoalMapper;
/**
* 保存配置信息到缓存
......@@ -53,6 +57,17 @@ public class InitSysServlet implements InitializingBean {
TimingAcquisition.gateInfoMap.putAll(gateInfoMap);
log.info("关卡数据缓存完成");
for (Map.Entry<String, List<Person>> entry : gateInfoMap.entrySet()) {
String gateNo = entry.getKey();
//-------------------------缓存关卡攻略数据---------------------
log.info("开始缓存关卡攻略数据");
String barrierTaskKey = PersistenceUtil.getConfigFromFile(configFilePath, "results_final_task.json");
List<BarrierTaskKeyDto> barrierTaskKeyList = JSON.parseObject(barrierTaskKey, new TypeReference<List<BarrierTaskKeyDto>>(){});
Map<String, List<BarrierTaskKeyDto>> barrierTaskKeyMap = new ConcurrentHashMap<>();
barrierTaskKeyMap.put(gateNo, barrierTaskKeyList);
TimingAcquisition.barrierTaskKeyMap.putAll(barrierTaskKeyMap);
log.info("关卡攻略数据缓存完成");
}
//--------------------------加载玩家数据----------------------
......@@ -79,6 +94,35 @@ public class InitSysServlet implements InitializingBean {
//--------------------加载话术-----------------
TimingAcquisition.speechLoading(speechFilePath);
//--------------------加载闲聊话术的excel表----------------
log.info("加载闲聊话术");
Map<Integer, List<ChatSpeech>> chatSpeechMap = SpeechUtil.getChatSpeechModel(speechFilePath);
TimingAcquisition.chatSpeechMap.putAll(chatSpeechMap);
log.info("闲聊话术加载完成");
//--------------------加载线索成功话术的excel表----------------
log.info("加载线索成功话术");
Map<Integer, List<ClueSpeech>> clueSpeechMap = SpeechUtil.getClueSpeechModel(speechFilePath);
TimingAcquisition.successClueSpeechMap.putAll(clueSpeechMap);
log.info("线索成功话术加载完成");
//--------------------加载任务成功话术的excel表----------------
log.info("加载任务成功话术");
Map<Integer, List<TaskSpeech>> taskSpeechMap = SpeechUtil.getTaskSpeechModel(speechFilePath);
TimingAcquisition.successTaskSpeechMap.putAll(taskSpeechMap);
log.info("任务成功话术加载完成");
//--------------------加载任务成功话术的excel表----------------
log.info("加载任务提示话术");
Map<Integer, List<TipSpeech>> tipSpeechMap = SpeechUtil.getTipSpeechModel(speechFilePath);
TimingAcquisition.tipSpeechMap.putAll(tipSpeechMap);
log.info("任务提示话术加载完成");
//--------------------加载人物见面话术的excel表----------------
log.info("加载人物见面话术");
Map<String, List<PersonSpeech>> personSpeechMap = SpeechUtil.getPersonSpeechModel(speechFilePath);
TimingAcquisition.personSpeechMap.putAll(personSpeechMap);
log.info("人物见面话术加载完成");
//-----------------缓存场所信息------------------
......@@ -134,5 +178,14 @@ public class InitSysServlet implements InitializingBean {
}
TimingAcquisition.systemConfigMap.putAll(systemConfigMap);
log.info("系统配置信息缓存完成");
//-----------------缓存结局目标配置信息------------------
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("结局目标配置信息缓存完成");
}
}
package com.qiwu.inference.common;
import com.qiwu.inference.common.utils.PersistenceUtil;
import com.qiwu.inference.common.utils.YamlUtil;
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.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
......@@ -23,6 +22,10 @@ public class TimingAcquisition {
*/
public volatile static Map<String, List<Person>> gateInfoMap = new ConcurrentHashMap<>();
/**
* 关卡攻略信息,Map<关卡编号, List<攻略任务>>
*/
public volatile static Map<String, List<BarrierTaskKeyDto>> barrierTaskKeyMap = new ConcurrentHashMap<>();
/**
* 用户id跟关卡编号对应关系
*/
public volatile static Map<String, String> uidGateNoMap = new ConcurrentHashMap<>();
......@@ -55,6 +58,10 @@ public class TimingAcquisition {
* 系统配置信息
*/
public volatile static Map<String, SystemConfigPojo> systemConfigMap = new ConcurrentHashMap<>();
/**
* 结局目标配置信息
*/
public volatile static Map<Integer, EndGoal> endGoalMap = new ConcurrentHashMap<>();
/**
* 询问模块话术
......@@ -72,6 +79,26 @@ public class TimingAcquisition {
* 查看模块话术
*/
public volatile static Map<String, Map<Integer, List<String>>> barrierSpeechMap = new ConcurrentHashMap<>();
/**
* 闲聊模块话术,Map<意图, List<话术配置>>
*/
public volatile static Map<Integer, List<ChatSpeech>> chatSpeechMap = new ConcurrentHashMap<>();
/**
* 线索成功话术,Map<线索id, List<话术配置>>
*/
public volatile static Map<Integer, List<ClueSpeech>> successClueSpeechMap = new ConcurrentHashMap<>();
/**
* 任务成功话术,Map<任务id, List<话术配置>>
*/
public volatile static Map<Integer, List<TaskSpeech>> successTaskSpeechMap = new ConcurrentHashMap<>();
/**
* 任务提示话术,Map<任务id, List<话术配置>>
*/
public volatile static Map<Integer, List<TipSpeech>> tipSpeechMap = new ConcurrentHashMap<>();
/**
* 人物见面话术,Map<人物名称, List<话术配置>>
*/
public volatile static Map<String, List<PersonSpeech>> personSpeechMap = new ConcurrentHashMap<>();
/**
* 通过yaml文件加载所有话术到缓存中
......
package com.qiwu.inference.common.cache;
import com.qiwu.inference.common.Constants;
import com.qiwu.inference.common.TimingAcquisition;
import com.qiwu.inference.common.utils.DateUtil;
import com.qiwu.inference.dto.Player;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;
import java.text.ParseException;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
* 任务提示线程
*/
@EnableAsync
@Component
public class TaskTipsThread implements Runnable{
@Override
public void run() {
while (true) {
try {
//每60秒检测一次
TimeUnit.SECONDS.sleep(60);
checkTaskTips();
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* 检测是否需要任务提示
*/
public void checkTaskTips() throws ParseException {
Map<String, Player> playerMap = TimingAcquisition.playerMap;
String nowTime = DateUtil.getCurrentTime();
String tipTime = TimingAcquisition.systemConfigMap.get("tipTime").getValue();
for (Map.Entry<String, Player> entry : playerMap.entrySet()) {
Player player = entry.getValue();
//在线玩家
if (player.getStatus().equals(Constants.ONLINE)) {
//上次提示时间已超过规定时间
if (DateUtil.subTime(nowTime, player.getNumUpdateTime()) >= Long.parseLong(tipTime)) {
Map<Integer,Map<Integer,Integer>> taskMap = player.getTaskMap();
//该玩家已完成任务个数
int num = 0;
for (Map.Entry<Integer,Map<Integer,Integer>> mapEntry : taskMap.entrySet()) {
num += mapEntry.getValue().size();
}
//第一次更新,不需要提示。做完了第一个任务之后再去提示
if (num == 0) {
continue;
}
if (num > player.getFinishedTaskNum()) {
player.setFinishedTaskNum(num);
} else {
//规定时间内没有完成新的任务,需要提示一个攻略
player.setTipFlag(true);
}
player.setNumUpdateTime(nowTime);
}
}
}
}
}
......@@ -34,10 +34,10 @@ public class DataTrimUtil {
public static void AdjustStatus(String uid, String offlineTime) throws ParseException {
//玩家当前为离线状态
Player player = TimingAcquisition.playerMap.get(uid);
//操作日期为今天之前,需更改为在线状态
//上次操作时间过期,需更改为在线状态
String nowTime = DateUtil.getCurrentTime();
if (!StringUtils.isEmpty(player.getOnlineTime())) {
if (DateUtil.compare(nowTime, player.getOnlineTime()) == 1) {
if (DateUtil.subTime(nowTime, player.getOnlineTime()) > (Long.parseLong(offlineTime) / 1000)) {
//更新玩家在线状态
statusUpdate(uid);
}
......@@ -65,7 +65,7 @@ public class DataTrimUtil {
/**
* 判断整数尾数是否为1
*/
public static CommonResult<ResultVarsResponse> AdjustParams(CommonResult<ResultVarsResponse> result) {
public static CommonResult<ResultVarsResponse> AdjustParams(String uid, CommonResult<ResultVarsResponse> result) {
if (StringUtils.isEmpty(result)) {
return CommonResult.failed("操作失败");
}
......@@ -88,7 +88,14 @@ public class DataTrimUtil {
", 后台附加返回:" + data.getVars().get后台附加返回() +
", 后台附加返回2:" + data.getVars().get后台附加返回2() +
"]";
//玩家有新消息提示
//需要给玩家提示任务线索
// if (TimingAcquisition.playerMap.get(uid).isTipFlag()) {
// String addText = PlayerUtil.getClueFromTaskKey(uid);
// if (!StringUtils.isEmpty(addText)) {
// TimingAcquisition.playerMap.get(uid).setTipFlag(false);
// data.getVars().set反馈文本(data.getVars().get反馈文本() + "【寒烟@正常】" + addText);
// }
// }
log.info(feedContent);
}
return result;
......
......@@ -33,6 +33,8 @@ public class RequestConversionUtil {
String[] name = subjectName.split("\\+");
subjectName = name[0];
}
//通过身份找到对应人物名称
subjectName = PlayerUtil.getName(commonRequest.getUid(), subjectName);
operationRequest.setSubjectName(subjectName);
Integer subjectId = TimingAcquisition.getPersonIdByName(commonRequest.getUid(), subjectName);
operationRequest.setSubjectId(subjectId);
......@@ -52,8 +54,12 @@ public class RequestConversionUtil {
objectName = objectName.replace(subjectName, "");
objectName = objectName.replace("+", "");
}
if (!objectName.equals(subjectName)) {
//通过身份找到对应人物名称
objectName = PlayerUtil.getName(commonRequest.getUid(), objectName);
operationRequest.setObjectName(objectName);
}
}
//---------------------存在"性格类型"-----------------------
String dispositionType = callRequest.get性格类型();
if (!StringUtils.isEmpty(dispositionType)) {
......
......@@ -11,6 +11,7 @@ import com.qiwu.inference.dto.response.ResultResponse;
import com.qiwu.inference.dto.response.ResultVarsResponse;
import com.qiwu.inference.service.ask.AskService;
import com.qiwu.inference.service.barrier.BarrierService;
import com.qiwu.inference.service.chat.ChatService;
import com.qiwu.inference.service.check.CheckService;
import com.qiwu.inference.service.login.LoginService;
import com.qiwu.inference.service.task.TaskService;
......@@ -49,6 +50,9 @@ public class CommonController {
@Autowired
private BarrierService barrierService;
@Autowired
private ChatService chatService;
@PostMapping(value = "/ask", produces = "application/json;charset=UTF-8")
public CommonResult<ResultVarsResponse> startGame(@RequestBody CommonRequest commonRequest) throws ParseException {
log.info(commonRequest.getUid() + "当前操作的原始请求参数:" + commonRequest.getVars());
......@@ -78,7 +82,22 @@ public class CommonController {
resultVarsResponse.setVars(resultResponse);
return CommonResult.success(resultVarsResponse);
}
//统计玩家闲聊次数
if ("闲聊".equals(operateName)) {
int chatTimes = TimingAcquisition.playerMap.get(uid).getChatTimes();
int times = Integer.parseInt(TimingAcquisition.systemConfigMap.get("chatTimes").getValue());
if (chatTimes > times) {
TimingAcquisition.playerMap.get(uid).setChatTimes(0);
} else {
TimingAcquisition.playerMap.get(uid).setChatTimes(TimingAcquisition.playerMap.get(uid).getChatTimes() + 1);
}
} else {
TimingAcquisition.playerMap.get(uid).setChatTimes(0);
}
switch (operateName) {
case "开始游戏":
result = loginService.startGame(operationReq);
break;
case "询问操作":
result = askService.ask(operationReq);
break;
......@@ -94,8 +113,11 @@ public class CommonController {
case "取消操作指令":
result = barrierService.cancel(operationReq);
break;
case "闲聊":
result = chatService.operate(operationReq);
break;
}
log.info(uid + "已完成操作:【" + operateName + "】");
return DataTrimUtil.AdjustParams(result);
return DataTrimUtil.AdjustParams(uid, result);
}
}
......@@ -5,6 +5,8 @@ import com.qiwu.inference.pojo.EndGoal;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* <p>
* Mapper 接口
......@@ -16,5 +18,5 @@ import org.springframework.stereotype.Repository;
@Mapper
@Repository
public interface EndGoalMapper extends BaseMapper<EndGoal> {
List<EndGoal> findAll();
}
package com.qiwu.inference.dto;
import lombok.Data;
@Data
public class BarrierTaskKeyDto {
/**
* id唯一标识
*/
private Integer id;
/**
* 需求任务id
*/
private Integer demandTaskId;
/**
* 任务主体
*/
private Integer subject;
/**
* 任务客体
*/
private Integer object;
/**
* 线索id
*/
private Integer clueId;
/**
* 线索类型
*/
private Integer type;
/**
* 任务标签
*/
private Integer taskLabel;
/**
* 后置任务
*/
private String postTask;
}
......@@ -4,6 +4,8 @@ import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
@Getter
......@@ -15,11 +17,11 @@ public class ClueDto implements Serializable {
/**
* id
*/
private Integer id;
private int id;
/**
* 线索id
*/
private Integer clueId;
private int clueId;
/**
* 线索名称
......@@ -28,11 +30,11 @@ public class ClueDto implements Serializable {
/**
* 主体
*/
private Integer subject;
private int subject;
/**
* 客体
*/
private Integer object;
private int object;
/**
* 描述
*/
......@@ -40,15 +42,15 @@ public class ClueDto implements Serializable {
/**
* 类型: 1:身份 2:场所 3:性格爱好 4:行为 5:关系 6:任务 9: 关键线索
*/
private Integer type;
private int type;
/**
* 信息级别
*/
private Integer infoLevel;
private int infoLevel;
/**
* 关联人物
*/
private Integer associatedPerson;
private int associatedPerson;
/**
* 线索模板
*/
......@@ -57,12 +59,29 @@ public class ClueDto implements Serializable {
/**
* 信任度
*/
private Integer trustDegree;
private int trustDegree=100;
/**
* 威胁
*/
private Integer threaten;
private int threaten=100;
/**
* 线索来源
*/
private List<Integer> sourceIdList;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ClueDto clue = (ClueDto) o;
return id == clue.id && clueId == clue.clueId && subject == clue.subject && clueName.equals(clue.clueName);
}
@Override
public int hashCode() {
return Objects.hash(id, clueId, clueName, subject);
}
}
package com.qiwu.inference.dto;
import com.qiwu.inference.pojo.DemandTask;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.util.Objects;
@Getter
......@@ -14,12 +16,12 @@ public class DemandTaskDto implements Serializable {
/**
* id
*/
private Integer id;
private int id;
/**
* demandTaskId
*/
private Integer demandTaskId;
private int demandTaskId;
/**
* 名称
......@@ -34,22 +36,44 @@ public class DemandTaskDto implements Serializable {
/**
* 主体
*/
private Integer subject;
private int subject;
/**
* 客体
*/
private Integer object;
private int object;
/**
* 开启条件信任度的开始
*/
private int trustStart=100;
/**
* 开启条件信任度的结束
*/
private int trustEnd=100;
/**
* 开启条件威胁度的开始
*/
private int deterrenceStart=100;
/**
* 开启条件威胁度的结束
*/
private int deterrenceEnd=100;
/**
* 开启条件信任度
* 后置任务
*/
private String trustCondition;
private String postTask;
/**
* 开启条件威慑度
* 线索开关 0 代表不需要线索就可执行,1 代表需要线索才能执行此任务 2 代表任务已解锁(操作添加,非ai)
*/
private String deterrenceCondition;
private int clueSwitch;
/**
* 条件1|次数
......@@ -64,12 +88,12 @@ public class DemandTaskDto implements Serializable {
/**
* 信任度增减
*/
private String trustDegree;
private int trustDegree;
/**
* 威慑度增减
*/
private String deterrenceDegree;
private int deterrenceDegree;
/**
* 完成奖励
......@@ -82,29 +106,40 @@ public class DemandTaskDto implements Serializable {
/**
* 有效次数
*/
private String effectiveDegree;
/**
* 后置任务
*/
private String postTask;
private int effectiveDegree;
/**
* 类型: 1:身份 2:场所 3:性格爱好 4:行为 5:关系 6:任务 9:关键线索
*/
private Integer type;
private int type;
/**
* 线索id
*/
private Integer clueId;
private int clueId;
/**
* 信息级别
*/
private Integer infoLevel;
private int infoLevel;
/**
* 任务标签 1普通任务 2关键任务 3目标任
*/
private Integer taskLabel;
private int taskLabel;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DemandTaskDto that = (DemandTaskDto) o;
return id == that.id && demandTaskId == that.demandTaskId && subject == that.subject && type == that.type && clueId == that.clueId && name.equals(that.name);
}
@Override
public int hashCode() {
return Objects.hash(id, demandTaskId, name, subject, type, clueId);
}
}
package com.qiwu.inference.dto;
import lombok.Data;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Data
public class LocationInfoDto {
/**
* 场所隐藏状态
*/
private String isHidden;
/**
* 该场所的所有人物id
*/
// List<Integer> personIdList = new ArrayList<>();
/**
* 该场所的所有人物id和见面次数
*/
Map<Integer, Integer> personInfoMap = new HashMap<>();
}
package com.qiwu.inference.dto;
import lombok.Data;
@Data
public class PersonInfoDto {
}
......@@ -37,9 +37,9 @@ public class Player {
*/
private String total;
/**
* 当前关卡已完成次数
* 当前关卡完成状态:0-未完成,1-已完成
*/
private String finished;
private int finished = 0;
/**
* 玩家在线状态
*/
......@@ -63,16 +63,16 @@ public class Player {
/**
* 人物集合
*/
private Map<Integer,Person> personMap;
private Map<Integer,Person> personMap = new HashMap<>();
/**
* 人物的姓名和编号转换 map
*/
private Map<String,Integer> name2IdMap;
private Map<String,Integer> name2IdMap = new HashMap<>();
/**
* 当前关卡的货币
*/
private Double currency = 1000.0;
private Double currency = 3000.0;
/**
* 当前关卡的积分
*/
......@@ -93,6 +93,11 @@ public class Player {
private Map<Integer,Map<Integer,List<ClueDto>>> clueMap = new HashMap<>();
/**
* 场所表
*/
private Map<String, LocationInfoDto> locationMap = new HashMap<>();
/**
* 线索集合表
*/
private List<ClueDto> clues = new ArrayList<>();
......@@ -102,21 +107,45 @@ public class Player {
*/
private Map<Integer,Map<Integer,Integer>> taskMap = new HashMap<>();
/**
* 已完成任务个数
*/
private int finishedTaskNum = 0;
public Player(){
//初始化推理游戏人物
List<String> keys = new ArrayList<>(TimingAcquisition.gateInfoMap.keySet());
int index = RandomUtil.randomInt(keys.size());
this.gateNo = keys.get(index);
List<Person> personList = TimingAcquisition.gateInfoMap.get(keys.get(index));
personMap = new HashMap<>();
name2IdMap = new HashMap<>();
for (Person person : personList) {
taskMap.put(person.getId(), new HashMap<>());
personMap.put(person.getId(), person);
name2IdMap.put(person.getName(), person.getId());
}
}
/**
* 任务个数更新时间
*/
private String numUpdateTime;
/**
* 需要提示任务线索的标识
*/
private boolean tipFlag = false;
/**
* 记录玩家当前闲聊次数
*/
private int chatTimes = 0;
// public Player(){
// //初始化推理游戏人物
// List<String> keys = new ArrayList<>(TimingAcquisition.gateInfoMap.keySet());
// int index = RandomUtil.randomInt(keys.size());
// this.gateNo = keys.get(index);
// List<Person> personList = TimingAcquisition.gateInfoMap.get(keys.get(index));
// List<Person> personCopyList = new ArrayList<>(personList);
// Map<Integer,Map<Integer,Integer>> taskMapCopy = new HashMap<>();
// Map<Integer,Person> personMapCopy = new HashMap<>();
// Map<String,Integer> name2IdMapCopy = new HashMap<>();
// for (Person person : personCopyList) {
// taskMapCopy.put(person.getId(), new HashMap<>());
// personMapCopy.put(person.getId(), person);
// name2IdMapCopy.put(person.getName(), person.getId());
// }
// taskMap.putAll(taskMapCopy);
// personMap.putAll(personMapCopy);
// name2IdMap.putAll(name2IdMapCopy);
// }
/**
* 读取json文件数据
......
package com.qiwu.inference.dto;
import lombok.Data;
import java.util.Map;
@Data
public class PostTaskDto {
/**
* 人物id
*/
private Integer personId;
/**
* 后置任务的前置任务完成情况: Map<后置任务id, Map<前置任务id, 完成状态>>
*/
Map<Integer, TaskStatusDto> taskStatusMap;
}
package com.qiwu.inference.dto;
import lombok.Data;
@Data
public class PostTaskRecordDto {
/**
* 人物id
*/
private Integer personId;
/**
* 后置任务id
*/
private Integer postTaskId;
/**
* 前置任务id
*/
private Integer preTaskId;
/**
* 完成状态: 0-未完成, 1-已完成
*/
private Integer status;
/**
* 优先级标记
*/
private Integer level;
}
package com.qiwu.inference.dto;
import lombok.Data;
@Data
public class TaskStatusDto {
/**
* 任务id
*/
private Integer taskId;
/**
* 完成状态
*/
private Integer status;
}
package com.qiwu.inference.pojo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@Data
public class ChatSpeech implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("意图反馈")
private Integer methodId;
@ApiModelProperty("身份")
private String identity;
@ApiModelProperty("人物ID")
private Integer personId;
@ApiModelProperty("性别")
private String gender;
@ApiModelProperty("年龄段")
private String age;
@ApiModelProperty("性格A")
private String dispositionIds;
@ApiModelProperty("行为")
private String behaviour;
@ApiModelProperty("任务状态")
private String taskStatus;
@ApiModelProperty("关系")
private String degree;
@ApiModelProperty("文本内容")
private String answer;
@ApiModelProperty("通用标签")
private String flag;
}
package com.qiwu.inference.pojo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@Data
public class ClueSpeech implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("线索ID")
private Integer clueId;
@ApiModelProperty("任务名称")
private String taskName;
@ApiModelProperty("身份1")
private String identity;
@ApiModelProperty("性别")
private String gender;
@ApiModelProperty("人物ID")
private Integer personId;
@ApiModelProperty("年龄段")
private String age;
@ApiModelProperty("性格A")
private String dispositionIds;
@ApiModelProperty("行为")
private String behaviour;
@ApiModelProperty("任务状态")
private Integer status;
@ApiModelProperty("线索文本")
private String answer;
@ApiModelProperty("自身线索文本")
private String answerSelf;
@ApiModelProperty("通用标签")
private Integer flag;
}
......@@ -37,6 +37,9 @@ public class EndGoal implements Serializable {
@ApiModelProperty("组合表:1|2|3|4|5")
private String clueGroup;
@ApiModelProperty("关键任务id:60034|60043")
private String associatedTaskId;
@ApiModelProperty("创建时间")
private Date createTime;
......
......@@ -38,6 +38,9 @@ public class Location implements Serializable {
@ApiModelProperty("是否隐藏")
private String isHidden;
@ApiModelProperty("是否必现")
private String isAppear;
@ApiModelProperty("对应线索模板:")
private String clueTemplate;
......
package com.qiwu.inference.pojo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@Data
public class PersonSpeech implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("ID")
private Integer personId;
@ApiModelProperty("人物名称")
private String name;
@ApiModelProperty("人物描述")
private String description;
@ApiModelProperty("首次回复")
private String firstAnswer;
@ApiModelProperty("回复")
private String answer;
}
package com.qiwu.inference.pojo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@Data
public class TaskSpeech implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("线索ID")
private Integer demandTaskId;
@ApiModelProperty("任务名称")
private String taskName;
@ApiModelProperty("身份1")
private String identity;
@ApiModelProperty("性别")
private String gender;
@ApiModelProperty("人物ID")
private Integer personId;
@ApiModelProperty("年龄段")
private String age;
@ApiModelProperty("性格A")
private String dispositionIds;
@ApiModelProperty("行为")
private String behaviour;
@ApiModelProperty("任务状态")
private Integer status;
@ApiModelProperty("进行中任务询问")
private String doingAsk;
@ApiModelProperty("进行中任务完成提醒")
private String doingFinishedAnswer;
@ApiModelProperty("未进行中任务完成提醒")
private String noDoingFinishedAnswer;
@ApiModelProperty("完成对话文本")
private String answer;
@ApiModelProperty("通用标签")
private Integer flag;
}
package com.qiwu.inference.pojo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@Data
public class TipSpeech implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("ID")
private Integer demandTaskId;
@ApiModelProperty("关于自身线索的指引")
private String selfClue;
@ApiModelProperty("关于他人线索的指引")
private String otherClue;
@ApiModelProperty("关于任务的指引")
private String taskClue;
}
......@@ -30,16 +30,6 @@ public class AskServiceImpl implements AskService {
@Override
public CommonResult<ResultVarsResponse> ask(OperationRequest operationReq) {
String uid = operationReq.getUid();
String subjectName = operationReq.getSubjectName(); //人物名称1
String objectName = operationReq.getObjectName(); //人物名称2
//当前玩家上一轮的请求信息
OperationRequest lastReq = (OperationRequest) CacheUtil.get(uid);
if (!StringUtils.isEmpty(lastReq)) {
subjectName = (subjectName == null) ? lastReq.getSubjectName() : subjectName;
objectName = (objectName == null) ? lastReq.getObjectName() : objectName;
}
operationReq.setSubjectName(subjectName);
operationReq.setObjectName(objectName);
//----------------记录见过的人--------------
PlayerUtil.recordClue(uid, TimingAcquisition.playerMap.get(uid).getPersonId());
......
package com.qiwu.inference.service.chat;
import com.qiwu.inference.common.api.CommonResult;
import com.qiwu.inference.dto.request.OperationRequest;
import com.qiwu.inference.dto.response.ResultVarsResponse;
public interface ChatService {
CommonResult<ResultVarsResponse> operate(OperationRequest operationReq);
}
package com.qiwu.inference.service.chat.impl;
import com.qiwu.inference.common.TimingAcquisition;
import com.qiwu.inference.common.api.CommonResult;
import com.qiwu.inference.common.utils.NumberUtil;
import com.qiwu.inference.common.utils.PlayerUtil;
import com.qiwu.inference.common.utils.SpeechUtil;
import com.qiwu.inference.dto.BarrierTaskKeyDto;
import com.qiwu.inference.dto.DispositionDto;
import com.qiwu.inference.dto.Person;
import com.qiwu.inference.dto.Player;
import com.qiwu.inference.dto.request.OperationRequest;
import com.qiwu.inference.dto.response.ResultResponse;
import com.qiwu.inference.dto.response.ResultVarsResponse;
import com.qiwu.inference.pojo.ChatSpeech;
import com.qiwu.inference.service.chat.ChatService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class ChatServiceImpl implements ChatService {
@Override
public CommonResult<ResultVarsResponse> operate(OperationRequest operationReq) {
ResultVarsResponse resultVarsResponse = new ResultVarsResponse();
ResultResponse resultResponse = new ResultResponse();
String uid = operationReq.getUid();
String methodId = operationReq.getMethodId(); //方法编号
Player player = TimingAcquisition.playerMap.get(uid);
//对话人的信息
Person current = player.getPersonMap().get(player.getPersonId());
//获取对应话术
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) {
//找到白名单内该人的任务中已解锁或无需解锁的任务
String addText = PlayerUtil.getTipInChat(uid, current);
if (!StringUtils.isEmpty(addText)) {
addText = "【寒烟@正常】" + addText;
text += addText;
}
}
resultResponse.set反馈ID(600101);
resultResponse.set反馈文本(text);
resultVarsResponse.setVars(resultResponse);
return CommonResult.success(resultVarsResponse);
}
}
......@@ -49,6 +49,8 @@ public class CommonService {
case "1026":
return playerService.askLocation(request);
case "1027":
case "1028":
case "1029":
return playerService.askPrompt(request);
case "2001":
case "2003":
......@@ -91,6 +93,13 @@ public class CommonService {
case "2039":
case "2040":
case "2041":
case "2101":
case "2102":
case "2104":
case "2106":
case "2107":
case "2108":
case "2109":
return playerService.performTask(request);
}
return null;
......
......@@ -7,4 +7,6 @@ import com.qiwu.inference.dto.response.ResultVarsResponse;
public interface LoginService {
CommonResult<ResultVarsResponse> login(String uid);
CommonResult<ResultVarsResponse> startGame(OperationRequest operationReq);
}
......@@ -6,19 +6,18 @@ import com.qiwu.inference.common.Constants;
import com.qiwu.inference.common.TimingAcquisition;
import com.qiwu.inference.common.api.CommonResult;
import com.qiwu.inference.common.utils.*;
import com.qiwu.inference.dto.LocationInfoDto;
import com.qiwu.inference.dto.Person;
import com.qiwu.inference.dto.Player;
import com.qiwu.inference.dto.request.OperationRequest;
import com.qiwu.inference.dto.response.*;
import com.qiwu.inference.pojo.EndGoal;
import com.qiwu.inference.service.login.LoginService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@Service
......@@ -35,11 +34,29 @@ public class LoginServiceImpl implements LoginService {
ResultResponse resultResponse = new ResultResponse();
//存放玩家数据
Map<String, String> sidGateNoMap = new ConcurrentHashMap<>();
String nowTime = DateUtil.getCurrentTime();
Player player = new Player();
player.setSid(uid);
player.setStatus(Constants.ONLINE);
player.setOnlineTime(DateUtil.getCurrentTime());
player.setOnlineTime(nowTime);
//初始化推理游戏人物
List<String> keys = new ArrayList<>(TimingAcquisition.gateInfoMap.keySet());
int random = RandomUtil.randomInt(keys.size());
player.setGateNo(keys.get(random));
List<Person> personsCopy = TimingAcquisition.gateInfoMap.get(keys.get(random));
//深拷贝list
List<Person> personCopyList = PlayerUtil.deepCopyList(personsCopy);
Map<Integer,Map<Integer,Integer>> taskMapCopy = new HashMap<>();
Map<Integer,Person> personMapCopy = new HashMap<>();
Map<String,Integer> name2IdMapCopy = new HashMap<>();
for (Person person : personCopyList) {
taskMapCopy.put(person.getId(), new HashMap<>());
personMapCopy.put(person.getId(), person);
name2IdMapCopy.put(person.getName(), person.getId());
}
player.setTaskMap(taskMapCopy);
player.setPersonMap(personMapCopy);
player.setName2IdMap(name2IdMapCopy);
//给玩家分配场所和对话人物
Map<String, List<Integer>> locationPersonMap = new HashMap<>();
Map<Integer, Person> personMap = player.getPersonMap();
......@@ -67,6 +84,11 @@ public class LoginServiceImpl implements LoginService {
List<Integer> personList = locationPersonMap.get(locationId);
int num = RandomUtil.randomInt(personList.size());
player.setPersonId(personList.get(num));
//生成场所表,包含场所隐藏状态和必现场所
Map<String, LocationInfoDto> locationMap = PlayerUtil.makeLocationMap(locationPersonMap);
player.setLocationMap(locationMap);
//记录玩家第一次的任务个数更新时间
player.setNumUpdateTime(nowTime);
TimingAcquisition.playerMap.put(uid, player);
String playerStr = JSON.toJSONString(player);
//持久化玩家数据
......@@ -79,4 +101,89 @@ public class LoginServiceImpl implements LoginService {
resultVarsResponse.setVars(resultResponse);
return CommonResult.success(resultVarsResponse);
}
@Override
public CommonResult<ResultVarsResponse> startGame(OperationRequest operationReq) {
ResultVarsResponse resultVarsResponse = new ResultVarsResponse();
ResultResponse resultResponse = new ResultResponse();
String uid = operationReq.getUid();
String text = "";
Player player = TimingAcquisition.playerMap.get(uid);
//数据重置
if (player.getFinished() == 1) {
//初始化推理游戏人物
List<String> keys = new ArrayList<>(TimingAcquisition.gateInfoMap.keySet());
int random = RandomUtil.randomInt(keys.size());
player.setGateNo(keys.get(random));
List<Person> personsCopy = TimingAcquisition.gateInfoMap.get(keys.get(random));
//深拷贝list
List<Person> personCopyList = PlayerUtil.deepCopyList(personsCopy);
Map<Integer,Map<Integer,Integer>> taskMapCopy = new HashMap<>();
Map<Integer,Person> personMapCopy = new HashMap<>();
Map<String,Integer> name2IdMapCopy = new HashMap<>();
for (Person person : personCopyList) {
taskMapCopy.put(person.getId(), new HashMap<>());
personMapCopy.put(person.getId(), person);
name2IdMapCopy.put(person.getName(), person.getId());
}
player.setTaskMap(taskMapCopy);
player.setPersonMap(personMapCopy);
player.setName2IdMap(name2IdMapCopy);
player.setCurrency(3000.0);
//给玩家分配场所和对话人物
Map<String, List<Integer>> locationPersonMap = new HashMap<>();
Map<Integer, Person> personMap = player.getPersonMap();
for (Map.Entry<Integer, Person> entry : personMap.entrySet()) {
Person person = entry.getValue();
if (!StringUtils.isEmpty(person.getLocation())) {
//没有当前场所
if (StringUtils.isEmpty(locationPersonMap.get(person.getLocation()))) {
List<Integer> personList = new ArrayList<>();
personList.add(entry.getKey());
locationPersonMap.put(person.getLocation(), personList);
}
//有当前场所,但是没有这个人
List<Integer> persons = locationPersonMap.get(person.getLocation());
if (!persons.contains(entry.getKey())) {
persons.add(entry.getKey());
}
}
}
List<String> locationList = new ArrayList<>(locationPersonMap.keySet());
int index = RandomUtil.randomInt(locationList.size());
String locationId = locationList.get(index);
player.setLocation(locationId);
//随机分配人物
List<Integer> personList = locationPersonMap.get(locationId);
int num = RandomUtil.randomInt(personList.size());
player.setPersonId(personList.get(num));
//生成场所表,包含场所隐藏状态和必现场所
Map<String, LocationInfoDto> locationMap = PlayerUtil.makeLocationMap(locationPersonMap);
player.setLocationMap(locationMap);
}
//关卡编号
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;
}
}
resultResponse.set反馈ID(100009);
resultResponse.set反馈文本(text);
resultVarsResponse.setVars(resultResponse);
return CommonResult.success(resultVarsResponse);
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
server:
port: 60018
serlvet:
context-type:/inference
#设置当前服务名
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/inference_game?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/inferenceGame/speech/
configFilePath: /home/jiaoyou/projects/inferenceGame/config/
userFilePath: /home/jiaoyou/projects/inferenceGame/user/
spring:
profiles:
active: dev
\ No newline at end of file
active: pro
\ No newline at end of file
......@@ -8,8 +8,12 @@
<result column="name" property="name" />
<result column="description" property="description" />
<result column="clue_group" property="clueGroup" />
<result column="associated_task_id" property="associatedTaskId" />
<result column="create_time" property="createTime" />
<result column="update_time" property="updateTime" />
</resultMap>
<select id="findAll" resultMap="BaseResultMap">
select * from end_goal
</select>
</mapper>
......@@ -4,13 +4,15 @@ aside:
- 【旁白@正常】好的,已为您取消操作。
#4001: 场所移动
400101:
- 【旁白@正常】您来到了【1】,【2】在这里,他对你微笑点头。
- 【旁白@正常】您来到了【1】,【2】在这里,【3】对你微笑点头。
400102:
- 【旁白@正常】还不知道这个地方在哪,找个人问问吧。
400103:
- 【旁白@正常】不知道您说的这个地方在哪呢。
400104:
- 【旁白@正常】这个地方没有你要找的人。
400105:
- 【旁白@正常】你想要去哪里呢?目前已知场所有:【1】。
#4002: 开启对话
400201:
- 【旁白@正常】【1】当前线索有:【2】,您要详细查看哪一类的线索呢?
......@@ -43,9 +45,9 @@ aside:
person:
#4001: 场所移动
400101:
- 【人物名称@正常】
- 【人物名称@正常】听说你已经把事办好了,不错不错。
400102:
- 【人物名称@正常】
- 【人物名称@正常】那件事办好了吗?
#4002: 开启对话
400201:
- 【人物名称@正常】【1】
......
......@@ -10,13 +10,13 @@ aside:
30010102:
- 【旁白@正常】当前已知人物有:【1】,需要查看【2】的详情呢?
300102:
- 【旁白@正常】【1】,年龄【2】,性别【3】,【4】对你的信任度为:【5】、威慑度为:【6】,要查看他的相关线索吗?
- 【旁白@正常】【1】,年龄【2】,性别【3】,【4】对你的信任度为:【5】、威慑度为:【6】,要查看【4】的相关线索吗?
30010201:
- 【旁白@正常】【1】,年龄不详,性别不明,可以去找找这个人。
300103:
- 【旁白@正常】【1】当前线索有:【2】,您要详细查看哪一类的线索呢?
30010301:
- 【旁白@正常】您还告诉我想看哪个人的线索呢。
- 【旁白@正常】您没还告诉我想看哪个人的线索呢。
30010302:
- 【旁白@正常】您只见过这个人,还没有收集到线索。
300104:
......@@ -51,7 +51,7 @@ aside:
30050501:
- 【旁白@正常】您当前还没有【1】线索。
300506:
- 【旁白@正常】【1】的【2】线索共【3】条,第【4】条:【5】。
- 【旁白@正常】【1】的【2】线索共【3】条,第【4】条:【5】要查看下一条吗?
30050601:
- 【旁白@正常】您当前还没有收集到【1】的【2】线索。
30050602:
......@@ -65,5 +65,14 @@ aside:
#3006: 询问谁和谁有某个关系
300601:
- 【旁白@正常】您当前排名积分为:【1】。
#3101: 询问某人的模糊处理操作
310101:
- 【寒烟@正常】您还没告诉要看谁的呢。
310102:
- 【寒烟@正常】没有您说的这个人哦。
310103:
- 【寒烟@正常】【1】,年龄【2】,性别【3】,身份【4】,其他信息不详。
310104:
- 【寒烟@正常】【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