Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
qwgame
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵国君
qwgame
Commits
58c4f76d
Commit
58c4f76d
authored
Dec 17, 2018
by
李进峰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add npc,goods nickname query
parent
50d42683
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
3 deletions
+51
-3
GameEnv.java
src/GameEnvironment/GameEnv.java
+51
-3
No files found.
src/GameEnvironment/GameEnv.java
View file @
58c4f76d
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
getNpcNam
eByNickname
(
String
curPlaceName
,
String
nickname
)
{
public
String
queryCurPlaceNpcInstanc
eByNickname
(
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的时候使用
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment