Commit d70969e1 by hxw

routine

parent 2f713101
...@@ -59,6 +59,7 @@ public class ChatCache { ...@@ -59,6 +59,7 @@ public class ChatCache {
k = iit.next(); k = iit.next();
infoPoint.put(k, userInfo.varInitialMap.get(k)); infoPoint.put(k, userInfo.varInitialMap.get(k));
} }
infoPoint.put("lastUpdateTime", String.valueOf(System.currentTimeMillis()));
} }
} }
...@@ -8,7 +8,7 @@ import java.util.Iterator; ...@@ -8,7 +8,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class JConfig { public class JConfig implements Cloneable{
private int id = 0; private int id = 0;
private String jCurPremise = ""; private String jCurPremise = "";
...@@ -69,6 +69,98 @@ public class JConfig { ...@@ -69,6 +69,98 @@ public class JConfig {
private String status = "waiting"; 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() { public String getUpdateKnowledge() {
return updateKnowledge; return updateKnowledge;
} }
...@@ -80,14 +172,15 @@ public class JConfig { ...@@ -80,14 +172,15 @@ public class JConfig {
private String updateKnowledge = ""; private String updateKnowledge = "";
private String nextStepStatus = "return"; private String nextStepStatus = "return";
Map<String, String> statusMap = new HashMap<String, String>() { static Map<String, String> statusMap = new HashMap<String, String>() {
{ {
put("return", "return"); put("return", "return");
put("return-1", "back"); put("return-1", "back");
put("return-0", "stay"); put("return-0", "stay");
put("active", "activate"); put("activate", "activate");
} }
}; };
static int querySkipCount = 10;
public void setStatus(String status) { public void setStatus(String status) {
this.status = status; this.status = status;
...@@ -252,7 +345,7 @@ public class JConfig { ...@@ -252,7 +345,7 @@ public class JConfig {
data.put("historyPremiseList", hisPremiseList); data.put("historyPremiseList", hisPremiseList);
//添加下一步状态 //添加下一步状态
data.put("nextStepStatus", statusMap.get(nextStepStatus));
//添加configName //添加configName
data.put("configName", configName); data.put("configName", configName);
...@@ -270,8 +363,15 @@ public class JConfig { ...@@ -270,8 +363,15 @@ public class JConfig {
pair = feat.substring(0, feat.length() - 1).split("\\(", 2); pair = feat.substring(0, feat.length() - 1).split("\\(", 2);
postURL = pair[1]; postURL = pair[1];
postType = pair[0].split("::")[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参数 //添加post参数
data.put("doPost", doPost); data.put("doPost", doPost);
data.put("postURL", postURL); data.put("postURL", postURL);
...@@ -319,4 +419,37 @@ public class JConfig { ...@@ -319,4 +419,37 @@ public class JConfig {
return text; 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;
}
} }
...@@ -10,11 +10,14 @@ import java.util.*; ...@@ -10,11 +10,14 @@ import java.util.*;
public class CharacterConstructor extends ElementConstructor { public class CharacterConstructor extends ElementConstructor {
public CharacterConstructor(SqlHelper helper, int botId, HashSet<String> exceptRelation) { public CharacterConstructor(SqlHelper helper, int botId, int skipCount, String botAccount, HashSet<String> exceptRelation, StringBuffer POS) {
super(); super();
this.helper = helper; this.helper = helper;
this.botId = botId; this.botId = botId;
this.botAccount = botAccount;
this.exceptRelation = exceptRelation; this.exceptRelation = exceptRelation;
this.skipCount = skipCount;
this.POS = POS;
} }
public void construct(JSONObject gameElements, UserInfo userinfo) { public void construct(JSONObject gameElements, UserInfo userinfo) {
...@@ -50,7 +53,11 @@ public class CharacterConstructor extends ElementConstructor { ...@@ -50,7 +53,11 @@ public class CharacterConstructor extends ElementConstructor {
for (JSONObject character : allNPC.toJavaList(JSONObject.class)) { for (JSONObject character : allNPC.toJavaList(JSONObject.class)) {
name = (String) character.get("name"); name = (String) character.get("name");
if(!name.equals(""))
POS.append("=" + name + "|人名\r\n");
className = (String) character.get("class"); className = (String) character.get("class");
if(!className.equals(""))
POS.append("=" + className + "|人名\r\n");
if (!classSet.contains(className)) { if (!classSet.contains(className)) {
classSet.add(className); classSet.add(className);
...@@ -64,6 +71,8 @@ public class CharacterConstructor extends ElementConstructor { ...@@ -64,6 +71,8 @@ public class CharacterConstructor extends ElementConstructor {
keywords.append("+" + repValue); keywords.append("+" + repValue);
while (attrIter.hasNext()) { while (attrIter.hasNext()) {
attrName = attrIter.next(); attrName = attrIter.next();
if(!attrName.equals(""))
POS.append("=" + attrName + "|名词\r\n");
attrValue = attribute.get(attrName); attrValue = attribute.get(attrName);
} }
...@@ -75,17 +84,25 @@ public class CharacterConstructor extends ElementConstructor { ...@@ -75,17 +84,25 @@ public class CharacterConstructor extends ElementConstructor {
for (String conditionName : relateConditions) { for (String conditionName : relateConditions) {
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + keywords, " ", 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); jConfigList.add(jConfig);
} }
//根据根据NPC类别和地点属性查询所有NPC实例 //根据根据NPC类别和地点属性查询所有NPC实例
for (String conditionName : relateConditions) { for (String conditionName : relateConditions) {
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + classKeywords, " ", 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); jConfigList.add(jConfig);
} }
}catch (Exception e){ }catch (Exception e){
operationStatus = 0; operationStatus = 0;
......
...@@ -16,11 +16,12 @@ public class ElementConstructor { ...@@ -16,11 +16,12 @@ public class ElementConstructor {
int operationStatus = 1; int operationStatus = 1;
int skipCount = 0;
SqlHelper helper = null; SqlHelper helper = null;
HashSet<String> exceptRelation = null; HashSet<String> exceptRelation = null;
JConfig jConfig = null; JConfig jConfig = null;
String CHITCHAT_URL = "http:192.168.1.178:1111/test"; String CHITCHAT_URL = "http:192.168.1.178:1111/test";
String userName; String botAccount;
...@@ -32,6 +33,7 @@ public class ElementConstructor { ...@@ -32,6 +33,7 @@ public class ElementConstructor {
StringBuffer configText = new StringBuffer(); StringBuffer configText = new StringBuffer();
Map<String, String> varInitialMap = new HashMap<String, String>(); Map<String, String> varInitialMap = new HashMap<String, String>();
Map<String, String> conditionDescription = new HashMap<String, String>(); Map<String, String> conditionDescription = new HashMap<String, String>();
StringBuffer POS = new StringBuffer();
public String getMessage() { return message; } public String getMessage() { return message; }
...@@ -57,7 +59,7 @@ public class ElementConstructor { ...@@ -57,7 +59,7 @@ public class ElementConstructor {
} }
public void ElementConstructor(String userName) { public void ElementConstructor(String userName) {
this.userName = userName; this.botAccount = botAccount;
} }
public String getConfigText() { public String getConfigText() {
......
...@@ -12,11 +12,14 @@ import java.util.Map; ...@@ -12,11 +12,14 @@ import java.util.Map;
public class GlobalVariableConstructor extends ElementConstructor { public class GlobalVariableConstructor extends ElementConstructor {
public GlobalVariableConstructor(SqlHelper helper, int botId, HashSet<String> exceptRelation) { public GlobalVariableConstructor(SqlHelper helper, int botId, int skipCount, String botAccount, HashSet<String> exceptRelation, StringBuffer POS) {
super(); super();
this.helper = helper; this.helper = helper;
this.botId = botId; this.botId = botId;
this.botAccount = botAccount;
this.exceptRelation = exceptRelation; this.exceptRelation = exceptRelation;
this.skipCount = skipCount;
this.POS = POS;
} }
public void construct(JSONObject gameElements, UserInfo userinfo) { public void construct(JSONObject gameElements, UserInfo userinfo) {
...@@ -34,7 +37,7 @@ public class GlobalVariableConstructor extends ElementConstructor { ...@@ -34,7 +37,7 @@ public class GlobalVariableConstructor extends ElementConstructor {
while (attrIter.hasNext()) { while (attrIter.hasNext()) {
attrName = attrIter.next(); attrName = attrIter.next();
attrValue = attribute.get(attrName); attrValue = attribute.get(attrName);
varInitialMap.put(category + "_" + attrName, attrValue); varInitialMap.put(attrName, attrValue);
} }
} }
}catch (Exception e){ }catch (Exception e){
......
...@@ -11,11 +11,15 @@ import java.util.*; ...@@ -11,11 +11,15 @@ import java.util.*;
public class ItemConstructor extends ElementConstructor { public class ItemConstructor extends ElementConstructor {
public ItemConstructor(SqlHelper helper, int botId, HashSet<String> exceptRelation) {
public ItemConstructor(SqlHelper helper, int botId, int skipCount, String botAccount, HashSet<String> exceptRelation, StringBuffer POS) {
super(); super();
this.helper = helper; this.helper = helper;
this.botId = botId; this.botId = botId;
this.botAccount = botAccount;
this.exceptRelation = exceptRelation; this.exceptRelation = exceptRelation;
this.skipCount = skipCount;
this.POS = POS;
} }
...@@ -46,7 +50,11 @@ public class ItemConstructor extends ElementConstructor { ...@@ -46,7 +50,11 @@ public class ItemConstructor extends ElementConstructor {
for (JSONObject good : goods.toJavaList(JSONObject.class)) { for (JSONObject good : goods.toJavaList(JSONObject.class)) {
name = (String) good.get("name"); name = (String) good.get("name");
if(!name.equals(""))
POS.append("=" + name + "|名词\r\n");
className = (String) good.get("class"); className = (String) good.get("class");
if(!className.equals(""))
POS.append("=" + className + "|名词\r\n");
if (!classSet.contains(className)) { if (!classSet.contains(className)) {
classSet.add(className); classSet.add(className);
...@@ -58,6 +66,9 @@ public class ItemConstructor extends ElementConstructor { ...@@ -58,6 +66,9 @@ public class ItemConstructor extends ElementConstructor {
attrIter = attribute.keySet().iterator(); attrIter = attribute.keySet().iterator();
while (attrIter.hasNext()) { while (attrIter.hasNext()) {
attrName = attrIter.next(); attrName = attrIter.next();
if(!attrName.equals(""))
POS.append("=" + attrName + "|名词\r\n");
attrValue = attribute.get(attrName); attrValue = attribute.get(attrName);
keywords.append("+" + name + ":" + attrName); keywords.append("+" + name + ":" + attrName);
...@@ -71,10 +82,11 @@ public class ItemConstructor extends ElementConstructor { ...@@ -71,10 +82,11 @@ public class ItemConstructor extends ElementConstructor {
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + keywords, " ", conditionName + "::match-Include=" + keywords, " ",
"match,return-0", "match,return-0",
"{goods_query-2}", "【{智能助手-2}】{goods_query-2}",
" ", " ",
"goods_query:queryAttrByGoodsName:" + conditionName "goods_query:queryAttrByGoodsName:" + conditionName
); );
jConfig.setAuxiliaryPriority("1");
jConfigList.add(jConfig); jConfigList.add(jConfig);
} }
...@@ -83,10 +95,11 @@ public class ItemConstructor extends ElementConstructor { ...@@ -83,10 +95,11 @@ public class ItemConstructor extends ElementConstructor {
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + classKeywords, " ", conditionName + "::match-Include=" + classKeywords, " ",
"match,return-0", "match,return-0",
"{goods_query-2}", "【{智能助手-2}】{goods_query-2}",
" ", " ",
"goods_query:queryAroundGoodsByClassName:" + conditionName "goods_query:queryAroundGoodsByClassName:" + conditionName
); );
jConfig.setAuxiliaryPriority("1");
jConfigList.add(jConfig); jConfigList.add(jConfig);
} }
} catch(Exception e){ } catch(Exception e){
......
...@@ -16,11 +16,15 @@ public class MapConstructor extends ElementConstructor { ...@@ -16,11 +16,15 @@ public class MapConstructor extends ElementConstructor {
Map<String, String> question2keyword = new HashMap<String, String>(); Map<String, String> question2keyword = new HashMap<String, String>();
JSONArray locations = null; JSONArray locations = null;
public MapConstructor(SqlHelper helper, int botId, HashSet<String> exceptRelation) {
public MapConstructor(SqlHelper helper, int botId, int skipCount, String botAccount, HashSet<String> exceptRelation, StringBuffer POS) {
super(); super();
this.helper = helper; this.helper = helper;
this.botId = botId; this.botId = botId;
this.botAccount = botAccount;
this.exceptRelation = exceptRelation; this.exceptRelation = exceptRelation;
this.skipCount = skipCount;
this.POS = POS;
} }
...@@ -32,10 +36,25 @@ public class MapConstructor extends ElementConstructor { ...@@ -32,10 +36,25 @@ public class MapConstructor extends ElementConstructor {
//ArrayList<ArrayList<Integer>> matrix= new ArrayList<ArrayList<Integer>>(); //ArrayList<ArrayList<Integer>> matrix= new ArrayList<ArrayList<Integer>>();
//ArrayList<Integer> vec1d = new ArrayList<Integer>(); //ArrayList<Integer> vec1d = new ArrayList<Integer>();
locationNum = locations.size(); locationNum = locations.size();
StringBuffer keywordSet = null;
for (int i = 0; i < locationNum; i++) { for (int i = 0; i < locationNum; i++) {
jobj = locations.getJSONObject(i); jobj = locations.getJSONObject(i);
jobj.put("index", i); jobj.put("index", i);
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"); locationId = (Integer) jobj.get("id");
id2j.put(locationId, jobj); id2j.put(locationId, jobj);
} }
...@@ -92,6 +111,7 @@ public class MapConstructor extends ElementConstructor { ...@@ -92,6 +111,7 @@ public class MapConstructor extends ElementConstructor {
} catch(Exception e){ } catch(Exception e){
operationStatus = 0; operationStatus = 0;
e.printStackTrace();
message = "地图处理出现异常"; message = "地图处理出现异常";
return; return;
} }
...@@ -101,17 +121,22 @@ public class MapConstructor extends ElementConstructor { ...@@ -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 conditionName = "rencheng";
String conditionKeywords = "qiwu:哪里+qiwu:哪+现在:哪里+现在:哪";
String zainaliKeywords = conditionKeywords.replace("botName", botName); String nickname = "qiwu";
String conditionKeywords = nickname + ":哪里+" + nickname + ":哪+现在:哪里+现在:哪";
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + zainaliKeywords, " ", conditionName + "::match-Include=" + conditionKeywords, " ",
"match", "你在{site-2}", "yaobuyao", "" "match", "【{智能助手-2}】你在{site-2}", "yaobuyao", ""
); );
jConfig.setNextStepStatus("return-0"); jConfig.setNextStepStatus("return-0");
jConfig.setAuxiliaryPriority("1");
jConfigList.add(jConfig); jConfigList.add(jConfig);
} }
...@@ -124,90 +149,76 @@ public class MapConstructor extends ElementConstructor { ...@@ -124,90 +149,76 @@ public class MapConstructor extends ElementConstructor {
public void generateHowToThere(int[][] pathMatirx, int[][] preTable, JSONObject gameElements) { public void generateHowToThere(int[][] pathMatirx, int[][] preTable, JSONObject gameElements) {
String conditionName = "want_know_zenmezuo"; String conditionName = "want_know_zenmezuo";
String conditionKeywords = "去:地点"; 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 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"); 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( jConfig = new JConfig(
conditionName + "::match-Include=" + placeKeywords conditionName + "::match-Include=" + placeKeywords
+ ",is_neighbour:"+ conditionName + "::match-Include=0", + ",isNeighbour:"+ conditionName + "::match-Include=0",
"site::match-Include=" + placeA , "site::match-Include=" + placeB ,
"match,return-0", "match,return-0",
"你已经在"+placeB + "了", "【{智能助手-2}】你已经在"+ "{" + conditionName + "-1}" + "了",
" ", " ",
"" ""
); );
jConfig.setNextStepStatus("return-0"); jConfig.setNextStepStatus("return-0");
jConfig.setAuxiliaryPriority("1");
jConfigList.add(jConfig); jConfigList.add(jConfig);
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + placeKeywords conditionName + "::match-Include=" + placeKeywords
+ ",is_neighbour:"+ conditionName + "::match-Include=1", + ",isNeighbour:"+ conditionName + "::match-Include=1",
"site::match-Include=" + placeA , "site::match-Include=" + placeB ,
"match,return-0", "match,return-0",
placeB + "就在旁边哦", "【{智能助手-2}】{" + conditionName + "-1}" + "就在旁边哦",
" ", " ",
"" ""
); );
jConfig.setNextStepStatus("return-0"); jConfig.setNextStepStatus("return-0");
jConfig.setAuxiliaryPriority("1");
jConfigList.add(jConfig); jConfigList.add(jConfig);
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + placeKeywords conditionName + "::match-Include=" + placeKeywords
+ ",is_neighbour:"+ conditionName + "::match-Include=2", + ",isNeighbour:"+ conditionName + "::match-Include=2",
"site::match-Include=" + placeA , "site::match-Include=" + placeB ,
"match,return-0", "match,return-0",
"{map_reply-2}", "【{智能助手-2}】{map_reply-2}",
" ", " ",
"map_reply:queryPathBySite:" + conditionName "map_reply:queryHowToPathBySite:" + conditionName
); );
jConfig.setNextStepStatus("return-0"); jConfig.setNextStepStatus("return-0");
jConfig.setAuxiliaryPriority("1");
jConfigList.add(jConfig); 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 { ...@@ -232,9 +243,10 @@ public class MapConstructor extends ElementConstructor {
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + conditionKeywords, "site::match-Include=" + placeA, 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.setNextStepStatus("return-0");
jConfig.setAuxiliaryPriority("1");
jConfigList.add(jConfig); jConfigList.add(jConfig);
} }
} }
...@@ -244,10 +256,11 @@ public class MapConstructor extends ElementConstructor { ...@@ -244,10 +256,11 @@ public class MapConstructor extends ElementConstructor {
* 生成‘我要去那里’所需要的配置文件 * 生成‘我要去那里’所需要的配置文件
*/ */
public void generateWantToThere(int[][] pathMatirx, int[][] preTable, JSONObject gameElements) { 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 conditionName = "yaobuyao";
String conditionKeywords = "地点"; String conditionKeywords = "地点";
String start = (String)gameElements.get("start"); String start = (String)gameElements.get("start");
String placeKeywords;
for (int i = 0; i < locationNum; i++) { for (int i = 0; i < locationNum; i++) {
...@@ -258,7 +271,7 @@ public class MapConstructor extends ElementConstructor { ...@@ -258,7 +271,7 @@ public class MapConstructor extends ElementConstructor {
*/ */
if(!varInitialMap.containsKey("任务线" + placeA + "最后一个condition")) { if(!varInitialMap.containsKey("任务线" + placeA + "最后一个condition")) {
varInitialMap.put("任务线" + placeA + "最后一个condition", "yaobuyao"); varInitialMap.put("任务线" + placeA + "最后一个condition", "yaobuyao");
varInitialMap.put("任务线" + placeA + "最后的回答", "你来到了" + placeA + ",现在什么都没有, 请继续之前的剧情,接着往下玩吧!"); varInitialMap.put("任务线" + placeA + "最后的回答", "你来到了" + placeA.split("\\+")[0] + ",现在什么都没有, 请继续之前的剧情,接着往下玩吧!");
conditionDescription.put("任务线" + placeA + "最后一个condition", "任务线" + placeA + "最后一个condition"); conditionDescription.put("任务线" + placeA + "最后一个condition", "任务线" + placeA + "最后一个condition");
conditionDescription.put("任务线" + placeA + "最后的回答", "任务线" + placeA + "最后的回答"); conditionDescription.put("任务线" + placeA + "最后的回答", "任务线" + placeA + "最后的回答");
} }
...@@ -274,103 +287,57 @@ public class MapConstructor extends ElementConstructor { ...@@ -274,103 +287,57 @@ public class MapConstructor extends ElementConstructor {
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + placeKeywords conditionName + "::match-Include=" + placeKeywords
+ ",is_neighbour:"+ conditionName + "::match-Include=0", + ",isNeighbour:"+ conditionName + "::match-Include=0",
"site::match-Include=" + placeA , "site::match-Include=" + placeA ,
"match,return-0", "match,return-0",
"你已经在"+placeB + "了", "【{智能助手-2}】你已经在"+placeB + "了",
" ", " ",
"" ""
); );
jConfig.setNextStepStatus("return-0"); jConfig.setAuxiliaryPriority("1");
jConfigList.add(jConfig); 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( jConfig = new JConfig(
conditionName + "::match-Include=" + placeKeywords + "," + conditionName + "::match-Include=" + placeKeywords, conditionName + "::match-Include=" + placeKeywords + "," + ",isNeighbour:"+ conditionName + "::match-Include=1",
"site::match-Include=" + placeA, "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); jConfigList.add(jConfig);
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + placeKeywords conditionName + "::match-Include=" + placeKeywords
+ ",is_neighbour:"+ conditionName + "::match-Include=2", + ",isNeighbour:"+ conditionName + "::match-Include=2",
"site::match-Include=" + placeA , "site::match-Include=" + placeA ,
"match,return-0", "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); 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(){ public void generateSurroundingPeople(){
String conditionName = "know_exist_what"; String conditionName = "know_exist_what";
String conditionKeywords = "周围:人+附近:人"; String conditionKeywords = "周围:人+附近:人";
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + conditionKeywords, " ", 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); jConfigList.add(jConfig);
} }
public void generateSurroundingItem(){ public void generateSurroundingItem(){
...@@ -379,10 +346,11 @@ public class MapConstructor extends ElementConstructor { ...@@ -379,10 +346,11 @@ public class MapConstructor extends ElementConstructor {
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + conditionKeywords, " ", 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); jConfigList.add(jConfig);
} }
public void generateSurroundThings(){ public void generateSurroundThings(){
...@@ -391,11 +359,12 @@ public class MapConstructor extends ElementConstructor { ...@@ -391,11 +359,12 @@ public class MapConstructor extends ElementConstructor {
jConfig = new JConfig( jConfig = new JConfig(
conditionName + "::match-Include=" + conditionKeywords, " ", 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); jConfigList.add(jConfig);
} }
} }
\ No newline at end of file
...@@ -14,8 +14,6 @@ import java.util.*; ...@@ -14,8 +14,6 @@ import java.util.*;
public class PlotConstructor extends ElementConstructor { public class PlotConstructor extends ElementConstructor {
String botName = "";
JSONArray plots = null; JSONArray plots = null;
HashMap<String, ArrayList<String>> adjList = new HashMap<String, ArrayList<String>>(); HashMap<String, ArrayList<String>> adjList = new HashMap<String, ArrayList<String>>();
HashMap<String, ArrayList<String>> revAdjList = new HashMap<String, ArrayList<String>>(); HashMap<String, ArrayList<String>> revAdjList = new HashMap<String, ArrayList<String>>();
...@@ -26,11 +24,14 @@ public class PlotConstructor extends ElementConstructor { ...@@ -26,11 +24,14 @@ public class PlotConstructor extends ElementConstructor {
return id2j; return id2j;
} }
public PlotConstructor(SqlHelper helper, int botId, HashSet<String> exceptRelation) { public PlotConstructor(SqlHelper helper, int botId, int skipCount, String botAccount, HashSet<String> exceptRelation, StringBuffer POS) {
super(); super();
this.helper = helper; this.helper = helper;
this.botId = botId; this.botId = botId;
this.botAccount = botAccount;
this.exceptRelation = exceptRelation; this.exceptRelation = exceptRelation;
this.skipCount = skipCount;
this.POS = POS;
} }
public void construct(JSONObject jsonObject, UserInfo userinfo) { public void construct(JSONObject jsonObject, UserInfo userinfo) {
...@@ -46,7 +47,7 @@ public class PlotConstructor extends ElementConstructor { ...@@ -46,7 +47,7 @@ public class PlotConstructor extends ElementConstructor {
if (id2j.containsKey(start)) { if (id2j.containsKey(start)) {
String taskLineName = "任务线_" + id2j.get(start).get("place") + "进度"; String taskLineName = "任务线_" + id2j.get(start).get("place") + "进度";
conditionDescription.put(taskLineName, taskLineName); conditionDescription.put(taskLineName, taskLineName);
varInitialMap.put(taskLineName, start);
varInitialMap.put("unknownText", "你说啥?"); varInitialMap.put("unknownText", "你说啥?");
varInitialMap.put("game_step", (String) id2j.get(start).get("id")); varInitialMap.put("game_step", (String) id2j.get(start).get("id"));
conditionDescription.put("unknownText", "对于无法识别的问题做出的回答"); conditionDescription.put("unknownText", "对于无法识别的问题做出的回答");
...@@ -61,7 +62,7 @@ public class PlotConstructor extends ElementConstructor { ...@@ -61,7 +62,7 @@ public class PlotConstructor extends ElementConstructor {
} else { } else {
System.out.println("start剧情不存在"); System.out.println("start剧情不存在");
operationStatus = 0; operationStatus = 0;
message = "start剧情不存在"; message = "开始剧情不存在,请到剧情列表设置";
return; return;
} }
} catch(Exception e){ } catch(Exception e){
...@@ -104,512 +105,64 @@ public class PlotConstructor extends ElementConstructor { ...@@ -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<String> 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<JSONObject> queue = new LinkedList<JSONObject>();
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<String, String> 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<String> adjNodeList = null;
int priority, taskStep, nextPriority, nextTaskStep, branchSize;
root.put("priority", 0);
root.put("taskName", id);
root.put("taskStep", 0);
Queue<JSONObject> queue = new LinkedList<JSONObject>();
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 root
* @param userinfo * @param userinfo
*/ */
public void BFSGenerate3(JSONObject root, UserInfo 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, 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; nextUnknownText, curUnknownText, nextCondition, location, nextLocation, taskLineName, nTaskLineName, lastTaskReply, lastTaskCondition;
boolean newBranch, manyParent; boolean newBranch, manyParent;
JSONObject node = null, branchNode = null, adjNode = null; JSONObject node = null, branchNode = null, adjNode = null;
JSONArray branch = null; JSONArray branch = null;
String taskLine = "任务线_%s进度";
List<String> adjNodeList = null; List<String> adjNodeList = null;
int priority, taskStep, nextPriority, nextTaskStep, branchSize; int priority, taskStep, nextPriority, nextTaskStep, branchSize;
root.put("nextUnknownText", varInitialMap.get("unknownText")); root.put("nextUnknownText", varInitialMap.get("unknownText"));
root.put("parentId", "null"); root.put("parentId", "null");
jsonObject.put("plotStartText", ((String)jsonObject.get("plotStartText")).replace("\n", "").replace(",", ","));
if(root.get("conditionName") != null && !root.get("conditionName").equals(""))
Queue<JSONObject> queue = new LinkedList<JSONObject>(); conditionName = (String)root.get("conditionName");
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<String, String> 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, "");
}
}
}
}
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( 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); jConfigList.add(jConfig);
jConfig = new 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); 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<String> 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<JSONObject> queue = new LinkedList<JSONObject>(); Queue<JSONObject> queue = new LinkedList<JSONObject>();
...@@ -664,13 +217,15 @@ public class PlotConstructor extends ElementConstructor { ...@@ -664,13 +217,15 @@ public class PlotConstructor extends ElementConstructor {
//如果存在下一剧情,就将下一步剧情的condition设为下一个激活的conditin,把地点更新为下一步剧情的地点,并更新任务线进度 //如果存在下一剧情,就将下一步剧情的condition设为下一个激活的conditin,把地点更新为下一步剧情的地点,并更新任务线进度
if (id2j.get(nextId) != null) { if (id2j.get(nextId) != null) {
nextCondition = (String) id2j.get(nextId).get("conditionName"); nextCondition = (String) id2j.get(nextId).get("conditionName");
if(nextCondition.equals(""))
nextCondition = "yaobuyao";
nextLocation = (String) id2j.get(nextId).get("place"); nextLocation = (String) id2j.get(nextId).get("place");
nTaskLineName = "任务线_" + nextLocation + "进度"; nTaskLineName = "任务线_" + nextLocation + "进度";
} else { } else {
//如果不存在下一剧情,就将condition设为空,任务线进度不变 //如果不存在下一剧情,就将condition设为空,任务线进度不变
nextCondition = " ";
nTaskLineName = taskLineName; nTaskLineName = taskLineName;
nextLocation = location; nextLocation = location;
nextCondition = "yaobuyao";
} }
lastTaskCondition = "任务线" + nextLocation + "最后一个condition"; lastTaskCondition = "任务线" + nextLocation + "最后一个condition";
...@@ -680,8 +235,8 @@ public class PlotConstructor extends ElementConstructor { ...@@ -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"; 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}" + extraUK = nTaskLineName + ":" + nextId + "-<-site:" + nextLocation + "-<-" + lastTaskCondition + ":" + nextCondition + "-<-" + lastTaskReply + ":var={reply-3}" +
"-<-" + id + ":" + "+1-<-" + nextId + ":" + "+1" + "-<-game_step:" + botName + "_plot_" + nextId; "-<-" + id + ":" + "+1-<-" + nextId + ":" + "+1" + "-<-game_step:" + botAccount + "_plot_" + nextId;
List<String> curPremiseList = JSONArray.parseArray(branchNode.getJSONArray("curPremise").toJSONString(), String.class); List<String> curPremiseList = JSONArray.parseArray(branchNode.getJSONArray("curPremise").toJSONString(), String.class);
...@@ -696,21 +251,13 @@ public class PlotConstructor extends ElementConstructor { ...@@ -696,21 +251,13 @@ public class PlotConstructor extends ElementConstructor {
if (curPremiseList.size() == 0){ if (curPremiseList.size() == 0){
jConfig.setFeature(jConfig.getFeature() + ",activate,post::all(http://simqa.sz.chewrobot.com:28081/game)"); jConfig.setFeature(jConfig.getFeature() + ",activate,post::all(http://simqa.sz.chewrobot.com:28081/game)");
jConfig.setNextStep("queryskip1,queryskip2"); jConfig.setNextStep("queryskip1,queryskip2,queryskip3");
jConfig.setUpdateKnowledge(jConfig.getUpdateKnowledge() + "-<-临时变量1:{nextStep-3}-<-临时变量2:{reply-3}"); jConfig.setUpdateKnowledge(jConfig.getUpdateKnowledge() + "-<-临时变量1:"+ nextCondition +"-<-临时变量2:var={reply-3}");
jConfig.setNextStepStatus("active"); jConfig.setNextStepStatus("active");
} }
jConfigList.add(jConfig); jConfigList.add(jConfig);
// try {
// keywordOptions += jConfig.getCurPremise().split(",")[0].split("=")[1].split("\\+")[0] + " 或者";
// } catch (Exception e) {
// e.printStackTrace();
// }
if (branchNode.get("nextPlotId") != null) { if (branchNode.get("nextPlotId") != null) {
adjId = (String) branchNode.get("nextPlotId"); adjId = (String) branchNode.get("nextPlotId");
if (visited.get(adjId) == null) { if (visited.get(adjId) == null) {
...@@ -750,11 +297,15 @@ public class PlotConstructor extends ElementConstructor { ...@@ -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( 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.setStatus("sleeping");
jConfig.setConfigName("queryskip1"); jConfig.setConfigName("queryskip1");
...@@ -763,7 +314,7 @@ public class PlotConstructor extends ElementConstructor { ...@@ -763,7 +314,7 @@ public class PlotConstructor extends ElementConstructor {
jConfig = new JConfig( 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.setStatus("sleeping");
jConfig.setConfigName("queryskip2"); jConfig.setConfigName("queryskip2");
...@@ -771,7 +322,7 @@ public class PlotConstructor extends ElementConstructor { ...@@ -771,7 +322,7 @@ public class PlotConstructor extends ElementConstructor {
jConfigList.add(jConfig); jConfigList.add(jConfig);
jConfig = new 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.setStatus("sleeping");
jConfig.setConfigName("queryskip3"); jConfig.setConfigName("queryskip3");
...@@ -781,7 +332,10 @@ public class PlotConstructor extends ElementConstructor { ...@@ -781,7 +332,10 @@ public class PlotConstructor extends ElementConstructor {
/**
* ----------------------------------------------------------------------------------------------------
* 待激活列表,用于qa问答
*/
jConfig = new JConfig( jConfig = new JConfig(
" ", "qa_status::match-Include=not_found", "match,return-0", "{unknownText-2}", " ", "" " ", "qa_status::match-Include=not_found", "match,return-0", "{unknownText-2}", " ", ""
...@@ -789,7 +343,6 @@ public class PlotConstructor extends ElementConstructor { ...@@ -789,7 +343,6 @@ public class PlotConstructor extends ElementConstructor {
jConfig.setStatus("sleeping"); jConfig.setStatus("sleeping");
jConfig.setConfigName("unknown1"); jConfig.setConfigName("unknown1");
jConfig.setjStatus(1); jConfig.setjStatus(1);
jConfig.setNextStepStatus("return-0");
jConfigList.add(jConfig); jConfigList.add(jConfig);
...@@ -801,7 +354,6 @@ public class PlotConstructor extends ElementConstructor { ...@@ -801,7 +354,6 @@ public class PlotConstructor extends ElementConstructor {
jConfig.setStatus("sleeping"); jConfig.setStatus("sleeping");
jConfig.setConfigName("unknown2"); jConfig.setConfigName("unknown2");
jConfig.setjStatus(1); jConfig.setjStatus(1);
jConfig.setNextStepStatus("return-0");
jConfigList.add(jConfig); jConfigList.add(jConfig);
...@@ -813,7 +365,6 @@ public class PlotConstructor extends ElementConstructor { ...@@ -813,7 +365,6 @@ public class PlotConstructor extends ElementConstructor {
jConfig.setStatus("sleeping"); jConfig.setStatus("sleeping");
jConfig.setConfigName("unknown3"); jConfig.setConfigName("unknown3");
jConfig.setjStatus(1); jConfig.setjStatus(1);
jConfig.setNextStepStatus("return-0");
jConfigList.add(jConfig); jConfigList.add(jConfig);
...@@ -823,7 +374,6 @@ public class PlotConstructor extends ElementConstructor { ...@@ -823,7 +374,6 @@ public class PlotConstructor extends ElementConstructor {
jConfig.setStatus("sleeping"); jConfig.setStatus("sleeping");
jConfig.setConfigName("unknown4"); jConfig.setConfigName("unknown4");
jConfig.setjStatus(1); jConfig.setjStatus(1);
jConfig.setNextStepStatus("return-0");
jConfigList.add(jConfig); jConfigList.add(jConfig);
...@@ -833,11 +383,19 @@ public class PlotConstructor extends ElementConstructor { ...@@ -833,11 +383,19 @@ public class PlotConstructor extends ElementConstructor {
jConfig.setStatus("sleeping"); jConfig.setStatus("sleeping");
jConfig.setConfigName("common_answer"); jConfig.setConfigName("common_answer");
jConfig.setjStatus(1); jConfig.setjStatus(1);
jConfig.setNextStepStatus("return-0");
jConfigList.add(jConfig); jConfigList.add(jConfig);
//--------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------
/**
* ----------------------------------------------------------------------------------------------------
* 用于处理开始游戏或者继续游戏
*
*
*/
} }
@Override @Override
......
...@@ -19,7 +19,7 @@ import java.util.Map; ...@@ -19,7 +19,7 @@ import java.util.Map;
public class ChatCacheController { public class ChatCacheController {
public static long TIME_OUT = 5000; public static long TIME_OUT = 300000;
private static String CHAT_CACHE_DIR = "ChatCache"; private static String CHAT_CACHE_DIR = "ChatCache";
...@@ -189,8 +189,8 @@ public class ChatCacheController { ...@@ -189,8 +189,8 @@ public class ChatCacheController {
try { try {
chatCache = chatCacheMap.get(chatKey); chatCache = chatCacheMap.get(chatKey);
if(chatCache == null){ if(chatCache == null){
if(receiveParamters.containsKey("yaobuyao") && (receiveParamters.get("yaobuyao")[0].contains("开始游戏") || if(receiveParamters.containsKey("start_options") && (receiveParamters.get("start_options")[0].contains("开始游戏") ||
receiveParamters.get("yaobuyao")[0].contains("继续游戏")|| receiveParamters.get("yaobuyao")[0].contains("开始"))) { receiveParamters.get("start_options")[0].contains("继续游戏")|| receiveParamters.get("start_options")[0].contains("继续"))) {
chatCache = loadChatCache(chatKey, context, userinfo, loadCacheStatus); chatCache = loadChatCache(chatKey, context, userinfo, loadCacheStatus);
}else { }else {
chatCache = new ChatCache(userinfo); chatCache = new ChatCache(userinfo);
......
...@@ -336,8 +336,15 @@ public class QuestionMatcher { ...@@ -336,8 +336,15 @@ public class QuestionMatcher {
keyword = gameEnv.queryGoodsAttrByGoodsName(nameSeries[2], nameSeries[3]); keyword = gameEnv.queryGoodsAttrByGoodsName(nameSeries[2], nameSeries[3]);
System.out.println("return" + keyword); System.out.println("return" + keyword);
} }
}else if(actionName.startsWith("is_neighbour")){ }else if(actionName.startsWith("isNeighbour")){
//keyword = gameEnv.isNeighbour(historyInfoPoint.get("site"), actionName.split(":")[1]); 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 { }else {
keyword = infoPoint.get(actionName); keyword = infoPoint.get(actionName);
...@@ -735,7 +742,10 @@ public class QuestionMatcher { ...@@ -735,7 +742,10 @@ public class QuestionMatcher {
//停留 //停留
} else if (ansCondition.featureMap.containsKey("return-0")) { } else if (ansCondition.featureMap.containsKey("return-0")) {
String activeList[] = historyInfoPoint.get("activeList").split("\\|"); 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")) { } else if (ansCondition.featureMap.containsKey("activate")) {
String activeList[] = historyInfoPoint.get("activeList").split("\\|"); String activeList[] = historyInfoPoint.get("activeList").split("\\|");
...@@ -759,13 +769,19 @@ public class QuestionMatcher { ...@@ -759,13 +769,19 @@ public class QuestionMatcher {
//用正则表达式将回答中的变量模板{conditionName-2}替换成后台存储的变量值 //用正则表达式将回答中的变量模板{conditionName-2}替换成后台存储的变量值
String keyword;
reply = ans.getAnswer(); reply = ans.getAnswer();
Matcher m = replacePattern.matcher(reply); Matcher m = replacePattern.matcher(reply);
while (m.find()) { while (m.find()) {
variable = m.group(1).substring(1, m.group(1).length() - 3); variable = m.group(1).substring(1, m.group(1).length() - 3);
if (m.group(1).endsWith("-1}")) { if (m.group(1).endsWith("-1}")) {
if (curInfoPoint.get(variable) != null && !curInfoPoint.get(variable).equals("")) if (curInfoPoint.get(variable) != null && !curInfoPoint.get(variable).equals("")) {
reply = reply.replace("{" + variable + "-1}", curInfoPoint.get(variable)); keyword = curInfoPoint.get(variable);
if(keyword.contains(":"))
keyword = keyword.split(":")[1];
reply = reply.replace("{" + variable + "-1}", keyword);
}
} else if (m.group(1).endsWith("-2}")) { } else if (m.group(1).endsWith("-2}")) {
if (historyInfoPoint.get(variable) != null) if (historyInfoPoint.get(variable) != null)
if(historyInfoPoint.get(variable).equals("do_reset")){ if(historyInfoPoint.get(variable).equals("do_reset")){
......
...@@ -130,28 +130,69 @@ public class WorldController { ...@@ -130,28 +130,69 @@ public class WorldController {
} }
break; break;
case "queryCanGoBySite": case "queryCanGoBySite":
if(!currentInfoPoint.containsKey(valuePair[1])) {
returnStr = "不可到达";
break;
}
sites = gameEnv.queryCanGoBySite(historyInfoPoint.get("site")); sites = gameEnv.queryCanGoBySite(historyInfoPoint.get("site"));
if(sites == null || sites.size() == 0) if(sites == null) {
returnStr = "没什么地方可去的,继续玩吧"; returnStr = "没什么地方可去的,继续玩吧";
else { }
else if(sites.size() == 0){
returnStr = "没什么地方可去的,继续玩吧";
} else {
returnStr = "可以去"; returnStr = "可以去";
if(sites.size() > 0) { if(sites.size() > 0) {
for (String site : sites) for (String site : sites)
returnStr += "、" + site; returnStr += "、" + site;
System.out.println("returnStr" + returnStr);
}else{ }else{
returnStr = "没什么地方可去的,继续玩吧"; returnStr = "没什么地方可去的,继续玩吧";
} }
} }
break; break;
case "queryPathBySite": case "queryHowToPathBySite":
sites = gameEnv.queryPathBySite(historyInfoPoint.get("site"), valuePair[1]); if(!currentInfoPoint.containsKey(valuePair[1])) {
if(sites == null || sites.size() == 0) returnStr = "不可到达";
break;
}
sites = gameEnv.queryPathBySite(historyInfoPoint.get("site"), currentInfoPoint.get(valuePair[1]).split(":")[1]);
if(sites == null) {
returnStr = "不可到达";
}
else if(sites.size() == 0){
returnStr = "就在附近哦"; 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 = "通过"; returnStr = "通过";
if(sites.size() > 0) { if(sites.size() > 0) {
for (String site : sites) for (String site : sites)
returnStr += "、" + site; returnStr += "、" + site;
returnStr += "可以到达";
}else{ }else{
returnStr = "就在附近哦"; returnStr = "就在附近哦";
} }
......
...@@ -35,15 +35,23 @@ public class GameDesignServlet extends HttpServlet { ...@@ -35,15 +35,23 @@ public class GameDesignServlet extends HttpServlet {
} }
}; };
//每个condition的三元组两端需要补充的关键词,比如npc名字、npc属性等
HashMap<String, HashSet<String>> relationKeywords = new HashMap<String, HashSet<String>>();
//特定的relation的三元组不会被添加到relationKeywords
HashSet<String> exceptRelation = new HashSet<String>();
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//所有需要修改的词性
StringBuffer POS = new StringBuffer();
//每个condition的三元组两端需要补充的关键词,比如npc名字、npc属性等
HashMap<String, HashSet<String>> relationKeywords = new HashMap<String, HashSet<String>>();
//特定的relation的三元组不会被添加到relationKeywords
HashSet<String> exceptRelation = new HashSet<String>();
Integer botId, projectId, dataId, returnStatus = 1; 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(); ServletContext context = this.getServletContext();
JSONObject json = null, root = null; JSONObject json = null, root = null;
Boolean flag; Boolean flag;
...@@ -95,37 +103,38 @@ public class GameDesignServlet extends HttpServlet { ...@@ -95,37 +103,38 @@ public class GameDesignServlet extends HttpServlet {
} }
Iterator<String> moduleIter = gameElements.keySet().iterator();
StringBuffer mergedConfigText = new StringBuffer(); 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) { switch (moduleName) {
case "map": case "map":
moduleName2 = "地图"; moduleName2 = "地图";
constructor = new MapConstructor(helper, botId, exceptRelation); constructor = new MapConstructor(helper, botId, skipCount, botAccount, exceptRelation, POS);
constructor.construct(gameElements, userinfo); constructor.construct(gameElements, userinfo);
break; break;
case "plots": case "plots":
moduleName2 = "剧情"; moduleName2 = "剧情";
constructor = new PlotConstructor(helper, botId, exceptRelation); constructor = new PlotConstructor(helper, botId, skipCount, botAccount, exceptRelation, POS);
constructor.construct(gameElements, userinfo); constructor.construct(gameElements, userinfo);
root = ((PlotConstructor) constructor).getId2j().get((String) gameElements.get("start")); root = ((PlotConstructor) constructor).getId2j().get((String) gameElements.get("start"));
break; break;
case "goods": case "goods":
moduleName2 = "物品"; moduleName2 = "物品";
constructor = new ItemConstructor(helper, botId, exceptRelation); constructor = new ItemConstructor(helper, botId, skipCount, botAccount, exceptRelation, POS);
constructor.construct(gameElements, userinfo); constructor.construct(gameElements, userinfo);
break; break;
case "globalVarialbe": case "globalVariable":
moduleName2 = "全局变量"; moduleName2 = "全局变量";
constructor = new GlobalVariableConstructor(helper, botId, exceptRelation); constructor = new GlobalVariableConstructor(helper, botId, skipCount, botAccount, exceptRelation, POS);
constructor.construct(gameElements, userinfo); constructor.construct(gameElements, userinfo);
break; break;
case "npc": case "npc":
moduleName2 = "NPC"; moduleName2 = "NPC";
constructor = new CharacterConstructor(helper, botId, exceptRelation); constructor = new CharacterConstructor(helper, botId, skipCount, botAccount, exceptRelation, POS);
constructor.construct(gameElements, userinfo); constructor.construct(gameElements, userinfo);
break; break;
default: default:
...@@ -166,7 +175,7 @@ public class GameDesignServlet extends HttpServlet { ...@@ -166,7 +175,7 @@ public class GameDesignServlet extends HttpServlet {
UserInfoController.buildUserInfo(br, userinfo, true); UserInfoController.buildUserInfo(br, userinfo, true);
context.setAttribute(botAccount, userinfo); context.setAttribute(botAccount, userinfo);
ConditionTableController.writeConfigText(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")){ if(!postResult.equals("success")){
returnStatus = 0; returnStatus = 0;
...@@ -221,22 +230,29 @@ public class GameDesignServlet extends HttpServlet { ...@@ -221,22 +230,29 @@ public class GameDesignServlet extends HttpServlet {
return deleteConfigFlag && deleteVariableFlag; return deleteConfigFlag && deleteVariableFlag;
} }
public String actionRegenerate(JSONObject root, JSONObject gameElements, UserInfo userInfo){ public String actionRegenerate(JSONObject root, JSONObject gameElements, UserInfo userInfo, HashMap<String, HashSet<String>> relationKeywords, HashSet<String> exceptRelation, StringBuffer POS){
String startCondition; String startCondition, POS2 = "";
String botName = (String)gameElements.get("botName"); String botName = (String)gameElements.get("botName");
JSONObject returnMessage = null; JSONObject returnMessage = null;
JSONObject actionPostData = new JSONObject(); JSONObject actionPostData = new JSONObject();
System.out.println("root"+ root.toJSONString()); System.out.println("root"+ root.toJSONString());
startCondition = (String)root.get("conditionName"); 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_yhm", (String)gameElements.get("botName"));
actionPostData.put("botName", botName); actionPostData.put("botName", botName);
actionPostData.put("botId", (Integer)gameElements.get("botId")); actionPostData.put("botId", (Integer)gameElements.get("botId"));
actionPostData.put("type", "game_plot_init"); actionPostData.put("type", "game_plot_init");
actionPostData.put("welcome", (String)gameElements.get("plotStartText")); actionPostData.put("welcome", "欢迎来到" + (String)gameElements.get("botName") + ",请说开始游戏或者继续游戏");
actionPostData.put("relationKeywords", relationKeywords); actionPostData.put("relationKeywords", relationKeywords);
if (gameElements.containsKey("POS"))
POS2 = (String)gameElements.get("POS");
actionPostData.put("POS", POS.toString() + POS2);
System.out.println(actionPostData.toJSONString()); System.out.println(actionPostData.toJSONString());
userInfo.extraInfo.put("activeAction", startCondition); userInfo.extraInfo.put("activeAction", startCondition);
......
...@@ -35,7 +35,7 @@ public class GetAnswerServlet extends HttpServlet { ...@@ -35,7 +35,7 @@ public class GetAnswerServlet extends HttpServlet {
String ansJ = "", return_str = "", state = "", chatKey = ""; String ansJ = "", return_str = "", state = "", chatKey = "";
String botName = receiveParamters.get("bot_name")[0]; 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; receiveParamters.get("chat_key")[0] = chatKey;
OutputStream out = response.getOutputStream(); OutputStream out = response.getOutputStream();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment