diff --git a/src/GameEnvironment/GameEnv.java b/src/GameEnvironment/GameEnv.java index f3c39ea..379efa0 100644 --- a/src/GameEnvironment/GameEnv.java +++ b/src/GameEnvironment/GameEnv.java @@ -24,9 +24,12 @@ public class GameEnv implements Serializable{ public Map goodsInstanceIndex; public Map globalAttrs; public Map placeIndex; + public Map placeLinkDirectGo; + public Map placeNoLinkDirectGo; public byte[][] mapGraph; public MapmapNames; public String[] mapIndexName; + @SuppressWarnings("unchecked") public GameEnv(String botName) throws Exception { // 通过文件来初始化游戏环境 // String fullName = "test.json"; @@ -37,11 +40,13 @@ public class GameEnv implements Serializable{ Map gameProjectMap = JSON.parseObject(jsonString); System.out.println(gameProjectMap); this.followNpcIndex = new HashMap(); + this.placeLinkDirectGo = new HashMap(); + this.placeNoLinkDirectGo = new HashMap(); if(!gameProjectMap.isEmpty()) { // 地图 Map map = (Map)gameProjectMap.get("map"); this.placeIndex = new HashMap(); - Map placeMapTmp = new HashMap(); + Map placeMapTmp = new HashMap(); this.mapGraph = new byte[map.size()][map.size()]; this.mapNames = new HashMap(); if(!map.isEmpty()) { @@ -53,7 +58,14 @@ public class GameEnv implements Serializable{ Place place = new Place(); place.setIntro((String)one.get("intro")); place.setName((String)one.get("name")); - place.setNickname((List)one.get("nickname")); + place.setGoFlag((Integer)one.get("goFlag")); + if(((Integer)one.get("goFlag")).equals(new Integer(2))) { + this.placeLinkDirectGo.put(place.getName(), place); + }else if(((Integer)one.get("goFlag")).equals(new Integer(3))) { + this.placeNoLinkDirectGo.put(place.getName(), place); + } + List nickname = (List)one.get("nickname"); + place.setNickname(nickname); mapNames.put((String)one.get("name"), i); i++; placeIndex.put((String)one.get("name"), place); @@ -136,7 +148,6 @@ public class GameEnv implements Serializable{ // instance Map instances = (Map)one.get("instance"); for(String instanceKey:instances.keySet()) { - Map instance = new HashMap(); NpcInstance npcInstance = new NpcInstance(); Map instanceAttrMap = (Map)instances.get(instanceKey); npcNames.put(instanceKey, (String)instanceAttrMap.get("name")); @@ -157,7 +168,8 @@ public class GameEnv implements Serializable{ npcInstance.setAttrs(npcInstanceAttrs); Place place = null; if(instanceAttrMap.get("placeId")!=null) { - place = placeIndex.get(((Map)map.get(String.valueOf(instanceAttrMap.get("placeId")))).get("name")); + Map placeMap = (Map)map.get(String.valueOf(instanceAttrMap.get("placeId"))); + place = placeIndex.get(placeMap.get("name")); List npcInstances = place.getNpcInstances(); if(npcInstances == null) { npcInstances = new ArrayList(); @@ -203,7 +215,6 @@ public class GameEnv implements Serializable{ // instance Map instances = (Map)one.get("instance"); - for(String instanceKey:instances.keySet()) { GoodsInstance goodsInstance = new GoodsInstance(); Map instanceAttrMap = (Map)instances.get(instanceKey); @@ -220,7 +231,8 @@ public class GameEnv implements Serializable{ } goodsInstance.setAttrs(goodsInstanceAttrs); if(instanceAttrMap.get("placeId")!=null) { - Place place = placeIndex.get(((Map)map.get(String.valueOf(instanceAttrMap.get("placeId")))).get("name")); + Map placeMap = (Map)map.get(String.valueOf(instanceAttrMap.get("placeId"))); + Place place = placeIndex.get(placeMap.get("name")); goodsInstance.setPlace(place); List placeGoodsInstances= place.getGoodsInstances(); if(placeGoodsInstances == null) { @@ -255,7 +267,6 @@ public class GameEnv implements Serializable{ this.globalAttrs = (Map)gameProjectMap.get("globalAttr"); } } - /********************************************地点******************************************/ // 周围有什么 public List queryAroundAllBySite(String site){ @@ -301,35 +312,43 @@ public class GameEnv implements Serializable{ ableGoString.add(this.mapIndexName[i]); } } + for(String placeName:this.placeLinkDirectGo.keySet()) { + ableGoString.add(placeName); + } + for(String placeName:this.placeNoLinkDirectGo.keySet()) { + ableGoString.add(placeName); + } return ableGoString; } - + // 是否相邻 public Integer isNeighbour(String placeA, String placeB) { try { int x = this.mapNames.get(placeA); if(placeA.equals(placeB) || this.placeIndex.get(placeA).getNickname().indexOf(placeB)>=0) { return 0; - }else { - int flag = 0; - for(int j=0;j=0) { - flag = 1; - break; - } + } + for(int j=0;j=0) { + return 1; } } - if(flag == 1) { - return 1; - }else { - return 2; + } + for(String placeName:this.placeLinkDirectGo.keySet()) { + if(placeName.equals(placeB) || this.placeLinkDirectGo.get(placeName).getNickname().indexOf(placeB)>=0) { + return 3; } } + for(String placeName:this.placeNoLinkDirectGo.keySet()) { + if(placeName.equals(placeB) || this.placeNoLinkDirectGo.get(placeName).getNickname().indexOf(placeB)>=0) { + return 4; + } + } + return 2; }catch(Exception e) { return 2; } } - // 通过别名查询当前地点最近的别名地点 public String getPlaceNameByNickname(String curPlaceName, String nickname) { if(this.placeIndex.get(curPlaceName).getNickname().indexOf(nickname)>=0) { @@ -344,7 +363,7 @@ public class GameEnv implements Serializable{ } } - // 两点之间的路径 // 使用广度优先算法单源最短路的SPFA算法的全称是:Shortest Path Faster Algorithm。 + // 两点之间的路径 // 使用广度优先算法单源最短路的SPFA算法的全称是:Shortest Path Faster Algorithm。只有状态为2的时候使用 public List getAllPath(String placeA, String placeB){ List paths = new ArrayList(); Deque placeDeque = new ArrayDeque(); @@ -385,6 +404,7 @@ public class GameEnv implements Serializable{ Collections.reverse(paths); return paths; } + // 两点之间的通过的地方 public List queryPathBySite(String placeA, String placeB){ List paths = this.getAllPath(placeA, placeB); System.out.println(paths); @@ -497,7 +517,6 @@ public class GameEnv implements Serializable{ List npcNames = new ArrayList(); List placeNpcInstances = this.placeIndex.get(site).getNpcInstances(); List npcInstances = this.goodsClassIndex.get(className).getNpcInstances(); - NpcInstance npcInstance = new NpcInstance(); for(int i=0; i nickname; private List ableGo; private List npcInstances; private List goodsInstances; - public String getName() { + public String getName() { return name; } + public void setName(String name) { this.name = name; } + public String getIntro() { return intro; } + public void setIntro(String intro) { this.intro = intro; } + + public Integer getGoFlag() { + return goFlag; + } + + + public void setGoFlag(Integer goFlag) { + this.goFlag = goFlag; + } + + public List getNickname() { return nickname; } + public void setNickname(List nickname) { this.nickname = nickname; } + public List getAbleGo() { return ableGo; } + public void setAbleGo(List ableGo) { this.ableGo = ableGo; } + public List getNpcInstances() { return npcInstances; } + public void setNpcInstances(List npcInstances) { this.npcInstances = npcInstances; } + public List getGoodsInstances() { return goodsInstances; } + public void setGoodsInstances(List goodsInstances) { this.goodsInstances = goodsInstances; } - public static long getSerialversionuid() { - return serialVersionUID; - } - @Override public String toString() { int ableGoSize = 0;