package gameDesign; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import db.SqlHelper; import entity.JConfig; import entity.UserInfo; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.Map; public class ItemConstructor extends ElementConstructor { public ItemConstructor(SqlHelper helper, int botId) { super(); this.helper = helper; this.botId = botId; } public void construct(JSONObject jsonObject, UserInfo userinfo) { String category, name, className, description, attrName, attrValue; JSONArray goods = jsonObject.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 = JSONObject.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); } } }