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.JConfig; import com.qiwu.chatbotbackend.entity.UserInfo; import java.util.*; public class ItemConstructor extends ElementConstructor { public ItemConstructor(SqlHelper helper, int botId, HashSet exceptRelation) { super(); this.helper = helper; this.botId = botId; this.exceptRelation = exceptRelation; } public void construct(JSONObject gameElements, UserInfo userinfo) { try { String category, name, className, description, attrName, attrValue; JSONArray goods = gameElements.getJSONArray("goods"); Map attribute = null; Iterator attrIter = null; HashSet classSet = new HashSet(); //与物品属性查询相关的所有condition ArrayList attrRelateConditions = new ArrayList() { { add("nums"); add("shishenme"); } }; //与物品类查询相关的所有condition ArrayList classRelateConditions = new ArrayList() { { add("know_exist_what"); } }; StringBuffer keywords = new StringBuffer(); StringBuffer classKeywords = new StringBuffer(); for (JSONObject good : goods.toJavaList(JSONObject.class)) { name = (String) good.get("name"); className = (String) good.get("class"); if (!classSet.contains(className)) { classSet.add(className); //添加周围有什么士兵等关于类别的关键词 classKeywords.append("+周围:" + className + "+附近:" + className); } attribute = gameElements.toJavaObject(good.getJSONObject("attr"), Map.class); attrIter = attribute.keySet().iterator(); while (attrIter.hasNext()) { attrName = attrIter.next(); attrValue = attribute.get(attrName); keywords.append("+" + name + ":" + attrName); } } //根据根据物品名字和属性查询属性值 for (String conditionName : attrRelateConditions) { jConfig = new JConfig( conditionName + "::match-Include=" + keywords, " ", "match,return-0", "{goods_query-2}", " ", "goods_query:queryAttrByGoodsName:" + conditionName ); jConfigList.add(jConfig); } //根据类名和地点查询所有实例 for (String conditionName : attrRelateConditions) { jConfig = new JConfig( conditionName + "::match-Include=" + classKeywords, " ", "match,return-0", "{goods_query-2}", " ", "goods_query:queryAroundGoodsByClassName:" + conditionName ); jConfigList.add(jConfig); } } catch(Exception e){ operationStatus = 0; message = "物品处理出现异常"; return; } } }