Commit e04fb7b2 by 李进峰

direct go add

parent 669b44ce
......@@ -24,9 +24,12 @@ public class GameEnv implements Serializable{
public Map<String, GoodsInstance> goodsInstanceIndex;
public Map<String, String> globalAttrs;
public Map<String, Place> placeIndex;
public Map<String, Place> placeLinkDirectGo;
public Map<String, Place> placeNoLinkDirectGo;
public byte[][] mapGraph;
public Map<String, Integer>mapNames;
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<String, Object> gameProjectMap = JSON.parseObject(jsonString);
System.out.println(gameProjectMap);
this.followNpcIndex = new HashMap<String, NpcInstance>();
this.placeLinkDirectGo = new HashMap<String, Place>();
this.placeNoLinkDirectGo = new HashMap<String, Place>();
if(!gameProjectMap.isEmpty()) {
// 地图
Map<String, Object> map = (Map<String, Object>)gameProjectMap.get("map");
this.placeIndex = new HashMap<String, Place>();
Map<String, Object> placeMapTmp = new HashMap();
Map<String, String> placeMapTmp = new HashMap<String, String>();
this.mapGraph = new byte[map.size()][map.size()];
this.mapNames = new HashMap<String, Integer>();
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<String> nickname = (List<String>)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<String, Object> instances = (Map<String, Object>)one.get("instance");
for(String instanceKey:instances.keySet()) {
Map<String, Object> instance = new HashMap<String, Object>();
NpcInstance npcInstance = new NpcInstance();
Map<String, Object> instanceAttrMap = (Map<String, Object>)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<String, Object>)map.get(String.valueOf(instanceAttrMap.get("placeId")))).get("name"));
Map<String, Object> placeMap = (Map<String, Object>)map.get(String.valueOf(instanceAttrMap.get("placeId")));
place = placeIndex.get(placeMap.get("name"));
List<NpcInstance> npcInstances = place.getNpcInstances();
if(npcInstances == null) {
npcInstances = new ArrayList<NpcInstance>();
......@@ -203,7 +215,6 @@ public class GameEnv implements Serializable{
// instance
Map<String, Object> instances = (Map<String, Object>)one.get("instance");
for(String instanceKey:instances.keySet()) {
GoodsInstance goodsInstance = new GoodsInstance();
Map<String, Object> instanceAttrMap = (Map<String, Object>)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<String, Object>)map.get(String.valueOf(instanceAttrMap.get("placeId")))).get("name"));
Map<String, Object> placeMap = (Map<String, Object>)map.get(String.valueOf(instanceAttrMap.get("placeId")));
Place place = placeIndex.get(placeMap.get("name"));
goodsInstance.setPlace(place);
List<GoodsInstance> placeGoodsInstances= place.getGoodsInstances();
if(placeGoodsInstances == null) {
......@@ -255,7 +267,6 @@ public class GameEnv implements Serializable{
this.globalAttrs = (Map<String,String>)gameProjectMap.get("globalAttr");
}
}
/********************************************地点******************************************/
// 周围有什么
public List<String> 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<this.mapGraph[x].length;j++) {
if(this.mapGraph[x][j] ==1) {
if(this.mapIndexName[j].equals(placeB) || this.placeIndex.get(this.mapIndexName[j]).getNickname().indexOf(placeB)>=0) {
flag = 1;
break;
}
}
for(int j=0;j<this.mapGraph[x].length;j++) {
if(this.mapGraph[x][j] ==1) {
if(this.mapIndexName[j].equals(placeB) || this.placeIndex.get(this.mapIndexName[j]).getNickname().indexOf(placeB)>=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<String> getAllPath(String placeA, String placeB){
List<String> paths = new ArrayList<String>();
Deque<PlaceLink> placeDeque = new ArrayDeque<PlaceLink>();
......@@ -385,6 +404,7 @@ public class GameEnv implements Serializable{
Collections.reverse(paths);
return paths;
}
// 两点之间的通过的地方
public List<String> queryPathBySite(String placeA, String placeB){
List<String> paths = this.getAllPath(placeA, placeB);
System.out.println(paths);
......@@ -497,7 +517,6 @@ public class GameEnv implements Serializable{
List<String> npcNames = new ArrayList<String>();
List<NpcInstance> placeNpcInstances = this.placeIndex.get(site).getNpcInstances();
List<NpcInstance> npcInstances = this.goodsClassIndex.get(className).getNpcInstances();
NpcInstance npcInstance = new NpcInstance();
for(int i=0; i<placeNpcInstances.size(); i++) {
for(int j=0; j<npcInstances.size(); j++) {
if(placeNpcInstances.get(i) == npcInstances.get(j)) {
......@@ -675,7 +694,6 @@ public class GameEnv implements Serializable{
return false;
}
}
// 更新npc的位置
public boolean updateFollowerLocation(String location) {
Place place = this.placeIndex.get(location);
......
......@@ -7,63 +7,81 @@ public class Place implements Serializable{
private static final long serialVersionUID = 1L;
private String name;
private String intro;
private Integer goFlag;
private List<String> nickname;
private List<Place> ableGo;
private List<NpcInstance> npcInstances;
private List<GoodsInstance> 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<String> getNickname() {
return nickname;
}
public void setNickname(List<String> nickname) {
this.nickname = nickname;
}
public List<Place> getAbleGo() {
return ableGo;
}
public void setAbleGo(List<Place> ableGo) {
this.ableGo = ableGo;
}
public List<NpcInstance> getNpcInstances() {
return npcInstances;
}
public void setNpcInstances(List<NpcInstance> npcInstances) {
this.npcInstances = npcInstances;
}
public List<GoodsInstance> getGoodsInstances() {
return goodsInstances;
}
public void setGoodsInstances(List<GoodsInstance> goodsInstances) {
this.goodsInstances = goodsInstances;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
@Override
public String toString() {
int ableGoSize = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment