Commit 58c4f76d by 李进峰

add npc,goods nickname query

parent 50d42683
package com.qiwu.chatbotbackend.GameEnvironment; package com.qiwu.chatbotbackend.GameEnvironment;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayDeque;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.ArrayDeque;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
...@@ -417,8 +419,8 @@ public class GameEnv implements Serializable{ ...@@ -417,8 +419,8 @@ public class GameEnv implements Serializable{
} }
} }
// 通过别名查询当前地点最近的npc
public String getNpcNameByNickname(String curPlaceName, String nickname) { public String queryCurPlaceNpcInstanceByNickname(String curPlaceName, String nickname) {
List<NpcInstance> npcInstances = this.placeIndex.get(curPlaceName).getNpcInstances(); List<NpcInstance> npcInstances = this.placeIndex.get(curPlaceName).getNpcInstances();
for(int i=0; i<npcInstances.size();i++) { for(int i=0; i<npcInstances.size();i++) {
NpcInstance npcInstance = npcInstances.get(i); NpcInstance npcInstance = npcInstances.get(i);
...@@ -426,6 +428,52 @@ public class GameEnv implements Serializable{ ...@@ -426,6 +428,52 @@ public class GameEnv implements Serializable{
return npcInstance.getName(); return npcInstance.getName();
} }
} }
return null;
}
public String queryCurPlaceGoodsInstanceByNickname(String curPlaceName, String nickname) {
List<GoodsInstance> goodsInstances = this.placeIndex.get(curPlaceName).getGoodsInstances();
for(int i=0; i<goodsInstances.size();i++) {
GoodsInstance goodsInstance = goodsInstances.get(i);
if(goodsInstance.getNickname().indexOf(nickname)>=0) {
return goodsInstance.getName();
}
}
return null;
}
// 通过别名查询当前地点最近的npc
public String getNpcNameByNickname(String curPlaceName, String nickname) {
// 寻找两层
// 查询当前地点的所有,和当前地点可以去到的地点相应的所有
String npcInstanceName = this.queryCurPlaceNpcInstanceByNickname(curPlaceName, nickname);
if(npcInstanceName!=null) {
return npcInstanceName;
}
List<Place> places = this.placeIndex.get(curPlaceName).getAbleGo();
for(int i=0; i<places.size(); i++) {
Place place = places.get(i);
npcInstanceName = this.queryCurPlaceNpcInstanceByNickname(place.getName(), nickname);
if(npcInstanceName!=null) {
return npcInstanceName;
}
}
return nickname;
}
// 通过别名查询当前地点最近的物品
public String getGoodsNameByNickname(String curPlaceName, String nickname) {
// 寻找两层
// 查询当前地点的所有,和当前地点可以去到的地点相应的所有
String npcInstanceName = this.queryCurPlaceGoodsInstanceByNickname(curPlaceName, nickname);
if(npcInstanceName!=null) {
return npcInstanceName;
}
List<Place> places = this.placeIndex.get(curPlaceName).getAbleGo();
for(int i=0; i<places.size(); i++) {
Place place = places.get(i);
npcInstanceName = this.queryCurPlaceGoodsInstanceByNickname(place.getName(), nickname);
if(npcInstanceName!=null) {
return npcInstanceName;
}
}
return nickname; return nickname;
} }
// 两点之间的路径 // 使用广度优先算法单源最短路的SPFA算法的全称是:Shortest Path Faster Algorithm。只有状态为2的时候使用 // 两点之间的路径 // 使用广度优先算法单源最短路的SPFA算法的全称是:Shortest Path Faster Algorithm。只有状态为2的时候使用
......
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