package com.qiwu.chatbotbackend.gameDesign; import com.alibaba.fastjson.JSONObject; import com.qiwu.chatbotbackend.db.SqlHelper; import com.qiwu.chatbotbackend.entity.UserInfo; 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; JSONObject globalVariable = gameElements.getJSONObject("globalVariable"); Map attribute = null; Iterator attrIter = null; for(String attrName:globalVariable.keySet()) { attrValue = (String)globalVariable.get(attrName); varInitialMap.put("globalVariable_" + attrName, attrValue); } varInitialMap.put("botType", "game"); varInitialMap.put("unknownTextList", (String)gameElements.get("unknownTextList")); varInitialMap.put("finalUnknownText", (String)gameElements.get("finalUnknownText")); varInitialMap.put("CC_URL", keywordMap.get("CC_URL").toString()); 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; } } }