package com.qiwu.chatbotbackend.processing; import com.qiwu.chatbotbackend.GameEnvironment.GameEnv; import java.util.ArrayList; import java.util.List; import java.util.Map; public class WorldController { public LogWriter logWriter = null; public WorldController(LogWriter logWriter) { this.logWriter = logWriter; } public String worldOperation(GameEnv gameEnv, String varName, String varValue, Map currentInfoPoint, MaphistoryInfoPoint){ String moduleName = "", valuePair[] = varValue.split(":", 2), returnStr=""; String namePair[] = varName.split("_"); boolean operationFlag = true; List textList = null; String subValuePair[] = null; logWriter.record(String.format("---------------------key:%s, value:%s", varName, varValue), 0); if(valuePair[0].startsWith("query")){ //查询专用 if(varName.startsWith("goods_")) { switch (valuePair[0]) { case "queryGoodsIntro": subValuePair = currentInfoPoint.get(valuePair[1]).split(":", 2); returnStr = gameEnv.queryGoodsIntroByGoodsName(subValuePair[1]); if(returnStr == null ) returnStr = "无"; break; case "queryAttrByGoodsName": subValuePair = currentInfoPoint.get(valuePair[1]).split(":", 2); subValuePair[0] = subValuePair[0].replace("哪里", "location"); returnStr = gameEnv.queryGoodsAttrByGoodsName(subValuePair[0], subValuePair[1]); if(returnStr == null) returnStr = "无"; break; case "queryAllAttrByGoodsName": textList = gameEnv.queryGoodsAllAttrByGoodsName(varName); if(textList == null || textList.size() == 0) returnStr = "无"; else { for (String site : textList) returnStr += "、" + site; returnStr = returnStr.substring(1); } break; case "queryAroundGoodsByClassName": textList = gameEnv.queryGoodsByClassAndSite(namePair[1], historyInfoPoint.get("site")); if(textList == null || textList.size() == 0) returnStr = "无"; else { for (String site : textList) returnStr += "、" + site; returnStr = returnStr.substring(1); } break; default: } }else if(varName.startsWith("NPC_")) { switch(valuePair[0]){ case "queryNpcIntro": //operationFlag = gameEnv.queryNpcIntro(valuePair[1], namePair[2]); subValuePair = currentInfoPoint.get(valuePair[1]).split(":", 2); returnStr = gameEnv.queryNpcIntroByNpcName(subValuePair[1]); if(returnStr == null) returnStr = "无"; break; case "queryAttrByNPCName": subValuePair = currentInfoPoint.get(valuePair[1]).split(":", 2); subValuePair[0] = subValuePair[0].replace("哪里", "location"); returnStr = gameEnv.queryNpcAttrByNpcName(subValuePair[0], subValuePair[1]); if(returnStr == null) returnStr = "无"; break; default: } }else if (varName.startsWith("map_")) { List sites = new ArrayList<>(); switch (valuePair[0]) { case "queryAroundAllBySite": sites = gameEnv.queryAroundAllBySite(historyInfoPoint.get("site")); if(sites == null || sites.size() == 0) returnStr = "啥都没有"; else { returnStr = "有"; if(sites.size() > 0) { for (String site : sites) returnStr += "、" + site; }else{ returnStr = "啥都没有"; } } break; case "queryAroundNpcBySite": sites = gameEnv.queryAroundNpcBySite(historyInfoPoint.get("site")); if(sites == null || sites.size() == 0) returnStr = "啥都没有"; else { returnStr = "有"; if(sites.size() > 0) { for (String site : sites) returnStr += "、" + site; }else{ returnStr = "啥都没有"; } } break; case "queryAroundGoodsBySite": sites = gameEnv.queryAroundGoodsBySite(historyInfoPoint.get("site")); if(sites == null || sites.size() == 0) returnStr = "啥都没有"; else { returnStr = "有"; if(sites.size() > 0) { for (String site : sites) returnStr += "、" + site; }else{ returnStr = "啥都没有"; } } break; case "queryCanGoBySite": if(!currentInfoPoint.containsKey(valuePair[1])) { returnStr = "不可到达"; break; } sites = gameEnv.queryCanGoBySite(historyInfoPoint.get("site")); if(sites == null) { returnStr = "没什么地方可去的,继续玩吧"; } else if(sites.size() == 0){ returnStr = "没什么地方可去的,继续玩吧"; } else { returnStr = "可以去"; if(sites.size() > 0) { for (String site : sites) returnStr += "、" + site; System.out.println("returnStr" + returnStr); }else{ returnStr = "没什么地方可去的,继续玩吧"; } } break; case "queryHowToPathBySite": if(!currentInfoPoint.containsKey(valuePair[1])) { returnStr = "不可到达"; break; } sites = gameEnv.queryPathBySite(historyInfoPoint.get("site"), currentInfoPoint.get(valuePair[1]).split(":")[1]); if(sites == null) { returnStr = "不可到达"; } else if(sites.size() == 0){ returnStr = "就在附近哦"; }else { returnStr = "通过"; if(sites.size() > 0) { for (String site : sites) returnStr += "、" + site; returnStr += "可以到达"; }else{ returnStr = "就在附近哦"; } } break; case "queryToDoPathBySite": if(!currentInfoPoint.containsKey(valuePair[1])) { returnStr = "不可到达"; break; } sites = gameEnv.queryPathBySite(historyInfoPoint.get("site"), currentInfoPoint.get(valuePair[1]).split(":")[1]); if(sites == null) { returnStr = "不可到达"; } else if(sites.size() == 0){ returnStr = "就在附近哦"; }else { returnStr = "通过"; if(sites.size() > 0) { for (String site : sites) returnStr += "、" + site; returnStr += "可以到达"; }else{ returnStr = "就在附近哦"; } } break; } } }else { //增删改统一使用 gameEnv.CUD(varName, valuePair[0], valuePair[1]); } logWriter.record("---------------------return:" + returnStr, 0); return returnStr; } }