Commit 0a43d064 by hxw

添加激活多个剧情

parent 3d56c4c5
...@@ -18,7 +18,7 @@ public class ChatCache implements DisposableBean { ...@@ -18,7 +18,7 @@ public class ChatCache implements DisposableBean {
private Map<String, String> infoPoint = null; private Map<String, String> infoPoint = null;
private GameEnv gameEnv = null; private GameEnv gameEnv = null;
private boolean reloading = false; private boolean gameStart = false;
public String getBotAccount() { public String getBotAccount() {
...@@ -29,9 +29,6 @@ public class ChatCache implements DisposableBean { ...@@ -29,9 +29,6 @@ public class ChatCache implements DisposableBean {
this.botAccount = botAccount; this.botAccount = botAccount;
} }
public boolean isReloading() {
return reloading;
}
public String getUserKey() { public String getUserKey() {
return userKey; return userKey;
...@@ -49,10 +46,6 @@ public class ChatCache implements DisposableBean { ...@@ -49,10 +46,6 @@ public class ChatCache implements DisposableBean {
this.randKey = randKey; this.randKey = randKey;
} }
public void setReloading(boolean reloading) {
this.reloading = reloading;
}
public Map<String, String> getInfoPoint() { public Map<String, String> getInfoPoint() {
return infoPoint; return infoPoint;
} }
...@@ -61,6 +54,14 @@ public class ChatCache implements DisposableBean { ...@@ -61,6 +54,14 @@ public class ChatCache implements DisposableBean {
this.infoPoint = infoPoint; this.infoPoint = infoPoint;
} }
public boolean isGameStart() {
return gameStart;
}
public void setGameStart(boolean gameStart) {
this.gameStart = gameStart;
}
public GameEnv getGameEnv() { public GameEnv getGameEnv() {
return gameEnv; return gameEnv;
} }
......
...@@ -121,7 +121,9 @@ public class CharacterConstructor extends ElementConstructor { ...@@ -121,7 +121,9 @@ public class CharacterConstructor extends ElementConstructor {
} }
} }
keywordMap.put("onlineModeTalkers", onlineModeTalkers);
varInitialMap.put("onlineModeTalkers", onlineModeTalkers.toString()); varInitialMap.put("onlineModeTalkers", onlineModeTalkers.toString());
//System.out.println("onlineModeTalkers" + varInitialMap.get("onlineModeTalkers"));
conditionDescription.put("onlineModeTalkers", "所有在线npc"); conditionDescription.put("onlineModeTalkers", "所有在线npc");
//根据根据NPC的名字查询地点 //根据根据NPC的名字查询地点
......
...@@ -37,17 +37,26 @@ public class MapConstructor extends ElementConstructor { ...@@ -37,17 +37,26 @@ public class MapConstructor extends ElementConstructor {
JSONObject jobj = null; JSONObject jobj = null;
int locationId, index; int locationId, index;
String locationName; String locationName, taskLineName = "";
//ArrayList<ArrayList<Integer>> matrix= new ArrayList<ArrayList<Integer>>();
//ArrayList<Integer> vec1d = new ArrayList<Integer>();
locationNum = locations.size(); locationNum = locations.size();
StringBuffer nameSet = null; StringBuffer nameSet = null;
keywordMap.putIfAbsent("site_list", new StringBuffer());
for (int i = 0; i < locationNum; i++) { for (int i = 0; i < locationNum; i++) {
jobj = locations.getJSONObject(i); jobj = locations.getJSONObject(i);
jobj.put("index", i); jobj.put("index", i);
locationName = (String) jobj.get("name"); locationName = (String) jobj.get("name");
keywordMap.get("site_list").append("+").append(locationName);
taskLineName = String.format(PlotConstructor.TASK_LINE, locationName);
if (!varInitialMap.containsKey(taskLineName)) {
conditionDescription.put(taskLineName, taskLineName);
varInitialMap.put(taskLineName, "");
}
nameSet = new StringBuffer(); nameSet = new StringBuffer();
nameSet.append(locationName); nameSet.append(locationName);
...@@ -211,8 +220,6 @@ public class MapConstructor extends ElementConstructor { ...@@ -211,8 +220,6 @@ public class MapConstructor extends ElementConstructor {
/** /**
* 生成‘怎么去哪里’所需要的配置文件 * 生成‘怎么去哪里’所需要的配置文件
*/ */
...@@ -220,66 +227,60 @@ public class MapConstructor extends ElementConstructor { ...@@ -220,66 +227,60 @@ public class MapConstructor extends ElementConstructor {
String conditionName = "want_know_zenmezuo"; String conditionName = "want_know_zenmezuo";
StringBuffer placeKeywords = new StringBuffer(); StringBuffer placeKeywords = new StringBuffer();
String placeA, placeB, descriptionB, text, pathNode; String nameSet;
for (int i = 0; i < locationNum; i++) { for (int i = 0; i < locationNum; i++) {
placeA = (String) locations.getJSONObject(i).get("nameSet"); nameSet = (String) locations.getJSONObject(i).get("nameSet");
placeKeywords.append("+" + placeA); placeKeywords.append("+").append(nameSet);
} }
for (int j = 0; j < locationNum; j++) {
placeB = (String) locations.getJSONObject(j).get("nameSet");
jConfig = new JConfig(
conditionName + "::match-Include=" + placeKeywords
+ ",isNeighbour:"+ conditionName + "::match-Include=0",
"site::match-Include=" + placeB ,
"match,return-0",
"",
" ",
"map_query:queryPathAt:"
);
jConfig.setNextStepStatus("return-0");
jConfig.setAuxiliaryPriority("1");
JConfig.activateCopy(jConfig, jConfigList, "map");
jConfig = new JConfig(
conditionName + "::match-Include=" + placeKeywords
+ ",isNeighbour:"+ conditionName + "::match-Include=0",
" ",
"match,return-0",
"",
" ",
"map_query:queryPathAt:"
);
jConfig.setNextStepStatus("return-0");
jConfig.setAuxiliaryPriority("1");
JConfig.activateCopy(jConfig, jConfigList, "map");
jConfig = new JConfig(
conditionName + "::match-Include=" + placeKeywords
+ ",isNeighbour:"+ conditionName + "::match-Include=1+3+4",
" " ,
"match,return-0",
"",
" ",
"map_query:queryPathAdjoin:"
);
jConfig.setNextStepStatus("return-0");
jConfig.setAuxiliaryPriority("1");
JConfig.activateCopy(jConfig, jConfigList, "map");
jConfig = new JConfig(
conditionName + "::match-Include=" + placeKeywords
+ ",isNeighbour:"+ conditionName + "::match-Include=1+3+4",
"site::match-Include=" + placeB ,
"match,return-0",
"",
" ",
"map_query:queryPathAdjoin:"
);
jConfig.setNextStepStatus("return-0");
jConfig.setAuxiliaryPriority("1");
JConfig.activateCopy(jConfig, jConfigList, "map");
jConfig = new JConfig(
conditionName + "::match-Include=" + placeKeywords
+ ",isNeighbour:"+ conditionName + "::match-Include=2",
" " ,
"match,return-0",
"",
" ",
"map_query:queryHowToPathBySite:" + conditionName
);
jConfig.setNextStepStatus("return-0");
jConfig.setAuxiliaryPriority("1");
JConfig.activateCopy(jConfig, jConfigList, "map");
jConfig = new JConfig(
conditionName + "::match-Include=" + placeKeywords
+ ",isNeighbour:"+ conditionName + "::match-Include=2",
"site::match-Include=" + placeB ,
"match,return-0",
"",
" ",
"map_query:queryHowToPathBySite:" + conditionName
);
jConfig.setNextStepStatus("return-0");
jConfig.setAuxiliaryPriority("1");
JConfig.activateCopy(jConfig, jConfigList, "map");
}
} }
......
...@@ -235,7 +235,7 @@ public class FormsPoster { ...@@ -235,7 +235,7 @@ public class FormsPoster {
} }
} else { } else {
logWriter.record(textscore + "没找到npc名字", 1); logWriter.record(textscore + "没找到npc名字", 1);
historyInfoPoint.put("common_answer", ResponseFilter.appendTalker((String)textscore.get(0), curInfoPoint, historyInfoPoint, gameEnv, worldController)); historyInfoPoint.put("common_answer", ResponseFilter.appendTalker((String)textscore.get(0), historyInfoPoint, gameEnv, worldController));
historyInfoPoint.put("qa_score", String.valueOf(textscore.get(1))); historyInfoPoint.put("qa_score", String.valueOf(textscore.get(1)));
break; break;
} }
......
...@@ -55,7 +55,7 @@ public class QuestionMatcher { ...@@ -55,7 +55,7 @@ public class QuestionMatcher {
/** /**
* 用迭代器迭代当前信息点中的非空关键字,由conditionName索引到状态表中保存包含conditionName这个条件的列表,并查询状态表中的条件是否满足及其优先级,满足条件且优先级更高就设为bestMatch * 用迭代器迭代当前信息点中的非空关键字,由conditionName索引到状态表中保存的包含conditionName这个条件的列表,并查询状态表中的条件是否满足,优先级是否更高,满足条件且优先级更高就设为bestMatch
* *
* @param conditionTable 满足什么条件,就回答什么,下一步跳什么 * @param conditionTable 满足什么条件,就回答什么,下一步跳什么
* @return bestMatch 状态表中满足条件最多的一条 * @return bestMatch 状态表中满足条件最多的一条
......
...@@ -5,9 +5,7 @@ import com.qiwu.chatbotbackend.entity.Condition; ...@@ -5,9 +5,7 @@ import com.qiwu.chatbotbackend.entity.Condition;
import com.qiwu.chatbotbackend.entity.UserInfo; import com.qiwu.chatbotbackend.entity.UserInfo;
import com.qiwu.chatbotbackend.gameDesign.PlotConstructor; import com.qiwu.chatbotbackend.gameDesign.PlotConstructor;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -31,7 +29,7 @@ public class ResponseFilter { ...@@ -31,7 +29,7 @@ public class ResponseFilter {
reply = MyFunc.randStr(reply.split("~")); reply = MyFunc.randStr(reply.split("~"));
if(reply.endsWith("开始游戏或者继续游戏")){ if(reply.endsWith("请说开始剧情或者继续剧情")){
return reply; return reply;
} }
...@@ -44,7 +42,7 @@ public class ResponseFilter { ...@@ -44,7 +42,7 @@ public class ResponseFilter {
}else if (sameLocation(reply, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 1){ }else if (sameLocation(reply, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 1){
return reply; return reply;
}else if (sameLocation(reply, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 0 && !reply.equals("")){ }else if (sameLocation(reply, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 0 && !reply.equals("")){
return appendTalker(reply,curInfoPoint, historyInfoPoint, gameEnv, worldController); return appendTalker(reply, historyInfoPoint, gameEnv, worldController);
}else if (reply.equals("") && ( }else if (reply.equals("") && (
(historyInfoPoint.get("common_answer") != null && !historyInfoPoint.get("common_answer").equals(""))) (historyInfoPoint.get("common_answer") != null && !historyInfoPoint.get("common_answer").equals("")))
|| (historyInfoPoint.get("map_query") != null && !historyInfoPoint.get("map_query").equals("")) || (historyInfoPoint.get("map_query") != null && !historyInfoPoint.get("map_query").equals(""))
...@@ -63,50 +61,51 @@ public class ResponseFilter { ...@@ -63,50 +61,51 @@ public class ResponseFilter {
String lastTalker = ""; String lastTalker = "";
//如果作者当前地点和剧情所在地点相同,那么回答unknown文本的人必须是上个剧情中的人 //如果作者当前地点和剧情所在地点相同,那么回答unknown文本的人必须是上个剧情中的人
if(historyInfoPoint.get("game_step").endsWith(historyInfoPoint.get(String.format(PlotConstructor.TASK_LINE, site)))){ // if(historyInfoPoint.get("game_step").endsWith(historyInfoPoint.get(String.format(PlotConstructor.TASK_LINE, site)))){
Matcher m = findTalker(historyInfoPoint.get(String.format(PlotConstructor.TASK_REPLY, site))); // Matcher m = findTalker(historyInfoPoint.get(String.format(PlotConstructor.TASK_REPLY, site)));
while(m.find()) { // while(m.find()) {
//回答unknown文本的npc必须处于在线模式 // //回答unknown文本的npc必须处于在线模式
npc = m.group(1); // npc = m.group(1);
if(historyInfoPoint.get("onlineModeTalkers").contains("," + npc + ",")) { // if(isOnlineMode(npc, historyInfoPoint)) {
lastTalker = npc; // lastTalker = npc;
}else{ // }else{
System.out.println(npc + "是离线模式"); // System.out.println(npc + "是离线模式");
} // }
} // }
//
for (String ans : userInfo.varInitialMap.get("unknownTextList").split("~")) { // for (String ans : userInfo.varInitialMap.get("unknownTextList").split("~")) {
if (ans.equals("")) // if (ans.equals(""))
continue; // continue;
if (ans.contains(lastTalker) &&sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 1) { // if (ans.contains(lastTalker) &&sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 1) {
//
unknownList.add(ans); // if(isOnlineText(ans, historyInfoPoint))
//return ans; // unknownList.add(ans);
} else if (sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 0) { // //return ans;
unknownList.add(appendTalker(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController)); // } else if (sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 0) {
} // unknownList.add(appendTalker(ans, historyInfoPoint, gameEnv, worldController));
} // }
if (unknownList.size() > 0) { // }
return MyFunc.randStr(unknownList); // if (unknownList.size() > 0) {
} // return MyFunc.randStr(unknownList);
// }
}else { //
// }else {
for (String ans : userInfo.varInitialMap.get("unknownTextList").split("~")) { for (String ans : userInfo.varInitialMap.get("unknownTextList").split("~")) {
if (ans.equals("")) if (ans.equals(""))
continue; continue;
if (sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 1) { if (sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 1) {
if(isOnlineText(ans, historyInfoPoint))
unknownList.add(ans); unknownList.add(ans);
//return ans; //return ans;
} else if (sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 0) { } else if (sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 0) {
unknownList.add(appendTalker(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController)); unknownList.add(appendTalker(ans, historyInfoPoint, gameEnv, worldController));
} }
} }
if (unknownList.size() > 0) { if (unknownList.size() > 0) {
return MyFunc.randStr(unknownList); return MyFunc.randStr(unknownList);
} }
} // }
} }
if(userInfo.varInitialMap.get("finalUnknownText") != null){ if(userInfo.varInitialMap.get("finalUnknownText") != null){
...@@ -118,10 +117,11 @@ public class ResponseFilter { ...@@ -118,10 +117,11 @@ public class ResponseFilter {
if(ans.equals("")) if(ans.equals(""))
continue; continue;
if (sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 1){ if (sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 1){
finalUnknownList.add(ans); if(isOnlineText(ans, historyInfoPoint))
finalUnknownList.add(ans);
//return ans; //return ans;
}else if(sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 0){ }else if(sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 0){
finalUnknownList.add(appendTalker(ans,curInfoPoint, historyInfoPoint, gameEnv, worldController)); finalUnknownList.add(appendTalker(ans, historyInfoPoint, gameEnv, worldController));
} }
} }
if(finalUnknownList.size() > 0){ if(finalUnknownList.size() > 0){
...@@ -148,7 +148,7 @@ public class ResponseFilter { ...@@ -148,7 +148,7 @@ public class ResponseFilter {
* 查看回答文本的说话这是否在当前地点 * 查看回答文本的说话这是否在当前地点
* 0:没有说话者 * 0:没有说话者
* 1:说话者在当前地点 * 1:说话者在当前地点
* 2:说话者不在当前地点 * 2:说话者不在当前地点或者不能说话
* @param reply * @param reply
* @param curInfoPoint * @param curInfoPoint
* @param historyInfoPoint * @param historyInfoPoint
...@@ -158,9 +158,6 @@ public class ResponseFilter { ...@@ -158,9 +158,6 @@ public class ResponseFilter {
* @param logWriter * @param logWriter
* @return * @return
*/ */
static Integer sameLocation(String reply, Map<String ,String> curInfoPoint, Map<String ,String> historyInfoPoint, GameEnv gameEnv, WorldController worldController, String site, LogWriter logWriter){ static Integer sameLocation(String reply, Map<String ,String> curInfoPoint, Map<String ,String> historyInfoPoint, GameEnv gameEnv, WorldController worldController, String site, LogWriter logWriter){
String npc, location; String npc, location;
...@@ -190,17 +187,50 @@ public class ResponseFilter { ...@@ -190,17 +187,50 @@ public class ResponseFilter {
} }
static String appendTalker(String reply, Map<String ,String> curInfoPoint, Map<String ,String> historyInfoPoint, GameEnv gameEnv, WorldController worldController){ /**
* 在头部没有【%s@%s】的文本加上【%s@%s】
* @param reply
* @param historyInfoPoint
* @param gameEnv
* @param worldController
* @return
*/
static String appendTalker(String reply, Map<String ,String> historyInfoPoint, GameEnv gameEnv, WorldController worldController){
List<String> npcList = gameEnv.queryAroundNpcBySite(historyInfoPoint.get("site")); List<String> npcList = gameEnv.queryAroundNpcBySite(historyInfoPoint.get("site"));
String npc = ""; String npc = "";
if(npcList.size() != 0) List<String> filtedNpcList = new ArrayList<String>();
npc = MyFunc.randStr(npcList);
for(String npcName:npcList){
if(isOnlineMode(npcName, historyInfoPoint)) {
filtedNpcList.add(npcName);
}else{
System.out.println(npcName + "是离线模式");
}
}
if(filtedNpcList.size() != 0)
npc = MyFunc.randStr(filtedNpcList);
else else
npc = historyInfoPoint.get(PlotConstructor.ASSISTANT); npc = historyInfoPoint.get(PlotConstructor.ASSISTANT);
return "【" + npc + "@0】" + reply;
return String.format(TALKER_PATTERN, npc, PlotConstructor.ASSISTANT_EMOTION) + reply;
}
static Boolean isOnlineMode(String npc, Map<String, String> historyInfoPoint){
return historyInfoPoint.get("onlineModeTalkers").contains("," + npc + ",");
}
static Boolean isOnlineText(String text, Map<String, String> historyInfoPoint){
Matcher m = findTalker(text);
String npc = "";
if(m.find()) {
npc = m.group(1);
return historyInfoPoint.get("onlineModeTalkers").contains("," + npc + ",");
}else{
System.out.println("竟然没找到npc");
return false;
}
} }
} }
package com.qiwu.chatbotbackend.servlet; package com.qiwu.chatbotbackend.servlet;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.processing.ChatCacheController2; import com.qiwu.chatbotbackend.processing.ChatCacheController;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.ServletException; import javax.servlet.ServletException;
...@@ -24,7 +24,7 @@ public class FindCacheServlet extends HttpServlet { ...@@ -24,7 +24,7 @@ public class FindCacheServlet extends HttpServlet {
Boolean exist = false; Boolean exist = false;
try { try {
exist = ChatCacheController2.findChatCache(userKey, context, botAccount); exist = ChatCacheController.findChatCache(userKey, context, botAccount);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -133,15 +133,15 @@ public class GameDesignServlet extends HttpServlet { ...@@ -133,15 +133,15 @@ public class GameDesignServlet extends HttpServlet {
switch (moduleName) { switch (moduleName) {
case "map": case "map":
moduleName2 = "地图"; moduleName2 = "地图";
constructor = new MapConstructor2(helper, botId, botAccount, keywordMap, exceptRelation, POS); constructor = new MapConstructor(helper, botId, botAccount, keywordMap, exceptRelation, POS);
constructor.construct(gameElements, userinfo); constructor.construct(gameElements, userinfo);
break; break;
case "plots": case "plots":
moduleName2 = "剧情"; moduleName2 = "剧情";
constructor = new PlotConstructor(helper, botId, botAccount, keywordMap, exceptRelation, POS); constructor = new PlotConstructor2(helper, botId, botAccount, keywordMap, exceptRelation, POS);
constructor.construct(gameElements, userinfo); constructor.construct(gameElements, userinfo);
root = ((PlotConstructor) constructor).getId2j().get((String) gameElements.get("start")); root = ((PlotConstructor2) constructor).getId2j().get((String) gameElements.get("start"));
break; break;
case "goods": case "goods":
moduleName2 = "物品"; moduleName2 = "物品";
......
...@@ -91,7 +91,7 @@ public class GetAnswerServlet extends HttpServlet { ...@@ -91,7 +91,7 @@ public class GetAnswerServlet extends HttpServlet {
Boolean loadCacheStatus = Boolean.valueOf(false); Boolean loadCacheStatus = Boolean.valueOf(false);
try { try {
//chatCache = ChatCacheController.getChatCache2(userKey, randKey, context, userinfo, receiveParamters, loadCacheStatus); //chatCache = ChatCacheController.getChatCache2(userKey, randKey, context, userinfo, receiveParamters, loadCacheStatus);
chatCache = ChatCacheController2.getChatCache(userKey, randKey, context, userinfo, receiveParamters, loadCacheStatus); chatCache = ChatCacheController.getChatCache(userKey, randKey, context, userinfo, receiveParamters, loadCacheStatus);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} catch (Exception e) { } catch (Exception e) {
...@@ -158,12 +158,12 @@ public class GetAnswerServlet extends HttpServlet { ...@@ -158,12 +158,12 @@ public class GetAnswerServlet extends HttpServlet {
matcher.infoTransfer(bestMatch, context, debugFlag); matcher.infoTransfer(bestMatch, context, debugFlag);
ChatCacheController2.updateChatCache4Insert(curInfoPoint, chatCache.getInfoPoint(), chatCache.getGameEnv(), context, userinfo); ChatCacheController.updateChatCache4Insert(curInfoPoint, chatCache.getInfoPoint(), chatCache.getGameEnv(), context, userinfo);
//清理超时的用户数据 //清理超时的用户数据
if (context.getAttribute("cacheUpdateTime") == null) if (context.getAttribute("cacheUpdateTime") == null)
context.setAttribute("cacheUpdateTime", System.currentTimeMillis()); context.setAttribute("cacheUpdateTime", System.currentTimeMillis());
if (System.currentTimeMillis() - (long) context.getAttribute("cacheUpdateTime") > ChatCacheController2.TIME_OUT) { if (System.currentTimeMillis() - (long) context.getAttribute("cacheUpdateTime") > ChatCacheController.TIME_OUT) {
ChatCacheController2.updateChatCache4Delete(chatKey, context, userinfo); ChatCacheController.updateChatCache4Delete(chatKey, context, userinfo);
context.setAttribute("cacheUpdateTime", System.currentTimeMillis()); context.setAttribute("cacheUpdateTime", System.currentTimeMillis());
} }
......
...@@ -2,7 +2,7 @@ package com.qiwu.chatbotbackend.servlet; ...@@ -2,7 +2,7 @@ package com.qiwu.chatbotbackend.servlet;
import com.qiwu.chatbotbackend.db.SqlHelper; import com.qiwu.chatbotbackend.db.SqlHelper;
import com.qiwu.chatbotbackend.entity.ChatCache; import com.qiwu.chatbotbackend.entity.ChatCache;
import com.qiwu.chatbotbackend.processing.ChatCacheController2; import com.qiwu.chatbotbackend.processing.ChatCacheController;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextEvent;
...@@ -38,7 +38,10 @@ public class MyListener implements ServletContextListener { ...@@ -38,7 +38,10 @@ public class MyListener implements ServletContextListener {
try { try {
helper = new SqlHelper(); helper = new SqlHelper();
System.out.println(String.format("saving %s", chatKey)); System.out.println(String.format("saving %s", chatKey));
ChatCacheController2.saveChatCache(cache, helper); //当用户id和随机对话id不同时,表示用户为登录状态,用户登录且开始游戏,则可以存档
if(cache != null && !cache.getRandKey().equals(cache.getUserKey()) && cache.isGameStart()) {
ChatCacheController.saveChatCache(cache, helper);
}
}catch (Exception e){ }catch (Exception e){
System.out.println(String.format("保存%s时出现异常", chatKey)); System.out.println(String.format("保存%s时出现异常", chatKey));
} }
......
...@@ -2,7 +2,7 @@ package com.qiwu.chatbotbackend.servlet; ...@@ -2,7 +2,7 @@ package com.qiwu.chatbotbackend.servlet;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.entity.ChatCache; import com.qiwu.chatbotbackend.entity.ChatCache;
import com.qiwu.chatbotbackend.processing.ChatCacheController2; import com.qiwu.chatbotbackend.processing.ChatCacheController;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.ServletException; import javax.servlet.ServletException;
...@@ -27,8 +27,8 @@ public class SaveChatCacheServlet extends HttpServlet { ...@@ -27,8 +27,8 @@ public class SaveChatCacheServlet extends HttpServlet {
ChatCache chatCache = chatCacheMap.get(chatKey); ChatCache chatCache = chatCacheMap.get(chatKey);
if(chatCache != null && !chatCache.getRandKey().equals(chatCache.getUserKey()) && chatCache.isReloading()) { if(chatCache != null && !chatCache.getRandKey().equals(chatCache.getUserKey()) && chatCache.isGameStart()) {
flag = ChatCacheController2.saveChatCache(chatCache, null); flag = ChatCacheController.saveChatCache(chatCache, null);
chatCacheMap.remove(chatKey); chatCacheMap.remove(chatKey);
} }
......
...@@ -5,7 +5,6 @@ import com.qiwu.chatbotbackend.db.SqlHelper; ...@@ -5,7 +5,6 @@ import com.qiwu.chatbotbackend.db.SqlHelper;
import com.qiwu.chatbotbackend.entity.*; import com.qiwu.chatbotbackend.entity.*;
import com.qiwu.chatbotbackend.gameDesign.PlotConstructor; import com.qiwu.chatbotbackend.gameDesign.PlotConstructor;
import com.qiwu.chatbotbackend.processing.ChatCacheController; import com.qiwu.chatbotbackend.processing.ChatCacheController;
import com.qiwu.chatbotbackend.processing.ChatCacheController2;
import com.qiwu.chatbotbackend.processing.LogWriter; import com.qiwu.chatbotbackend.processing.LogWriter;
import com.qiwu.chatbotbackend.processing.WorldController; import com.qiwu.chatbotbackend.processing.WorldController;
...@@ -88,6 +87,8 @@ public class GameBotUtil extends BasicBotUtil{ ...@@ -88,6 +87,8 @@ public class GameBotUtil extends BasicBotUtil{
} }
} }
//将自动跳转文本、qa文本、查询文本拼接
String queryList[] = { "plot_jump_text" ,"common_answer","map_query", "goods_query", "npc_query"}; String queryList[] = { "plot_jump_text" ,"common_answer","map_query", "goods_query", "npc_query"};
String queryResult; String queryResult;
for(String queryName:queryList){ for(String queryName:queryList){
...@@ -215,13 +216,13 @@ public class GameBotUtil extends BasicBotUtil{ ...@@ -215,13 +216,13 @@ public class GameBotUtil extends BasicBotUtil{
if(ansCondition.featureMap.containsKey("newGame")) { if(ansCondition.featureMap.containsKey("newGame")) {
System.out.println("newGame"); System.out.println("newGame");
this.chatCache.setReloading(true); this.chatCache.setGameStart(true);
}else if (ansCondition.featureMap.containsKey("gameBackup")) { }else if (ansCondition.featureMap.containsKey("gameBackup")) {
System.out.println("gameBackup"); System.out.println("gameBackup");
if(! userKey.equals(randKey)) { //两者不同时表示用户已登录,才有权限存档 if(! userKey.equals(randKey)) { //两者不同时表示用户已登录,才有权限存档
chatCache = new ChatCache(userKey, randKey, gameEnv, historyInfoPoint); chatCache = new ChatCache(userKey, randKey, gameEnv, historyInfoPoint);
flag = ChatCacheController2.saveChatCache(chatCache, null); flag = ChatCacheController.saveChatCache(chatCache, null);
if(flag) if(flag)
solution.setAnswer(String.format(TALKER_PATTERN, historyInfoPoint.get(ASSISTANT), ASSISTANT_EMOTION) + "存档成功"); solution.setAnswer(String.format(TALKER_PATTERN, historyInfoPoint.get(ASSISTANT), ASSISTANT_EMOTION) + "存档成功");
else else
...@@ -235,6 +236,7 @@ public class GameBotUtil extends BasicBotUtil{ ...@@ -235,6 +236,7 @@ public class GameBotUtil extends BasicBotUtil{
System.out.println("loadLastArchive"); System.out.println("loadLastArchive");
ArchiveInfo archiveInfo = helper.queryUserLastGameArchive(userKey); ArchiveInfo archiveInfo = helper.queryUserLastGameArchive(userKey);
loading(archiveInfo, solution); loading(archiveInfo, solution);
this.chatCache.setGameStart(true);
} else if (ansCondition.featureMap.containsKey("loadArchiveBySite")) { } else if (ansCondition.featureMap.containsKey("loadArchiveBySite")) {
System.out.println("loadArchiveBySite"); System.out.println("loadArchiveBySite");
...@@ -243,6 +245,7 @@ public class GameBotUtil extends BasicBotUtil{ ...@@ -243,6 +245,7 @@ public class GameBotUtil extends BasicBotUtil{
System.out.println("要读取的存档的地点是:" + site); System.out.println("要读取的存档的地点是:" + site);
ArchiveInfo archiveInfo = helper.queryUserLastGameArchiveBySite(userKey, site); ArchiveInfo archiveInfo = helper.queryUserLastGameArchiveBySite(userKey, site);
loading(archiveInfo, solution); loading(archiveInfo, solution);
this.chatCache.setGameStart(true);
}else{ }else{
System.out.println("没有识别到" + LOAD_BY_SITE_CONDITION); System.out.println("没有识别到" + LOAD_BY_SITE_CONDITION);
} }
...@@ -261,9 +264,14 @@ public class GameBotUtil extends BasicBotUtil{ ...@@ -261,9 +264,14 @@ public class GameBotUtil extends BasicBotUtil{
String keyword = "", site; String keyword = "", site;
ChatCache loadCache = null; ChatCache loadCache = null;
//如果存在读档,就要将自动跳转和qa的临时数据清空
historyInfoPoint.put("plot_jump_text", "");
historyInfoPoint.put("common_answer", "");
if (archiveInfo != null) { if (archiveInfo != null) {
try { try {
loadCache = ChatCacheController2.loadChatCache(archiveInfo); loadCache = ChatCacheController.loadChatCache(archiveInfo);
} catch (Exception e) { } catch (Exception e) {
System.out.println("从本地加载存档失败"); System.out.println("从本地加载存档失败");
solution.setAnswer("从本地加载存档失败"); solution.setAnswer("从本地加载存档失败");
...@@ -271,8 +279,6 @@ public class GameBotUtil extends BasicBotUtil{ ...@@ -271,8 +279,6 @@ public class GameBotUtil extends BasicBotUtil{
} }
this.chatCache.setInfoPoint(loadCache.getInfoPoint()); this.chatCache.setInfoPoint(loadCache.getInfoPoint());
this.chatCache.setGameEnv(loadCache.getGameEnv()); this.chatCache.setGameEnv(loadCache.getGameEnv());
// this.historyInfoPoint = chatCache.getInfoPoint();
// this.gameEnv = chatCache.getGameEnv();
System.out.println("----------读档中------------"); System.out.println("----------读档中------------");
......
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