package com.qiwu.chatbotbackend.gameDesign; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.qiwu.chatbotbackend.db.SqlHelper; import com.qiwu.chatbotbackend.entity.UserInfo; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; public class GlobalVariableConstructor extends ElementConstructor { public GlobalVariableConstructor(SqlHelper helper, int botId, String botAccount, Map keywordMap, HashSet exceptRelation, StringBuffer POS) { super(); this.helper = helper; this.botId = botId; this.botAccount = botAccount; this.exceptRelation = exceptRelation; this.keywordMap = keywordMap; this.POS = POS; } public void construct(JSONObject gameElements, UserInfo userinfo) { try { String category, name, description, attrValue; JSONArray globalVariable = gameElements.getJSONArray("globalVariable"); Map attribute = null; Iterator attrIter = null; for (JSONObject variableList : globalVariable.toJavaList(JSONObject.class)) { category = (String) variableList.get("category"); attribute = gameElements.toJavaObject(variableList.getJSONObject("variables"), Map.class); for(String attrName:attribute.keySet()) { attrValue = attribute.get(attrName); varInitialMap.put("globalVariable_" + category + "_" + attrName, attrValue); } } varInitialMap.put("botType", "game"); varInitialMap.put("unknownTextList", (String)gameElements.get("unknownTextList")); varInitialMap.put("finalUnknownText", (String)gameElements.get("finalUnknownText")); JSONObject script = gameElements.getJSONObject("speechcraft"); for(String key:script.keySet()){ attrValue = (String)script.get(key); varInitialMap.put(key, attrValue); } }catch (Exception e){ operationStatus = 0; message = "全局变量处理出现异常"; e.printStackTrace(); return; } } }