From 0fcd792a314642ead54bcfce30b1db8f9165055e Mon Sep 17 00:00:00 2001 From: hxw Date: Sat, 8 Dec 2018 14:24:35 +0800 Subject: [PATCH] 解决智能助手切换的bug --- src/gameDesign/CharacterConstructor.java | 4 ++-- src/gameDesign/GlobalVariableConstructor.java | 4 +++- src/gameDesign/ItemConstructor.java | 4 ++-- src/gameDesign/MapConstructor.java | 20 ++++++++++---------- src/gameDesign/MapConstructor2.java | 21 +++++++++++---------- src/gameDesign/PlotConstructor.java | 37 +++++++++++++++++++++++-------------- src/processing/FormsPoster.java | 10 ++++++++-- src/processing/ResponseFilter.java | 8 +++++--- src/processing/WorldController.java | 15 ++++++++++++++- 9 files changed, 78 insertions(+), 45 deletions(-) diff --git a/src/gameDesign/CharacterConstructor.java b/src/gameDesign/CharacterConstructor.java index da231f0..fc29ae7 100644 --- a/src/gameDesign/CharacterConstructor.java +++ b/src/gameDesign/CharacterConstructor.java @@ -84,7 +84,7 @@ public class CharacterConstructor extends ElementConstructor { for (String conditionName : relateConditions) { jConfig = new JConfig( conditionName + "::match-Include=" + keywords, " ", - "match,return-0", "【{智能助手-2}】{NPC_query-2}", "yaobuyao", "NPC_query:queryAttrByNPCName:" + conditionName + "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{NPC_query-2}", "yaobuyao", "NPC_query:queryAttrByNPCName:" + conditionName ); jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); @@ -98,7 +98,7 @@ public class CharacterConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + classKeywords, " ", - "match,return-0", "【{智能助手-2}】{NPC_query-2}", "yaobuyao", "NPC_query:queryAroundNpcByClassName:" + conditionName + "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{NPC_query-2}", "yaobuyao", "NPC_query:queryAroundNpcByClassName:" + conditionName ); jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); diff --git a/src/gameDesign/GlobalVariableConstructor.java b/src/gameDesign/GlobalVariableConstructor.java index 1413d19..92a1314 100644 --- a/src/gameDesign/GlobalVariableConstructor.java +++ b/src/gameDesign/GlobalVariableConstructor.java @@ -37,11 +37,13 @@ public class GlobalVariableConstructor extends ElementConstructor { while (attrIter.hasNext()) { attrName = attrIter.next(); attrValue = attribute.get(attrName); - varInitialMap.put(attrName, attrValue); + varInitialMap.put("globalVariable_" + category + "_" + attrName, attrValue); } } varInitialMap.put("botType", "game"); + varInitialMap.put("unknownTextList", (String)gameElements.get("unknownTextList")); + varInitialMap.put("finalUnknownText", (String)gameElements.get("finalUnknownText")); JSONObject script = gameElements.getJSONObject("speechcraft"); diff --git a/src/gameDesign/ItemConstructor.java b/src/gameDesign/ItemConstructor.java index 6e8bc4c..082e4f4 100644 --- a/src/gameDesign/ItemConstructor.java +++ b/src/gameDesign/ItemConstructor.java @@ -82,7 +82,7 @@ public class ItemConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + keywords, " ", "match,return-0", - "【{智能助手-2}】{goods_query-2}", + "【{" + PlotConstructor.ASSISTANT + "-2}】" +"{goods_query-2}", " ", "goods_query:queryAttrByGoodsName:" + conditionName ); @@ -95,7 +95,7 @@ public class ItemConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + classKeywords, " ", "match,return-0", - "【{智能助手-2}】{goods_query-2}", + "【{" + PlotConstructor.ASSISTANT + "-2}】" +"{goods_query-2}", " ", "goods_query:queryAroundGoodsByClassName:" + conditionName ); diff --git a/src/gameDesign/MapConstructor.java b/src/gameDesign/MapConstructor.java index f9ad37d..4a7969c 100644 --- a/src/gameDesign/MapConstructor.java +++ b/src/gameDesign/MapConstructor.java @@ -169,7 +169,7 @@ public class MapConstructor extends ElementConstructor { String conditionKeywords = nickname + ":哪里+" + nickname + ":哪+现在:哪里+现在:哪"; jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match", "【{智能助手-2}】" + String.format(script.get("WHERE_I_AM"), "{site-2}"), "yaobuyao", "" + "match", "【{" + PlotConstructor.ASSISTANT + "-2}】" + String.format(script.get("WHERE_I_AM"), "{site-2}"), "yaobuyao", "" ); jConfig.setNextStepStatus("return-0"); jConfig.setAuxiliaryPriority("1"); @@ -211,7 +211,7 @@ public class MapConstructor extends ElementConstructor { + ",isNeighbour:"+ conditionName + "::match-Include=0", "site::match-Include=" + placeB , "match,return-0", - "【{智能助手-2}】" + String.format(script.get("PATH_AT"), "{site-2}"), + "【{" + PlotConstructor.ASSISTANT + "-2}】" + String.format(script.get("PATH_AT"), "{site-2}"), " ", "" ); @@ -228,7 +228,7 @@ public class MapConstructor extends ElementConstructor { + ",isNeighbour:"+ conditionName + "::match-Include=1", "site::match-Include=" + placeB , "match,return-0", - "【{智能助手-2}】" + String.format(script.get("PATH_ADJOINT"), "{site-2}"), + "【{" + PlotConstructor.ASSISTANT + "-2}】" + String.format(script.get("PATH_ADJOINT"), "{site-2}"), " ", "" ); @@ -244,7 +244,7 @@ public class MapConstructor extends ElementConstructor { + ",isNeighbour:"+ conditionName + "::match-Include=2", "site::match-Include=" + placeB , "match,return-0", - "【{智能助手-2}】{map_reply-2}", + "【{" + PlotConstructor.ASSISTANT + "-2}】"+"{map_reply-2}", " ", "map_reply:queryHowToPathBySite:" + conditionName ); @@ -279,7 +279,7 @@ public class MapConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, "site::match-Include=" + placeA, - "match,return-0", "【{智能助手-2}】{map_reply-2}", " ", "map_reply:queryCanGoBySite:" + "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】"+"{map_reply-2}", " ", "map_reply:queryCanGoBySite:" ); jConfig.setNextStepStatus("return-0"); jConfig.setAuxiliaryPriority("1"); @@ -328,7 +328,7 @@ public class MapConstructor extends ElementConstructor { + ",isNeighbour:"+ conditionName + "::match-Include=0", "site::match-Include=" + placeA , "match,return-0", - "【{智能助手-2}】" + String.format(script.get("PATH_AT"), placeBMain), + "【{" + PlotConstructor.ASSISTANT + "-2}】" + String.format(script.get("PATH_AT"), placeBMain), " ", "" ); @@ -353,7 +353,7 @@ public class MapConstructor extends ElementConstructor { + ",isNeighbour:"+ conditionName + "::match-Include=2", "site::match-Include=" + placeA , "match,return-0", - "【{智能助手-2}】{map_reply-2}", + "【{" + PlotConstructor.ASSISTANT + "-2}】"+"{map_reply-2}", " ", "map_reply:queryToDoPathBySite:" + conditionName ); @@ -371,7 +371,7 @@ public class MapConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match,return-0", "【{智能助手-2}】{map_query-2}。", "yaobuyao", "map_query:queryAroundNpcBySite:" + "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_query-2}。", "yaobuyao", "map_query:queryAroundNpcBySite:" ); jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); @@ -384,7 +384,7 @@ public class MapConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match,return-0", "【{智能助手-2}】{map_query-2}。", "yaobuyao", "map_query:queryAroundGoodsBySite:" + "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_query-2}。", "yaobuyao", "map_query:queryAroundGoodsBySite:" ); jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); @@ -398,7 +398,7 @@ public class MapConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match,return-0", "【{智能助手-2}】{map_query-2}。", "yaobuyao", "map_query:queryAroundAllBySite:" + "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_query-2}。", "yaobuyao", "map_query:queryAroundAllBySite:" ); jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); diff --git a/src/gameDesign/MapConstructor2.java b/src/gameDesign/MapConstructor2.java index bccaeda..e725ab8 100644 --- a/src/gameDesign/MapConstructor2.java +++ b/src/gameDesign/MapConstructor2.java @@ -172,7 +172,7 @@ public class MapConstructor2 extends ElementConstructor { String conditionKeywords = nickname + ":哪里+" + nickname + ":哪+现在:哪里+现在:哪"; jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match", "【{智能助手-2}】" + String.format(script.get("WHERE_I_AM"), "{site-2}") , "yaobuyao", "" + "match", "【{" + PlotConstructor.ASSISTANT + "-2}】" + String.format(script.get("WHERE_I_AM"), "{site-2}") , "yaobuyao", "" ); jConfig.setNextStepStatus("return-0"); jConfig.setAuxiliaryPriority("1"); @@ -213,7 +213,7 @@ public class MapConstructor2 extends ElementConstructor { + ",isNeighbour:"+ conditionName + "::match-Include=0", "site::match-Include=" + placeB , "match,return-0", - "【{智能助手-2}】" + String.format(script.get("PATH_AT"), "{site-2}"), + "【{" + PlotConstructor.ASSISTANT + "-2}】" + String.format(script.get("PATH_AT"), "{site-2}"), " ", "" ); @@ -230,7 +230,7 @@ public class MapConstructor2 extends ElementConstructor { + ",isNeighbour:"+ conditionName + "::match-Include=1", "site::match-Include=" + placeB , "match,return-0", - "【{智能助手-2}】" + String.format(script.get("PATH_ADJOINT"), "{site-2}"), + "【{" + PlotConstructor.ASSISTANT + "-2}】" + String.format(script.get("PATH_ADJOINT"), "{site-2}"), " ", "" ); @@ -246,7 +246,7 @@ public class MapConstructor2 extends ElementConstructor { + ",isNeighbour:"+ conditionName + "::match-Include=2", "site::match-Include=" + placeB , "match,return-0", - "【{智能助手-2}】{map_reply-2}", + "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_reply-2}", " ", "map_reply:queryHowToPathBySite:" + conditionName ); @@ -281,7 +281,7 @@ public class MapConstructor2 extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, "site::match-Include=" + placeA, - "match,return-0", "【{智能助手-2}】{map_reply-2}", " ", "map_reply:queryCanGoBySite:" + "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_reply-2}", " ", "map_reply:queryCanGoBySite:" ); jConfig.setNextStepStatus("return-0"); jConfig.setAuxiliaryPriority("1"); @@ -330,7 +330,7 @@ public class MapConstructor2 extends ElementConstructor { + ",isNeighbour:"+ conditionName + "::match-Include=0", "site::match-Include=" + placeA , "match,return-0", - "【{智能助手-2}】" + String.format(script.get("PATH_AT"), placeBMain), + "【{" + PlotConstructor.ASSISTANT + "-2}】" + String.format(script.get("PATH_AT"), placeBMain), " ", "" ); @@ -352,6 +352,7 @@ public class MapConstructor2 extends ElementConstructor { //上一个配置文件激活时的默认选项 jConfig = new JConfig( " ", " ", "", "{" + lastTaskReply + "-2}" ," ", "process-nextStep:var={" + lastTaskCondition +"-2}-<-site:" + placeBMain + + "-<-npc_update:updateFollowerLocation:"+ placeBMain ); jConfig.setStatus("sleeping"); jConfig.setConfigName("plot_"+placeBMain + "_doudi",false); @@ -365,7 +366,7 @@ public class MapConstructor2 extends ElementConstructor { + ",isNeighbour:"+ conditionName + "::match-Include=2", "site::match-Include=" + placeA , "match,return-0", - "【{智能助手-2}】{map_reply-2}", + "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_reply-2}", " ", "map_reply:queryToDoPathBySite:" + conditionName ); @@ -383,7 +384,7 @@ public class MapConstructor2 extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match,return-0", "【{智能助手-2}】{map_query-2}。", "yaobuyao", "map_query:queryAroundNpcBySite:" + "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_query-2}。", "yaobuyao", "map_query:queryAroundNpcBySite:" ); JConfig.activateCopy(jConfig, jConfigList); @@ -395,7 +396,7 @@ public class MapConstructor2 extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match,return-0", "【{智能助手-2}】{map_query-2}。", "yaobuyao", "map_query:queryAroundGoodsBySite:" + "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_query-2}。", "yaobuyao", "map_query:queryAroundGoodsBySite:" ); JConfig.activateCopy(jConfig, jConfigList); @@ -408,7 +409,7 @@ public class MapConstructor2 extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match,return-0", "【{智能助手-2}】{map_query-2}。", "yaobuyao", "map_query:queryAroundAllBySite:" + "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_query-2}。", "yaobuyao", "map_query:queryAroundAllBySite:" ); JConfig.activateCopy(jConfig, jConfigList); diff --git a/src/gameDesign/PlotConstructor.java b/src/gameDesign/PlotConstructor.java index c13b2eb..c66040a 100644 --- a/src/gameDesign/PlotConstructor.java +++ b/src/gameDesign/PlotConstructor.java @@ -5,15 +5,19 @@ import com.alibaba.fastjson.JSONObject; import com.qiwu.chatbotbackend.db.SqlHelper; import com.qiwu.chatbotbackend.entity.JConfig; import com.qiwu.chatbotbackend.entity.UserInfo; +import com.qiwu.chatbotbackend.processing.FormsPoster; import org.apache.http.message.BasicNameValuePair; import com.qiwu.chatbotbackend.processing.MyFunc; import java.io.UnsupportedEncodingException; import java.util.*; +import static com.qiwu.chatbotbackend.processing.FormsPoster.QA_URL; + public class PlotConstructor extends ElementConstructor { + public static String ASSISTANT = "globalVariable_默认_智能助手"; String GAME_STEP_FORMAT = "%s_plot_%s"; JSONArray plots = null; @@ -304,7 +308,7 @@ public class PlotConstructor extends ElementConstructor { + "," + nextId + "::number-BiggerOrEqual=" + 1, "match", (String)branchNode.get("reply"), (String) nextCondition, "-<-game_step:" + String.format(GAME_STEP_FORMAT, botAccount, nextId) - + "-<-unknownText:" + nextUnknownText + "-<-site:" + nextLocation + + "-<-unknownText:" + nextUnknownText + "-<-site:" + nextLocation + "-<-npc_update:updateFollowerLocation:"+ nextLocation ); jConfig.setStatus("sleeping"); jConfig.setConfigName("plot_" + nextLocation + "_" + id,false); @@ -312,6 +316,11 @@ public class PlotConstructor extends ElementConstructor { jConfigList.add(jConfig); + + //如果当前剧情所在地喝下一步剧情所在地不一样,那么unknown文本 + //只有到达下一步剧情所在地时才会更新 + updateKnowledge.remove("unknownText"); + //必须在上一个jConfig添加完之后 //extraUK = extraUK.replace("-<-" + nextId + ":" + "+1", ""); @@ -332,7 +341,7 @@ public class PlotConstructor extends ElementConstructor { //没有当前条件的限制, if (curPremiseList.size() == 0){ - jConfig.setFeature(jConfig.getFeature() + ",activate,post::gameQA(http://simqa.sz.chewrobot.com:28081/game)"); + jConfig.setFeature(jConfig.getFeature() + ",activate,post::gameQA(" + QA_URL + ")"); jConfig.setNextStep("queryskip*,map*"); jConfig.setUpdateKnowledge(jConfig.getUpdateKnowledge() + "-<-临时变量condition:"+ nextCondition +"-<-临时变量reply:var={reply-3}"); jConfig.setNextStepStatus("active"); @@ -368,17 +377,17 @@ public class PlotConstructor extends ElementConstructor { //对于unknown的特殊处理 //对于unknown的特殊处理 - if (curUnknownText.equals("")) { - jConfig = new JConfig( - conditionName + "::match-Include=unknown", - "任务线_" + location + "进度::match-Include=" + parentId, - "match,return-0,post::gameQA(" + CHITCHAT_URL + ")", - " ", - " ", - "" - ); - jConfigList.add(jConfig); - } +// if (curUnknownText.equals("")) { +// jConfig = new JConfig( +// conditionName + "::match-Include=unknown", +// "任务线_" + location + "进度::match-Include=" + parentId, +// "match,return-0,post::gameQA(" + CHITCHAT_URL + ")", +// " ", +// " ", +// "" +// ); +// jConfigList.add(jConfig); +// } } @@ -497,7 +506,7 @@ public class PlotConstructor extends ElementConstructor { @Override public void postProcessing(List idList, int categoryId){ if (idList.size() != 0) { - jConfig = new JConfig(" ", " ", "activate,post::gameQA(http://simqa.sz.chewrobot.com:28081/game)", "", "unknown4,unknown3,unknown2,unknown1,common_answer", ""); + jConfig = new JConfig(" ", " ", "activate,post::gameQA(" + QA_URL+ ")", "", "unknown4,unknown3,unknown2,unknown1,common_answer", ""); jConfig.setNextStepStatus("active"); JSONObject json = jConfig.toJson(this.getConditionDescription()); helper.insertConfigByBotId(botId, json, idList, categoryId); diff --git a/src/processing/FormsPoster.java b/src/processing/FormsPoster.java index 3399da7..82f9901 100644 --- a/src/processing/FormsPoster.java +++ b/src/processing/FormsPoster.java @@ -17,6 +17,7 @@ public class FormsPoster { LogWriter logWriter = null; + public static String QA_URL = "http://qcloud-gz1.chewrobot.com:58000/game"; public FormsPoster(LogWriter logWriter) { this.logWriter = logWriter; @@ -88,7 +89,8 @@ public class FormsPoster { } } }else { - if(URL.equals("http://simqa.sz.chewrobot.com:28081/game")) + if(URL.equals(QA_URL + )) ans.setAnswer("qa_threshold, game_step, query_text 看看少了哪个"); else ans.setAnswer("提交表单出现异常"); @@ -188,10 +190,12 @@ public class FormsPoster { logWriter.record("提交表单接收到的数据:
" + jobj.toJSONString(), 2); String text,score, site = historyInfoPoint.get("site"), npc; + 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"); List candidates = JSON.toJavaObject(jobj.getJSONArray("qa_candidates"), List.class); for(JSONArray pair:candidates){ @@ -204,9 +208,11 @@ public class FormsPoster { npc = m.group(1); if (worldController.worldOperation(gameEnv, "NPC_query", "queryLocationByNPCName:" + npc, curInfoPoint, historyInfoPoint).equals(site)){ historyInfoPoint.put("common_answer", textscore.get(0)); - historyInfoPoint.put("qa_score", textscore.get(1)); + historyInfoPoint.put("qa_score", String.valueOf(textscore.get(1))); break; } + }else{ + logWriter.record(textscore + "没找到npc名字",1 ); } diff --git a/src/processing/ResponseFilter.java b/src/processing/ResponseFilter.java index acaa447..edd3795 100644 --- a/src/processing/ResponseFilter.java +++ b/src/processing/ResponseFilter.java @@ -4,6 +4,7 @@ import com.qiwu.chatbotbackend.GameEnvironment.GameEnv; import com.qiwu.chatbotbackend.entity.Condition; import com.qiwu.chatbotbackend.entity.Solution; import com.qiwu.chatbotbackend.entity.UserInfo; +import com.qiwu.chatbotbackend.gameDesign.PlotConstructor; import java.util.Map; import java.util.regex.Matcher; @@ -19,8 +20,7 @@ public class ResponseFilter { if(botType == null){ - int randNum = (int) (Math.random() * ansCondition.answer.length); - return ansCondition.answer[randNum]; + return reply; }else if (botType.equals("game")){ @@ -30,7 +30,7 @@ public class ResponseFilter { String answer[] = reply.split("~"); int randNum = (int) (Math.random() * answer.length); reply = answer[randNum]; - if(reply.startsWith("【" + historyInfoPoint.get("智能助手"))){ + if(reply.startsWith("【" + historyInfoPoint.get(PlotConstructor.ASSISTANT))){ return reply; }else if (sameLocation(reply, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter)){ return reply; @@ -39,6 +39,8 @@ public class ResponseFilter { if(userInfo.varInitialMap.get("unknownTextList") != null){ for(String ans:userInfo.varInitialMap.get("unknownTextList").split("~")){ + if(ans.equals("")) + continue; if (sameLocation(ans, curInfoPoint, historyInfoPoint, gameEnv, worldController, site, logWriter)){ return ans; } diff --git a/src/processing/WorldController.java b/src/processing/WorldController.java index 11aeb9b..8596c48 100644 --- a/src/processing/WorldController.java +++ b/src/processing/WorldController.java @@ -247,7 +247,20 @@ public class WorldController { } } - }else { //增删改统一使用 + }else if(valuePair[0].startsWith("update")){ + Boolean flag = true; + switch (valuePair[0]) { + case "updateFollowerLocation": + flag = gameEnv.updateFollowerLocation(valuePair[1]); + + } + + if(flag){ + returnStr = "更新成功"; + }else + returnStr = "更新失败"; + + }else{ //增删改统一使用 gameEnv.CUD(varName, valuePair[0], valuePair[1]); } -- libgit2 0.27.1