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 CharacterConstructor extends ElementConstructor { public CharacterConstructor(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 allNPC = jsonObject.getJSONArray("npc"); Map attribute = null; Iterator attrIter = null; HashSet classSet = new HashSet(); //与npc属性相关的所有condition ArrayList relateConditions = new ArrayList(){ { add("wenzainali"); add("shishenme"); } }; //与npc类相关的所有condition ArrayList classRelateConditions = new ArrayList(){ { add("know_exist_what"); } }; String conditionValue = "哪里:人称", repValue; StringBuffer keywords = new StringBuffer(); StringBuffer classKeywords = new StringBuffer(); for (JSONObject character : allNPC.toJavaList(JSONObject.class)) { name = (String) character.get("name"); className = (String)character.get("class"); if(!classSet.contains(className)) { classSet.add(className); classKeywords.append("+周围:" + className + "+附近" + className); } attribute = JSONObject.toJavaObject(character.getJSONObject("attr"), Map.class); attrIter = attribute.keySet().iterator(); repValue = conditionValue.replace("人称", name); keywords.append("+" + repValue); while (attrIter.hasNext()) { attrName = attrIter.next(); attrValue = attribute.get(attrName); } System.out.println(name); } //根据根据NPC名字和属性查询属性值 for(String conditionName: relateConditions) { jConfig = new JConfig( conditionName + "::match-Include=" + keywords, " ", "match,return-0", "{NPC_query-2}", "yaobuyao", "NPC_query:queryAttrByNPCName:" + conditionName ); jConfigList.add(jConfig); } //根据根据NPC类别和地点属性查询所有NPC实例 for(String conditionName: relateConditions) { jConfig = new JConfig( conditionName + "::match-Include=" + classKeywords, " ", "match,return-0", "{NPC_query-2}", "yaobuyao", "NPC_query:queryAroundNpcByClassName:" + conditionName ); jConfigList.add(jConfig); } } }