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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
208 additions
and
163 deletions
+208
-163
GameEnv.java
src/GameEnvironment/GameEnv.java
+208
-163
No files found.
src/GameEnvironment/GameEnv.java
View file @
f8d00711
...
...
@@ -13,179 +13,188 @@ import GameEnvironment.bean.SuperClass;
import
GameEnvironment.bean.NpcInstance
;
import
GameEnvironment.bean.Place
;
public
class
GameEnv
{
public
Map
<
String
,
SuperClass
>
npcClassIndex
=
null
;
public
Map
<
String
,
NpcInstance
>
npcInstanceIndex
=
null
;
public
Map
<
String
,
SuperClass
>
goodsClassIndex
=
null
;
public
Map
<
String
,
GoodsInstance
>
goodsInstanceIndex
=
null
;
public
Map
<
String
,
Place
>
placeIndex
=
null
;
public
class
GameEnv
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
public
Map
<
String
,
SuperClass
>
npcClassIndex
;
public
Map
<
String
,
NpcInstance
>
npcInstanceIndex
;
public
Map
<
String
,
SuperClass
>
goodsClassIndex
;
public
Map
<
String
,
GoodsInstance
>
goodsInstanceIndex
;
public
Map
<
String
,
Place
>
placeIndex
;
public
GameEnv
(
String
botName
)
throws
Exception
{
// 通过文件来初始化游戏环境
// String fullName = "E:\\projects\\env\\"+projectId+".json";
//
// String jsonString = Util.getJsonString(fullName);
// String fullName = "test.json";
try
{
String
jsonString
=
""
;
//DBUtil.queryEnvJsonByBotName(botName);
Map
<
String
,
Object
>
gameProjectMap
=
JSON
.
parseObject
(
jsonString
);
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
gameProjectMap
.
get
(
"map"
);
// String jsonString = Util.getJsonString(fullName);
// System.out.println(jsonString);
String
jsonString
=
DBUtil
.
queryEnvJsonByBotName
(
botName
);
Map
<
String
,
Object
>
gameProjectMap
=
JSON
.
parseObject
(
jsonString
);
// System.out.println(gameProjectMap);
if
(!
gameProjectMap
.
isEmpty
())
{
// 地图
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
gameProjectMap
.
get
(
"map"
);
this
.
placeIndex
=
new
HashMap
<
String
,
Place
>();
Map
<
String
,
Object
>
placeMapTmp
=
new
HashMap
();
for
(
String
key
:
map
.
keySet
())
{
Map
<
String
,
Object
>
one
=
(
Map
<
String
,
Object
>)
map
.
get
(
key
);
placeMapTmp
.
put
(
key
,
(
String
)
one
.
get
(
"name"
));
Place
place
=
new
Place
();
place
.
setIntro
((
String
)
one
.
get
(
"intro"
));
place
.
setName
((
String
)
one
.
get
(
"name"
));
placeIndex
.
put
((
String
)
one
.
get
(
"name"
),
place
);
}
for
(
String
tmp
:
placeMapTmp
.
keySet
())
{
List
<
Place
>
ableGos
=
new
ArrayList
<
Place
>();
List
<
Long
>
ableGoLongs
=
(
List
<
Long
>)
((
Map
<
String
,
Object
>)
map
.
get
(
tmp
)).
get
(
"canGo"
);
for
(
int
j
=
0
;
j
<
ableGoLongs
.
size
();
j
++)
{
String
idName
=
String
.
valueOf
(
ableGoLongs
.
get
(
j
));
ableGos
.
add
(
placeIndex
.
get
(
placeMapTmp
.
get
(
idName
)));
if
(!
map
.
isEmpty
())
{
for
(
String
key:
map
.
keySet
())
{
Map
<
String
,
Object
>
one
=
(
Map
<
String
,
Object
>)
map
.
get
(
key
);
placeMapTmp
.
put
(
key
,
(
String
)
one
.
get
(
"name"
));
Place
place
=
new
Place
();
place
.
setIntro
((
String
)
one
.
get
(
"intro"
));
place
.
setName
((
String
)
one
.
get
(
"name"
));
placeIndex
.
put
((
String
)
one
.
get
(
"name"
),
place
);
}
for
(
String
tmp:
placeMapTmp
.
keySet
())
{
List
<
Place
>
ableGos
=
new
ArrayList
<
Place
>();
List
<
Long
>
ableGoLongs
=
(
List
<
Long
>)((
Map
<
String
,
Object
>)
map
.
get
(
tmp
)).
get
(
"canGo"
);
for
(
int
j
=
0
;
j
<
ableGoLongs
.
size
();
j
++)
{
String
idName
=
String
.
valueOf
(
ableGoLongs
.
get
(
j
));
ableGos
.
add
(
placeIndex
.
get
(
placeMapTmp
.
get
(
idName
)));
}
placeIndex
.
get
(
placeMapTmp
.
get
(
tmp
)).
setAbleGo
(
ableGos
);
}
placeIndex
.
get
(
placeMapTmp
.
get
(
tmp
)).
setAbleGo
(
ableGos
);
}
// npc
// 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
>();
this
.
npcClassIndex
=
new
HashMap
<
String
,
SuperClass
>();
this
.
npcInstanceIndex
=
new
HashMap
<
String
,
NpcInstance
>();
for
(
String
classKey
:
npcClasses
.
keySet
())
{
Map
<
String
,
Object
>
one
=
(
Map
<
String
,
Object
>)
npcClasses
.
get
(
classKey
);
// class
Map
<
String
,
Object
>
oneClass
=
(
Map
<
String
,
Object
>)
one
.
get
(
"class"
);
SuperClass
npcClass
=
new
SuperClass
();
npcClass
.
setName
(
classKey
);
npcClass
.
setIntro
((
String
)
oneClass
.
get
(
"intro"
));
if
(!
npcClasses
.
isEmpty
())
{
for
(
String
classKey:
npcClasses
.
keySet
())
{
Map
<
String
,
Object
>
one
=
(
Map
<
String
,
Object
>)
npcClasses
.
get
(
classKey
);
// class
Map
<
String
,
Object
>
oneClass
=
(
Map
<
String
,
Object
>)
one
.
get
(
"class"
);
SuperClass
npcClass
=
new
SuperClass
();
npcClass
.
setName
(
classKey
);
npcClass
.
setIntro
((
String
)
oneClass
.
get
(
"intro"
));
List
<
Attr
>
attrs
=
new
ArrayList
<
Attr
>();
for
(
String
attrKey
:
oneClass
.
keySet
())
{
if
(
attrKey
!=
"intro"
)
{
Attr
attr
=
new
Attr
();
attr
.
setName
(
attrKey
);
attr
.
setValue
((
String
)
oneClass
.
get
(
attrKey
));
attrs
.
add
(
attr
);
}
}
npcClass
.
setAttrs
(
attrs
);
// instance
Map
<
String
,
Object
>
instances
=
(
Map
<
String
,
Object
>)
one
.
get
(
"instance"
);
for
(
String
instanceKey
:
instances
.
keySet
())
{
Map
<
String
,
Object
>
instance
=
new
HashMap
<
String
,
Object
>();
NpcInstance
npcInstance
=
new
NpcInstance
();
Map
<
String
,
Object
>
instanceAttrMap
=
(
Map
<
String
,
Object
>)
instances
.
get
(
instanceKey
);
npcNames
.
put
(
instanceKey
,
(
String
)
instanceAttrMap
.
get
(
"name"
));
npcInstance
.
setName
((
String
)
instanceAttrMap
.
get
(
"name"
));
npcInstance
.
setIntro
((
String
)
instanceAttrMap
.
get
(
"intro"
));
List
<
Attr
>
npcInstanceAttrs
=
new
ArrayList
<
Attr
>();
for
(
String
instanceAttrKey
:
instanceAttrMap
.
keySet
())
{
if
(
instanceAttrKey
!=
"name"
&&
instanceAttrKey
!=
"intro"
&&
instanceAttrKey
!=
"placeId"
)
{
List
<
Attr
>
attrs
=
new
ArrayList
<
Attr
>();
for
(
String
attrKey:
oneClass
.
keySet
())
{
if
(!
attrKey
.
equals
(
"intro"
)
&&
!
attrKey
.
equals
(
"class"
)
&&
!
attrKey
.
equals
(
""
))
{
Attr
attr
=
new
Attr
();
attr
.
setName
(
instanceA
ttrKey
);
attr
.
setValue
((
String
)
instanceAttrMap
.
get
(
instanceA
ttrKey
));
npcInstanceA
ttrs
.
add
(
attr
);
attr
.
setName
(
a
ttrKey
);
attr
.
setValue
((
String
)
oneClass
.
get
(
a
ttrKey
));
a
ttrs
.
add
(
attr
);
}
}
npcInstance
.
setAttrs
(
npcInstanceAttrs
);
Place
place
=
placeIndex
.
get
(((
Map
<
String
,
Object
>)
map
.
get
(
String
.
valueOf
(
instanceAttrMap
.
get
(
"placeId"
)))).
get
(
"name"
));
List
<
NpcInstance
>
npcInstances
=
place
.
getNpcInstances
();
if
(
npcInstances
==
null
)
{
npcInstances
=
new
ArrayList
<
NpcInstance
>();
}
npcInstances
.
add
(
npcInstance
);
place
.
setNpcInstances
(
npcInstances
);
List
<
NpcInstance
>
npcInstanceClass
=
npcClass
.
getNpcInstances
();
if
(
npcInstanceClass
==
null
)
{
npcInstanceClass
=
new
ArrayList
<
NpcInstance
>();
npcClass
.
setAttrs
(
attrs
);
// instance
Map
<
String
,
Object
>
instances
=
(
Map
<
String
,
Object
>)
one
.
get
(
"instance"
);
for
(
String
instanceKey:
instances
.
keySet
())
{
Map
<
String
,
Object
>
instance
=
new
HashMap
<
String
,
Object
>();
NpcInstance
npcInstance
=
new
NpcInstance
();
Map
<
String
,
Object
>
instanceAttrMap
=
(
Map
<
String
,
Object
>)
instances
.
get
(
instanceKey
);
npcNames
.
put
(
instanceKey
,
(
String
)
instanceAttrMap
.
get
(
"name"
));
npcInstance
.
setName
((
String
)
instanceAttrMap
.
get
(
"name"
));
npcInstance
.
setIntro
((
String
)
instanceAttrMap
.
get
(
"intro"
));
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"
))
{
Attr
attr
=
new
Attr
();
attr
.
setName
(
instanceAttrKey
);
attr
.
setValue
((
String
)
instanceAttrMap
.
get
(
instanceAttrKey
));
npcInstanceAttrs
.
add
(
attr
);
}
}
npcInstance
.
setAttrs
(
npcInstanceAttrs
);
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
();
if
(
npcInstances
==
null
)
{
npcInstances
=
new
ArrayList
<
NpcInstance
>();
}
npcInstances
.
add
(
npcInstance
);
place
.
setNpcInstances
(
npcInstances
);
}
List
<
NpcInstance
>
npcInstanceClass
=
npcClass
.
getNpcInstances
();
if
(
npcInstanceClass
==
null
)
{
npcInstanceClass
=
new
ArrayList
<
NpcInstance
>();
}
npcInstanceClass
.
add
(
npcInstance
);
npcClass
.
setNpcInstances
(
npcInstanceClass
);
npcInstance
.
setPlace
(
place
);
this
.
npcInstanceIndex
.
put
((
String
)
instanceAttrMap
.
get
(
"name"
),
npcInstance
);
}
npcInstanceClass
.
add
(
npcInstance
);
npcClass
.
setNpcInstances
(
npcInstanceClass
);
npcInstance
.
setPlace
(
place
);
this
.
npcInstanceIndex
.
put
((
String
)
instanceAttrMap
.
get
(
"name"
),
npcInstance
);
this
.
npcClassIndex
.
put
(
classKey
,
npcClass
);
}
this
.
npcClassIndex
.
put
(
classKey
,
npcClass
);
}
// 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
.
goodsInstanceIndex
=
new
HashMap
<
String
,
GoodsInstance
>();
for
(
String
classKey
:
goodsClasses
.
keySet
())
{
Map
<
String
,
Object
>
one
=
(
Map
<
String
,
Object
>)
goodsClasses
.
get
(
classKey
);
// class
Map
<
String
,
Object
>
oneClass
=
(
Map
<
String
,
Object
>)
one
.
get
(
"class"
);
SuperClass
goodsClass
=
new
SuperClass
();
goodsClass
.
setName
(
classKey
);
goodsClass
.
setIntro
((
String
)
oneClass
.
get
(
"intro"
));
if
(!
goodsClasses
.
isEmpty
())
{
for
(
String
classKey:
goodsClasses
.
keySet
())
{
Map
<
String
,
Object
>
one
=
(
Map
<
String
,
Object
>)
goodsClasses
.
get
(
classKey
);
// class
Map
<
String
,
Object
>
oneClass
=
(
Map
<
String
,
Object
>)
one
.
get
(
"class"
);
SuperClass
goodsClass
=
new
SuperClass
();
goodsClass
.
setName
(
classKey
);
goodsClass
.
setIntro
((
String
)
oneClass
.
get
(
"intro"
));
List
<
Attr
>
attrs
=
new
ArrayList
<
Attr
>();
for
(
String
attrKey
:
oneClass
.
keySet
())
{
if
(
attrKey
!=
"intro"
)
{
Attr
attr
=
new
Attr
();
attr
.
setName
(
attrKey
);
attr
.
setValue
((
String
)
oneClass
.
get
(
attrKey
));
attrs
.
add
(
attr
);
List
<
Attr
>
attrs
=
new
ArrayList
<
Attr
>();
for
(
String
attrKey:
oneClass
.
keySet
())
{
if
(!
attrKey
.
equals
(
"intro"
)&&!
attrKey
.
equals
(
"placeId"
)&&!
attrKey
.
equals
(
"npcName"
)&&!
attrKey
.
equals
(
"class"
)&&!
attrKey
.
equals
(
"placeName"
))
{
Attr
attr
=
new
Attr
();
attr
.
setName
(
attrKey
);
attr
.
setValue
((
String
)
oneClass
.
get
(
attrKey
));
attrs
.
add
(
attr
);
}
}
}
goodsClass
.
setAttrs
(
attrs
);
goodsClass
.
setAttrs
(
attrs
);
// instance
Map
<
String
,
Object
>
instances
=
(
Map
<
String
,
Object
>)
one
.
get
(
"instance"
);
// instance
Map
<
String
,
Object
>
instances
=
(
Map
<
String
,
Object
>)
one
.
get
(
"instance"
);
for
(
String
instanceKey
:
instances
.
keySet
())
{
Map
<
String
,
Object
>
instance
=
new
HashMap
<
String
,
Object
>();
GoodsInstance
goodsInstance
=
new
GoodsInstance
();
Map
<
String
,
Object
>
instanceAttrMap
=
(
Map
<
String
,
Object
>)
instances
.
get
(
instanceKey
);
goodsInstance
.
setName
((
String
)
instanceAttrMap
.
get
(
"name"
));
goodsInstance
.
setIntro
((
String
)
instanceAttrMap
.
get
(
"intro"
));
List
<
Attr
>
goodsInstanceAttrs
=
new
ArrayList
<
Attr
>();
for
(
String
instanceAttrKey
:
instanceAttrMap
.
keySet
())
{
if
(
instanceAttrKey
!=
"placeId"
&&
instanceAttrKey
!=
"npcId"
&&
instanceAttrKey
!=
"name"
&&
instanceAttrKey
!=
"intro"
)
{
Attr
attr
=
new
Attr
();
attr
.
setName
(
instanceAttrKey
);
attr
.
setValue
((
String
)
instanceAttrMap
.
get
(
instanceAttrKey
));
goodsInstanceAttrs
.
add
(
attr
);
for
(
String
instanceKey:
instances
.
keySet
())
{
Map
<
String
,
Object
>
instance
=
new
HashMap
<
String
,
Object
>();
GoodsInstance
goodsInstance
=
new
GoodsInstance
();
Map
<
String
,
Object
>
instanceAttrMap
=
(
Map
<
String
,
Object
>)
instances
.
get
(
instanceKey
);
goodsInstance
.
setName
((
String
)
instanceAttrMap
.
get
(
"name"
));
goodsInstance
.
setIntro
((
String
)
instanceAttrMap
.
get
(
"intro"
));
List
<
Attr
>
goodsInstanceAttrs
=
new
ArrayList
<
Attr
>();
for
(
String
instanceAttrKey:
instanceAttrMap
.
keySet
())
{
if
(
instanceAttrKey
!=
"placeId"
&&
instanceAttrKey
!=
"npcId"
&&
instanceAttrKey
!=
"name"
&&
instanceAttrKey
!=
"intro"
)
{
Attr
attr
=
new
Attr
();
attr
.
setName
(
instanceAttrKey
);
attr
.
setValue
((
String
)
instanceAttrMap
.
get
(
instanceAttrKey
));
goodsInstanceAttrs
.
add
(
attr
);
}
}
goodsInstance
.
setAttrs
(
goodsInstanceAttrs
);
if
(
instanceAttrMap
.
get
(
"placeId"
)!=
null
)
{
Place
place
=
placeIndex
.
get
(((
Map
<
String
,
Object
>)
map
.
get
(
String
.
valueOf
(
instanceAttrMap
.
get
(
"placeId"
)))).
get
(
"name"
));
goodsInstance
.
setPlace
(
place
);
List
<
GoodsInstance
>
placeGoodsInstances
=
place
.
getGoodsInstances
();
if
(
placeGoodsInstances
==
null
)
{
placeGoodsInstances
=
new
ArrayList
<
GoodsInstance
>();
}
placeGoodsInstances
.
add
(
goodsInstance
);
place
.
setGoodsInstances
(
placeGoodsInstances
);
}
if
(
instanceAttrMap
.
get
(
"npcId"
)!=
null
){
NpcInstance
npc
=
this
.
npcInstanceIndex
.
get
(
npcNames
.
get
(
String
.
valueOf
(
instanceAttrMap
.
get
(
"npcId"
))));
goodsInstance
.
setNpc
(
npc
);
List
<
GoodsInstance
>
npcGoodsInstances
=
npc
.
getGoodsInstances
();
if
(
npcGoodsInstances
==
null
)
{
npcGoodsInstances
=
new
ArrayList
<
GoodsInstance
>();
}
npcGoodsInstances
.
add
(
goodsInstance
);
npc
.
setGoodsInstances
(
npcGoodsInstances
);
}
}
goodsInstance
.
setAttrs
(
goodsInstanceAttrs
);
Place
place
=
placeIndex
.
get
(((
Map
<
String
,
Object
>)
map
.
get
(
String
.
valueOf
(
instanceAttrMap
.
get
(
"placeId"
)))).
get
(
"name"
));
goodsInstance
.
setPlace
(
place
);
List
<
GoodsInstance
>
placeGoodsInstances
=
place
.
getGoodsInstances
();
if
(
placeGoodsInstances
==
null
)
{
placeGoodsInstances
=
new
ArrayList
<
GoodsInstance
>();
}
placeGoodsInstances
.
add
(
goodsInstance
);
place
.
setGoodsInstances
(
placeGoodsInstances
);
NpcInstance
npc
=
this
.
npcInstanceIndex
.
get
(
npcNames
.
get
(
String
.
valueOf
(
instanceAttrMap
.
get
(
"npcId"
))));
goodsInstance
.
setNpc
(
npc
);
List
<
GoodsInstance
>
npcGoodsInstances
=
npc
.
getGoodsInstances
();
if
(
npcGoodsInstances
==
null
)
{
npcGoodsInstances
=
new
ArrayList
<
GoodsInstance
>();
}
npcGoodsInstances
.
add
(
goodsInstance
);
npc
.
setGoodsInstances
(
npcGoodsInstances
);
List
<
GoodsInstance
>
goodsInstancesClass
=
goodsClass
.
getGoodsInstances
();
if
(
goodsInstancesClass
==
null
)
{
goodsInstancesClass
=
new
ArrayList
<
GoodsInstance
>();
List
<
GoodsInstance
>
goodsInstancesClass
=
goodsClass
.
getGoodsInstances
();
if
(
goodsInstancesClass
==
null
)
{
goodsInstancesClass
=
new
ArrayList
<
GoodsInstance
>();
}
goodsInstancesClass
.
add
(
goodsInstance
);
goodsClass
.
setGoodsInstances
(
goodsInstancesClass
);
this
.
goodsInstanceIndex
.
put
((
String
)
instanceAttrMap
.
get
(
"name"
),
goodsInstance
);
}
goodsInstancesClass
.
add
(
goodsInstance
);
goodsClass
.
setGoodsInstances
(
goodsInstancesClass
);
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,10 +210,12 @@ public class GameEnv {
public
List
<
String
>
queryAroundNpcBySite
(
String
site
){
Place
place
=
this
.
placeIndex
.
get
(
site
);
List
<
String
>
queryNpc
=
new
ArrayList
<
String
>();
List
<
NpcInstance
>
npcInstances
=
place
.
getNpcInstances
();
if
(
npcInstances
!=
null
)
{
for
(
int
i
=
0
;
i
<
npcInstances
.
size
();
i
++)
{
queryNpc
.
add
(
npcInstances
.
get
(
i
).
getName
());
if
(
place
!=
null
)
{
List
<
NpcInstance
>
npcInstances
=
place
.
getNpcInstances
();
if
(
npcInstances
!=
null
)
{
for
(
int
i
=
0
;
i
<
npcInstances
.
size
();
i
++)
{
queryNpc
.
add
(
npcInstances
.
get
(
i
).
getName
());
}
}
}
return
queryNpc
;
...
...
@@ -213,10 +224,12 @@ public class GameEnv {
public
List
<
String
>
queryAroundGoodsBySite
(
String
site
){
Place
place
=
this
.
placeIndex
.
get
(
site
);
List
<
String
>
queryGoods
=
new
ArrayList
<
String
>();
List
<
GoodsInstance
>
goodsInstances
=
place
.
getGoodsInstances
();
if
(
goodsInstances
!=
null
)
{
for
(
int
i
=
0
;
i
<
goodsInstances
.
size
();
i
++)
{
queryGoods
.
add
(
goodsInstances
.
get
(
i
).
getName
());
if
(
place
!=
null
)
{
List
<
GoodsInstance
>
goodsInstances
=
place
.
getGoodsInstances
();
if
(
goodsInstances
!=
null
)
{
for
(
int
i
=
0
;
i
<
goodsInstances
.
size
();
i
++)
{
queryGoods
.
add
(
goodsInstances
.
get
(
i
).
getName
());
}
}
}
return
queryGoods
;
...
...
@@ -235,18 +248,34 @@ public class GameEnv {
public
List
<
String
>
queryPathBySite
(
String
start
,
String
destination
){
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
){
List
<
String
>
goodsNames
=
new
ArrayList
<
String
>();
List
<
GoodsInstance
>
placeGoodsInstances
=
this
.
placeIndex
.
get
(
site
).
getGoodsInstances
();
List
<
GoodsInstance
>
goodsInstances
=
this
.
goodsClassIndex
.
get
(
className
).
getGoodsInstances
();
GoodsInstance
goodsInstance
=
new
GoodsInstance
();
for
(
int
i
=
0
;
i
<
placeGoodsInstances
.
size
();
i
++)
{
for
(
int
j
=
0
;
j
<
goodsInstances
.
size
();
j
++)
{
if
(
placeGoodsInstances
.
get
(
i
)
==
goodsInstances
.
get
(
j
))
{
goodsNames
.
add
(
placeGoodsInstances
.
get
(
i
).
getName
());
List
<
GoodsInstance
>
placeGoodsInstances
=
null
;
List
<
GoodsInstance
>
goodsInstances
=
null
;
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
j
=
0
;
j
<
goodsInstances
.
size
();
j
++)
{
if
(
placeGoodsInstances
.
get
(
i
)
==
goodsInstances
.
get
(
j
))
{
goodsNames
.
add
(
placeGoodsInstances
.
get
(
i
).
getName
());
}
}
}
}
...
...
@@ -260,7 +289,11 @@ public class GameEnv {
// 查询指定物品的简介
public
String
queryGoodsIntroByGoodsName
(
String
name
){
GoodsInstance
goodsInstance
=
this
.
queryGoodsByGoodsName
(
name
);
return
goodsInstance
.
getIntro
();
if
(
goodsInstance
!=
null
)
{
return
goodsInstance
.
getIntro
();
}
else
{
return
null
;
}
}
// 查询指定物品的属性值
public
String
queryGoodsAttrByGoodsName
(
String
name
,
String
attrName
){
...
...
@@ -269,9 +302,18 @@ public class GameEnv {
goodsInstance
=
queryGoodsByGoodsName
(
attrName
);
attrName
=
name
;
}
if
(
goodsInstance
!=
null
)
{
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
++)
{
if
(
attrs
.
get
(
i
).
getName
().
equals
(
attrName
))
{
return
attrs
.
get
(
i
).
getValue
();
...
...
@@ -284,7 +326,7 @@ public class GameEnv {
}
// 查询指定物品的所有属性
public
List
<
String
>
queryGoodsAllAttrByGoodsName
(
String
name
){
List
<
String
>
attrnames
=
new
ArrayList
<
String
>();
List
<
String
>
attrnames
=
new
ArrayList
<
String
>();
GoodsInstance
goodsInstance
=
queryGoodsByGoodsName
(
name
);
if
(
goodsInstance
!=
null
)
{
List
<
Attr
>
attrs
=
goodsInstance
.
getAttrs
();
...
...
@@ -312,7 +354,6 @@ public class GameEnv {
}
return
npcNames
;
}
// 查询指定的npc
public
NpcInstance
queryNpcByNpcName
(
String
npcName
){
NpcInstance
npcInstance
=
this
.
npcInstanceIndex
.
get
(
npcName
);
...
...
@@ -334,7 +375,11 @@ public class GameEnv {
npcInstance
=
queryNpcByNpcName
(
attrName
);
attrName
=
name
;
}
if
(
attrName
.
equals
(
"location"
))
{
if
(
npcInstance
.
getPlace
()!=
null
)
{
return
npcInstance
.
getPlace
().
getName
();
}
}
if
(
npcInstance
!=
null
)
{
List
<
Attr
>
attrs
=
npcInstance
.
getAttrs
();
for
(
int
i
=
0
;
i
<
attrs
.
size
();
i
++)
{
...
...
@@ -465,5 +510,5 @@ public class GameEnv {
}
else
{
return
false
;
}
}
}
}
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