From d70969e1053fd51899848dc789ad33f268566b2b Mon Sep 17 00:00:00 2001 From: hxw Date: Sat, 1 Dec 2018 09:48:03 +0800 Subject: [PATCH] routine --- src/entity/ChatCache.java | 1 + src/entity/JConfig.java | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- src/gameDesign/CharacterConstructor.java | 23 ++++++++++++++++++++--- src/gameDesign/ElementConstructor.java | 6 ++++-- src/gameDesign/GlobalVariableConstructor.java | 7 +++++-- src/gameDesign/ItemConstructor.java | 19 ++++++++++++++++--- src/gameDesign/MapConstructor.java | 217 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------------------------------- src/gameDesign/PlotConstructor.java | 566 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ src/processing/ChatCacheController.java | 6 +++--- src/processing/QuestionMatcher.java | 26 +++++++++++++++++++++----- src/processing/WorldController.java | 53 +++++++++++++++++++++++++++++++++++++++++++++++------ src/servlet/GameDesignServlet.java | 54 +++++++++++++++++++++++++++++++++++------------------- src/servlet/GetAnswerServlet.java | 2 +- 13 files changed, 445 insertions(+), 676 deletions(-) diff --git a/src/entity/ChatCache.java b/src/entity/ChatCache.java index dcba96a..60bfd6e 100644 --- a/src/entity/ChatCache.java +++ b/src/entity/ChatCache.java @@ -59,6 +59,7 @@ public class ChatCache { k = iit.next(); infoPoint.put(k, userInfo.varInitialMap.get(k)); } + infoPoint.put("lastUpdateTime", String.valueOf(System.currentTimeMillis())); } } diff --git a/src/entity/JConfig.java b/src/entity/JConfig.java index 9a282af..32dfda9 100644 --- a/src/entity/JConfig.java +++ b/src/entity/JConfig.java @@ -8,7 +8,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -public class JConfig { +public class JConfig implements Cloneable{ private int id = 0; private String jCurPremise = ""; @@ -69,6 +69,98 @@ public class JConfig { private String status = "waiting"; + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getjCurPremise() { + return jCurPremise; + } + + public void setjCurPremise(String jCurPremise) { + this.jCurPremise = jCurPremise; + } + + public String getjHisPremise() { + return jHisPremise; + } + + public void setjHisPremise(String jHisPremise) { + this.jHisPremise = jHisPremise; + } + + public String getjFeature() { + return jFeature; + } + + public void setjFeature(String jFeature) { + this.jFeature = jFeature; + } + + public String getjNextStep() { + return jNextStep; + } + + public void setjNextStep(String jNextStep) { + this.jNextStep = jNextStep; + } + + public String getjReply() { + return jReply; + } + + public void setjReply(String jReply) { + this.jReply = jReply; + } + + public String getjAuxiliaryPriority() { + return jAuxiliaryPriority; + } + + public void setjAuxiliaryPriority(String jAuxiliaryPriority) { + this.jAuxiliaryPriority = jAuxiliaryPriority; + } + + public int getjStatus() { + return jStatus; + } + + public void setCurPremise(String curPremise) { + this.curPremise = curPremise; + } + + public String getHisPremise() { + return hisPremise; + } + + public void setHisPremise(String hisPremise) { + this.hisPremise = hisPremise; + } + + public String getReply() { + return reply; + } + + public void setReply(String reply) { + this.reply = reply; + } + + public String getAuxiliaryPriority() { + return auxiliaryPriority; + } + + public String getStatus() { + return status; + } + + public String getNextStepStatus() { + return nextStepStatus; + } + public String getUpdateKnowledge() { return updateKnowledge; } @@ -80,14 +172,15 @@ public class JConfig { private String updateKnowledge = ""; private String nextStepStatus = "return"; - Map statusMap = new HashMap() { + static Map statusMap = new HashMap() { { put("return", "return"); put("return-1", "back"); put("return-0", "stay"); - put("active", "activate"); + put("activate", "activate"); } }; + static int querySkipCount = 10; public void setStatus(String status) { this.status = status; @@ -252,7 +345,7 @@ public class JConfig { data.put("historyPremiseList", hisPremiseList); //添加下一步状态 - data.put("nextStepStatus", statusMap.get(nextStepStatus)); + //添加configName data.put("configName", configName); @@ -270,8 +363,15 @@ public class JConfig { pair = feat.substring(0, feat.length() - 1).split("\\(", 2); postURL = pair[1]; postType = pair[0].split("::")[1]; + }else if(feat.equals("return-0")){ + nextStepStatus = "return-0"; + }else if(feat.equals("activate")){ + nextStepStatus = "activate"; } } + + + data.put("nextStepStatus", statusMap.get(nextStepStatus)); //添加post参数 data.put("doPost", doPost); data.put("postURL", postURL); @@ -319,4 +419,37 @@ public class JConfig { return text; } + + public Object clone() { + Object o=null; + try{ + o= super.clone(); + }catch(CloneNotSupportedException e){ + System.out.println(e.toString()); + } + return o; + } + + + public static JConfig activateCopy(JConfig jConfig){ + + JConfig jConfig2 = (JConfig) jConfig.clone(); + jConfig2.setReply(jConfig2.getReply() + ",{临时变量2-2}"); + jConfig2.setUpdateKnowledge(jConfig2.getUpdateKnowledge() + "-<-process-nextStep:var={临时变量1-2}"); + jConfig2.setStatus("sleeping"); + jConfig2.setConfigName("queryskip" + String.valueOf(querySkipCount)); + querySkipCount++; + jConfig2.setjStatus(1); + jConfig2.setAuxiliaryPriority("2"); + + return jConfig2; + } + + + public static JConfig simpleCopy(JConfig jConfig){ + + JConfig jConfig2 = (JConfig) jConfig.clone(); + + return jConfig2; + } } diff --git a/src/gameDesign/CharacterConstructor.java b/src/gameDesign/CharacterConstructor.java index 37940fe..da231f0 100644 --- a/src/gameDesign/CharacterConstructor.java +++ b/src/gameDesign/CharacterConstructor.java @@ -10,11 +10,14 @@ import java.util.*; public class CharacterConstructor extends ElementConstructor { - public CharacterConstructor(SqlHelper helper, int botId, HashSet exceptRelation) { + public CharacterConstructor(SqlHelper helper, int botId, int skipCount, String botAccount, HashSet exceptRelation, StringBuffer POS) { super(); this.helper = helper; this.botId = botId; + this.botAccount = botAccount; this.exceptRelation = exceptRelation; + this.skipCount = skipCount; + this.POS = POS; } public void construct(JSONObject gameElements, UserInfo userinfo) { @@ -50,7 +53,11 @@ public class CharacterConstructor extends ElementConstructor { for (JSONObject character : allNPC.toJavaList(JSONObject.class)) { name = (String) character.get("name"); + if(!name.equals("")) + POS.append("=" + name + "|人名\r\n"); className = (String) character.get("class"); + if(!className.equals("")) + POS.append("=" + className + "|人名\r\n"); if (!classSet.contains(className)) { classSet.add(className); @@ -64,6 +71,8 @@ public class CharacterConstructor extends ElementConstructor { keywords.append("+" + repValue); while (attrIter.hasNext()) { attrName = attrIter.next(); + if(!attrName.equals("")) + POS.append("=" + attrName + "|名词\r\n"); attrValue = attribute.get(attrName); } @@ -75,17 +84,25 @@ public class CharacterConstructor extends ElementConstructor { for (String conditionName : relateConditions) { jConfig = new JConfig( conditionName + "::match-Include=" + keywords, " ", - "match,return-0", "{NPC_query-2}", "yaobuyao", "NPC_query:queryAttrByNPCName:" + conditionName + "match,return-0", "【{智能助手-2}】{NPC_query-2}", "yaobuyao", "NPC_query:queryAttrByNPCName:" + conditionName ); + jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); + + + + } //根据根据NPC类别和地点属性查询所有NPC实例 for (String conditionName : relateConditions) { + jConfig = new JConfig( conditionName + "::match-Include=" + classKeywords, " ", - "match,return-0", "{NPC_query-2}", "yaobuyao", "NPC_query:queryAroundNpcByClassName:" + conditionName + "match,return-0", "【{智能助手-2}】{NPC_query-2}", "yaobuyao", "NPC_query:queryAroundNpcByClassName:" + conditionName ); + jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); + } }catch (Exception e){ operationStatus = 0; diff --git a/src/gameDesign/ElementConstructor.java b/src/gameDesign/ElementConstructor.java index 4a8eb60..bf1f0b3 100644 --- a/src/gameDesign/ElementConstructor.java +++ b/src/gameDesign/ElementConstructor.java @@ -16,11 +16,12 @@ public class ElementConstructor { int operationStatus = 1; + int skipCount = 0; SqlHelper helper = null; HashSet exceptRelation = null; JConfig jConfig = null; String CHITCHAT_URL = "http:192.168.1.178:1111/test"; - String userName; + String botAccount; @@ -32,6 +33,7 @@ public class ElementConstructor { StringBuffer configText = new StringBuffer(); Map varInitialMap = new HashMap(); Map conditionDescription = new HashMap(); + StringBuffer POS = new StringBuffer(); public String getMessage() { return message; } @@ -57,7 +59,7 @@ public class ElementConstructor { } public void ElementConstructor(String userName) { - this.userName = userName; + this.botAccount = botAccount; } public String getConfigText() { diff --git a/src/gameDesign/GlobalVariableConstructor.java b/src/gameDesign/GlobalVariableConstructor.java index cb5233a..59c9b09 100644 --- a/src/gameDesign/GlobalVariableConstructor.java +++ b/src/gameDesign/GlobalVariableConstructor.java @@ -12,11 +12,14 @@ import java.util.Map; public class GlobalVariableConstructor extends ElementConstructor { - public GlobalVariableConstructor(SqlHelper helper, int botId, HashSet exceptRelation) { + public GlobalVariableConstructor(SqlHelper helper, int botId, int skipCount, String botAccount, HashSet exceptRelation, StringBuffer POS) { super(); this.helper = helper; this.botId = botId; + this.botAccount = botAccount; this.exceptRelation = exceptRelation; + this.skipCount = skipCount; + this.POS = POS; } public void construct(JSONObject gameElements, UserInfo userinfo) { @@ -34,7 +37,7 @@ public class GlobalVariableConstructor extends ElementConstructor { while (attrIter.hasNext()) { attrName = attrIter.next(); attrValue = attribute.get(attrName); - varInitialMap.put(category + "_" + attrName, attrValue); + varInitialMap.put(attrName, attrValue); } } }catch (Exception e){ diff --git a/src/gameDesign/ItemConstructor.java b/src/gameDesign/ItemConstructor.java index 00f74a6..6e8bc4c 100644 --- a/src/gameDesign/ItemConstructor.java +++ b/src/gameDesign/ItemConstructor.java @@ -11,11 +11,15 @@ import java.util.*; public class ItemConstructor extends ElementConstructor { - public ItemConstructor(SqlHelper helper, int botId, HashSet exceptRelation) { + + public ItemConstructor(SqlHelper helper, int botId, int skipCount, String botAccount, HashSet exceptRelation, StringBuffer POS) { super(); this.helper = helper; this.botId = botId; + this.botAccount = botAccount; this.exceptRelation = exceptRelation; + this.skipCount = skipCount; + this.POS = POS; } @@ -46,7 +50,11 @@ public class ItemConstructor extends ElementConstructor { for (JSONObject good : goods.toJavaList(JSONObject.class)) { name = (String) good.get("name"); + if(!name.equals("")) + POS.append("=" + name + "|名词\r\n"); className = (String) good.get("class"); + if(!className.equals("")) + POS.append("=" + className + "|名词\r\n"); if (!classSet.contains(className)) { classSet.add(className); @@ -58,6 +66,9 @@ public class ItemConstructor extends ElementConstructor { attrIter = attribute.keySet().iterator(); while (attrIter.hasNext()) { attrName = attrIter.next(); + + if(!attrName.equals("")) + POS.append("=" + attrName + "|名词\r\n"); attrValue = attribute.get(attrName); keywords.append("+" + name + ":" + attrName); @@ -71,10 +82,11 @@ public class ItemConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + keywords, " ", "match,return-0", - "{goods_query-2}", + "【{智能助手-2}】{goods_query-2}", " ", "goods_query:queryAttrByGoodsName:" + conditionName ); + jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); } @@ -83,10 +95,11 @@ public class ItemConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + classKeywords, " ", "match,return-0", - "{goods_query-2}", + "【{智能助手-2}】{goods_query-2}", " ", "goods_query:queryAroundGoodsByClassName:" + conditionName ); + jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); } } catch(Exception e){ diff --git a/src/gameDesign/MapConstructor.java b/src/gameDesign/MapConstructor.java index 1ae0ecd..7780b4e 100644 --- a/src/gameDesign/MapConstructor.java +++ b/src/gameDesign/MapConstructor.java @@ -16,11 +16,15 @@ public class MapConstructor extends ElementConstructor { Map question2keyword = new HashMap(); JSONArray locations = null; - public MapConstructor(SqlHelper helper, int botId, HashSet exceptRelation) { + + public MapConstructor(SqlHelper helper, int botId, int skipCount, String botAccount, HashSet exceptRelation, StringBuffer POS) { super(); this.helper = helper; this.botId = botId; + this.botAccount = botAccount; this.exceptRelation = exceptRelation; + this.skipCount = skipCount; + this.POS = POS; } @@ -32,10 +36,25 @@ public class MapConstructor extends ElementConstructor { //ArrayList> matrix= new ArrayList>(); //ArrayList vec1d = new ArrayList(); locationNum = locations.size(); + StringBuffer keywordSet = null; for (int i = 0; i < locationNum; i++) { jobj = locations.getJSONObject(i); jobj.put("index", i); + + keywordSet = new StringBuffer(); + keywordSet.append(jobj.get("name")); + POS.append("=" + jobj.get("name") + "|地名\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"); + } + } + } + jobj.put("name", keywordSet.toString()); + locationId = (Integer) jobj.get("id"); id2j.put(locationId, jobj); } @@ -92,6 +111,7 @@ public class MapConstructor extends ElementConstructor { } catch(Exception e){ operationStatus = 0; + e.printStackTrace(); message = "地图处理出现异常"; return; } @@ -101,17 +121,22 @@ public class MapConstructor extends ElementConstructor { /** * 生成‘我在哪里’所需要的配置文件 */ - public void generateWhereIam(JSONObject gameElements, String botName) { + public void generateWhereIam(JSONObject gameElements, String botAccount) { String conditionName = "rencheng"; - String conditionKeywords = "qiwu:哪里+qiwu:哪+现在:哪里+现在:哪"; - String zainaliKeywords = conditionKeywords.replace("botName", botName); + + String nickname = "qiwu"; + + String conditionKeywords = nickname + ":哪里+" + nickname + ":哪+现在:哪里+现在:哪"; jConfig = new JConfig( - conditionName + "::match-Include=" + zainaliKeywords, " ", - "match", "你在{site-2}", "yaobuyao", "" + conditionName + "::match-Include=" + conditionKeywords, " ", + "match", "【{智能助手-2}】你在{site-2}", "yaobuyao", "" ); jConfig.setNextStepStatus("return-0"); + jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); + + } @@ -124,90 +149,76 @@ public class MapConstructor extends ElementConstructor { public void generateHowToThere(int[][] pathMatirx, int[][] preTable, JSONObject gameElements) { String conditionName = "want_know_zenmezuo"; String conditionKeywords = "去:地点"; + StringBuffer placeKeywords = new StringBuffer(); - String placeA, placeB, descriptionB, placeKeywords, text, pathNode; + String placeA, placeB, descriptionB, text, pathNode; for (int i = 0; i < locationNum; i++) { - for (int j = 0; j < locationNum; j++) { + placeA = (String) locations.getJSONObject(i).get("name"); + placeKeywords.append("+" + placeA); +// for(String nickname:JSONArray.parseArray(locations.getJSONObject(i).getJSONArray("nickname").toJSONString(), String.class)){ +// placeKeywords.append("+" + nickname); +// } + } + + for (int j = 0; j < locationNum; j++) { - placeA = (String) locations.getJSONObject(i).get("name"); placeB = (String) locations.getJSONObject(j).get("name"); - placeKeywords = conditionKeywords.replace("地点", placeB); +// for(String nickname:JSONArray.parseArray(locations.getJSONObject(i).getJSONArray("nickname").toJSONString(), String.class)){ +// placeB += "+" + nickname; +// } jConfig = new JConfig( conditionName + "::match-Include=" + placeKeywords - + ",is_neighbour:"+ conditionName + "::match-Include=0", - "site::match-Include=" + placeA , + + ",isNeighbour:"+ conditionName + "::match-Include=0", + "site::match-Include=" + placeB , "match,return-0", - "你已经在"+placeB + "了", + "【{智能助手-2}】你已经在"+ "{" + conditionName + "-1}" + "了", " ", "" ); jConfig.setNextStepStatus("return-0"); + jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); + + + + jConfig = new JConfig( conditionName + "::match-Include=" + placeKeywords - + ",is_neighbour:"+ conditionName + "::match-Include=1", - "site::match-Include=" + placeA , + + ",isNeighbour:"+ conditionName + "::match-Include=1", + "site::match-Include=" + placeB , "match,return-0", - placeB + "就在旁边哦", + "【{智能助手-2}】{" + conditionName + "-1}" + "就在旁边哦", " ", "" ); jConfig.setNextStepStatus("return-0"); + jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); + + + jConfig = new JConfig( conditionName + "::match-Include=" + placeKeywords - + ",is_neighbour:"+ conditionName + "::match-Include=2", - "site::match-Include=" + placeA , + + ",isNeighbour:"+ conditionName + "::match-Include=2", + "site::match-Include=" + placeB , "match,return-0", - "{map_reply-2}", + "【{智能助手-2}】{map_reply-2}", " ", - "map_reply:queryPathBySite:" + conditionName + "map_reply:queryHowToPathBySite:" + conditionName ); jConfig.setNextStepStatus("return-0"); + jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); - - - -// if (i == j) { -// jConfig = new JConfig( -// conditionName + "::match-Include=" + placeKeywords, "site::match-Include=" + placeA, -// "match", "你已经在" + placeB + "了", "yaobuyao", "" -// ); -// jConfigList.add(jConfig); -// continue; -// } -// ; -// if (pathMatirx[i][j] == 1) { -// jConfig = new JConfig( -// conditionName + "::match-Include=" + placeKeywords, "site::match-Include=" + placeA, -// "match", placeB + "就在附近哦", "yaobuyao", "" -// ); -// jConfigList.add(jConfig); -// -// } else if (pathMatirx[i][j] > 1 && pathMatirx[i][j] < Integer.MAX_VALUE) { -// int k = preTable[i][j]; -// pathNode = ""; -// while (k != j) { -// pathNode += (String) locations.getJSONObject(k).get("name"); -// k = preTable[k][j]; -// } -// -// jConfig = new JConfig( -// conditionName + "::match-Include=" + placeKeywords, "site::match-Include=" + placeA, -// "match", "经过" + pathNode + "就可以到达" + placeB, "yaobuyao", "" -// ); -// jConfigList.add(jConfig); -// } } - } + } @@ -232,9 +243,10 @@ public class MapConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, "site::match-Include=" + placeA, - "match,return-0", "你可以去{map_reply-2}" + pathNode, " ", "map_reply:queryCanGoBySite:" + "match,return-0", "【{智能助手-2}】{map_reply-2}", " ", "map_reply:queryCanGoBySite:" ); jConfig.setNextStepStatus("return-0"); + jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); } } @@ -244,10 +256,11 @@ public class MapConstructor extends ElementConstructor { * 生成‘我要去那里’所需要的配置文件 */ public void generateWantToThere(int[][] pathMatirx, int[][] preTable, JSONObject gameElements) { - String placeA, placeB, descriptionB, placeKeywords, text, pathNode, lastTaskCondition, lastTaskReply; + String placeA, placeB, descriptionB, text, pathNode, lastTaskCondition, lastTaskReply; String conditionName = "yaobuyao"; String conditionKeywords = "地点"; String start = (String)gameElements.get("start"); + String placeKeywords; for (int i = 0; i < locationNum; i++) { @@ -258,7 +271,7 @@ public class MapConstructor extends ElementConstructor { */ if(!varInitialMap.containsKey("任务线" + placeA + "最后一个condition")) { varInitialMap.put("任务线" + placeA + "最后一个condition", "yaobuyao"); - varInitialMap.put("任务线" + placeA + "最后的回答", "你来到了" + placeA + ",现在什么都没有, 请继续之前的剧情,接着往下玩吧!"); + varInitialMap.put("任务线" + placeA + "最后的回答", "你来到了" + placeA.split("\\+")[0] + ",现在什么都没有, 请继续之前的剧情,接着往下玩吧!"); conditionDescription.put("任务线" + placeA + "最后一个condition", "任务线" + placeA + "最后一个condition"); conditionDescription.put("任务线" + placeA + "最后的回答", "任务线" + placeA + "最后的回答"); } @@ -274,103 +287,57 @@ public class MapConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + placeKeywords - + ",is_neighbour:"+ conditionName + "::match-Include=0", + + ",isNeighbour:"+ conditionName + "::match-Include=0", "site::match-Include=" + placeA , "match,return-0", - "你已经在"+placeB + "了", + "【{智能助手-2}】你已经在"+placeB + "了", " ", "" ); - jConfig.setNextStepStatus("return-0"); + jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); - jConfig = new JConfig( - conditionName + "::match-Include=" + placeKeywords + "," + conditionName + "::match-Include=" + placeKeywords, - - "site::match-Include=" + placeA + "," + lastTaskCondition + "::match-Include=null" + "," + lastTaskReply + "::match-Include=null", - "match, reutrn-0", "地点尚未激活", "yaobuyao", "" - ); - jConfig.setNextStepStatus("return-0"); - jConfigList.add(jConfig); jConfig = new JConfig( - conditionName + "::match-Include=" + placeKeywords + "," + conditionName + "::match-Include=" + placeKeywords, + conditionName + "::match-Include=" + placeKeywords + "," + ",isNeighbour:"+ conditionName + "::match-Include=1", "site::match-Include=" + placeA, - "match, reutrn-0", "{" + lastTaskReply + "-2}", "yaobuyao", "site:" + placeB + "-<-process-nextStep:var={" + lastTaskCondition +"-2}" + "match, reutrn-0", "【{智能助手-2}】{" + lastTaskReply + "-2}", "yaobuyao", "site:" + placeB + "-<-process-nextStep:var={" + lastTaskCondition +"-2}" ); + jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); jConfig = new JConfig( conditionName + "::match-Include=" + placeKeywords - + ",is_neighbour:"+ conditionName + "::match-Include=2", + + ",isNeighbour:"+ conditionName + "::match-Include=2", "site::match-Include=" + placeA , "match,return-0", - "{map_reply-2}", + "【{智能助手-2}】{map_reply-2}", " ", - "map_reply:queryPathBySite:" + conditionName + "map_reply:queryToDoPathBySite:" + conditionName ); - jConfig.setNextStepStatus("return-0"); + jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); -// if (i == j) { -// jConfig = new JConfig( -// conditionName + "::match-Include=" + placeKeywords, "site::match-Include=" + placeA, -// "match", "你已经在" + placeB + "了", "yaobuyao", "" -// ); -// jConfigList.add(jConfig); -// continue; -// } -// ; -// -// //如果两点相邻 -// if (pathMatirx[i][j] == 1) { -// jConfig = new JConfig( -// conditionName + "::match-Include=" + placeKeywords, -// "site::match-Include=" + placeA + "," + lastTaskCondition + "::match-Include=null" + "," + lastTaskReply + "::match-Include=null", -// "match, reutrn-0", "地点尚未激活", "yaobuyao", "" -// ); -// jConfigList.add(jConfig); -// jConfig = new JConfig( -// conditionName + "::match-Include=" + placeKeywords, "site::match-Include=" + placeA, -// "match", "{" + lastTaskReply + "-2}", "yaobuyao", "site:" + placeB + "-<-process-nextStep:var={" + lastTaskCondition +"-2}" -// ); -// jConfigList.add(jConfig); -// -// -// //如果两点不是相邻点 -// } else if (pathMatirx[i][j] > 1 && pathMatirx[i][j] < Integer.MAX_VALUE) { -// -// -// int k = preTable[i][j]; -// pathNode = ""; -// while (k != j) { -// pathNode += (String) locations.getJSONObject(k).get("name"); -// k = preTable[k][j]; -// } -// jConfig = new JConfig( -// conditionName + "::match-Include=" + placeKeywords, -// "site::match-Include=" + placeA, -// "match", "从" + placeA + "不能直接到达" + placeB + ", 需要经过" + pathNode + "才能到达" + placeB, "yaobuyao", "" -// ); -// jConfigList.add(jConfig); -// } + } } + } public void generateSurroundingPeople(){ String conditionName = "know_exist_what"; String conditionKeywords = "周围:人+附近:人"; - jConfig = new JConfig( + jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match,return-0", "周围{map_query-2}。", "yaobuyao", "map_query:queryAroundNpcBySite:" + "match,return-0", "【{智能助手-2}】周围{map_query-2}。", "yaobuyao", "map_query:queryAroundNpcBySite:" ); - jConfig.setNextStepStatus("return-0"); + jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); + } public void generateSurroundingItem(){ @@ -379,10 +346,11 @@ public class MapConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match,return-0", "周围{map_query-2}。", "yaobuyao", "map_query:queryAroundGoodsBySite:" + "match,return-0", "【{智能助手-2}】周围{map_query-2}。", "yaobuyao", "map_query:queryAroundGoodsBySite:" ); - jConfig.setNextStepStatus("return-0"); + jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); + } public void generateSurroundThings(){ @@ -391,11 +359,12 @@ public class MapConstructor extends ElementConstructor { jConfig = new JConfig( conditionName + "::match-Include=" + conditionKeywords, " ", - "match,return-0", "周围{map_query-2}。", "yaobuyao", "map_query:queryAroundAllBySite:" + "match,return-0", "【{智能助手-2}】周围{map_query-2}。", "yaobuyao", "map_query:queryAroundAllBySite:" ); - jConfig.setNextStepStatus("return-0"); + jConfig.setAuxiliaryPriority("1"); jConfigList.add(jConfig); + } -} +} \ No newline at end of file diff --git a/src/gameDesign/PlotConstructor.java b/src/gameDesign/PlotConstructor.java index 18dbab5..a7c576e 100644 --- a/src/gameDesign/PlotConstructor.java +++ b/src/gameDesign/PlotConstructor.java @@ -14,8 +14,6 @@ import java.util.*; public class PlotConstructor extends ElementConstructor { - String botName = ""; - JSONArray plots = null; HashMap> adjList = new HashMap>(); HashMap> revAdjList = new HashMap>(); @@ -26,11 +24,14 @@ public class PlotConstructor extends ElementConstructor { return id2j; } - public PlotConstructor(SqlHelper helper, int botId, HashSet exceptRelation) { + public PlotConstructor(SqlHelper helper, int botId, int skipCount, String botAccount, HashSet exceptRelation, StringBuffer POS) { super(); this.helper = helper; this.botId = botId; + this.botAccount = botAccount; this.exceptRelation = exceptRelation; + this.skipCount = skipCount; + this.POS = POS; } public void construct(JSONObject jsonObject, UserInfo userinfo) { @@ -46,7 +47,7 @@ public class PlotConstructor extends ElementConstructor { if (id2j.containsKey(start)) { String taskLineName = "任务线_" + id2j.get(start).get("place") + "进度"; conditionDescription.put(taskLineName, taskLineName); - varInitialMap.put(taskLineName, start); + varInitialMap.put("unknownText", "你说啥?"); varInitialMap.put("game_step", (String) id2j.get(start).get("id")); conditionDescription.put("unknownText", "对于无法识别的问题做出的回答"); @@ -61,7 +62,7 @@ public class PlotConstructor extends ElementConstructor { } else { System.out.println("start剧情不存在"); operationStatus = 0; - message = "start剧情不存在"; + message = "开始剧情不存在,请到剧情列表设置"; return; } } catch(Exception e){ @@ -104,512 +105,64 @@ public class PlotConstructor extends ElementConstructor { } - /** - * 根据每个剧情点的进度设置计数器 - * @param root - * @param userinfo - */ - public void BFSGenerate(JSONObject root, UserInfo userinfo) { - String id = (String) root.get("id"), adjId, nextId, taskName = "", value = "", extraHP = "", extraUK = "", nextTaskName, keywordOptions, conditionName, - nextUnknownText, curUnknownText, nextCondition; - boolean newBranch, manyParent; - JSONObject node = null, branchNode = null, adjNode = null; - JSONArray branch = null; - - List adjNodeList = null; - int priority, taskStep, nextPriority, nextTaskStep, branchSize; - - root.put("priority", 0); - root.put("taskName", id); - root.put("taskStep", 0); - root.put("nextUnknownText", varInitialMap.get("unknownText")); - ; - - - Queue queue = new LinkedList(); - - queue.add(root); - - while (!queue.isEmpty()) { - node = queue.remove(); - id = (String) node.get("id"); - conditionDescription.put(id, "剧情" + id + "进度"); - varInitialMap.put(id, ""); - - - taskName = (String) node.get("taskName"); - priority = (Integer) node.get("priority"); - taskStep = (Integer) node.get("taskStep"); - conditionName = (String) node.get("conditionName"); - curUnknownText = (String) node.get("nextUnknownText"); - - //初始化 - newBranch = false; - manyParent = false; - - adjNodeList = adjList.get(id); - visited.put(id, true); - - //查看是否存在多个子结点,如果有就是一个分支 - if (adjNodeList.size() > 1) - newBranch = true; - - //查看是否存在多个父节点 - if (revAdjList.get(id) != null) - manyParent = revAdjList.get(id).size() > 1; - - if (newBranch) { - //多个分支时nextTaskName为子结点的id名,不在这里设 - nextTaskStep = 1; - } else { - if (manyParent) { - nextTaskName = id; - nextTaskStep = 1; - priority++; - } else { - nextTaskName = taskName; - nextTaskStep = taskStep + 1; - } - } - - - branch = node.getJSONArray("branch"); - branchSize = branch.size(); - //当两次出现unknown时给用户一下候选项 - keywordOptions = ""; - - - for (int i = 0; i < branchSize; i++) { - - branchNode = branch.getJSONObject(i); - nextId = (String) branchNode.get("nextPlotId"); - Map updateKnowledge = JSONObject.toJavaObject(branchNode.getJSONObject("updateKnowledge"), Map.class); - nextUnknownText = updateKnowledge.get("unknownText"); - - - if (id2j.get(nextId) != null) - nextCondition = (String) id2j.get(nextId).get("conditionName"); - else - nextCondition = " "; - - - //unknown计数器更新为0, 当前任务状态+1 - if (newBranch) - extraUK = taskName + ":" + taskStep; - //多余步骤,以后要处理掉 - - else - extraUK = taskName + ":" + (taskStep + 1); - - - extraHP = taskName + "::match-Include=" + taskStep; - if (newBranch || (revAdjList.get(nextId) != null && revAdjList.get(nextId).size() > 1)) - extraHP += "," + nextId + "::match-Include=null"; - extraUK += "-<-" + nextId + ":" + 1; - - jConfig = new JConfig( - JSONArray.parseArray(branchNode.getJSONArray("curPremise").toJSONString(), String.class), - JSONArray.parseArray(branchNode.getJSONArray("hisPremise").toJSONString(), String.class), - updateKnowledge, - "", extraHP, extraUK, - "match", (String) branchNode.get("reply"), (String) nextCondition, String.valueOf(priority) - ); - jConfigList.add(jConfig); - - - try { - keywordOptions += jConfig.getCurPremise().split(",")[0].split("=")[1].split("\\+")[0] + " 或者"; - } catch (Exception e) { - e.printStackTrace(); - } - - - if (branchNode.get("nextPlotId") != null) { - adjId = (String) branchNode.get("nextPlotId"); - if (visited.get(adjId) == null) { - if (id2j.get(adjId) != null) { - adjNode = id2j.get(adjId); - - adjNode.put("nextUnknownText", nextUnknownText); - adjNode.put("taskStep", nextTaskStep); - if (newBranch) { - adjNode.put("priority", priority + 1); - adjNode.put("taskName", adjId); - } else { - adjNode.put("priority", priority); - adjNode.put("taskName", taskName); - } - queue.add(adjNode); - } else { - conditionDescription.put(adjId, "剧情" + adjId + "进度"); - varInitialMap.put(adjId, ""); - } - } - } - } - - - //对于unknown的特殊处理 - if (curUnknownText.equals("")) { - jConfig = new JConfig( - conditionName + "::match-Include=unknown", - extraHP = taskName + "::match-Include=" + taskStep, - "match,return-0,post::all(" + CHITCHAT_URL + ")", - " ", - " ", - "" - ); - jConfigList.add(jConfig); - } - /* - jConfig.setNextStepStatus("return-0"); - jConfigList.add(jConfig); - jConfig = new JConfig( - conditionName + "::match-Keyword=unknown", - extraHP + ",unknown_counter::number-SmallOrEqual=0", - "match", - "{unknownReply-2}", - " ", - "unknown_counter:+1" - ); - jConfig.setNextStepStatus("return-0"); - jConfigList.add(jConfig); - jConfig = new JConfig( - conditionName + "::match-Keyword=unknown", - extraHP + ",unknown_counter::number-BiggerOrEqual=1", - "match", - "你可以说" + keywordOptions, - " ", - "unknown_counter:+1" - ); - jConfig.setNextStepStatus("return-0"); - jConfigList.add(jConfig); - - */ - - - } - //unknown时的处理 - jConfig = new JConfig(" ", " ", "", "{unknownText-2}", " ", ""); - jConfig.setNextStepStatus("return-0"); - jConfigList.add(jConfig); - - - } - - - //每个结点分为0、1、2三种状态 - public void BFSGenerate2(JSONObject root) { - String id = (String) root.get("id"), adjId, nextId, taskName = "", value = "", extraHP = "", extraUK = "", nextTaskName, keywordOptions, conditionName, - unknownReply1, unknownReply2, nextCondition; - boolean newBranch, manyParent; - JSONObject node = null, branchNode = null, adjNode = null; - JSONArray branch = null; - - List adjNodeList = null; - int priority, taskStep, nextPriority, nextTaskStep, branchSize; - - root.put("priority", 0); - root.put("taskName", id); - root.put("taskStep", 0); - - - Queue queue = new LinkedList(); - - queue.add(root); - - while (!queue.isEmpty()) { - node = queue.remove(); - id = (String) node.get("id"); - - - //初始化 - newBranch = false; - manyParent = false; - - adjNodeList = adjList.get(id); - visited.put(id, true); - - /* - //查看是否存在多个子结点,如果有就是一个分支 - if(adjNodeList.size() > 1) - newBranch = true; - - //查看是否存在多个父节点 - if(revAdjList.get(id) != null) - manyParent = revAdjList.get(id).size() > 1; - - if(newBranch){ - //多个分支时nextTaskName为子结点的id名,不在这里设 - nextTaskStep = 1; - } - else{ - if(manyParent){ - nextTaskName = id; - nextTaskStep = 1; - priority++; - } - else{ - nextTaskName = taskName; - nextTaskStep = taskStep + 1; - } - } - */ - - - branch = node.getJSONArray("branch"); - branchSize = branch.size(); - //当两次出现unknown时给用户一下候选项 - keywordOptions = ""; - extraHP = id + "::match-Include=" + 1; - - - for (int i = 0; i < branchSize; i++) { - - branchNode = branch.getJSONObject(i); - nextId = (String) branchNode.get("nextPlotId"); - if (id2j.get(nextId) != null) - nextCondition = (String) id2j.get(nextId).get("conditionName"); - else - nextCondition = " "; - - - extraUK = id + ":" + "+1-<-" + nextId + ":" + "+1"; - - - //if(newBranch || (revAdjList.get(nextId) != null && revAdjList.get(nextId).size() > 1)) - // extraUK += "-<-" + nextId + ":" + 1; - - jConfig = new JConfig( - JSONArray.parseArray(branchNode.getJSONArray("curPremise").toJSONString(), String.class), - JSONArray.parseArray(branchNode.getJSONArray("hisPremise").toJSONString(), String.class), - JSONObject.toJavaObject(branchNode.getJSONObject("updateKnowledge"), Map.class), - "", extraHP, extraUK, - "match", (String) branchNode.get("reply"), (String) nextCondition, "0" - ); - jConfigList.add(jConfig); - - try { - keywordOptions += jConfig.getCurPremise().split(",")[0].split("=")[1].split("\\+")[0] + " 或者"; - } catch (Exception e) { - e.printStackTrace(); - } - - - if (branchNode.get("nextPlotId") != null) { - adjId = (String) branchNode.get("nextPlotId"); - if (visited.get(adjId) == null && id2j.get(adjId) != null) { - adjNode = id2j.get(adjId); - - queue.add(adjNode); - } - } - } - - - } - //unknown时的处理 - jConfig = new JConfig(" ", " ", "", "{unknownText-2}", " ", ""); - jConfig.setNextStepStatus("return-0"); - jConfigList.add(jConfig); - - - } - /** * 将所有剧情根据地点分为多条剧情线,每一条剧情线都有一个计数器,记录当前地点的剧情到了第几步。 + * 加上剧情计数器, 每一步分为三个状态 * @param root * @param userinfo */ - public void BFSGenerate3(JSONObject root, UserInfo userinfo) { - String id, rootId = (String) root.get("id"), adjId, nextId, parentId, taskName = "", value = "", extraHP = "", extraUK = "", nextTaskName, keywordOptions, conditionName, + public void BFSGenerate4(JSONObject root, UserInfo userinfo, JSONObject jsonObject) { + String id, rootId = (String) root.get("id"), adjId, nextId, parentId, taskName = "", value = "", extraHP = "", extraUK = "", nextTaskName, keywordOptions, conditionName = "yaobuyao", nextUnknownText, curUnknownText, nextCondition, location, nextLocation, taskLineName, nTaskLineName, lastTaskReply, lastTaskCondition; boolean newBranch, manyParent; JSONObject node = null, branchNode = null, adjNode = null; JSONArray branch = null; + String taskLine = "任务线_%s进度"; + List adjNodeList = null; int priority, taskStep, nextPriority, nextTaskStep, branchSize; - - root.put("nextUnknownText", varInitialMap.get("unknownText")); root.put("parentId", "null"); + jsonObject.put("plotStartText", ((String)jsonObject.get("plotStartText")).replace("\n", "").replace(",", ",")); - - Queue queue = new LinkedList(); - System.out.println("rootId"); - - queue.add(root); - - while (!queue.isEmpty()) { - node = queue.remove(); - id = (String) node.get("id"); - parentId = (String) node.get("parentId"); - location = (String) node.get("place"); - conditionName = (String) node.get("conditionName"); - curUnknownText = (String) node.get("nextUnknownText"); - taskLineName = "任务线_" + location + "进度"; - //本任务线的最后一个condition和本任务线的最后一个回答 - - - - if (!varInitialMap.containsKey(taskLineName)) { - conditionDescription.put(taskLineName, taskLineName); - varInitialMap.put(taskLineName, ""); - } - - //初始化 - newBranch = false; - manyParent = false; - - adjNodeList = adjList.get(id); - visited.put(id, true); - - - branch = node.getJSONArray("branch"); - branchSize = branch.size(); - //当两次出现unknown时给用户一下候选项 - keywordOptions = ""; - - - for (int i = 0; i < branchSize; i++) { - - branchNode = branch.getJSONObject(i); - - nextId = (String) branchNode.get("nextPlotId"); - Map updateKnowledge = JSONObject.toJavaObject(branchNode.getJSONObject("updateKnowledge"), Map.class); - nextUnknownText = updateKnowledge.get("unknownText"); - - - //如果存在下一剧情,就将下一步剧情的condition设为下一个激活的conditin,把地点更新为下一步剧情的地点,并更新任务线进度 - if (id2j.get(nextId) != null) { - nextCondition = (String) id2j.get(nextId).get("conditionName"); - nextLocation = (String) id2j.get(nextId).get("place"); - nTaskLineName = "任务线_" + nextLocation + "进度"; - } else { - //如果不存在下一剧情,就将condition设为空,任务线进度不变 - nextCondition = " "; - nTaskLineName = taskLineName; - nextLocation = location; - } - - lastTaskCondition = "任务线" + nextLocation + "最后一个condition"; - lastTaskReply = "任务线" + nextLocation + "最后的回答"; - - - //额外条件是任务线进度达到当前剧情,额外更新变量是将任务线移动至下一剧情 - extraHP = taskLineName + "::match-Include=" + id + ",site::match-Include=" + location; - - - - //测试用 - System.out.println(id); - - extraUK = nTaskLineName + ":" + nextId + "-<-site:" + nextLocation + "-<-" + lastTaskCondition + ":var={nextStep-3}" + "-<-" + lastTaskReply + ":var={reply-3}"; - - - - jConfig = new JConfig( - JSONArray.parseArray(branchNode.getJSONArray("curPremise").toJSONString(), String.class), - JSONArray.parseArray(branchNode.getJSONArray("hisPremise").toJSONString(), String.class), - updateKnowledge, - "", extraHP, extraUK, - "match", (String) branchNode.get("reply"), (String) nextCondition, "0" - ); - jConfigList.add(jConfig); - - - -// try { -// keywordOptions += jConfig.getCurPremise().split(",")[0].split("=")[1].split("\\+")[0] + " 或者"; -// } catch (Exception e) { -// e.printStackTrace(); -// } - - - if (branchNode.get("nextPlotId") != null) { - adjId = (String) branchNode.get("nextPlotId"); - if (visited.get(adjId) == null) { - if (id2j.get(adjId) != null) { - adjNode = id2j.get(adjId); - - adjNode.put("parentId", id); - adjNode.put("nextUnknownText", nextUnknownText); - queue.add(adjNode); - } else { - conditionDescription.put(adjId, "剧情" + adjId + "进度"); - varInitialMap.put(adjId, ""); - } - } - } - } - + if(root.get("conditionName") != null && !root.get("conditionName").equals("")) + conditionName = (String)root.get("conditionName"); + String startPlace = (String)root.get("place"); + varInitialMap.put("site", startPlace); + varInitialMap.put("任务线" + startPlace + "最后一个condition", ""); + varInitialMap.put("任务线" + startPlace + "最后的回答", ""); + conditionDescription.put("任务线" + startPlace + "最后一个condition","任务线" + startPlace + "最后一个condition"); + conditionDescription.put("任务线" + startPlace + "最后的回答", "任务线" + startPlace + "最后的回答"); - //对于unknown的特殊处理 - if (curUnknownText.equals("")) { - jConfig = new JConfig( - conditionName + "::match-Include=unknown", - extraHP = "任务线_" + location + "进度::match-Include=" + parentId, - "match,return-0,post::all(" + CHITCHAT_URL + ")", - " ", - " ", - "" - ); - jConfigList.add(jConfig); - } - } + //用于开始游戏的配置 jConfig = new JConfig( - " ", " ", "", " ", " ", "" + "start_options::match-Include=+开始+开始游戏+继续游戏+继续", + "任务线" + startPlace + "最后一个condition::match-Include=+null", + "match", + (String)jsonObject.get("plotStartText"), + conditionName, + "任务线" + startPlace + "最后一个condition:" + conditionName + "-<-" + root.get("id") + ":+1" + + "-<-任务线" + startPlace + "最后的回答:" + (String)jsonObject.get("plotStartText") + "-<-" + String.format(taskLine, root.get("place")) + ":" + root.get("id") ); - jConfig.setStatus("sleeping"); - jConfig.setConfigName("unknown"); - jConfig.setjStatus(1); jConfigList.add(jConfig); jConfig = new JConfig( - " ", "", "", " " ," ", "" + " ", + "任务线" + startPlace + "最后一个condition::match-Include=+null", + "match", + "请说开始游戏或者继续游戏", + "start_options", + "" ); - jConfig.setStatus("sleeping"); - jConfig.setConfigName("common_answer"); - jConfig.setjStatus(1); jConfigList.add(jConfig); - } - - - /** - * 将所有剧情根据地点分为多条剧情线,每一条剧情线都有一个计数器,记录当前地点的剧情到了第几步。 - * 加上剧情计数器, 每一步分为三个状态 - * @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 = "", extraHP = "", extraUK = "", nextTaskName, keywordOptions, conditionName, - nextUnknownText, curUnknownText, nextCondition, location, nextLocation, taskLineName, nTaskLineName, lastTaskReply, lastTaskCondition; - boolean newBranch, manyParent; - JSONObject node = null, branchNode = null, adjNode = null; - JSONArray branch = null; - - List adjNodeList = null; - int priority, taskStep, nextPriority, nextTaskStep, branchSize; - - root.put("nextUnknownText", varInitialMap.get("unknownText")); - root.put("parentId", "null"); - - - String startPlace = (String)root.get("place"); - varInitialMap.put("site", startPlace); - varInitialMap.put("任务线" + startPlace + "最后一个condition", (String)root.get("conditionName")); - varInitialMap.put("任务线" + startPlace + "最后的回答", (String)jsonObject.get("plotStartText")); - conditionDescription.put("任务线" + startPlace + "最后一个condition","任务线" + startPlace + "最后一个condition"); - conditionDescription.put("任务线" + startPlace + "最后的回答", "任务线" + startPlace + "最后的回答"); - Queue queue = new LinkedList(); @@ -664,13 +217,15 @@ public class PlotConstructor extends ElementConstructor { //如果存在下一剧情,就将下一步剧情的condition设为下一个激活的conditin,把地点更新为下一步剧情的地点,并更新任务线进度 if (id2j.get(nextId) != null) { nextCondition = (String) id2j.get(nextId).get("conditionName"); + if(nextCondition.equals("")) + nextCondition = "yaobuyao"; nextLocation = (String) id2j.get(nextId).get("place"); nTaskLineName = "任务线_" + nextLocation + "进度"; } else { //如果不存在下一剧情,就将condition设为空,任务线进度不变 - nextCondition = " "; nTaskLineName = taskLineName; nextLocation = location; + nextCondition = "yaobuyao"; } lastTaskCondition = "任务线" + nextLocation + "最后一个condition"; @@ -680,8 +235,8 @@ 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 + "-<-site:" + nextLocation + "-<-" + lastTaskCondition + ":var={nextStep-3}" + "-<-" + lastTaskReply + ":var={reply-3}" + - "-<-" + id + ":" + "+1-<-" + nextId + ":" + "+1" + "-<-game_step:" + botName + "_plot_" + nextId; + extraUK = nTaskLineName + ":" + nextId + "-<-site:" + nextLocation + "-<-" + lastTaskCondition + ":" + nextCondition + "-<-" + lastTaskReply + ":var={reply-3}" + + "-<-" + id + ":" + "+1-<-" + nextId + ":" + "+1" + "-<-game_step:" + botAccount + "_plot_" + nextId; List curPremiseList = JSONArray.parseArray(branchNode.getJSONArray("curPremise").toJSONString(), String.class); @@ -696,21 +251,13 @@ public class PlotConstructor extends ElementConstructor { if (curPremiseList.size() == 0){ jConfig.setFeature(jConfig.getFeature() + ",activate,post::all(http://simqa.sz.chewrobot.com:28081/game)"); - jConfig.setNextStep("queryskip1,queryskip2"); - jConfig.setUpdateKnowledge(jConfig.getUpdateKnowledge() + "-<-临时变量1:{nextStep-3}-<-临时变量2:{reply-3}"); + jConfig.setNextStep("queryskip1,queryskip2,queryskip3"); + jConfig.setUpdateKnowledge(jConfig.getUpdateKnowledge() + "-<-临时变量1:"+ nextCondition +"-<-临时变量2:var={reply-3}"); jConfig.setNextStepStatus("active"); } jConfigList.add(jConfig); - -// try { -// keywordOptions += jConfig.getCurPremise().split(",")[0].split("=")[1].split("\\+")[0] + " 或者"; -// } catch (Exception e) { -// e.printStackTrace(); -// } - - if (branchNode.get("nextPlotId") != null) { adjId = (String) branchNode.get("nextPlotId"); if (visited.get(adjId) == null) { @@ -750,11 +297,15 @@ public class PlotConstructor extends ElementConstructor { /** * ---------------------------------------------------------------------------------------------------- - * 待激活列表,用于qa问答 + * 不设剧情不设条件时的处理 + * 1. 如果qa返回大于90则回答common_answer+ 剧情回答,并进入下一步剧情,这里的下一步condition是从激活之前保存的临时变量中读取出来的 + * 2. 如果qa返回小于90则只回答剧情文本 + * 3. 如果qa返回not_found则只回答剧情文本 + * 4. 无论哪种情况都会跳下一步剧情 */ jConfig = new JConfig( - " ", "qa_status::match-Include=ok,qa_score::number-Smaller=90", "match", "{临时变量2-2}", " ", "process-nextStep:{临时变量1-2}" + " ", "qa_status::match-Include=ok,qa_score::number-Smaller=90", "match", "{临时变量2-2}", " ", "process-nextStep:var={临时变量1-2}" ); jConfig.setStatus("sleeping"); jConfig.setConfigName("queryskip1"); @@ -763,7 +314,7 @@ public class PlotConstructor extends ElementConstructor { jConfig = new JConfig( - " ", "qa_status::match-Include=ok,qa_score::number-BiggerOrEqual=90", "match", "{common_answer-2}, {临时变量2-2}", " ", "process-nextStep:{临时变量1-2}" + " ", "qa_status::match-Include=ok,qa_score::number-BiggerOrEqual=90", "match", "{common_answer-2}, {临时变量2-2}", " ", "process-nextStep:var={临时变量1-2}" ); jConfig.setStatus("sleeping"); jConfig.setConfigName("queryskip2"); @@ -771,7 +322,7 @@ public class PlotConstructor extends ElementConstructor { jConfigList.add(jConfig); jConfig = new JConfig( - " ", "qa_status::match-Include=not_found", "match", "{临时变量2-2}", " ", "process-nextStep:{临时变量1-2}" + " ", "qa_status::match-Include=not_found", "match", "{临时变量2-2}", " ", "process-nextStep:var={临时变量1-2}" ); jConfig.setStatus("sleeping"); jConfig.setConfigName("queryskip3"); @@ -781,7 +332,10 @@ public class PlotConstructor extends ElementConstructor { - + /** + * ---------------------------------------------------------------------------------------------------- + * 待激活列表,用于qa问答 + */ jConfig = new JConfig( " ", "qa_status::match-Include=not_found", "match,return-0", "{unknownText-2}", " ", "" @@ -789,7 +343,6 @@ public class PlotConstructor extends ElementConstructor { jConfig.setStatus("sleeping"); jConfig.setConfigName("unknown1"); jConfig.setjStatus(1); - jConfig.setNextStepStatus("return-0"); jConfigList.add(jConfig); @@ -801,7 +354,6 @@ public class PlotConstructor extends ElementConstructor { jConfig.setStatus("sleeping"); jConfig.setConfigName("unknown2"); jConfig.setjStatus(1); - jConfig.setNextStepStatus("return-0"); jConfigList.add(jConfig); @@ -813,7 +365,6 @@ public class PlotConstructor extends ElementConstructor { jConfig.setStatus("sleeping"); jConfig.setConfigName("unknown3"); jConfig.setjStatus(1); - jConfig.setNextStepStatus("return-0"); jConfigList.add(jConfig); @@ -823,7 +374,6 @@ public class PlotConstructor extends ElementConstructor { jConfig.setStatus("sleeping"); jConfig.setConfigName("unknown4"); jConfig.setjStatus(1); - jConfig.setNextStepStatus("return-0"); jConfigList.add(jConfig); @@ -833,11 +383,19 @@ public class PlotConstructor extends ElementConstructor { jConfig.setStatus("sleeping"); jConfig.setConfigName("common_answer"); jConfig.setjStatus(1); - jConfig.setNextStepStatus("return-0"); jConfigList.add(jConfig); //--------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------- + + /** + * ---------------------------------------------------------------------------------------------------- + * 用于处理开始游戏或者继续游戏 + * + * + */ + + } @Override diff --git a/src/processing/ChatCacheController.java b/src/processing/ChatCacheController.java index 5837a46..2e2deff 100644 --- a/src/processing/ChatCacheController.java +++ b/src/processing/ChatCacheController.java @@ -19,7 +19,7 @@ import java.util.Map; public class ChatCacheController { - public static long TIME_OUT = 5000; + public static long TIME_OUT = 300000; private static String CHAT_CACHE_DIR = "ChatCache"; @@ -189,8 +189,8 @@ public class ChatCacheController { try { chatCache = chatCacheMap.get(chatKey); if(chatCache == null){ - if(receiveParamters.containsKey("yaobuyao") && (receiveParamters.get("yaobuyao")[0].contains("开始游戏") || - receiveParamters.get("yaobuyao")[0].contains("继续游戏")|| receiveParamters.get("yaobuyao")[0].contains("开始"))) { + if(receiveParamters.containsKey("start_options") && (receiveParamters.get("start_options")[0].contains("开始游戏") || + receiveParamters.get("start_options")[0].contains("继续游戏")|| receiveParamters.get("start_options")[0].contains("继续"))) { chatCache = loadChatCache(chatKey, context, userinfo, loadCacheStatus); }else { chatCache = new ChatCache(userinfo); diff --git a/src/processing/QuestionMatcher.java b/src/processing/QuestionMatcher.java index 326f59d..2d75f16 100644 --- a/src/processing/QuestionMatcher.java +++ b/src/processing/QuestionMatcher.java @@ -336,8 +336,15 @@ public class QuestionMatcher { keyword = gameEnv.queryGoodsAttrByGoodsName(nameSeries[2], nameSeries[3]); System.out.println("return" + keyword); } - }else if(actionName.startsWith("is_neighbour")){ - //keyword = gameEnv.isNeighbour(historyInfoPoint.get("site"), actionName.split(":")[1]); + }else if(actionName.startsWith("isNeighbour")){ + String opPair[] = actionName.split(":"); + if(!curInfoPoint.containsKey(opPair[1]) || curInfoPoint.get(opPair[1]).equals("unknown")){ + keyword = "not_exist"; + }else { + logWriter.record("isNeighbour(" + historyInfoPoint.get("site") + "," + curInfoPoint.get(opPair[1]).split(":")[1] + ")", 1); + keyword = String.valueOf(gameEnv.isNeighbour(historyInfoPoint.get("site"), curInfoPoint.get(opPair[1]).split(":")[1])); + logWriter.record("返回:" + keyword, 1); + } }else { keyword = infoPoint.get(actionName); @@ -735,7 +742,10 @@ public class QuestionMatcher { //停留 } else if (ansCondition.featureMap.containsKey("return-0")) { String activeList[] = historyInfoPoint.get("activeList").split("\\|"); - ans.setNext("nextStep=" + activeList[activeList.length - 1]); + if(activeList.length > 0) + ans.setNext("nextStep=" + activeList[activeList.length - 1]); + else + ans.setNext("nextStep= "); //激活 } else if (ansCondition.featureMap.containsKey("activate")) { String activeList[] = historyInfoPoint.get("activeList").split("\\|"); @@ -759,13 +769,19 @@ public class QuestionMatcher { //用正则表达式将回答中的变量模板{conditionName-2}替换成后台存储的变量值 + String keyword; reply = ans.getAnswer(); Matcher m = replacePattern.matcher(reply); while (m.find()) { variable = m.group(1).substring(1, m.group(1).length() - 3); if (m.group(1).endsWith("-1}")) { - if (curInfoPoint.get(variable) != null && !curInfoPoint.get(variable).equals("")) - reply = reply.replace("{" + variable + "-1}", curInfoPoint.get(variable)); + if (curInfoPoint.get(variable) != null && !curInfoPoint.get(variable).equals("")) { + keyword = curInfoPoint.get(variable); + if(keyword.contains(":")) + keyword = keyword.split(":")[1]; + + reply = reply.replace("{" + variable + "-1}", keyword); + } } else if (m.group(1).endsWith("-2}")) { if (historyInfoPoint.get(variable) != null) if(historyInfoPoint.get(variable).equals("do_reset")){ diff --git a/src/processing/WorldController.java b/src/processing/WorldController.java index 77f357e..d6dd61f 100644 --- a/src/processing/WorldController.java +++ b/src/processing/WorldController.java @@ -130,28 +130,69 @@ public class WorldController { } break; case "queryCanGoBySite": + if(!currentInfoPoint.containsKey(valuePair[1])) { + returnStr = "不可到达"; + break; + } sites = gameEnv.queryCanGoBySite(historyInfoPoint.get("site")); - if(sites == null || sites.size() == 0) + if(sites == null) { returnStr = "没什么地方可去的,继续玩吧"; - else { + } + else if(sites.size() == 0){ + returnStr = "没什么地方可去的,继续玩吧"; + } else { returnStr = "可以去"; if(sites.size() > 0) { for (String site : sites) returnStr += "、" + site; + System.out.println("returnStr" + returnStr); }else{ returnStr = "没什么地方可去的,继续玩吧"; } } break; - case "queryPathBySite": - sites = gameEnv.queryPathBySite(historyInfoPoint.get("site"), valuePair[1]); - if(sites == null || sites.size() == 0) + case "queryHowToPathBySite": + if(!currentInfoPoint.containsKey(valuePair[1])) { + returnStr = "不可到达"; + break; + } + + sites = gameEnv.queryPathBySite(historyInfoPoint.get("site"), currentInfoPoint.get(valuePair[1]).split(":")[1]); + if(sites == null) { + returnStr = "不可到达"; + } + else if(sites.size() == 0){ returnStr = "就在附近哦"; - else { + }else { + returnStr = "通过"; + if(sites.size() > 0) { + for (String site : sites) + returnStr += "、" + site; + returnStr += "可以到达"; + }else{ + returnStr = "就在附近哦"; + } + } + break; + + case "queryToDoPathBySite": + if(!currentInfoPoint.containsKey(valuePair[1])) { + returnStr = "不可到达"; + break; + } + + sites = gameEnv.queryPathBySite(historyInfoPoint.get("site"), currentInfoPoint.get(valuePair[1]).split(":")[1]); + if(sites == null) { + returnStr = "不可到达"; + } + else if(sites.size() == 0){ + returnStr = "就在附近哦"; + }else { returnStr = "通过"; if(sites.size() > 0) { for (String site : sites) returnStr += "、" + site; + returnStr += "可以到达"; }else{ returnStr = "就在附近哦"; } diff --git a/src/servlet/GameDesignServlet.java b/src/servlet/GameDesignServlet.java index 1dc1649..dbeccfa 100644 --- a/src/servlet/GameDesignServlet.java +++ b/src/servlet/GameDesignServlet.java @@ -35,15 +35,23 @@ public class GameDesignServlet extends HttpServlet { } }; - //每个condition的三元组两端需要补充的关键词,比如npc名字、npc属性等 - HashMap> relationKeywords = new HashMap>(); - //特定的relation的三元组不会被添加到relationKeywords - HashSet exceptRelation = new HashSet(); protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + + //所有需要修改的词性 + StringBuffer POS = new StringBuffer(); + + //每个condition的三元组两端需要补充的关键词,比如npc名字、npc属性等 + HashMap> relationKeywords = new HashMap>(); + + //特定的relation的三元组不会被添加到relationKeywords + HashSet exceptRelation = new HashSet(); + + Integer botId, projectId, dataId, returnStatus = 1; - String botAccount = null, moduleName, userName, moduleName2, returnMessage = "Success"; + String botAccount = null, userName, moduleName2, returnMessage = "Success"; ServletContext context = this.getServletContext(); JSONObject json = null, root = null; Boolean flag; @@ -95,37 +103,38 @@ public class GameDesignServlet extends HttpServlet { } - Iterator moduleIter = gameElements.keySet().iterator(); StringBuffer mergedConfigText = new StringBuffer(); - while (moduleIter.hasNext()) { + int skipCount = 0; + + String moduleList[] = {"map", "goods", "globalVariable", "npc", "plots"}; + for(String moduleName: moduleList){ - moduleName = moduleIter.next(); switch (moduleName) { case "map": moduleName2 = "地图"; - constructor = new MapConstructor(helper, botId, exceptRelation); + constructor = new MapConstructor(helper, botId, skipCount, botAccount, exceptRelation, POS); constructor.construct(gameElements, userinfo); break; case "plots": moduleName2 = "剧情"; - constructor = new PlotConstructor(helper, botId, exceptRelation); + constructor = new PlotConstructor(helper, botId, skipCount, botAccount, exceptRelation, POS); constructor.construct(gameElements, userinfo); root = ((PlotConstructor) constructor).getId2j().get((String) gameElements.get("start")); break; case "goods": moduleName2 = "物品"; - constructor = new ItemConstructor(helper, botId, exceptRelation); + constructor = new ItemConstructor(helper, botId, skipCount, botAccount, exceptRelation, POS); constructor.construct(gameElements, userinfo); break; - case "globalVarialbe": + case "globalVariable": moduleName2 = "全局变量"; - constructor = new GlobalVariableConstructor(helper, botId, exceptRelation); + constructor = new GlobalVariableConstructor(helper, botId, skipCount, botAccount, exceptRelation, POS); constructor.construct(gameElements, userinfo); break; case "npc": moduleName2 = "NPC"; - constructor = new CharacterConstructor(helper, botId, exceptRelation); + constructor = new CharacterConstructor(helper, botId, skipCount, botAccount, exceptRelation, POS); constructor.construct(gameElements, userinfo); break; default: @@ -166,7 +175,7 @@ public class GameDesignServlet extends HttpServlet { UserInfoController.buildUserInfo(br, userinfo, true); context.setAttribute(botAccount, userinfo); ConditionTableController.writeConfigText(botAccount, userinfo); - String postResult = actionRegenerate(root, gameElements, userinfo); + String postResult = actionRegenerate(root, gameElements, userinfo, relationKeywords, exceptRelation, POS); if(!postResult.equals("success")){ returnStatus = 0; @@ -221,22 +230,29 @@ public class GameDesignServlet extends HttpServlet { return deleteConfigFlag && deleteVariableFlag; } - public String actionRegenerate(JSONObject root, JSONObject gameElements, UserInfo userInfo){ - String startCondition; + public String actionRegenerate(JSONObject root, JSONObject gameElements, UserInfo userInfo, HashMap> relationKeywords, HashSet exceptRelation, StringBuffer POS){ + String startCondition, POS2 = ""; String botName = (String)gameElements.get("botName"); JSONObject returnMessage = null; JSONObject actionPostData = new JSONObject(); System.out.println("root"+ root.toJSONString()); startCondition = (String)root.get("conditionName"); - actionPostData.put("startCondition", startCondition); + actionPostData.put("startCondition", "start_options"); actionPostData.put("botName_yhm", (String)gameElements.get("botName")); actionPostData.put("botName", botName); actionPostData.put("botId", (Integer)gameElements.get("botId")); actionPostData.put("type", "game_plot_init"); - actionPostData.put("welcome", (String)gameElements.get("plotStartText")); + actionPostData.put("welcome", "欢迎来到" + (String)gameElements.get("botName") + ",请说开始游戏或者继续游戏"); actionPostData.put("relationKeywords", relationKeywords); + + if (gameElements.containsKey("POS")) + POS2 = (String)gameElements.get("POS"); + + actionPostData.put("POS", POS.toString() + POS2); + + System.out.println(actionPostData.toJSONString()); userInfo.extraInfo.put("activeAction", startCondition); diff --git a/src/servlet/GetAnswerServlet.java b/src/servlet/GetAnswerServlet.java index ef6bf5f..362cb58 100644 --- a/src/servlet/GetAnswerServlet.java +++ b/src/servlet/GetAnswerServlet.java @@ -35,7 +35,7 @@ public class GetAnswerServlet extends HttpServlet { String ansJ = "", return_str = "", state = "", chatKey = ""; String botName = receiveParamters.get("bot_name")[0]; - chatKey = receiveParamters.get("chat_key")[0].split("-")[0]; + chatKey = receiveParamters.get("chat_key")[0].split("@")[0]; receiveParamters.get("chat_key")[0] = chatKey; OutputStream out = response.getOutputStream(); -- libgit2 0.27.1