diff --git a/src/gameDesign/CharacterConstructor.java b/src/gameDesign/CharacterConstructor.java index 5f29450..d67e3f4 100644 --- a/src/gameDesign/CharacterConstructor.java +++ b/src/gameDesign/CharacterConstructor.java @@ -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:" ); diff --git a/src/gameDesign/GlobalVariableConstructor.java b/src/gameDesign/GlobalVariableConstructor.java index fb4c9ab..1f464a8 100644 --- a/src/gameDesign/GlobalVariableConstructor.java +++ b/src/gameDesign/GlobalVariableConstructor.java @@ -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 attribute = null; Iterator 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")); diff --git a/src/gameDesign/ItemConstructor.java b/src/gameDesign/ItemConstructor.java index e5399fc..0f0cb9e 100644 --- a/src/gameDesign/ItemConstructor.java +++ b/src/gameDesign/ItemConstructor.java @@ -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 ); diff --git a/src/gameDesign/MapConstructor.java b/src/gameDesign/MapConstructor.java index a238409..34b60d8 100644 --- a/src/gameDesign/MapConstructor.java +++ b/src/gameDesign/MapConstructor.java @@ -6,10 +6,7 @@ import com.qiwu.chatbotbackend.db.SqlHelper; import com.qiwu.chatbotbackend.entity.JConfig; import com.qiwu.chatbotbackend.entity.UserInfo; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; +import java.util.*; public class MapConstructor extends ElementConstructor { @@ -18,6 +15,7 @@ public class MapConstructor extends ElementConstructor { int locationNum; HashMap id2j = new HashMap(); Map question2keyword = new HashMap(); + Map> name2nickname = new HashMap>(); JSONArray locations = null; Map script = null; //话术模板 @@ -39,29 +37,33 @@ public class MapConstructor extends ElementConstructor { JSONObject jobj = null; int locationId, index; + String locationName; //ArrayList> matrix= new ArrayList>(); //ArrayList vec1d = new ArrayList(); locationNum = locations.size(); - StringBuffer keywordSet = null; + StringBuffer nameSet = null; for (int i = 0; i < locationNum; i++) { jobj = locations.getJSONObject(i); jobj.put("index", i); + locationName = (String) jobj.get("name"); - keywordSet = new StringBuffer(); - keywordSet.append(jobj.get("name")); - POS.append("=" + jobj.get("name") + "|地名\r\n"); + nameSet = new StringBuffer(); + nameSet.append(locationName); + name2nickname.putIfAbsent(locationName, new ArrayList<>()); + POS.append("=" + locationName + "|地名\r\n"); if(jobj.containsKey("nickname")){ for(String nickname:JSONArray.parseArray(locations.getJSONObject(i).getJSONArray("nickname").toJSONString(), String.class)){ if(!nickname.equals("")) { - keywordSet.append("+" + nickname); - POS.append("=" + nickname + "|地名\r\n"); + nameSet.append("+").append(nickname); + POS.append("=").append(nickname).append("|地名\r\n"); + name2nickname.get(locationName).add(nickname); } } } - jobj.put("name", keywordSet.toString()); + jobj.put("nameSet", nameSet.toString()); locationId = (Integer) jobj.get("id"); id2j.put(locationId, jobj); @@ -146,10 +148,6 @@ public class MapConstructor extends ElementConstructor { script.put("TASK_DESCRIPTION", "我们的任务是[任务描述]"); - - - - if(script == null){ throw new Exception("话术不存在"); } @@ -200,7 +198,8 @@ public class MapConstructor extends ElementConstructor { jConfig = new JConfig( condition + "::match-Include=" + conditionKeywords, " ", - "match", "【{" + PlotConstructor.ASSISTANT + "-2}】" + script.get("WHERE_I_AM").replace("[地点名]", "{site-2}"), "yaobuyao", "" + "match", "", "yaobuyao", + "map_query:queryWhereIam:" ); jConfig.setNextStepStatus("return-0"); jConfig.setAuxiliaryPriority("1"); @@ -225,13 +224,13 @@ public class MapConstructor extends ElementConstructor { for (int i = 0; i < locationNum; i++) { - placeA = (String) locations.getJSONObject(i).get("name"); + placeA = (String) locations.getJSONObject(i).get("nameSet"); placeKeywords.append("+" + placeA); } for (int j = 0; j < locationNum; j++) { - placeB = (String) locations.getJSONObject(j).get("name"); + placeB = (String) locations.getJSONObject(j).get("nameSet"); jConfig = new JConfig( @@ -239,9 +238,9 @@ public class MapConstructor extends ElementConstructor { + ",isNeighbour:"+ conditionName + "::match-Include=0", "site::match-Include=" + placeB , "match,return-0", - "【{" + PlotConstructor.ASSISTANT + "-2}】" + script.get("PATH_AT").replace("[地点名]", "{site-2}"), + "", " ", - "" + "map_query:queryPathAt:" ); jConfig.setNextStepStatus("return-0"); jConfig.setAuxiliaryPriority("1"); @@ -256,9 +255,9 @@ public class MapConstructor extends ElementConstructor { + ",isNeighbour:"+ conditionName + "::match-Include=1+3+4", "site::match-Include=" + placeB , "match,return-0", - "【{" + PlotConstructor.ASSISTANT + "-2}】" + script.get("PATH_ADJOINT"), + "", " ", - "" + "map_query:queryPathAdjoin:" ); jConfig.setNextStepStatus("return-0"); jConfig.setAuxiliaryPriority("1"); @@ -272,9 +271,9 @@ public class MapConstructor extends ElementConstructor { + ",isNeighbour:"+ conditionName + "::match-Include=2", "site::match-Include=" + placeB , "match,return-0", - "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_reply-2}", + "", " ", - "map_reply:queryHowToPathBySite:" + conditionName + "map_query:queryHowToPathBySite:" + conditionName ); jConfig.setNextStepStatus("return-0"); jConfig.setAuxiliaryPriority("1"); @@ -297,7 +296,8 @@ public class MapConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_reply-2}", " ", "map_reply:queryCanGoBySite:" + "match,return-0", "", " ", + "map_query:queryCanGoBySite:" ); jConfig.setNextStepStatus("return-0"); jConfig.setAuxiliaryPriority("1"); @@ -313,88 +313,109 @@ public class MapConstructor extends ElementConstructor { String placeA, placeB, descriptionB, text, pathNode, lastTaskCondition, lastTaskReply; String conditionName = "yaobuyao"; String conditionKeywords = "地点"; - String start = (String)gameElements.get("start"); + String start = (String) gameElements.get("start"); String placeKeywords; + //包含去xx的所有地点的关键词集合 + StringBuffer toAllSiteskeywords = new StringBuffer(); + + //包含去xx这个特定地点的关键词的集合(包含别名) + StringBuffer toSitekeywords = new StringBuffer(); + + + String goRelateConditions[] = {"yaobuyao"}; + String gotoMapptern = keywordMap.get("map_" + goRelateConditions[0]).toString(), gotoSite = ""; + for (int i = 0; i < locationNum; i++) { + toSitekeywords.setLength(0); placeA = (String) locations.getJSONObject(i).get("name"); + gotoSite = gotoMapptern.replace("name", placeA); + toAllSiteskeywords.append(gotoSite); + toSitekeywords.append(gotoSite); + for (String nickname : name2nickname.get(placeA)) { + gotoSite = gotoMapptern.replace("name", nickname); + toAllSiteskeywords.append(gotoSite); + toSitekeywords.append(gotoSite); + } + + lastTaskCondition = String.format(PlotConstructor.TASK_CONDITION, placeA); + lastTaskReply = String.format(PlotConstructor.TASK_REPLY, placeA); + + + //地点任务和地点回答的初始化 + if (!varInitialMap.containsKey(lastTaskCondition)) { + varInitialMap.put(lastTaskCondition, goRelateConditions[0]); + varInitialMap.put(lastTaskReply, script.get("SITE_NOT_ACTIVE").replace("[地点名]", placeA)); + conditionDescription.put(lastTaskCondition, lastTaskCondition); + conditionDescription.put(lastTaskReply, lastTaskReply); + } + /** - * 添加初始化变量 + * 要去某个地方,并且该地点相邻或者可以直接到达 */ - String placeAMain = placeA.split("\\+")[0]; - if(!varInitialMap.containsKey("任务线" + placeAMain + "最后一个condition")) { - varInitialMap.put("任务线" + placeAMain + "最后一个condition", "yaobuyao"); - varInitialMap.put("任务线" + placeAMain + "最后的回答", script.get("SITE_NOT_ACTIVE").replace("[地点名]", placeAMain)); - conditionDescription.put("任务线" + placeAMain + "最后一个condition", "任务线" + placeAMain + "最后一个condition"); - conditionDescription.put("任务线" + placeAMain + "最后的回答", "任务线" + placeAMain + "最后的回答"); - } + conditionName = goRelateConditions[0]; + jConfig = new JConfig( + conditionName + "::match-Include=" + toSitekeywords + "," + ",isNeighbour:" + conditionName + "::match-Include=1+3+4", + " ", + "match, reutrn-0,activate", "{" + lastTaskReply + "-2}", "plot_" + placeA + "_*", "" + + ); + jConfig.setConfigName("map", true); + jConfigList.add(jConfig); + + + //上一个配置文件激活时的默认选项 + jConfig = new JConfig( + " ", " ", "", "{" + lastTaskReply + "-2}", " ", "process-nextStep:var={" + lastTaskCondition + "-2}-<-site:" + placeA + + "-<-npc_update:updateFollowerLocation:" + placeA + ); + jConfig.setStatus("sleeping"); + jConfig.setConfigName("plot_" + placeA + "_doudi", false); + jConfig.setjStatus(1); + jConfigList.add(jConfig); - for (int j = 0; j < locationNum; j++) { - placeB = (String) locations.getJSONObject(j).get("name"); - String placeBMain = placeB.split("\\+")[0]; - descriptionB = (String) locations.getJSONObject(j).get("description"); - placeKeywords = conditionKeywords.replace("地点", placeB); - lastTaskCondition = "任务线" + placeBMain + "最后一个condition"; - lastTaskReply = "任务线" + placeBMain + "最后的回答"; - - - jConfig = new JConfig( - conditionName + "::match-Include=" + placeKeywords - + ",isNeighbour:"+ conditionName + "::match-Include=0", - "site::match-Include=" + placeA , - "match,return-0", - "【{" + PlotConstructor.ASSISTANT + "-2}】" + script.get("PATH_AT").replace("[地点名]", placeBMain), - " ", - "" - ); - jConfig.setConfigName("map",true); - jConfigList.add(jConfig); - - - jConfig = new JConfig( - conditionName + "::match-Include=" + placeKeywords + "," + ",isNeighbour:"+ conditionName + "::match-Include=1+3+4", - - "site::match-Include=" + placeA, - "match, reutrn-0,activate", "{" + lastTaskReply + "-2}", "plot_"+placeBMain + "_*","" - - ); - jConfig.setConfigName("map",true); - jConfigList.add(jConfig); - - - //上一个配置文件激活时的默认选项 - 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); - jConfig.setjStatus(1); - jConfigList.add(jConfig); - - - - jConfig = new JConfig( - conditionName + "::match-Include=" + placeKeywords - + ",isNeighbour:"+ conditionName + "::match-Include=2", - "site::match-Include=" + placeA , - "match,return-0", - "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_reply-2}", - " ", - "map_reply:queryToDoPathBySite:" + conditionName - ); - jConfig.setConfigName("map",true); - jConfigList.add(jConfig); - } } + /** + * 要去的地方就在当前地点 + */ + jConfig = new JConfig( + conditionName + "::match-Include=" + toAllSiteskeywords + + ",isNeighbour:" + conditionName + "::match-Include=0", + " ", + "match,return-0", + "", + " ", + "map_query:queryPathAt:" + ); + jConfig.setConfigName("map", true); + jConfigList.add(jConfig); + + + /** + * 要去的地方要经过几个地点才能到达 + */ + jConfig = new JConfig( + conditionName + "::match-Include=" + toAllSiteskeywords + + ",isNeighbour:" + conditionName + "::match-Include=2", + " ", + "match,return-0", + "", + " ", + "map_query:queryToDoPathBySite:" + conditionName + ); + jConfig.setConfigName("map", true); + jConfigList.add(jConfig); + + } + /** * 生成‘周围有什么人’所需要的配置文件 */ @@ -404,7 +425,8 @@ public class MapConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_query-2}。", "yaobuyao", "map_query:queryAroundNpcBySite:" + "match,return-0", "", "yaobuyao", + "map_query:queryAroundNpcBySite:" ); JConfig.activateCopy(jConfig, jConfigList, "map"); @@ -420,7 +442,8 @@ public class MapConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_query-2}。", "yaobuyao", "map_query:queryAroundGoodsBySite:" + "match,return-0", "", "yaobuyao", + "map_query:queryAroundGoodsBySite:" ); JConfig.activateCopy(jConfig, jConfigList, "map"); @@ -437,7 +460,8 @@ public class MapConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_query-2}。", "yaobuyao", "map_query:queryAroundAllBySite:" + "match,return-0", "", "yaobuyao", + "map_query:queryAroundAllBySite:" ); JConfig.activateCopy(jConfig, jConfigList, "map"); @@ -453,7 +477,8 @@ public class MapConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_reply-2}", " ", "map_reply:queryAroundPlace:" + "match,return-0", "", " ", + "map_query:queryAroundPlace:" ); jConfig.setNextStepStatus("return-0"); JConfig.activateCopy(jConfig, jConfigList, "map"); @@ -471,7 +496,8 @@ public class MapConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{goods_reply-2}", " ", "goods_reply:queryPlayerItems:" + "match,return-0", "", " ", + "goods_query:queryPlayerItems:" ); jConfig.setNextStepStatus("return-0"); JConfig.activateCopy(jConfig, jConfigList, "map"); @@ -496,7 +522,8 @@ public class MapConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_reply-2}", " ", "map_reply:queryInnerNpcBySite:" + "match,return-0", "", " ", + "map_query:queryInnerNpcBySite:" ); jConfig.setNextStepStatus("return-0"); JConfig.activateCopy(jConfig, jConfigList, "map"); @@ -520,7 +547,8 @@ public class MapConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_reply-2}", " ", "map_reply:queryTaskDescription:" + "match,return-0", "", " ", + "map_query:queryTaskDescription:" ); jConfig.setNextStepStatus("return-0"); JConfig.activateCopy(jConfig, jConfigList, "map"); diff --git a/src/gameDesign/MapConstructor2.java b/src/gameDesign/MapConstructor2.java index e725ab8..dada4d3 100644 --- a/src/gameDesign/MapConstructor2.java +++ b/src/gameDesign/MapConstructor2.java @@ -6,29 +6,29 @@ import com.qiwu.chatbotbackend.db.SqlHelper; import com.qiwu.chatbotbackend.entity.JConfig; import com.qiwu.chatbotbackend.entity.UserInfo; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; +import java.util.*; public class MapConstructor2 extends ElementConstructor { + String nickname = "qiwu"; int[][] matrix; int locationNum; HashMap id2j = new HashMap(); Map question2keyword = new HashMap(); + Map> name2nickname = new HashMap>(); JSONArray locations = null; Map script = null; //话术模板 - public MapConstructor2(SqlHelper helper, int botId, int skipCount, String botAccount, HashSet exceptRelation, StringBuffer POS) { + + public MapConstructor2(SqlHelper helper, int botId, String botAccount, Map keywordMap, HashSet exceptRelation, StringBuffer POS) { super(); this.helper = helper; this.botId = botId; this.botAccount = botAccount; this.exceptRelation = exceptRelation; - this.skipCount = skipCount; + this.keywordMap = keywordMap; this.POS = POS; } @@ -37,29 +37,41 @@ public class MapConstructor2 extends ElementConstructor { JSONObject jobj = null; int locationId, index; + String locationName, taskLineName = ""; - //ArrayList> matrix= new ArrayList>(); - //ArrayList vec1d = new ArrayList(); locationNum = locations.size(); - StringBuffer keywordSet = null; + StringBuffer nameSet = null; for (int i = 0; i < locationNum; i++) { jobj = locations.getJSONObject(i); jobj.put("index", i); + locationName = (String) jobj.get("name"); + + + taskLineName = String.format(PlotConstructor.TASK_LINE, locationName); + + - keywordSet = new StringBuffer(); - keywordSet.append(jobj.get("name")); - POS.append("=" + jobj.get("name") + "|地名\r\n"); + if (!varInitialMap.containsKey(taskLineName)) { + conditionDescription.put(taskLineName, taskLineName); + varInitialMap.put(taskLineName, ""); + } + + nameSet = new StringBuffer(); + nameSet.append(locationName); + name2nickname.putIfAbsent(locationName, new ArrayList<>()); + POS.append("=" + locationName + "|地名\r\n"); if(jobj.containsKey("nickname")){ for(String nickname:JSONArray.parseArray(locations.getJSONObject(i).getJSONArray("nickname").toJSONString(), String.class)){ if(!nickname.equals("")) { - keywordSet.append("+" + nickname); - POS.append("=" + nickname + "|地名\r\n"); + nameSet.append("+").append(nickname); + POS.append("=").append(nickname).append("|地名\r\n"); + name2nickname.get(locationName).add(nickname); } } } - jobj.put("name", keywordSet.toString()); + jobj.put("nameSet", nameSet.toString()); locationId = (Integer) jobj.get("id"); id2j.put(locationId, jobj); @@ -90,9 +102,6 @@ public class MapConstructor2 extends ElementConstructor { try { - - - conditionDescription.put("site", "当前地点"); JSONObject map = gameElements.getJSONObject("map"); @@ -100,30 +109,51 @@ public class MapConstructor2 extends ElementConstructor { script = JSONObject.toJavaObject(gameElements.getJSONObject("speechcraft"), Map.class); if(!script.containsKey("PATH_AT")) - script.put("PATH_AT", "你已经在%s"); + script.put("PATH_AT", "你已经在[地点名]了"); if(!script.containsKey("WHERE_I_AM")) - script.put("WHERE_I_AM", "在%s"); + script.put("WHERE_I_AM", "在[地点名]"); if(!script.containsKey("PATH_ADJOINT")) script.put("PATH_ADJOINT", "就在附近哦"); if(!script.containsKey("PATH_EXIST")) - script.put("PATH_EXIST", "通过%s可以到达目的地"); + script.put("PATH_EXIST", "通过[途径]可以到达[目的地]"); if(!script.containsKey("PATH_NOT_EXIST")) script.put("PATH_NOT_EXIST", "不可到达"); if(!script.containsKey("CAN_GO_SITES")) - script.put("CAN_GO_SITES", "你可以去%s"); + script.put("CAN_GO_SITES", "你可以去[可去列表]"); if(!script.containsKey("CAN_GO_NOWHERE")) script.put("CAN_GO_NOWHERE", "没什么地方可去的,继续玩吧"); if(!script.containsKey("SITE_NOT_ACTIVE")) - script.put("SITE_NOT_ACTIVE", "你来到了%s\""); + script.put("SITE_NOT_ACTIVE", "你来到了[地点名]"); if(!script.containsKey("SITE_NOT_ADJOINT")) - script.put("SITE_NOT_ADJOINT", "通过%s可以到达目的地"); + script.put("SITE_NOT_ADJOINT", "通过[途径]可以到达[目的地]"); if(!script.containsKey("AROUND_PEOPLE")) - script.put("AROUND_PEOPLE", "周围有%s"); + script.put("AROUND_PEOPLE", "周围有[人物列表]"); if(!script.containsKey("AROUND_ITEMS")) - script.put("AROUND_ITEMS", "周围有%s"); + script.put("AROUND_ITEMS", "周围有[物品列表]"); if(!script.containsKey("AROUND_THINGS")) - script.put("AROUND_THINGS", "周围有%s"); - + script.put("AROUND_THINGS", "周围有[人物物品列表]"); + if(!script.containsKey("FIND_ITEM_LOCATION")) + script.put("FIND_ITEM_LOCATION", "[物品名]在[地点]"); + if(!script.containsKey("FIND_NPC_LOCATION")) + script.put("FIND_NPC_LOCATION", "[人名]在[地点]"); + if(!script.containsKey("AROUND_PLACE")) + script.put("AROUND_PLACE", "周围有[地点列表]"); + if(!script.containsKey("FIND_ITEM_WAY")) + script.put("FIND_ITEM_WAY", "[人名]在[地点]"); + if(!script.containsKey("FIND_NPC_WAY")) + script.put("FIND_NPC_WAY", "[物品名]在[地点]"); + if(!script.containsKey("GET_ITEM_ATTR")) + script.put("GET_ITEM_ATTR", "[物品名]的[属性名]是[属性值]"); + if(!script.containsKey("WE_HAVE")) + script.put("WE_HAVE", "我们有[物品列表]"); + if(!script.containsKey("GET_NPC_ATTR")) + script.put("GET_NPC_ATTR", "[人名]的[属性名]是[属性值]"); + if(!script.containsKey("INNER_PEOPLE")) + script.put("INNER_PEOPLE", "里面有[人物列表]"); + if(!script.containsKey("WHO_YOU_ARE")) + script.put("WHO_YOU_ARE", "我是[人名]"); + if(!script.containsKey("TASK_DESCRIPTION")) + script.put("TASK_DESCRIPTION", "我们的任务是[任务描述]"); if(script == null){ @@ -140,22 +170,23 @@ public class MapConstructor2 extends ElementConstructor { Floyd floyd = new Floyd(); floyd.findShortestPath(matrix, locationNum); floyd.printPath(matrix, locationNum); - generateWantToThere(floyd.pathMatirx, floyd.preTable, gameElements); - generateWhereCanIgo(floyd.pathMatirx, floyd.preTable, gameElements); - generateWhereIam(gameElements, userName); - generateHowToThere(floyd.pathMatirx, floyd.preTable, gameElements); - generateSurroundingItem(); - generateSurroundingPeople(); - generateSurroundThings(); - - + generateWantToThere(floyd.pathMatirx, floyd.preTable, gameElements, keywordMap); + generateWhereCanIgo(floyd.pathMatirx, floyd.preTable, gameElements, keywordMap); + generateWhereIam(gameElements, userName, keywordMap); + generateHowToThere(floyd.pathMatirx, floyd.preTable, gameElements, keywordMap); + generateSurroundingItem(keywordMap); + generateSurroundingPeople(keywordMap); + generateSurroundThings(keywordMap); + generateSurroundPlace(keywordMap); + generateWeHave(keywordMap); + generateInnerPeople(keywordMap); + generateTaskDescription(keywordMap); } catch(Exception e){ operationStatus = 0; e.printStackTrace(); message = "地图处理出现异常:"; - message += e.getMessage(); return; } @@ -164,19 +195,24 @@ public class MapConstructor2 extends ElementConstructor { /** * 生成‘我在哪里’所需要的配置文件 */ - public void generateWhereIam(JSONObject gameElements, String botAccount) { - String conditionName = "rencheng"; + public void generateWhereIam(JSONObject gameElements, String botAccount, Map keywordMap) { + String conditionNameList[] = {"zainali", "wenzainali"}; + String conditionKeywords = ""; - String nickname = "qiwu"; - String conditionKeywords = nickname + ":哪里+" + nickname + ":哪+现在:哪里+现在:哪"; - jConfig = new JConfig( - conditionName + "::match-Include=" + conditionKeywords, " ", - "match", "【{" + PlotConstructor.ASSISTANT + "-2}】" + String.format(script.get("WHERE_I_AM"), "{site-2}") , "yaobuyao", "" - ); - jConfig.setNextStepStatus("return-0"); - jConfig.setAuxiliaryPriority("1"); - JConfig.activateCopy(jConfig, jConfigList); + for(String condition:conditionNameList) { + + conditionKeywords = keywordMap.get("map_" + condition).toString(); + + jConfig = new JConfig( + condition + "::match-Include=" + conditionKeywords, " ", + "match", "", "yaobuyao", + "map_query:queryWhereIam:" + ); + jConfig.setNextStepStatus("return-0"); + jConfig.setAuxiliaryPriority("1"); + JConfig.activateCopy(jConfig, jConfigList, "map"); + } } @@ -188,74 +224,64 @@ public class MapConstructor2 extends ElementConstructor { /** * 生成‘怎么去哪里’所需要的配置文件 */ - public void generateHowToThere(int[][] pathMatirx, int[][] preTable, JSONObject gameElements) { + public void generateHowToThere(int[][] pathMatirx, int[][] preTable, JSONObject gameElements, Map keywordMap) { String conditionName = "want_know_zenmezuo"; - String conditionKeywords = "去:地点"; StringBuffer placeKeywords = new StringBuffer(); - String placeA, placeB, descriptionB, text, pathNode; + String nameSet; for (int i = 0; i < locationNum; i++) { - placeA = (String) locations.getJSONObject(i).get("name"); - placeKeywords.append("+" + placeA); - - + nameSet = (String) locations.getJSONObject(i).get("nameSet"); + placeKeywords.append("+").append(nameSet); } - for (int j = 0; j < locationNum; j++) { - - placeB = (String) locations.getJSONObject(j).get("name"); - - - jConfig = new JConfig( - conditionName + "::match-Include=" + placeKeywords - + ",isNeighbour:"+ conditionName + "::match-Include=0", - "site::match-Include=" + placeB , - "match,return-0", - "【{" + PlotConstructor.ASSISTANT + "-2}】" + String.format(script.get("PATH_AT"), "{site-2}"), - " ", - "" - ); - jConfig.setNextStepStatus("return-0"); - jConfig.setAuxiliaryPriority("1"); - JConfig.activateCopy(jConfig, jConfigList); - + 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", - "site::match-Include=" + placeB , - "match,return-0", - "【{" + PlotConstructor.ASSISTANT + "-2}】" + String.format(script.get("PATH_ADJOINT"), "{site-2}"), - " ", - "" - ); - jConfig.setNextStepStatus("return-0"); - jConfig.setAuxiliaryPriority("1"); - JConfig.activateCopy(jConfig, jConfigList); + 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=2", - "site::match-Include=" + placeB , - "match,return-0", - "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_reply-2}", - " ", - "map_reply:queryHowToPathBySite:" + conditionName - ); - jConfig.setNextStepStatus("return-0"); - jConfig.setAuxiliaryPriority("1"); - JConfig.activateCopy(jConfig, jConfigList); + 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"); - } } @@ -263,155 +289,271 @@ public class MapConstructor2 extends ElementConstructor { /** * 生成‘我能去哪里’所需要的配置文件 */ - public void generateWhereCanIgo(int[][] pathMatirx, int[][] preTable, JSONObject gameElements) { - String conditionKeywords = "去:哪里+能去:哪+能去:哪里+能去:哪儿"; + public void generateWhereCanIgo(int[][] pathMatirx, int[][] preTable, JSONObject gameElements, Map keywordMap) { String conditionName = "choose_gowhere"; + String conditionKeywords = keywordMap.get("map_" + conditionName).toString(); + String placeA, placeB, pathNode; - for (int i = 0; i < locationNum; i++) { - placeA = (String) locations.getJSONObject(i).get("name"); - pathNode = ""; - for (int j = 0; j < locationNum; j++) { - if (pathMatirx[i][j] == 1) { - placeB = (String) locations.getJSONObject(j).get("name"); - pathNode += "、" + placeB; - } - } + jConfig = new JConfig( + conditionName + "::match-Include=" + conditionKeywords, " ", + "match,return-0", "", " ", + "map_query:queryCanGoBySite:" + ); + jConfig.setNextStepStatus("return-0"); + jConfig.setAuxiliaryPriority("1"); + JConfig.activateCopy(jConfig, jConfigList, "map"); - jConfig = new JConfig( - conditionName + "::match-Include=" + conditionKeywords, "site::match-Include=" + placeA, - "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_reply-2}", " ", "map_reply:queryCanGoBySite:" - ); - jConfig.setNextStepStatus("return-0"); - jConfig.setAuxiliaryPriority("1"); - JConfig.activateCopy(jConfig, jConfigList); - } } /** * 生成‘我要去那里’所需要的配置文件 */ - public void generateWantToThere(int[][] pathMatirx, int[][] preTable, JSONObject gameElements) { + public void generateWantToThere(int[][] pathMatirx, int[][] preTable, JSONObject gameElements, Map keywordMap) { String placeA, placeB, descriptionB, text, pathNode, lastTaskCondition, lastTaskReply; String conditionName = "yaobuyao"; String conditionKeywords = "地点"; - String start = (String)gameElements.get("start"); + String start = (String) gameElements.get("start"); String placeKeywords; + //包含去xx的所有地点的关键词集合 + StringBuffer toAllSiteskeywords = new StringBuffer(); + + //包含去xx这个特定地点的关键词的集合(包含别名) + StringBuffer toSitekeywords = new StringBuffer(); + + + String goRelateConditions[] = {"yaobuyao"}; + String gotoMapptern = keywordMap.get("map_" + goRelateConditions[0]).toString(), gotoSite = ""; + for (int i = 0; i < locationNum; i++) { + toSitekeywords.setLength(0); placeA = (String) locations.getJSONObject(i).get("name"); + gotoSite = gotoMapptern.replace("name", placeA); + toAllSiteskeywords.append(gotoSite); + toSitekeywords.append(gotoSite); + for (String nickname : name2nickname.get(placeA)) { + gotoSite = gotoMapptern.replace("name", nickname); + toAllSiteskeywords.append(gotoSite); + toSitekeywords.append(gotoSite); + } + + lastTaskCondition = String.format(PlotConstructor.TASK_CONDITION, placeA); + lastTaskReply = String.format(PlotConstructor.TASK_REPLY, placeA); + + + //地点任务和地点回答的初始化 + if (!varInitialMap.containsKey(lastTaskCondition)) { + varInitialMap.put(lastTaskCondition, goRelateConditions[0]); + varInitialMap.put(lastTaskReply, script.get("SITE_NOT_ACTIVE").replace("[地点名]", placeA)); + conditionDescription.put(lastTaskCondition, lastTaskCondition); + conditionDescription.put(lastTaskReply, lastTaskReply); + } + /** - * 添加初始化变量 + * 要去某个地方,并且该地点相邻或者可以直接到达 */ - String placeAMain = placeA.split("\\+")[0]; - if(!varInitialMap.containsKey("任务线" + placeAMain + "最后一个condition")) { - varInitialMap.put("任务线" + placeAMain + "最后一个condition", "yaobuyao"); - varInitialMap.put("任务线" + placeAMain + "最后的回答", "你来到了" + placeAMain + ",现在什么都没有, 请继续之前的剧情,接着往下玩吧!"); - conditionDescription.put("任务线" + placeAMain + "最后一个condition", "任务线" + placeAMain + "最后一个condition"); - conditionDescription.put("任务线" + placeAMain + "最后的回答", "任务线" + placeAMain + "最后的回答"); - } + conditionName = goRelateConditions[0]; + jConfig = new JConfig( + conditionName + "::match-Include=" + toSitekeywords + "," + ",isNeighbour:" + conditionName + "::match-Include=1+3+4", + " ", + "match, reutrn-0,activate", "{" + lastTaskReply + "-2}", "plot_" + placeA + "_*", "" + + ); + jConfig.setConfigName("map", true); + jConfigList.add(jConfig); + + + //上一个配置文件激活时的默认选项 + jConfig = new JConfig( + " ", " ", "", "{" + lastTaskReply + "-2}", " ", "process-nextStep:var={" + lastTaskCondition + "-2}-<-site:" + placeA + + "-<-npc_update:updateFollowerLocation:" + placeA + ); + jConfig.setStatus("sleeping"); + jConfig.setConfigName("plot_" + placeA + "_doudi", false); + jConfig.setjStatus(1); + jConfigList.add(jConfig); - for (int j = 0; j < locationNum; j++) { - placeB = (String) locations.getJSONObject(j).get("name"); - String placeBMain = placeB.split("\\+")[0]; - descriptionB = (String) locations.getJSONObject(j).get("description"); - placeKeywords = conditionKeywords.replace("地点", placeB); - lastTaskCondition = "任务线" + placeBMain + "最后一个condition"; - lastTaskReply = "任务线" + placeBMain + "最后的回答"; - - - jConfig = new JConfig( - conditionName + "::match-Include=" + placeKeywords - + ",isNeighbour:"+ conditionName + "::match-Include=0", - "site::match-Include=" + placeA , - "match,return-0", - "【{" + PlotConstructor.ASSISTANT + "-2}】" + String.format(script.get("PATH_AT"), placeBMain), - " ", - "" - ); - jConfig.setConfigName("map",true); - jConfigList.add(jConfig); - - - - jConfig = new JConfig( - conditionName + "::match-Include=" + placeKeywords + "," + ",isNeighbour:"+ conditionName + "::match-Include=1", - - "site::match-Include=" + placeA, - "match, reutrn-0,activate", "{" + lastTaskReply + "-2}", "plot_"+placeBMain + "_*","" - - ); - jConfig.setConfigName("map",true); - jConfigList.add(jConfig); - - //上一个配置文件激活时的默认选项 - 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); - jConfig.setjStatus(1); - jConfigList.add(jConfig); - - - - jConfig = new JConfig( - conditionName + "::match-Include=" + placeKeywords - + ",isNeighbour:"+ conditionName + "::match-Include=2", - "site::match-Include=" + placeA , - "match,return-0", - "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_reply-2}", - " ", - "map_reply:queryToDoPathBySite:" + conditionName - ); - jConfig.setConfigName("map",true); - jConfigList.add(jConfig); - } } + /** + * 要去的地方就在当前地点 + */ + jConfig = new JConfig( + conditionName + "::match-Include=" + toAllSiteskeywords + + ",isNeighbour:" + conditionName + "::match-Include=0", + " ", + "match,return-0", + "", + " ", + "map_query:queryPathAt:" + ); + jConfig.setConfigName("map", true); + jConfigList.add(jConfig); + + + /** + * 要去的地方要经过几个地点才能到达 + */ + jConfig = new JConfig( + conditionName + "::match-Include=" + toAllSiteskeywords + + ",isNeighbour:" + conditionName + "::match-Include=2", + " ", + "match,return-0", + "", + " ", + "map_query:queryToDoPathBySite:" + conditionName + ); + jConfig.setConfigName("map", true); + jConfigList.add(jConfig); + + } - public void generateSurroundingPeople(){ + + + /** + * 生成‘周围有什么人’所需要的配置文件 + */ + public void generateSurroundingPeople(Map keywordMap){ String conditionName = "know_exist_what"; - String conditionKeywords = "周围:人+附近:人"; + String conditionKeywords = keywordMap.get("people_" + conditionName).toString(); + + jConfig = new JConfig( + conditionName + "::match-Include=" + conditionKeywords, " ", + "match,return-0", "", "yaobuyao", + "map_query:queryAroundNpcBySite:" + ); + JConfig.activateCopy(jConfig, jConfigList, "map"); + + } + + + /** + * 生成‘周围有什么物品’所需要的配置文件 + */ + public void generateSurroundingItem(Map keywordMap){ + String conditionName = "know_exist_what"; + String conditionKeywords = keywordMap.get("item_" + conditionName).toString(); + + jConfig = new JConfig( + conditionName + "::match-Include=" + conditionKeywords, " ", + "match,return-0", "", "yaobuyao", + "map_query:queryAroundGoodsBySite:" + ); + JConfig.activateCopy(jConfig, jConfigList, "map"); + + } + + + + /** + * 生成‘周围有什么(包含人和物品)’所需要的配置文件 + */ + public void generateSurroundThings(Map keywordMap){ + String conditionName = "know_exist_what_mohu"; + String conditionKeywords = keywordMap.get("things_" + conditionName).toString(); jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_query-2}。", "yaobuyao", "map_query:queryAroundNpcBySite:" + "match,return-0", "", "yaobuyao", + "map_query:queryAroundAllBySite:" ); - JConfig.activateCopy(jConfig, jConfigList); + JConfig.activateCopy(jConfig, jConfigList, "map"); } - public void generateSurroundingItem(){ + + /** + * 生成‘周围有什么地点’所需要的配置文件 + */ + public void generateSurroundPlace(Map keywordMap){ String conditionName = "know_exist_what"; - String conditionKeywords = "周围:物品+周围:东西+附近:物品+附近:东西"; + String conditionKeywords = keywordMap.get("place_" + conditionName).toString(); jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_query-2}。", "yaobuyao", "map_query:queryAroundGoodsBySite:" + "match,return-0", "", " ", + "map_query:queryAroundPlace:" ); - JConfig.activateCopy(jConfig, jConfigList); + jConfig.setNextStepStatus("return-0"); + JConfig.activateCopy(jConfig, jConfigList, "map"); } - public void generateSurroundThings(){ + + /** + * 生成‘我们有什么’所需要的配置文件 + */ + public void generateWeHave(Map keywordMap){ String conditionName = "know_exist_what_mohu"; - String conditionKeywords = "有什么:周围+有什么:附近"; + String conditionKeywords = keywordMap.get("we_have_" + conditionName).toString(); jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match,return-0", "【{" + PlotConstructor.ASSISTANT + "-2}】" + "{map_query-2}。", "yaobuyao", "map_query:queryAroundAllBySite:" + "match,return-0", "", " ", + "goods_query:queryPlayerItems:" ); - JConfig.activateCopy(jConfig, jConfigList); + jConfig.setNextStepStatus("return-0"); + JConfig.activateCopy(jConfig, jConfigList, "map"); + + } + + + + /** + * 生成‘里面有什么人’所需要的配置文件 + */ + public void generateInnerPeople(Map keywordMap){ + + + //与里面有谁相关的condition + String innerNPCRelateConditions[] = {"shishui"}; + + keywordMap.putIfAbsent("inner_shishui", new StringBuffer()); + String conditionName = "shishui"; + String conditionKeywords = keywordMap.get("inner_" + conditionName).toString(); + + + jConfig = new JConfig( + conditionName + "::match-Include=" + conditionKeywords, " ", + "match,return-0", "", " ", + "map_query:queryInnerNpcBySite:" + ); + jConfig.setNextStepStatus("return-0"); + JConfig.activateCopy(jConfig, jConfigList, "map"); + + } + + + + /** + * 生成‘我们的任务是什么’所需要的配置文件 + */ + public void generateTaskDescription(Map keywordMap){ + + + //与里面有谁相关的condition + String innerNPCRelateConditions[] = {}; + + keywordMap.putIfAbsent("task_shishenme", new StringBuffer()); + String conditionName = "shishenme"; + String conditionKeywords = keywordMap.get("task_" + conditionName).toString(); + + jConfig = new JConfig( + conditionName + "::match-Include=" + conditionKeywords, " ", + "match,return-0", "", " ", + "map_query:queryTaskDescription:" + ); + jConfig.setNextStepStatus("return-0"); + JConfig.activateCopy(jConfig, jConfigList, "map"); } diff --git a/src/gameDesign/PlotConstructor.java b/src/gameDesign/PlotConstructor.java index a284b04..4dfe0ec 100644 --- a/src/gameDesign/PlotConstructor.java +++ b/src/gameDesign/PlotConstructor.java @@ -14,6 +14,7 @@ import static com.qiwu.chatbotbackend.processing.FormsPoster.QA_URL; public class PlotConstructor extends ElementConstructor { public static String ASSISTANT = "globalVariable_智能助手"; + public static String ASSISTANT_EMOTION = "0"; public static String TASK_DESCRIPTION = "globalVariable_任务"; public static String TALKER_PATTERN = "【%s】"; @@ -48,6 +49,8 @@ public class PlotConstructor extends ElementConstructor { public void construct(JSONObject jsonObject, UserInfo userinfo) { try { + + JSONArray plots = jsonObject.getJSONArray("plots"); String start = (String) jsonObject.get("start"), startCondition; JSONObject returnMessage = null; @@ -128,22 +131,21 @@ public class PlotConstructor extends ElementConstructor { /** * 将所有剧情根据地点分为多条剧情线,每一条剧情线都有一个计数器,记录当前地点的剧情到了第几步。 - * 加上剧情计数器, 每一步分为三个状态 + * 加上剧情计数器, null时未激活,大于等于1时表示已激活 * @param root * @param userinfo */ public void BFSGenerate4(JSONObject root, UserInfo userinfo, JSONObject jsonObject) { - String id, rootId = (String) root.get("id"), adjId, nextId, parentId, taskName = "", value = "", nextTaskName, keywordOptions, conditionName = "yaobuyao", + String id, rootId = (String) root.get("id"), adjId, nextId, conditionName = "yaobuyao", nextUnknownText, curUnknownText, nextCondition, location, nextLocation, nextGameStep, taskLineName, nTaskLineName, lastTaskReply, lastTaskCondition, reply; String beforeJumpLocatin, jumpNextNextId, jumpNextNextLocation, extraBeforeJumpUK; JSONObject node = null, branchNode = null, adjNode = null; - StringBuffer skipText = null; - //StringBuffer extraHP = new StringBuffer(), extraUK = new StringBuffer(), extraFT = new StringBuffer(); + StringBuffer skipText = new StringBuffer(); String extraHP = "", extraUK = "", extraFT = ""; JSONArray branch = null; - int priority, taskStep, nextPriority, nextTaskStep, branchSize; + int branchSize; List curPremiseList, historyPremiseList; @@ -159,12 +161,15 @@ public class PlotConstructor extends ElementConstructor { } + String startPlace = ((String)root.get("place")).split("\\+")[0]; + String startTaskCondition = String.format(PlotConstructor.TASK_CONDITION, startPlace); + String startTaskReply = String.format(PlotConstructor.TASK_REPLY, startPlace); varInitialMap.put("site", startPlace); - varInitialMap.put("任务线" + startPlace + "最后一个condition", ""); - varInitialMap.put("任务线" + startPlace + "最后的回答", ""); - conditionDescription.put("任务线" + startPlace + "最后一个condition","任务线" + startPlace + "最后一个condition"); - conditionDescription.put("任务线" + startPlace + "最后的回答", "任务线" + startPlace + "最后的回答"); + varInitialMap.put(startTaskCondition, ""); + varInitialMap.put(startTaskReply, ""); + conditionDescription.put(startTaskCondition,startTaskCondition); + conditionDescription.put(startTaskReply, startTaskReply); @@ -180,17 +185,14 @@ public class PlotConstructor extends ElementConstructor { location = ((String) node.get("place")).split("\\+")[0]; conditionName = (String) node.get("conditionName"); curUnknownText = (String) node.get("nextUnknownText"); - taskLineName = "任务线_" + location + "进度"; + taskLineName = String.format(PlotConstructor.TASK_LINE, location); conditionDescription.put(id, "剧情" + id + "状态"); varInitialMap.put(id ,""); - skipText = new StringBuffer(); + skipText.setLength(0); //本任务线的最后一个condition和本任务线的最后一个回答 - if (!varInitialMap.containsKey(taskLineName)) { - conditionDescription.put(taskLineName, taskLineName); - varInitialMap.put(taskLineName, ""); - } + visited.put(id, true); @@ -208,9 +210,10 @@ public class PlotConstructor extends ElementConstructor { Map updateKnowledge = JSONObject.toJavaObject(branchNode.getJSONObject("updateKnowledge"), Map.class); nextUnknownText = updateKnowledge.get("unknownText"); nextId = (String)branchNode.get("nextPlotId"); + //skipText.append(); - if(nextId == null || nextId.equals("")){ + if(nextId == null || nextId.equals("") || !id2j.containsKey(nextId)){ nextId = id + "_end"; branchNode.put("nextPlotId", nextId); createEndNode(node, id, nextId, curUnknownText); @@ -229,7 +232,8 @@ public class PlotConstructor extends ElementConstructor { JSONObject jumpNextNode = id2j.get(nextId); JSONObject jumpBranchNode = jumpNextNode.getJSONArray("branch").getJSONObject(0); - skipText.append((String)jumpBranchNode.get("reply")); + skipText.append((String)branchNode.get("reply")); + branchNode.put("reply", jumpBranchNode.get("reply")); Map newUpdateKnowledge = jumpBranchNode.getJSONObject("updateKnowledge"); autoJumpUpdateKnowledge.putAll(newUpdateKnowledge); nextUnknownText = (String)newUpdateKnowledge.get("unknownText"); @@ -238,7 +242,10 @@ public class PlotConstructor extends ElementConstructor { jumpNextNextId = (String)jumpBranchNode.get("nextPlotId"); - if(jumpNextNextId != null && !jumpNextNextId.equals("")){ + //如果下一步剧情存在 + if(jumpNextNextId != null && !jumpNextNextId.equals("") && id2j.containsKey(jumpNextNextId)){ + System.out.println(jumpNextNextId); + System.out.println(id2j.get(jumpNextNextId)); jumpNextNextLocation = (String)id2j.get(jumpNextNextId).get("place"); autoJumpUpdateKnowledge.put("site", jumpNextNextLocation); @@ -287,7 +294,7 @@ public class PlotConstructor extends ElementConstructor { */ extraHP = taskLineName + "::match-Include=" + id + ",site::match-Include=" + location + "," + id + "::number-BiggerOrEqual=" + 1 + "," + nextId + "::match-Include=null"; - extraUK = nTaskLineName + ":" + nextId + "-<-" + lastTaskCondition + ":" + nextCondition + "-<-" + lastTaskReply + ":" + (String)branchNode.get("reply") + + extraUK = nTaskLineName + ":" + nextId + "-<-" + lastTaskCondition + ":" + nextCondition + "-<-" + lastTaskReply + ":" + reply + "-<-" + id + ":" + "+1-<-" + nextId + ":" + "+1" + "-<-plot_jump_text:" + skipText; if(!beforeJumpLocatin.equals(nextLocation)) { @@ -323,17 +330,21 @@ public class PlotConstructor extends ElementConstructor { * 3. 自动跳转完成后的地点 */ + //自动跳转前的剧情也要记下来 + String beforeJumpTaskCondition = String.format(TASK_CONDITION, beforeJumpLocatin); + String beforeJumpTaskReply = String.format(TASK_REPLY, beforeJumpLocatin); + String beforeJumpUK = "-<-" + beforeJumpTaskCondition + ":yaobuyao" + "-<-" + beforeJumpTaskReply + ":" + skipText + "-<-" + id + ":" + "+1-<-" + nextId + ":" + "+1" ; + //如果主角的位置随着剧情移动 if((!branchNode.containsKey("moveWithPlot") || (Boolean)branchNode.get("moveWithPlot")) || location.equals(beforeJumpLocatin)) { - extraUK += "-<-site:" + nextLocation + "-<-game_step:" + String.format(GAME_STEP_FORMAT, botAccount, nextGameStep); + extraUK = beforeJumpUK + "-<-" + extraUK + "-<-site:" + nextLocation + "-<-game_step:" + String.format(GAME_STEP_FORMAT, botAccount, nextGameStep); + updateKnowledge.putAll(autoJumpUpdateKnowledge); }else { //任务线最后一个condition - String beforeJumpTaskCondition = String.format(TASK_CONDITION, beforeJumpLocatin); - String beforeJumpTaskReply = String.format(TASK_REPLY, beforeJumpLocatin); - String beforeJumpUK = "-<-" + lastTaskCondition + ":yaobuyao" + "-<-" + lastTaskReply + ":" + skipText + "-<-" + id + ":" + "+1-<-" + nextId + ":" + "+1" ; + @@ -479,6 +490,12 @@ public class PlotConstructor extends ElementConstructor { * 待激活列表,用于qa问答 */ + jConfig = new JConfig(" ", " ", "activate,post::gameQA(" + QA_URL+ ")", "", "unknown4,unknown3,unknown2,unknown1,common_answer", ""); + jConfig.setNextStepStatus("active"); + jConfig.setjStatus(1); + jConfig.setAuxiliaryPriority("0"); + jConfigList.add(jConfig); + jConfig = new JConfig( " ", "qa_status::match-Include=not_found", "match,return-0", "{unknownText-2}", " ", "" ); @@ -575,15 +592,9 @@ public class PlotConstructor extends ElementConstructor { jConfig.setAuxiliaryPriority("2"); jConfigList.add(jConfig); } + @Override public void postProcessing(List idList, int categoryId){ - if (idList.size() != 0) { - 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); - jConfigList.add(jConfig); - } } public void createEndNode(JSONObject node, String id, String nextId, String nextUnknownText){ @@ -613,7 +624,7 @@ public class PlotConstructor extends ElementConstructor { - //如果是无条件剧情,那么需要跟这一个激活操作 + //如果是无条件剧情,那么需要跟着一个激活操作 public void unconditionalPlotProcess(JConfig jConfig, String nextCondition){ jConfig.setFeature(jConfig.getFeature() + ",activate,post::gameQA(" + QA_URL + ")"); jConfig.setNextStep("queryskip*,map*,item*,npc*"); diff --git a/src/processing/FormsPoster.java b/src/processing/FormsPoster.java index c577522..bce3c63 100644 --- a/src/processing/FormsPoster.java +++ b/src/processing/FormsPoster.java @@ -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("提交表单的数据:
" + 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"); diff --git a/src/processing/MyFunc.java b/src/processing/MyFunc.java index ca34d56..2e67210 100644 --- a/src/processing/MyFunc.java +++ b/src/processing/MyFunc.java @@ -184,6 +184,7 @@ public class MyFunc { } } catch (Exception e) { e.printStackTrace(); + jobj.put("post_status", 0); } diff --git a/src/processing/QuestionMatcher.java b/src/processing/QuestionMatcher.java index a75a26a..557a984 100644 --- a/src/processing/QuestionMatcher.java +++ b/src/processing/QuestionMatcher.java @@ -1,21 +1,12 @@ 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; diff --git a/src/processing/ResponseFilter.java b/src/processing/ResponseFilter.java index a76ff0f..11ddd94 100644 --- a/src/processing/ResponseFilter.java +++ b/src/processing/ResponseFilter.java @@ -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 unknownList = new ArrayList(); - 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 finalUnknownList = new ArrayList(); + + 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; } diff --git a/src/processing/WorldController.java b/src/processing/WorldController.java index e15273d..379b5db 100644 --- a/src/processing/WorldController.java +++ b/src/processing/WorldController.java @@ -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]); + } } diff --git a/src/servlet/GameDesignServlet.java b/src/servlet/GameDesignServlet.java index 027cb87..74cd9e2 100644 --- a/src/servlet/GameDesignServlet.java +++ b/src/servlet/GameDesignServlet.java @@ -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()); diff --git a/src/servlet/GetAnswerServlet.java b/src/servlet/GetAnswerServlet.java index e673334..ae551ee 100644 --- a/src/servlet/GetAnswerServlet.java +++ b/src/servlet/GetAnswerServlet.java @@ -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"); diff --git a/src/task/utils/BasicBotUtil.java b/src/task/utils/BasicBotUtil.java index 30fa0d9..632f369 100644 --- a/src/task/utils/BasicBotUtil.java +++ b/src/task/utils/BasicBotUtil.java @@ -1,11 +1,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; diff --git a/src/task/utils/GameBotUtil.java b/src/task/utils/GameBotUtil.java index 3f6e982..a9c70e0 100644 --- a/src/task/utils/GameBotUtil.java +++ b/src/task/utils/GameBotUtil.java @@ -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 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); }