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
f8d00711
Commit
f8d00711
authored
Nov 24, 2018
by
李进峰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
7a10c080
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
124 additions
and
79 deletions
+124
-79
GameEnv.java
src/GameEnvironment/GameEnv.java
+124
-79
No files found.
src/GameEnvironment/GameEnv.java
View file @
f8d00711
...
@@ -13,179 +13,188 @@ import GameEnvironment.bean.SuperClass;
...
@@ -13,179 +13,188 @@ import GameEnvironment.bean.SuperClass;
import
GameEnvironment.bean.NpcInstance
;
import
GameEnvironment.bean.NpcInstance
;
import
GameEnvironment.bean.Place
;
import
GameEnvironment.bean.Place
;
public
class
GameEnv
{
public
class
GameEnv
implements
Serializable
{
public
Map
<
String
,
SuperClass
>
npcClassIndex
=
null
;
private
static
final
long
serialVersionUID
=
1L
;
public
Map
<
String
,
NpcInstance
>
npcInstanceIndex
=
null
;
public
Map
<
String
,
SuperClass
>
npcClassIndex
;
public
Map
<
String
,
SuperClass
>
goodsClassIndex
=
null
;
public
Map
<
String
,
NpcInstance
>
npcInstanceIndex
;
public
Map
<
String
,
GoodsInstance
>
goodsInstanceIndex
=
null
;
public
Map
<
String
,
SuperClass
>
goodsClassIndex
;
public
Map
<
String
,
Place
>
placeIndex
=
null
;
public
Map
<
String
,
GoodsInstance
>
goodsInstanceIndex
;
public
Map
<
String
,
Place
>
placeIndex
;
public
GameEnv
(
String
botName
)
throws
Exception
{
public
GameEnv
(
String
botName
)
throws
Exception
{
// 通过文件来初始化游戏环境
// 通过文件来初始化游戏环境
// String fullName = "E:\\projects\\env\\"+projectId+".json";
// String fullName = "test.json";
//
// String jsonString = Util.getJsonString(fullName);
try
{
// String jsonString = Util.getJsonString(fullName);
String
jsonString
=
""
;
//DBUtil.queryEnvJsonByBotName(botName);
// System.out.println(jsonString);
String
jsonString
=
DBUtil
.
queryEnvJsonByBotName
(
botName
);
Map
<
String
,
Object
>
gameProjectMap
=
JSON
.
parseObject
(
jsonString
);
Map
<
String
,
Object
>
gameProjectMap
=
JSON
.
parseObject
(
jsonString
);
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
gameProjectMap
.
get
(
"map"
);
// System.out.println(gameProjectMap);
if
(!
gameProjectMap
.
isEmpty
())
{
// 地图
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
gameProjectMap
.
get
(
"map"
);
this
.
placeIndex
=
new
HashMap
<
String
,
Place
>();
this
.
placeIndex
=
new
HashMap
<
String
,
Place
>();
Map
<
String
,
Object
>
placeMapTmp
=
new
HashMap
();
Map
<
String
,
Object
>
placeMapTmp
=
new
HashMap
();
if
(!
map
.
isEmpty
())
{
for
(
String
key
:
map
.
keySet
())
{
for
(
String
key:
map
.
keySet
())
{
Map
<
String
,
Object
>
one
=
(
Map
<
String
,
Object
>)
map
.
get
(
key
);
Map
<
String
,
Object
>
one
=
(
Map
<
String
,
Object
>)
map
.
get
(
key
);
placeMapTmp
.
put
(
key
,
(
String
)
one
.
get
(
"name"
));
placeMapTmp
.
put
(
key
,
(
String
)
one
.
get
(
"name"
));
Place
place
=
new
Place
();
Place
place
=
new
Place
();
place
.
setIntro
((
String
)
one
.
get
(
"intro"
));
place
.
setIntro
((
String
)
one
.
get
(
"intro"
));
place
.
setName
((
String
)
one
.
get
(
"name"
));
place
.
setName
((
String
)
one
.
get
(
"name"
));
placeIndex
.
put
((
String
)
one
.
get
(
"name"
),
place
);
placeIndex
.
put
((
String
)
one
.
get
(
"name"
),
place
);
}
}
for
(
String
tmp
:
placeMapTmp
.
keySet
())
{
for
(
String
tmp:
placeMapTmp
.
keySet
())
{
List
<
Place
>
ableGos
=
new
ArrayList
<
Place
>();
List
<
Place
>
ableGos
=
new
ArrayList
<
Place
>();
List
<
Long
>
ableGoLongs
=
(
List
<
Long
>)
((
Map
<
String
,
Object
>)
map
.
get
(
tmp
)).
get
(
"canGo"
);
List
<
Long
>
ableGoLongs
=
(
List
<
Long
>)((
Map
<
String
,
Object
>)
map
.
get
(
tmp
)).
get
(
"canGo"
);
for
(
int
j
=
0
;
j
<
ableGoLongs
.
size
();
j
++)
{
for
(
int
j
=
0
;
j
<
ableGoLongs
.
size
();
j
++)
{
String
idName
=
String
.
valueOf
(
ableGoLongs
.
get
(
j
));
String
idName
=
String
.
valueOf
(
ableGoLongs
.
get
(
j
));
ableGos
.
add
(
placeIndex
.
get
(
placeMapTmp
.
get
(
idName
)));
ableGos
.
add
(
placeIndex
.
get
(
placeMapTmp
.
get
(
idName
)));
}
}
placeIndex
.
get
(
placeMapTmp
.
get
(
tmp
)).
setAbleGo
(
ableGos
);
placeIndex
.
get
(
placeMapTmp
.
get
(
tmp
)).
setAbleGo
(
ableGos
);
}
}
}
// npc
// npc
// npc class
// npc class
Map
<
String
,
Object
>
npcClasses
=
(
Map
<
String
,
Object
>)
gameProjectMap
.
get
(
"npc"
);
Map
<
String
,
Object
>
npcClasses
=
(
Map
<
String
,
Object
>)
gameProjectMap
.
get
(
"npc"
);
Map
<
String
,
Object
>
npcNames
=
new
HashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
npcNames
=
new
HashMap
<
String
,
Object
>();
this
.
npcClassIndex
=
new
HashMap
<
String
,
SuperClass
>();
this
.
npcClassIndex
=
new
HashMap
<
String
,
SuperClass
>();
this
.
npcInstanceIndex
=
new
HashMap
<
String
,
NpcInstance
>();
this
.
npcInstanceIndex
=
new
HashMap
<
String
,
NpcInstance
>();
for
(
String
classKey
:
npcClasses
.
keySet
())
{
if
(!
npcClasses
.
isEmpty
())
{
Map
<
String
,
Object
>
one
=
(
Map
<
String
,
Object
>)
npcClasses
.
get
(
classKey
);
for
(
String
classKey:
npcClasses
.
keySet
())
{
Map
<
String
,
Object
>
one
=
(
Map
<
String
,
Object
>)
npcClasses
.
get
(
classKey
);
// class
// class
Map
<
String
,
Object
>
oneClass
=
(
Map
<
String
,
Object
>)
one
.
get
(
"class"
);
Map
<
String
,
Object
>
oneClass
=
(
Map
<
String
,
Object
>)
one
.
get
(
"class"
);
SuperClass
npcClass
=
new
SuperClass
();
SuperClass
npcClass
=
new
SuperClass
();
npcClass
.
setName
(
classKey
);
npcClass
.
setName
(
classKey
);
npcClass
.
setIntro
((
String
)
oneClass
.
get
(
"intro"
));
npcClass
.
setIntro
((
String
)
oneClass
.
get
(
"intro"
));
List
<
Attr
>
attrs
=
new
ArrayList
<
Attr
>();
List
<
Attr
>
attrs
=
new
ArrayList
<
Attr
>();
for
(
String
attrKey
:
oneClass
.
keySet
())
{
for
(
String
attrKey:
oneClass
.
keySet
())
{
if
(
attrKey
!=
"intro"
)
{
if
(!
attrKey
.
equals
(
"intro"
)
&&
!
attrKey
.
equals
(
"class"
)
&&
!
attrKey
.
equals
(
""
)
)
{
Attr
attr
=
new
Attr
();
Attr
attr
=
new
Attr
();
attr
.
setName
(
attrKey
);
attr
.
setName
(
attrKey
);
attr
.
setValue
((
String
)
oneClass
.
get
(
attrKey
));
attr
.
setValue
((
String
)
oneClass
.
get
(
attrKey
));
attrs
.
add
(
attr
);
attrs
.
add
(
attr
);
}
}
}
}
npcClass
.
setAttrs
(
attrs
);
npcClass
.
setAttrs
(
attrs
);
// instance
// instance
Map
<
String
,
Object
>
instances
=
(
Map
<
String
,
Object
>)
one
.
get
(
"instance"
);
Map
<
String
,
Object
>
instances
=
(
Map
<
String
,
Object
>)
one
.
get
(
"instance"
);
for
(
String
instanceKey
:
instances
.
keySet
())
{
for
(
String
instanceKey:
instances
.
keySet
())
{
Map
<
String
,
Object
>
instance
=
new
HashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
instance
=
new
HashMap
<
String
,
Object
>();
NpcInstance
npcInstance
=
new
NpcInstance
();
NpcInstance
npcInstance
=
new
NpcInstance
();
Map
<
String
,
Object
>
instanceAttrMap
=
(
Map
<
String
,
Object
>)
instances
.
get
(
instanceKey
);
Map
<
String
,
Object
>
instanceAttrMap
=
(
Map
<
String
,
Object
>)
instances
.
get
(
instanceKey
);
npcNames
.
put
(
instanceKey
,
(
String
)
instanceAttrMap
.
get
(
"name"
));
npcNames
.
put
(
instanceKey
,
(
String
)
instanceAttrMap
.
get
(
"name"
));
npcInstance
.
setName
((
String
)
instanceAttrMap
.
get
(
"name"
));
npcInstance
.
setName
((
String
)
instanceAttrMap
.
get
(
"name"
));
npcInstance
.
setIntro
((
String
)
instanceAttrMap
.
get
(
"intro"
));
npcInstance
.
setIntro
((
String
)
instanceAttrMap
.
get
(
"intro"
));
List
<
Attr
>
npcInstanceAttrs
=
new
ArrayList
<
Attr
>();
List
<
Attr
>
npcInstanceAttrs
=
new
ArrayList
<
Attr
>();
for
(
String
instanceAttrKey
:
instanceAttrMap
.
keySet
())
{
for
(
String
instanceAttrKey:
instanceAttrMap
.
keySet
())
{
if
(
instanceAttrKey
!=
"name"
&&
instanceAttrKey
!=
"intro"
&&
instanceAttrKey
!=
"placeId"
)
{
if
(!
instanceAttrKey
.
equals
(
"name"
)&&!
instanceAttrKey
.
equals
(
"intro"
)&&!
instanceAttrKey
.
equals
(
"placeId"
)&&!
instanceAttrKey
.
equals
(
"placeName"
)&&!
instanceAttrKey
.
equals
(
"class"
)
)
{
Attr
attr
=
new
Attr
();
Attr
attr
=
new
Attr
();
attr
.
setName
(
instanceAttrKey
);
attr
.
setName
(
instanceAttrKey
);
attr
.
setValue
((
String
)
instanceAttrMap
.
get
(
instanceAttrKey
));
attr
.
setValue
((
String
)
instanceAttrMap
.
get
(
instanceAttrKey
));
npcInstanceAttrs
.
add
(
attr
);
npcInstanceAttrs
.
add
(
attr
);
}
}
}
}
npcInstance
.
setAttrs
(
npcInstanceAttrs
);
npcInstance
.
setAttrs
(
npcInstanceAttrs
);
Place
place
=
placeIndex
.
get
(((
Map
<
String
,
Object
>)
map
.
get
(
String
.
valueOf
(
instanceAttrMap
.
get
(
"placeId"
)))).
get
(
"name"
));
Place
place
=
null
;
if
(
instanceAttrMap
.
get
(
"placeId"
)!=
null
)
{
place
=
placeIndex
.
get
(((
Map
<
String
,
Object
>)
map
.
get
(
String
.
valueOf
(
instanceAttrMap
.
get
(
"placeId"
)))).
get
(
"name"
));
List
<
NpcInstance
>
npcInstances
=
place
.
getNpcInstances
();
List
<
NpcInstance
>
npcInstances
=
place
.
getNpcInstances
();
if
(
npcInstances
==
null
)
{
if
(
npcInstances
==
null
)
{
npcInstances
=
new
ArrayList
<
NpcInstance
>();
npcInstances
=
new
ArrayList
<
NpcInstance
>();
}
}
npcInstances
.
add
(
npcInstance
);
npcInstances
.
add
(
npcInstance
);
place
.
setNpcInstances
(
npcInstances
);
place
.
setNpcInstances
(
npcInstances
);
}
List
<
NpcInstance
>
npcInstanceClass
=
npcClass
.
getNpcInstances
();
List
<
NpcInstance
>
npcInstanceClass
=
npcClass
.
getNpcInstances
();
if
(
npcInstanceClass
==
null
)
{
if
(
npcInstanceClass
==
null
)
{
npcInstanceClass
=
new
ArrayList
<
NpcInstance
>();
npcInstanceClass
=
new
ArrayList
<
NpcInstance
>();
}
}
npcInstanceClass
.
add
(
npcInstance
);
npcInstanceClass
.
add
(
npcInstance
);
npcClass
.
setNpcInstances
(
npcInstanceClass
);
npcClass
.
setNpcInstances
(
npcInstanceClass
);
npcInstance
.
setPlace
(
place
);
npcInstance
.
setPlace
(
place
);
this
.
npcInstanceIndex
.
put
((
String
)
instanceAttrMap
.
get
(
"name"
),
npcInstance
);
this
.
npcInstanceIndex
.
put
((
String
)
instanceAttrMap
.
get
(
"name"
),
npcInstance
);
}
}
this
.
npcClassIndex
.
put
(
classKey
,
npcClass
);
this
.
npcClassIndex
.
put
(
classKey
,
npcClass
);
}
}
}
// goods
// goods
Map
<
String
,
Object
>
goodsClasses
=
(
Map
<
String
,
Object
>)
gameProjectMap
.
get
(
"goods"
);
Map
<
String
,
Object
>
goodsClasses
=
(
Map
<
String
,
Object
>)
gameProjectMap
.
get
(
"goods"
);
this
.
goodsClassIndex
=
new
HashMap
<
String
,
SuperClass
>();
this
.
goodsClassIndex
=
new
HashMap
<
String
,
SuperClass
>();
this
.
goodsInstanceIndex
=
new
HashMap
<
String
,
GoodsInstance
>();
this
.
goodsInstanceIndex
=
new
HashMap
<
String
,
GoodsInstance
>();
for
(
String
classKey
:
goodsClasses
.
keySet
())
{
if
(!
goodsClasses
.
isEmpty
())
{
Map
<
String
,
Object
>
one
=
(
Map
<
String
,
Object
>)
goodsClasses
.
get
(
classKey
);
for
(
String
classKey:
goodsClasses
.
keySet
())
{
Map
<
String
,
Object
>
one
=
(
Map
<
String
,
Object
>)
goodsClasses
.
get
(
classKey
);
// class
// class
Map
<
String
,
Object
>
oneClass
=
(
Map
<
String
,
Object
>)
one
.
get
(
"class"
);
Map
<
String
,
Object
>
oneClass
=
(
Map
<
String
,
Object
>)
one
.
get
(
"class"
);
SuperClass
goodsClass
=
new
SuperClass
();
SuperClass
goodsClass
=
new
SuperClass
();
goodsClass
.
setName
(
classKey
);
goodsClass
.
setName
(
classKey
);
goodsClass
.
setIntro
((
String
)
oneClass
.
get
(
"intro"
));
goodsClass
.
setIntro
((
String
)
oneClass
.
get
(
"intro"
));
List
<
Attr
>
attrs
=
new
ArrayList
<
Attr
>();
List
<
Attr
>
attrs
=
new
ArrayList
<
Attr
>();
for
(
String
attrKey
:
oneClass
.
keySet
())
{
for
(
String
attrKey:
oneClass
.
keySet
())
{
if
(
attrKey
!=
"intro"
)
{
if
(!
attrKey
.
equals
(
"intro"
)&&!
attrKey
.
equals
(
"placeId"
)&&!
attrKey
.
equals
(
"npcName"
)&&!
attrKey
.
equals
(
"class"
)&&!
attrKey
.
equals
(
"placeName"
)
)
{
Attr
attr
=
new
Attr
();
Attr
attr
=
new
Attr
();
attr
.
setName
(
attrKey
);
attr
.
setName
(
attrKey
);
attr
.
setValue
((
String
)
oneClass
.
get
(
attrKey
));
attr
.
setValue
((
String
)
oneClass
.
get
(
attrKey
));
attrs
.
add
(
attr
);
attrs
.
add
(
attr
);
}
}
}
}
goodsClass
.
setAttrs
(
attrs
);
goodsClass
.
setAttrs
(
attrs
);
// instance
// instance
Map
<
String
,
Object
>
instances
=
(
Map
<
String
,
Object
>)
one
.
get
(
"instance"
);
Map
<
String
,
Object
>
instances
=
(
Map
<
String
,
Object
>)
one
.
get
(
"instance"
);
for
(
String
instanceKey
:
instances
.
keySet
())
{
for
(
String
instanceKey:
instances
.
keySet
())
{
Map
<
String
,
Object
>
instance
=
new
HashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
instance
=
new
HashMap
<
String
,
Object
>();
GoodsInstance
goodsInstance
=
new
GoodsInstance
();
GoodsInstance
goodsInstance
=
new
GoodsInstance
();
Map
<
String
,
Object
>
instanceAttrMap
=
(
Map
<
String
,
Object
>)
instances
.
get
(
instanceKey
);
Map
<
String
,
Object
>
instanceAttrMap
=
(
Map
<
String
,
Object
>)
instances
.
get
(
instanceKey
);
goodsInstance
.
setName
((
String
)
instanceAttrMap
.
get
(
"name"
));
goodsInstance
.
setName
((
String
)
instanceAttrMap
.
get
(
"name"
));
goodsInstance
.
setIntro
((
String
)
instanceAttrMap
.
get
(
"intro"
));
goodsInstance
.
setIntro
((
String
)
instanceAttrMap
.
get
(
"intro"
));
List
<
Attr
>
goodsInstanceAttrs
=
new
ArrayList
<
Attr
>();
List
<
Attr
>
goodsInstanceAttrs
=
new
ArrayList
<
Attr
>();
for
(
String
instanceAttrKey
:
instanceAttrMap
.
keySet
())
{
for
(
String
instanceAttrKey:
instanceAttrMap
.
keySet
())
{
if
(
instanceAttrKey
!=
"placeId"
&&
instanceAttrKey
!=
"npcId"
&&
instanceAttrKey
!=
"name"
&&
instanceAttrKey
!=
"intro"
)
{
if
(
instanceAttrKey
!=
"placeId"
&&
instanceAttrKey
!=
"npcId"
&&
instanceAttrKey
!=
"name"
&&
instanceAttrKey
!=
"intro"
)
{
Attr
attr
=
new
Attr
();
Attr
attr
=
new
Attr
();
attr
.
setName
(
instanceAttrKey
);
attr
.
setName
(
instanceAttrKey
);
attr
.
setValue
((
String
)
instanceAttrMap
.
get
(
instanceAttrKey
));
attr
.
setValue
((
String
)
instanceAttrMap
.
get
(
instanceAttrKey
));
goodsInstanceAttrs
.
add
(
attr
);
goodsInstanceAttrs
.
add
(
attr
);
}
}
}
}
goodsInstance
.
setAttrs
(
goodsInstanceAttrs
);
goodsInstance
.
setAttrs
(
goodsInstanceAttrs
);
Place
place
=
placeIndex
.
get
(((
Map
<
String
,
Object
>)
map
.
get
(
String
.
valueOf
(
instanceAttrMap
.
get
(
"placeId"
)))).
get
(
"name"
));
if
(
instanceAttrMap
.
get
(
"placeId"
)!=
null
)
{
Place
place
=
placeIndex
.
get
(((
Map
<
String
,
Object
>)
map
.
get
(
String
.
valueOf
(
instanceAttrMap
.
get
(
"placeId"
)))).
get
(
"name"
));
goodsInstance
.
setPlace
(
place
);
goodsInstance
.
setPlace
(
place
);
List
<
GoodsInstance
>
placeGoodsInstances
=
place
.
getGoodsInstances
();
List
<
GoodsInstance
>
placeGoodsInstances
=
place
.
getGoodsInstances
();
if
(
placeGoodsInstances
==
null
)
{
if
(
placeGoodsInstances
==
null
)
{
placeGoodsInstances
=
new
ArrayList
<
GoodsInstance
>();
placeGoodsInstances
=
new
ArrayList
<
GoodsInstance
>();
}
}
placeGoodsInstances
.
add
(
goodsInstance
);
placeGoodsInstances
.
add
(
goodsInstance
);
place
.
setGoodsInstances
(
placeGoodsInstances
);
place
.
setGoodsInstances
(
placeGoodsInstances
);
}
if
(
instanceAttrMap
.
get
(
"npcId"
)!=
null
){
NpcInstance
npc
=
this
.
npcInstanceIndex
.
get
(
npcNames
.
get
(
String
.
valueOf
(
instanceAttrMap
.
get
(
"npcId"
))));
NpcInstance
npc
=
this
.
npcInstanceIndex
.
get
(
npcNames
.
get
(
String
.
valueOf
(
instanceAttrMap
.
get
(
"npcId"
))));
goodsInstance
.
setNpc
(
npc
);
goodsInstance
.
setNpc
(
npc
);
List
<
GoodsInstance
>
npcGoodsInstances
=
npc
.
getGoodsInstances
();
List
<
GoodsInstance
>
npcGoodsInstances
=
npc
.
getGoodsInstances
();
if
(
npcGoodsInstances
==
null
)
{
if
(
npcGoodsInstances
==
null
)
{
npcGoodsInstances
=
new
ArrayList
<
GoodsInstance
>();
npcGoodsInstances
=
new
ArrayList
<
GoodsInstance
>();
}
}
npcGoodsInstances
.
add
(
goodsInstance
);
npcGoodsInstances
.
add
(
goodsInstance
);
npc
.
setGoodsInstances
(
npcGoodsInstances
);
npc
.
setGoodsInstances
(
npcGoodsInstances
);
}
List
<
GoodsInstance
>
goodsInstancesClass
=
goodsClass
.
getGoodsInstances
();
List
<
GoodsInstance
>
goodsInstancesClass
=
goodsClass
.
getGoodsInstances
();
if
(
goodsInstancesClass
==
null
)
{
if
(
goodsInstancesClass
==
null
)
{
goodsInstancesClass
=
new
ArrayList
<
GoodsInstance
>();
goodsInstancesClass
=
new
ArrayList
<
GoodsInstance
>();
}
}
goodsInstancesClass
.
add
(
goodsInstance
);
goodsInstancesClass
.
add
(
goodsInstance
);
goodsClass
.
setGoodsInstances
(
goodsInstancesClass
);
goodsClass
.
setGoodsInstances
(
goodsInstancesClass
);
this
.
goodsInstanceIndex
.
put
((
String
)
instanceAttrMap
.
get
(
"name"
),
goodsInstance
);
this
.
goodsInstanceIndex
.
put
((
String
)
instanceAttrMap
.
get
(
"name"
),
goodsInstance
);
}
}
this
.
goodsClassIndex
.
put
(
classKey
,
goodsClass
);
this
.
goodsClassIndex
.
put
(
classKey
,
goodsClass
);
}
}
}
catch
(
Exception
e
){
}
System
.
out
.
println
(
"处理有误"
);
}
}
}
}
...
@@ -201,24 +210,28 @@ public class GameEnv {
...
@@ -201,24 +210,28 @@ public class GameEnv {
public
List
<
String
>
queryAroundNpcBySite
(
String
site
){
public
List
<
String
>
queryAroundNpcBySite
(
String
site
){
Place
place
=
this
.
placeIndex
.
get
(
site
);
Place
place
=
this
.
placeIndex
.
get
(
site
);
List
<
String
>
queryNpc
=
new
ArrayList
<
String
>();
List
<
String
>
queryNpc
=
new
ArrayList
<
String
>();
if
(
place
!=
null
)
{
List
<
NpcInstance
>
npcInstances
=
place
.
getNpcInstances
();
List
<
NpcInstance
>
npcInstances
=
place
.
getNpcInstances
();
if
(
npcInstances
!=
null
)
{
if
(
npcInstances
!=
null
)
{
for
(
int
i
=
0
;
i
<
npcInstances
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
npcInstances
.
size
();
i
++)
{
queryNpc
.
add
(
npcInstances
.
get
(
i
).
getName
());
queryNpc
.
add
(
npcInstances
.
get
(
i
).
getName
());
}
}
}
}
}
return
queryNpc
;
return
queryNpc
;
}
}
// 周围有什么物品
// 周围有什么物品
public
List
<
String
>
queryAroundGoodsBySite
(
String
site
){
public
List
<
String
>
queryAroundGoodsBySite
(
String
site
){
Place
place
=
this
.
placeIndex
.
get
(
site
);
Place
place
=
this
.
placeIndex
.
get
(
site
);
List
<
String
>
queryGoods
=
new
ArrayList
<
String
>();
List
<
String
>
queryGoods
=
new
ArrayList
<
String
>();
if
(
place
!=
null
)
{
List
<
GoodsInstance
>
goodsInstances
=
place
.
getGoodsInstances
();
List
<
GoodsInstance
>
goodsInstances
=
place
.
getGoodsInstances
();
if
(
goodsInstances
!=
null
)
{
if
(
goodsInstances
!=
null
)
{
for
(
int
i
=
0
;
i
<
goodsInstances
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
goodsInstances
.
size
();
i
++)
{
queryGoods
.
add
(
goodsInstances
.
get
(
i
).
getName
());
queryGoods
.
add
(
goodsInstances
.
get
(
i
).
getName
());
}
}
}
}
}
return
queryGoods
;
return
queryGoods
;
}
}
// 我现在能去哪
// 我现在能去哪
...
@@ -235,14 +248,29 @@ public class GameEnv {
...
@@ -235,14 +248,29 @@ public class GameEnv {
public
List
<
String
>
queryPathBySite
(
String
start
,
String
destination
){
public
List
<
String
>
queryPathBySite
(
String
start
,
String
destination
){
return
null
;
return
null
;
}
}
/******************************************通过npc获取物品列表**********************************************/
// 通过npcName获取所有物品名称列表
public
List
<
String
>
queryGoodsByNpcName
(
String
npcName
){
List
<
String
>
goodsNames
=
new
ArrayList
<
String
>();
if
(
this
.
npcInstanceIndex
.
get
(
npcName
)!=
null
)
{
List
<
GoodsInstance
>
goodsInstances
=
this
.
npcInstanceIndex
.
get
(
npcName
).
getGoodsInstances
();
if
(
goodsInstances
!=
null
)
{
for
(
int
i
=
0
;
i
<
goodsInstances
.
size
();
i
++)
{
goodsNames
.
add
(
goodsInstances
.
get
(
i
).
getName
());
}
}
}
return
goodsNames
;
}
/**************************************物品***************************/
/**************************************物品***************************/
// 通过类和地点查询所有物品名称
// 通过类和地点查询所有物品名称
public
List
<
String
>
queryGoodsByClassAndSite
(
String
className
,
String
site
){
public
List
<
String
>
queryGoodsByClassAndSite
(
String
className
,
String
site
){
List
<
String
>
goodsNames
=
new
ArrayList
<
String
>();
List
<
String
>
goodsNames
=
new
ArrayList
<
String
>();
List
<
GoodsInstance
>
placeGoodsInstances
=
this
.
placeIndex
.
get
(
site
).
getGoodsInstances
();
List
<
GoodsInstance
>
placeGoodsInstances
=
null
;
List
<
GoodsInstance
>
goodsInstances
=
this
.
goodsClassIndex
.
get
(
className
).
getGoodsInstances
();
List
<
GoodsInstance
>
goodsInstances
=
null
;
GoodsInstance
goodsInstance
=
new
GoodsInstance
();
if
(
this
.
placeIndex
.
get
(
site
)!=
null
&&
this
.
goodsClassIndex
.
get
(
className
)!=
null
)
{
placeGoodsInstances
=
this
.
placeIndex
.
get
(
site
).
getGoodsInstances
();
goodsInstances
=
this
.
goodsClassIndex
.
get
(
className
).
getGoodsInstances
();
for
(
int
i
=
0
;
i
<
placeGoodsInstances
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
placeGoodsInstances
.
size
();
i
++)
{
for
(
int
j
=
0
;
j
<
goodsInstances
.
size
();
j
++)
{
for
(
int
j
=
0
;
j
<
goodsInstances
.
size
();
j
++)
{
if
(
placeGoodsInstances
.
get
(
i
)
==
goodsInstances
.
get
(
j
))
{
if
(
placeGoodsInstances
.
get
(
i
)
==
goodsInstances
.
get
(
j
))
{
...
@@ -250,6 +278,7 @@ public class GameEnv {
...
@@ -250,6 +278,7 @@ public class GameEnv {
}
}
}
}
}
}
}
return
goodsNames
;
return
goodsNames
;
}
}
// 查询指定物品
// 查询指定物品
...
@@ -260,7 +289,11 @@ public class GameEnv {
...
@@ -260,7 +289,11 @@ public class GameEnv {
// 查询指定物品的简介
// 查询指定物品的简介
public
String
queryGoodsIntroByGoodsName
(
String
name
){
public
String
queryGoodsIntroByGoodsName
(
String
name
){
GoodsInstance
goodsInstance
=
this
.
queryGoodsByGoodsName
(
name
);
GoodsInstance
goodsInstance
=
this
.
queryGoodsByGoodsName
(
name
);
if
(
goodsInstance
!=
null
)
{
return
goodsInstance
.
getIntro
();
return
goodsInstance
.
getIntro
();
}
else
{
return
null
;
}
}
}
// 查询指定物品的属性值
// 查询指定物品的属性值
public
String
queryGoodsAttrByGoodsName
(
String
name
,
String
attrName
){
public
String
queryGoodsAttrByGoodsName
(
String
name
,
String
attrName
){
...
@@ -269,9 +302,18 @@ public class GameEnv {
...
@@ -269,9 +302,18 @@ public class GameEnv {
goodsInstance
=
queryGoodsByGoodsName
(
attrName
);
goodsInstance
=
queryGoodsByGoodsName
(
attrName
);
attrName
=
name
;
attrName
=
name
;
}
}
if
(
goodsInstance
!=
null
)
{
if
(
goodsInstance
!=
null
)
{
List
<
Attr
>
attrs
=
goodsInstance
.
getAttrs
();
List
<
Attr
>
attrs
=
goodsInstance
.
getAttrs
();
if
(
attrName
.
equals
(
"location"
))
{
if
(
goodsInstance
.
getPlace
()!=
null
)
{
return
goodsInstance
.
getPlace
().
getName
();
}
}
if
(
attrName
.
equals
(
"owner"
))
{
if
(
goodsInstance
.
getNpc
()!=
null
)
{
return
goodsInstance
.
getNpc
().
getName
();
}
}
for
(
int
i
=
0
;
i
<
attrs
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
attrs
.
size
();
i
++)
{
if
(
attrs
.
get
(
i
).
getName
().
equals
(
attrName
))
{
if
(
attrs
.
get
(
i
).
getName
().
equals
(
attrName
))
{
return
attrs
.
get
(
i
).
getValue
();
return
attrs
.
get
(
i
).
getValue
();
...
@@ -312,7 +354,6 @@ public class GameEnv {
...
@@ -312,7 +354,6 @@ public class GameEnv {
}
}
return
npcNames
;
return
npcNames
;
}
}
// 查询指定的npc
// 查询指定的npc
public
NpcInstance
queryNpcByNpcName
(
String
npcName
){
public
NpcInstance
queryNpcByNpcName
(
String
npcName
){
NpcInstance
npcInstance
=
this
.
npcInstanceIndex
.
get
(
npcName
);
NpcInstance
npcInstance
=
this
.
npcInstanceIndex
.
get
(
npcName
);
...
@@ -334,7 +375,11 @@ public class GameEnv {
...
@@ -334,7 +375,11 @@ public class GameEnv {
npcInstance
=
queryNpcByNpcName
(
attrName
);
npcInstance
=
queryNpcByNpcName
(
attrName
);
attrName
=
name
;
attrName
=
name
;
}
}
if
(
attrName
.
equals
(
"location"
))
{
if
(
npcInstance
.
getPlace
()!=
null
)
{
return
npcInstance
.
getPlace
().
getName
();
}
}
if
(
npcInstance
!=
null
)
{
if
(
npcInstance
!=
null
)
{
List
<
Attr
>
attrs
=
npcInstance
.
getAttrs
();
List
<
Attr
>
attrs
=
npcInstance
.
getAttrs
();
for
(
int
i
=
0
;
i
<
attrs
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
attrs
.
size
();
i
++)
{
...
...
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