Commit 1e2dc2d2 by 李进峰

add nickname bug repair

parent 15fa3483
......@@ -153,9 +153,15 @@ public class GameEnv implements Serializable{
npcNames.put(instanceKey, (String)instanceAttrMap.get("name"));
npcInstance.setName((String)instanceAttrMap.get("name"));
npcInstance.setIntro((String)instanceAttrMap.get("intro"));
npcInstance.setNickname((List<String>)instanceAttrMap.get("nickname"));
List<Attr> npcInstanceAttrs = new ArrayList<Attr>();
for(String instanceAttrKey:instanceAttrMap.keySet()) {
if(!instanceAttrKey.equals("name")&&!instanceAttrKey.equals("intro")&&!instanceAttrKey.equals("placeId")&&!instanceAttrKey.equals("placeName")&&!instanceAttrKey.equals("class")) {
if(!instanceAttrKey.equals("name")
&&!instanceAttrKey.equals("intro")
&&!instanceAttrKey.equals("placeId")
&&!instanceAttrKey.equals("placeName")
&&!instanceAttrKey.equals("class")
&&!instanceAttrKey.equals("nickname")) {
Attr attr = new Attr();
attr.setName(instanceAttrKey);
attr.setValue((String)instanceAttrMap.get(instanceAttrKey));
......@@ -169,13 +175,15 @@ public class GameEnv implements Serializable{
Place place = null;
if(instanceAttrMap.get("placeId")!=null) {
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>();
if(placeMap!=null) {
place = placeIndex.get(placeMap.get("name"));
List<NpcInstance> npcInstances = place.getNpcInstances();
if(npcInstances == null) {
npcInstances = new ArrayList<NpcInstance>();
}
npcInstances.add(npcInstance);
place.setNpcInstances(npcInstances);
}
npcInstances.add(npcInstance);
place.setNpcInstances(npcInstances);
}
List<NpcInstance> npcInstanceClass = npcClass.getNpcInstances();
if(npcInstanceClass == null) {
......@@ -220,9 +228,14 @@ public class GameEnv implements Serializable{
Map<String, Object> instanceAttrMap = (Map<String, Object>)instances.get(instanceKey);
goodsInstance.setName((String)instanceAttrMap.get("name"));
goodsInstance.setIntro((String)instanceAttrMap.get("intro"));
goodsInstance.setNickname((List<String>)instanceAttrMap.get("nickname"));
List<Attr> goodsInstanceAttrs = new ArrayList<Attr>();
for(String instanceAttrKey:instanceAttrMap.keySet()) {
if(instanceAttrKey!="placeId"&&instanceAttrKey!="npcId"&&instanceAttrKey!="name"&&instanceAttrKey!="intro") {
if(instanceAttrKey!="placeId"
&&instanceAttrKey!="npcId"
&&instanceAttrKey!="name"
&&instanceAttrKey!="intro"
&&instanceAttrKey!="nickname") {
Attr attr = new Attr();
attr.setName(instanceAttrKey);
attr.setValue((String)instanceAttrMap.get(instanceAttrKey));
......@@ -363,6 +376,17 @@ public class GameEnv implements Serializable{
}
}
// 通过别名查询当前地点最近的npc
public String getNpcNameByNickname(String curPlaceName, String nickname) {
List<NpcInstance> npcInstances = this.placeIndex.get(curPlaceName).getNpcInstances();
for(int i=0; i<npcInstances.size();i++) {
NpcInstance npcInstance = npcInstances.get(i);
if(npcInstance.getNickname().indexOf(nickname)>=0) {
return npcInstance.getName();
}
}
return nickname;
}
// 两点之间的路径 // 使用广度优先算法单源最短路的SPFA算法的全称是:Shortest Path Faster Algorithm。只有状态为2的时候使用
public List<String> getAllPath(String placeA, String placeB){
List<String> paths = new ArrayList<String>();
......
......@@ -5,6 +5,7 @@ import java.util.List;
public class GoodsInstance extends SuperClass implements Serializable{
private static final long serialVersionUID = 1L;
private List<String> nickname;
private Place place;
private NpcInstance npc;
public Place getPlace() {
......@@ -19,7 +20,13 @@ public class GoodsInstance extends SuperClass implements Serializable{
public void setNpc(NpcInstance npc) {
this.npc = npc;
}
@Override
public List<String> getNickname() {
return nickname;
}
public void setNickname(List<String> nickname) {
this.nickname = nickname;
}
@Override
public String toString() {
String placeName = "";
if(place != null) {
......@@ -29,7 +36,7 @@ public class GoodsInstance extends SuperClass implements Serializable{
if(npc != null) {
npcName = npc.getName();
}
return super.toString()+"GoodsInstance [placeName=" + placeName + ", npcName=" + npcName + "]";
return super.toString()+"GoodsInstance [placeName=" + placeName + ", npcName=" + npcName +",nickname="+nickname+"]";
}
}
......@@ -5,21 +5,34 @@ import java.util.List;
public class NpcInstance extends SuperClass implements Serializable{
private static final long serialVersionUID = 1L;
private List<String> nickname;
private Place place;
private List<GoodsInstance> goodsInstances;
public List<String> getNickname() {
return nickname;
}
public void setNickname(List<String> nickname) {
this.nickname = nickname;
}
public Place getPlace() {
return place;
}
public void setPlace(Place place) {
this.place = place;
}
public List<GoodsInstance> getGoodsInstances() {
return goodsInstances;
}
public void setGoodsInstances(List<GoodsInstance> goodsInstances) {
this.goodsInstances = goodsInstances;
}
@Override
@Override
public String toString() {
String placeName = "";
if(place != null) {
......@@ -29,7 +42,7 @@ public class NpcInstance extends SuperClass implements Serializable{
if(goodsInstances!=null) {
goodsInstancesSize = goodsInstances.size();
}
return super.toString()+"NpcInstance [placeName=" + placeName + ", goodsInstancesSize=" + goodsInstancesSize + "]";
return super.toString()+"NpcInstance [placeName=" + placeName + ", goodsInstancesSize=" + goodsInstancesSize +",nickname="+nickname+"]";
}
}
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