Commit f0e522d1 by hxw

优化游戏生成效率

parent 955c5e93
......@@ -116,14 +116,15 @@ public class CharacterConstructor extends ElementConstructor {
for (String conditionName : locationRelateConditions) {
jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName), " ",
"match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{npc_query-2}", "yaobuyao", "npc_query:queryLocationByConditionName:" + conditionName
"match,return-0", "", "yaobuyao", "npc_query:queryLocationByConditionName:" + conditionName
);
JConfig.activateCopy(jConfig, jConfigList, "npc");
//zainali 和wenzainali 都识别到时优先匹配wenzainali
jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName) + "," +
"zainali::match-Keyword=" + keywordMap.get("map_zainali").toString(), " ",
"match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{npc_query-2}", "yaobuyao", "npc_query:queryLocationByConditionName:" + conditionName
"match,return-0", "", "yaobuyao", "npc_query:queryLocationByConditionName:" + conditionName
);
JConfig.activateCopy(jConfig, jConfigList, "npc");
//jConfigList.add(jConfig);
......@@ -133,7 +134,7 @@ public class CharacterConstructor extends ElementConstructor {
for(String conditionName: attrRelateConditions){
jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName), " ",
"match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{npc_query-2}", "yaobuyao",
"match,return-0", "", "yaobuyao",
"npc_query:queryAttrByNPCName:" + conditionName
);
JConfig.activateCopy(jConfig, jConfigList, "npc");
......@@ -144,7 +145,7 @@ public class CharacterConstructor extends ElementConstructor {
jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName), " ",
"match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{npc_query-2}", "yaobuyao",
"match,return-0", "", "yaobuyao",
"npc_query:queryAroundNpcByClassName:" + conditionName
);
JConfig.activateCopy(jConfig, jConfigList, "npc");
......@@ -156,7 +157,7 @@ public class CharacterConstructor extends ElementConstructor {
jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("npc_" + conditionName).toString(), " ",
"match,return-0",
"【{" + PlotConstructor.ASSISTANT + "-2}】" +"{npc_query-2}",
"",
" ",
"npc_query:queryFindNPCWay:" + conditionName
);
......@@ -168,7 +169,7 @@ public class CharacterConstructor extends ElementConstructor {
jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("talker_" + conditionName).toString().replace("botname", botName), " ",
"match,return-0",
"{npc_query-2}",
"",
" ",
"npc_query:queryLastTalker:"
);
......
......@@ -26,20 +26,18 @@ public class GlobalVariableConstructor extends ElementConstructor {
try {
String category, name, description, attrValue;
JSONArray globalVariable = gameElements.getJSONArray("globalVariable");
JSONObject globalVariable = gameElements.getJSONObject("globalVariable");
Map<String, String> attribute = null;
Iterator<String> attrIter = null;
for (JSONObject variableList : globalVariable.toJavaList(JSONObject.class)) {
category = (String) variableList.get("category");
attribute = gameElements.toJavaObject(variableList.getJSONObject("variables"), Map.class);
for(String attrName:attribute.keySet()) {
attrValue = attribute.get(attrName);
for(String attrName:globalVariable.keySet()) {
attrValue = (String)globalVariable.get(attrName);
varInitialMap.put("globalVariable_" + attrName, attrValue);
}
}
varInitialMap.put("botType", "game");
varInitialMap.put("unknownTextList", (String)gameElements.get("unknownTextList"));
......
......@@ -113,7 +113,7 @@ public class ItemConstructor extends ElementConstructor {
conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString() + "," +
"zainali::match-Keyword=" + keywordMap.get("map_zainali").toString(), " ",
"match,return-0",
"【{" + PlotConstructor.ASSISTANT + "-2}】" +"{goods_query-2}",
"",
" ",
"goods_query:queryLocationByConditionName:" + conditionName
);
......@@ -121,7 +121,7 @@ public class ItemConstructor extends ElementConstructor {
jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ",
"match,return-0",
"【{" + PlotConstructor.ASSISTANT + "-2}】" +"{goods_query-2}",
"",
" ",
"goods_query:queryLocationByConditionName:" + conditionName
);
......@@ -134,7 +134,7 @@ public class ItemConstructor extends ElementConstructor {
jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ",
"match,return-0",
"【{" + PlotConstructor.ASSISTANT + "-2}】" +"{goods_query-2}",
"",
" ",
"goods_query:queryAttrByGoodsName:" + conditionName
);
......@@ -147,7 +147,7 @@ public class ItemConstructor extends ElementConstructor {
jConfig = new JConfig(
conditionName + "::match-Include=" + classKeywords, " ",
"match,return-0",
"【{" + PlotConstructor.ASSISTANT + "-2}】" +"{goods_query-2}",
"",
" ",
"goods_query:queryAroundGoodsByClassName:" + conditionName
);
......@@ -159,7 +159,7 @@ public class ItemConstructor extends ElementConstructor {
jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ",
"match,return-0",
"【{" + PlotConstructor.ASSISTANT + "-2}】" +"{goods_query-2}",
"",
" ",
"goods_query:queryPlayerItems:" + conditionName
);
......@@ -171,7 +171,7 @@ public class ItemConstructor extends ElementConstructor {
jConfig = new JConfig(
conditionName + "::match-Include=" + keywordMap.get("item_" + conditionName).toString(), " ",
"match,return-0",
"【{" + PlotConstructor.ASSISTANT + "-2}】" +"{goods_query-2}",
"",
" ",
"goods_query:queryFindItemWay:" + conditionName
);
......
......@@ -18,7 +18,7 @@ public class FormsPoster {
LogWriter logWriter = null;
public static String QA_URL = "http://qcloud-gz1.chewrobot.com:58000/game";
public static String QA_URL = "http://aliyun-hz1.chewrobot.com:58000/game";
public FormsPoster(LogWriter logWriter) {
this.logWriter = logWriter;
......@@ -33,7 +33,7 @@ public class FormsPoster {
}
};
static String TALKER = "^【(.*?)】";
static String TALKER = "【(.*?)@.*?】";
/**
* 提交类型为all时,会把当前信息点和历史信息点都作为post到另一个服务器
......@@ -51,7 +51,7 @@ public class FormsPoster {
k_iter = curInfoPoint.keySet().iterator();
while (k_iter.hasNext()) {
key = k_iter.next();
if (curInfoPoint.get(key) != "")
if (curInfoPoint.get(key) != null && !curInfoPoint.get(key).equals(""))
//infoMap.put(key + "_cur", curInfoPoint.get(key)[0]);
pairList.add(new BasicNameValuePair(key, curInfoPoint.get(key)));
}
......@@ -59,13 +59,16 @@ public class FormsPoster {
k_iter = historyInfoPoint.keySet().iterator();
while (k_iter.hasNext()) {
key = k_iter.next();
if (historyInfoPoint.get(key) != "")
//infoMap.put(key + "_his", historyInfoPoint.get(key));
if (key.equals("game_step") || key.equals("qa_threshold"))
if(historyInfoPoint.get(key) != null && !historyInfoPoint.get(key).equals("")) {
if (skipSet.contains(key))
continue;
if (curInfoPoint.get(key) == null || curInfoPoint.equals("")) {
pairList.add(new BasicNameValuePair(key, historyInfoPoint.get(key)));
else if(skipSet.contains(key)){}
else
} else {
pairList.add(new BasicNameValuePair(key + "_his", historyInfoPoint.get(key)));
}
}
}
......@@ -121,16 +124,20 @@ public class FormsPoster {
k_iter = ansCondition.currentPremise.keySet().iterator();
while (k_iter.hasNext()) {
key = k_iter.next().split("::")[0];
if (curInfoPoint.get(key) != "")
if (curInfoPoint.get(key) != null && !curInfoPoint.equals(""))
pairList.add(new BasicNameValuePair(key, curInfoPoint.get(key)));
}
k_iter = ansCondition.historyPremise.keySet().iterator();
while (k_iter.hasNext()) {
key = k_iter.next().split("::")[0];
if (historyInfoPoint.get(key) != "")
pairList.add(new BasicNameValuePair(key + "_his", historyInfoPoint.get(key)));
//infoMap.put(key + "_his", historyInfoPoint.get(key));
if(!historyInfoPoint.get(key).equals("")) {
if (curInfoPoint.get(key) == null || curInfoPoint.equals("")) {
pairList.add(new BasicNameValuePair(key, historyInfoPoint.get(key)));
} else {
pairList.add(new BasicNameValuePair(key + "_his", historyInfoPoint.get(key)));
}
}
}
logWriter.record("提交表单的数据:<br>" + pairList.toString(), 2);
......@@ -193,6 +200,7 @@ public class FormsPoster {
System.out.println(jobj.toJSONString());
if((Integer)jobj.get("post_status") == 1){
if(jobj.getJSONArray("qa_candidates") != null && jobj.get("qa_status").equals("OK")){
//设置初始值
historyInfoPoint.put("common_answer", "");
historyInfoPoint.put("qa_score", "0");
historyInfoPoint.put("qa_status", "OK");
......
......@@ -184,6 +184,7 @@ public class MyFunc {
}
} catch (Exception e) {
e.printStackTrace();
jobj.put("post_status", 0);
}
......
package com.qiwu.chatbotbackend.processing;
import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.GameEnvironment.GameEnv;
import com.qiwu.chatbotbackend.entity.Solution;
import com.qiwu.chatbotbackend.entity.Condition;
import com.qiwu.chatbotbackend.entity.UserInfo;
import com.qiwu.chatbotbackend.gameDesign.GameUtil;
import com.qiwu.chatbotbackend.task.utils.BasicBotUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import javax.servlet.ServletContext;
import java.io.*;
......@@ -58,6 +49,11 @@ public class QuestionMatcher {
}
public QuestionMatcher(){
}
/**
......@@ -93,15 +89,19 @@ public class QuestionMatcher {
for (Condition condition : conditionList) {
if (condition.status.equals("waiting")){
if ((condition.auxiliaryPriority > bestMatch.auxiliaryPriority) || (condition.auxiliaryPriority == bestMatch.auxiliaryPriority && condition.priority > bestMatch.priority)){
if ((condition.auxiliaryPriority > bestMatch.auxiliaryPriority) || (condition.auxiliaryPriority == bestMatch.auxiliaryPriority && condition.priority > bestMatch.priority)
|| condition.featureMap.get("activate") != null){
if(conditionSatisfy(condition)){
if (condition.featureMap.get("activate") != null && !condition.featureMap.containsKey("post")) {
//有post这个feature的配置条目会在最后激活它的待激活列表,这里就不激活了。
activateCondition(activatedQueue, curInfoPoint.get("bot_name"), condition.priority, condition.auxiliaryPriority, condition.nextStep, context);
}
bestMatch = condition;
logWriter.record("匹配更新为:\"" + userinfo.id2config.get(condition.id) + "\"", 2);
logWriter.writeln();
if((condition.auxiliaryPriority > bestMatch.auxiliaryPriority) || (condition.auxiliaryPriority == bestMatch.auxiliaryPriority && condition.priority > bestMatch.priority)) {
bestMatch = condition;
logWriter.record("匹配更新为:\"" + userinfo.id2config.get(condition.id) + "\"", 2);
logWriter.writeln();
}
}
......@@ -139,6 +139,7 @@ public class QuestionMatcher {
if ((condition.auxiliaryPriority > bestMatch.auxiliaryPriority) || (condition.auxiliaryPriority == bestMatch.auxiliaryPriority && condition.activePriority > bestMatch.activePriority)
|| condition.featureMap.get("activate") != null
|| bestMatch.nextStep.contains(String.valueOf(condition.id)) || (!condition.configName.equals("") && bestMatch.nextStep.contains(condition.configName.substring(0,3)))){
//激活优先级先比较,但是如果激活的是无条件的就直接判断名字。
if(conditionSatisfy(condition)){
......@@ -146,9 +147,12 @@ public class QuestionMatcher {
activateCondition(activatedQueue, curInfoPoint.get("bot_name"), condition.priority, condition.auxiliaryPriority, condition.nextStep, context);
}
bestMatch = condition;
logWriter.record("匹配更新为:\"" + userinfo.id2config.get(condition.id) + "\"", 2);
logWriter.writeln();
if((condition.auxiliaryPriority > bestMatch.auxiliaryPriority) || (condition.auxiliaryPriority == bestMatch.auxiliaryPriority && condition.activePriority > bestMatch.activePriority)) {
bestMatch = condition;
logWriter.record("匹配更新为:\"" + userinfo.id2config.get(condition.id) + "\"", 2);
logWriter.writeln();
}
}
......@@ -259,7 +263,7 @@ public class QuestionMatcher {
String operator = "";
try {
String splitPair[] = cmpType.split("-");
String splitPair[] = cmpType.split("-", 2);
if (splitPair.length > 1) {
operator = splitPair[1];
cmpType = splitPair[0];
......@@ -279,10 +283,25 @@ public class QuestionMatcher {
}
}
} else if(operator.equals("Exclude")) {
if (keywordSet.contains(keyword)) {
flag = false;
if(keyword.contains(":")){
String ks[] = keyword.split(":", 2);
if(keywordSet.contains(ks[0]) || keywordSet.contains(ks[1]))
flag = false;
}else {
if (keywordSet.contains(keyword)) {
flag = false;
}
}
}else {
}else if(operator.equals("Have")){
for(String key:keywordSet){
if(key.equals(""))
continue;
if(!keyword.contains(key)){
flag = false;
break;
}
}
}else{
flag = false;
}
......@@ -474,81 +493,6 @@ public class QuestionMatcher {
}
//--------------------------------------------------------------------
//为兼容旧数据
else if (cmpType.equals("numberBigger") && StringUtils.isNumeric(keyword)) {
int candidateA = 0;
int candidateB = 0;
candidateA = Integer.parseInt(keyword);
for (String k : keywordSet) {
if (!k.equals("")) {
candidateB = Integer.parseInt(k);
break;
}
}
flag = candidateA > candidateB;
} else if (cmpType.equals("numberBiggerOrEqual") && StringUtils.isNumeric(keyword)) {
int candidateA = 0;
int candidateB = 0;
candidateA = Integer.parseInt(keyword);
for (String k : keywordSet) {
if (!k.equals("")) {
candidateB = Integer.parseInt(k);
break;
}
}
flag = candidateA >= candidateB;
} else if (cmpType.equals("numberSmaller") && StringUtils.isNumeric(keyword)) {
int candidateA = 0;
int candidateB = 0;
candidateA = Integer.parseInt(keyword);
for (String k : keywordSet) {
if (!k.equals("")) {
candidateB = Integer.parseInt(k);
break;
}
}
flag = candidateA < candidateB;
} else if (cmpType.equals("numberSmallerOrEqual") && StringUtils.isNumeric(keyword)) {
int candidateA = 0;
int candidateB = 0;
candidateA = Integer.parseInt(keyword);
for (String k : keywordSet) {
if (!k.equals("")) {
candidateB = Integer.parseInt(k);
break;
}
}
flag = candidateA <= candidateB;
} else if (cmpType.equals("timeEarly")) {
long candidateA, candidateB = 0;
candidateA = MyFunc.transferToMillisecond(keyword);
for (String k : keywordSet) {
if (!k.equals("")) {
candidateB = MyFunc.transferToMillisecond(k);
break;
}
}
flag = candidateA < candidateB;
} else if (cmpType.equals("timeLater")) {
long candidateA, candidateB = 0;
candidateA = MyFunc.transferToMillisecond(keyword);
for (String k : keywordSet) {
if (!k.equals("")) {
candidateB = MyFunc.transferToMillisecond(k);
break;
}
}
flag = candidateA > candidateB;
} else if (cmpType.equals("any")) {
if (keyword.equals("")) //当前信息点中的关键词不为空即满足条件,为空则不满足
flag = false;
......
......@@ -38,36 +38,75 @@ public class ResponseFilter {
return reply;
}
if(reply.startsWith("【" + historyInfoPoint.get(PlotConstructor.ASSISTANT)+ "】") ){
if(reply.startsWith("【" + historyInfoPoint.get(PlotConstructor.ASSISTANT) + "@" + PlotConstructor.ASSISTANT_EMOTION + "】") ){
return reply;
}else if (sameLocation(reply, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 1){
return reply;
}else if (sameLocation(reply, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 0 && !reply.equals("")){
return appendTalker(reply,curInfoPoint, historyInfoPoint, gameEnv, worldController);
}else if (reply.equals("") && !historyInfoPoint.get("common_answer").equals("")){
}else if (reply.equals("") && (
(historyInfoPoint.get("common_answer") != null && !historyInfoPoint.get("common_answer").equals("")))
|| (historyInfoPoint.get("map_query") != null && !historyInfoPoint.get("map_query").equals(""))
|| (historyInfoPoint.get("goods_query") != null && !historyInfoPoint.get("goods_query").equals("") )
|| (historyInfoPoint.get("npc_query") != null && !historyInfoPoint.get("npc_query").equals(""))
){
return reply;
}
if(userInfo.varInitialMap.get("unknownTextList") != null){
List<String> unknownList = new ArrayList<String>();
for(String ans:userInfo.varInitialMap.get("unknownTextList").split("~")){
if(ans.equals(""))
continue;
if (sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 1){
unknownList.add(ans);
//return ans;
}else if(sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 0){
unknownList.add(appendTalker(ans,curInfoPoint, historyInfoPoint, gameEnv, worldController));
String lastTalker = "";
//如果作者当前地点和剧情所在地点相同,那么回答unknown文本的人必须是剧情中的人
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)));
while(m.find()) {
lastTalker = m.group(1);
}
for (String ans : userInfo.varInitialMap.get("unknownTextList").split("~")) {
if (ans.equals(""))
continue;
if (ans.contains(lastTalker) &&sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 1) {
unknownList.add(ans);
//return ans;
} else if (sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 0) {
unknownList.add(appendTalker(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController));
}
}
if (unknownList.size() > 0) {
return MyFunc.randStr(unknownList);
}
}else {
for (String ans : userInfo.varInitialMap.get("unknownTextList").split("~")) {
if (ans.equals(""))
continue;
if (sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 1) {
unknownList.add(ans);
//return ans;
} else if (sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter) == 0) {
unknownList.add(appendTalker(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController));
}
}
if (unknownList.size() > 0) {
return MyFunc.randStr(unknownList);
}
}
if(unknownList.size() > 0){
return MyFunc.randStr(unknownList);
}
}
if(userInfo.varInitialMap.get("finalUnknownText") != null){
finalUnknownText = userInfo.varInitialMap.get("finalUnknownText");
List<String> finalUnknownList = new ArrayList<String>();
for(String ans:finalUnknownText.split("~")){
if(ans.equals(""))
continue;
......@@ -121,8 +160,14 @@ public class ResponseFilter {
npc = m.group(1);
location = worldController.worldOperation(gameEnv, "npc_query", "queryLocationByNPCName:" + npc, curInfoPoint, historyInfoPoint);
if (location.equals(site) || location.equals("无处不在") || location.equals("任意地点")){
logWriter.record("\"" + reply + "\":匹配", 1);
flag = 1;
if(gameEnv.queryNpcAttrByNpcName(npc, "能否说话").equals("能")){
flag = 1;
logWriter.record("\"" + reply + "\":匹配", 1);
}else {
flag = 2;
logWriter.record(npc + "不能说话", 1);
}
}else {
logWriter.record("\"" + reply + "\":" + npc +"不在" + site + ",跳过",1 );
flag = 2;
......@@ -144,7 +189,7 @@ public class ResponseFilter {
else
npc = historyInfoPoint.get(PlotConstructor.ASSISTANT);
return "【" + npc + "】" + reply;
return "【" + npc + "@0】" + reply;
}
......
......@@ -414,6 +414,15 @@ public class WorldController {
returnStr = format.replace("[任务描述]", userInfo.varInitialMap.get(PlotConstructor.TASK_DESCRIPTION));
break;
case "queryWhereIam":
returnStr = userInfo.varInitialMap.get("WHERE_I_AM").replace("[地点名]", historyInfoPoint.get("site"));
break;
case "queryPathAt":
returnStr = userInfo.varInitialMap.get("PATH_AT").replace("[地点名]", historyInfoPoint.get("site"));
break;
case "queryPathAdjoin":
returnStr = userInfo.varInitialMap.get("PATH_ADJOINT");
break;
}
}
......@@ -432,7 +441,11 @@ public class WorldController {
}else{ //增删改统一使用
logWriter.record("更新环境--varName:" + varName + "valuePair:" + valuePair[0] + ":" + valuePair[1], 1);
gameEnv.CUD(varName, valuePair[0], valuePair[1]);
try {
gameEnv.CUD(varName, valuePair[0], valuePair[1]);
} catch (Exception e){
System.out.println("更新环境出现异常--varName:" + varName + "valuePair:" + valuePair[0] + ":" + valuePair[1]);
}
}
......
......@@ -17,6 +17,8 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
......@@ -40,6 +42,12 @@ public class GameDesignServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
DateTimeFormatter dtf=DateTimeFormatter.ofPattern("MM-dd HH:mm:ss.SSS");
StringBuffer timeUsedDetect = new StringBuffer();
LocalDateTime ldt = LocalDateTime.now();
String now = ldt.format(dtf);
timeUsedDetect.append("接收请求的时间:").append(now);
//所有需要修改的词性
StringBuffer POS = new StringBuffer();
......@@ -115,13 +123,17 @@ public class GameDesignServlet extends HttpServlet {
System.out.println("----------------------read-------------------------/r------------------------------------------------------");
readKeywords(keywordMap, KEYWORD_DIR);
ldt = LocalDateTime.now();
now = ldt.format(dtf);
timeUsedDetect.append("\n,预处理之后:").append(now);
String moduleList[] = {"map", "goods", "globalVariable", "npc", "plots"};
for(String moduleName: moduleList){
switch (moduleName) {
case "map":
moduleName2 = "地图";
constructor = new MapConstructor(helper, botId, botAccount, keywordMap, exceptRelation, POS);
constructor = new MapConstructor2(helper, botId, botAccount, keywordMap, exceptRelation, POS);
constructor.construct(gameElements, userinfo);
break;
case "plots":
......@@ -176,17 +188,31 @@ public class GameDesignServlet extends HttpServlet {
break;
}
ldt = LocalDateTime.now();
now = ldt.format(dtf);
timeUsedDetect.append("\n,").append(moduleName2).append("模块:").append(now);
}
if(returnStatus == 1) {
ldt = LocalDateTime.now();
now = ldt.format(dtf);
timeUsedDetect.append("\n发送post请求预处理:").append(now);
StringReader sr = new StringReader(mergedConfigText.toString());
BufferedReader br = new BufferedReader(sr);
//System.out.println(mergedConfigText.toString());
UserInfoController.buildUserInfo(br, userinfo, true);
context.setAttribute(botAccount, userinfo);
ConditionTableController.writeConfigText(botAccount, userinfo);
ldt = LocalDateTime.now();
now = ldt.format(dtf);
timeUsedDetect.append("\n发送post请求前:").append(now);
String postResult = actionRegenerate(root, gameElements, userinfo, additionalKeywords, exceptRelation, POS);
ldt = LocalDateTime.now();
now = ldt.format(dtf);
timeUsedDetect.append("\n发送post请求后:").append(now);
if(!postResult.equals("success")){
returnStatus = 0;
returnMessage = postResult;
......@@ -204,12 +230,18 @@ public class GameDesignServlet extends HttpServlet {
}
System.out.println(timeUsedDetect.toString());
JSONObject responseJSONObject = new JSONObject();
responseJSONObject.put("status", returnStatus);
responseJSONObject.put("message", returnMessage);
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
System.out.println("xx:" + responseJSONObject.toJSONString());
......
......@@ -25,8 +25,8 @@ public class GetAnswerServlet extends HttpServlet {
*/
String NAME_MISSING_ERROR = "没找到bot名?";
//String LOG_PATH = "/var/www/html/logs/";
String LOG_PATH = "/home/hxw/source/logs/";
String LOG_PATH = "/var/www/html/logs/";
//String LOG_PATH = "/home/hxw/source/logs/";
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
......
package com.qiwu.chatbotbackend.task.utils;
import com.qiwu.chatbotbackend.GameEnvironment.GameEnv;
import com.qiwu.chatbotbackend.entity.Solution;
import com.qiwu.chatbotbackend.entity.UserInfo;
import com.qiwu.chatbotbackend.gameDesign.GameUtil;
import com.qiwu.chatbotbackend.processing.LogWriter;
import com.qiwu.chatbotbackend.processing.WorldController;
import javax.servlet.ServletContext;
import java.io.IOException;
......
......@@ -3,12 +3,14 @@ package com.qiwu.chatbotbackend.task.utils;
import com.qiwu.chatbotbackend.GameEnvironment.GameEnv;
import com.qiwu.chatbotbackend.entity.Solution;
import com.qiwu.chatbotbackend.entity.UserInfo;
import com.qiwu.chatbotbackend.gameDesign.PlotConstructor;
import com.qiwu.chatbotbackend.processing.ChatCacheController;
import com.qiwu.chatbotbackend.processing.LogWriter;
import com.qiwu.chatbotbackend.processing.WorldController;
import javax.servlet.ServletContext;
import java.io.IOException;
import java.util.List;
import java.util.Map;
public class GameBotUtil extends BasicBotUtil{
......@@ -47,6 +49,8 @@ public class GameBotUtil extends BasicBotUtil{
}
}
historyInfoPoint.put("current_plot_site", historyInfoPoint.get("site"));
String activeList[] = historyInfoPoint.get("activeList").split("\\|");
if(activeList.length == 0){
historyInfoPoint.put("临时变量condition", "yaobuyao");
......@@ -67,21 +71,26 @@ public class GameBotUtil extends BasicBotUtil{
e.printStackTrace();
}
}
String plot_jump_text = historyInfoPoint.get("plot_jump_text");
if(plot_jump_text != null && !plot_jump_text.equals("")) {
bestMatch.setAnswer(bestMatch.getAnswer() + plot_jump_text + " " );
historyInfoPoint.put("plot_jump_text", "");
}
String common_answer = historyInfoPoint.get("common_answer");
if(common_answer != null && !common_answer.equals("") && !common_answer.equals("no answer")){
bestMatch.setAnswer(common_answer + " " + bestMatch.getAnswer());
historyInfoPoint.put("common_answer", "");
String queryList[] = { "plot_jump_text" ,"common_answer","map_query", "goods_query", "npc_query"};
String queryResult;
for(String queryName:queryList){
queryResult = historyInfoPoint.get(queryName);
if(queryResult != null && !queryResult.equals("")){
if(queryName.equals("common_answer") && queryResult.equals("no answer"))
continue;
if(queryName.equals("map_query") || queryName.equals("goods_query") || queryName.equals("npc_query")){
queryResult = "【" + historyInfoPoint.get(PlotConstructor.ASSISTANT) + "@" + PlotConstructor.ASSISTANT_EMOTION + "】" + queryResult;
}
bestMatch.setAnswer(queryResult + bestMatch.getAnswer() + " " );
historyInfoPoint.put(queryName, "");
}
}
return true;
}
......@@ -93,12 +102,26 @@ public class GameBotUtil extends BasicBotUtil{
if(actionName.startsWith("npc_")){
if(nameSeries.length == 4){
keyword = gameEnv.queryNpcAttrByNpcName(nameSeries[2], nameSeries[3]);
}else if (nameSeries.length == 3){
if(nameSeries[1].equals("玩家") && nameSeries[2].equals("物品栏")) {
StringBuffer sb = new StringBuffer();
List<String> goods = gameEnv.queryGoodsByNpcName("玩家");
for (String good : goods) {
sb.append("+").append(good);
}
keyword = sb.toString();
}else{
keyword = gameEnv.queryNpcAttrByNpcName(nameSeries[1], nameSeries[2]);
}
}
}else if (actionName.startsWith("goods_")) {
if (nameSeries.length == 4) {
keyword = gameEnv.queryGoodsAttrByGoodsName(nameSeries[2], nameSeries[3]);
System.out.println("return" + keyword);
}else if (nameSeries.length == 3){
keyword = gameEnv.queryNpcAttrByNpcName(nameSeries[1], nameSeries[2]);
}
}else if(actionName.startsWith("isNeighbour")){
String opPair[] = actionName.split(":");
......@@ -130,19 +153,22 @@ public class GameBotUtil extends BasicBotUtil{
@Override
public void putKeyword(String variableName, String updateValue){
//如果变量名开头为NPC或者item,就专门交给world处理
if((variableName.startsWith("npc_") || variableName.startsWith("goods_") || variableName.startsWith("map_") || variableName.startsWith("place_"))){
try {
if(!updateValue.startsWith("query") && !updateValue.startsWith("update")){
updateValue = "update:" + updateValue;
String namePair[] = variableName.split("_");
//如果变量名开头为NPC或者item,就专门交给world处理
if ((namePair[0].equals("npc") || namePair[0].equals("goods") || namePair[0].equals("map") || namePair[0].equals("place"))) {
try {
if (!updateValue.startsWith("query") && !updateValue.startsWith("update")) {
updateValue = "update:" + updateValue;
}
String returnStr = worldController.worldOperation(gameEnv, variableName, updateValue, curInfoPoint, historyInfoPoint);
updateValue = returnStr;
} catch (Exception e) {
e.printStackTrace();
updateValue = "游戏模块处理出错";
}
String returnStr = worldController.worldOperation(gameEnv, variableName, updateValue, curInfoPoint, historyInfoPoint);
updateValue = returnStr;
}catch (Exception e){
e.printStackTrace();
updateValue = "游戏模块处理出错";
}
}
historyInfoPoint.put(variableName, updateValue);
}
......
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