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
ff2aa1bb
Commit
ff2aa1bb
authored
Dec 07, 2018
by
李进峰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add follow player
parent
a0a9bad4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
11 deletions
+42
-11
GameEnv.java
src/GameEnvironment/GameEnv.java
+42
-11
No files found.
src/GameEnvironment/GameEnv.java
View file @
ff2aa1bb
...
...
@@ -19,13 +19,13 @@ public class GameEnv implements Serializable{
private
static
final
long
serialVersionUID
=
1L
;
public
Map
<
String
,
SuperClass
>
npcClassIndex
;
public
Map
<
String
,
NpcInstance
>
npcInstanceIndex
;
public
Map
<
String
,
NpcInstance
>
followNpcIndex
;
public
Map
<
String
,
SuperClass
>
goodsClassIndex
;
public
Map
<
String
,
GoodsInstance
>
goodsInstanceIndex
;
public
Map
<
String
,
Place
>
placeIndex
;
public
byte
[][]
mapGraph
;
public
Map
<
String
,
Integer
>
mapNames
;
public
String
[]
mapIndexName
;
public
GameEnv
(
String
botName
)
throws
Exception
{
// 通过文件来初始化游戏环境
// String fullName = "test.json";
...
...
@@ -35,6 +35,7 @@ public class GameEnv implements Serializable{
String
jsonString
=
DBUtil
.
queryEnvJsonByBotName
(
botName
);
Map
<
String
,
Object
>
gameProjectMap
=
JSON
.
parseObject
(
jsonString
);
System
.
out
.
println
(
gameProjectMap
);
this
.
followNpcIndex
=
new
HashMap
<
String
,
NpcInstance
>();
if
(!
gameProjectMap
.
isEmpty
())
{
// 地图
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
gameProjectMap
.
get
(
"map"
);
...
...
@@ -147,6 +148,9 @@ public class GameEnv implements Serializable{
attr
.
setName
(
instanceAttrKey
);
attr
.
setValue
((
String
)
instanceAttrMap
.
get
(
instanceAttrKey
));
npcInstanceAttrs
.
add
(
attr
);
if
(
instanceAttrKey
.
equals
(
"跟随玩家"
)&&((
String
)
instanceAttrMap
.
get
(
instanceAttrKey
)).
equals
(
"是"
))
{
this
.
followNpcIndex
.
put
(
npcInstance
.
getName
(),
npcInstance
);
}
}
}
npcInstance
.
setAttrs
(
npcInstanceAttrs
);
...
...
@@ -299,20 +303,28 @@ public class GameEnv implements Serializable{
}
public
Integer
isNeighbour
(
String
placeA
,
String
placeB
)
{
if
(
placeA
.
equals
(
placeB
))
{
return
0
;
}
else
{
try
{
int
x
=
this
.
mapNames
.
get
(
placeA
);
int
y
=
this
.
mapNames
.
get
(
placeB
);
if
(
this
.
mapGraph
[
x
][
y
]
==
1
)
{
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
;
}
}
}
if
(
flag
==
1
)
{
return
1
;
}
else
{
return
2
;
}
}
catch
(
Exception
e
)
{
return
-
1
;
}
}
catch
(
Exception
e
)
{
return
2
;
}
}
// 两点之间的路径 // 使用广度优先算法单源最短路的SPFA算法的全称是:Shortest Path Faster Algorithm。
...
...
@@ -339,7 +351,7 @@ public class GameEnv implements Serializable{
placeLinkNodeSecond
.
setIndex
(
i
);
placeLinkNodeSecond
.
setPlaceLink
(
placeLinkNode
);
List
<
String
>
nickname
=
this
.
placeIndex
.
get
(
this
.
mapIndexName
[
i
]).
getNickname
();
if
(
this
.
mapIndexName
[
i
].
equals
(
placeB
)
||
(
nickname
!=
null
&&
nickname
.
indexOf
(
placeB
)>
0
))
{
if
(
this
.
mapIndexName
[
i
].
equals
(
placeB
)
||
(
nickname
!=
null
&&
nickname
.
indexOf
(
placeB
)>
=
0
))
{
while
(
placeLinkNodeSecond
.
getPlaceLink
()
!=
null
)
{
paths
.
add
(
this
.
mapIndexName
[
placeLinkNodeSecond
.
getIndex
()]);
placeLinkNodeSecond
=
placeLinkNodeSecond
.
getPlaceLink
();
...
...
@@ -358,6 +370,7 @@ public class GameEnv implements Serializable{
}
public
List
<
String
>
queryPathBySite
(
String
placeA
,
String
placeB
){
List
<
String
>
paths
=
this
.
getAllPath
(
placeA
,
placeB
);
System
.
out
.
println
(
paths
);
List
<
String
>
path
=
new
ArrayList
<
String
>();
if
(
paths
.
size
()>
1
)
{
for
(
int
i
=
0
;
i
<
paths
.
size
();
i
++)
{
...
...
@@ -610,6 +623,15 @@ public class GameEnv implements Serializable{
List
<
Attr
>
attrs
=
npcInstance
.
getAttrs
();
for
(
int
j
=
0
;
j
<
attrs
.
size
();
j
++)
{
if
(
names
[
3
].
equals
(
attrs
.
get
(
j
).
getName
()))
{
if
(
names
[
3
].
equals
(
"跟随玩家"
))
{
if
(
value
.
equals
(
"是"
))
{
this
.
followNpcIndex
.
put
(
npcInstance
.
getName
(),
npcInstance
);
}
else
if
(
value
.
equals
(
"否"
))
{
this
.
followNpcIndex
.
remove
(
npcInstance
.
getName
());
}
else
{
continue
;
}
}
attrs
.
get
(
j
).
setValue
(
value
);
return
true
;
}
...
...
@@ -634,4 +656,13 @@ public class GameEnv implements Serializable{
return
false
;
}
}
// 更新npc的位置
public
boolean
updateFollowerLocation
(
String
location
)
{
Place
place
=
this
.
placeIndex
.
get
(
location
);
for
(
String
instanceKey:
this
.
followNpcIndex
.
keySet
())
{
this
.
followNpcIndex
.
get
(
instanceKey
).
setPlace
(
place
);
}
return
true
;
}
}
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