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
398088a6
Commit
398088a6
authored
Nov 28, 2018
by
hxw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
删除无用文件夹
parent
eaf78424
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
0 additions
and
816 deletions
+0
-816
DBUtil.java
src/GameEnvironment/GameEnvironment/DBUtil.java
+0
-40
GameEnv.java
src/GameEnvironment/GameEnvironment/GameEnv.java
+0
-515
Util.java
src/GameEnvironment/GameEnvironment/Util.java
+0
-51
Attr.java
src/GameEnvironment/GameEnvironment/bean/Attr.java
+0
-26
GoodsInstance.java
src/GameEnvironment/GameEnvironment/bean/GoodsInstance.java
+0
-35
NpcInstance.java
src/GameEnvironment/GameEnvironment/bean/NpcInstance.java
+0
-35
Place.java
src/GameEnvironment/GameEnvironment/bean/Place.java
+0
-61
SuperClass.java
src/GameEnvironment/GameEnvironment/bean/SuperClass.java
+0
-53
No files found.
src/GameEnvironment/GameEnvironment/DBUtil.java
deleted
100644 → 0
View file @
eaf78424
package
com
.
qiwu
.
chatbotbackend
.
GameEnvironment
.
GameEnvironment
;
import
com.qiwu.chatbotbackend.db.C3p0Utils
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
public
class
DBUtil
{
public
static
String
queryEnvJsonByBotName
(
String
botName
)
throws
Exception
{
Connection
conn
=
C3p0Utils
.
getConnection
();
String
sql
=
"select * from generate_json_tb where bot_name = ?"
;
String
result
=
"{}"
;
try
{
PreparedStatement
ps
=
conn
.
prepareStatement
(
sql
);
ps
.
setString
(
1
,
String
.
valueOf
(
botName
));
ResultSet
rs
=
ps
.
executeQuery
();
if
(
rs
.
next
())
result
=
rs
.
getString
(
"env_json_text"
);
ps
.
close
();
rs
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
if
(
conn
!=
null
)
{
try
{
conn
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
return
result
;
}
}
src/GameEnvironment/GameEnvironment/GameEnv.java
deleted
100644 → 0
View file @
eaf78424
package
com
.
qiwu
.
chatbotbackend
.
GameEnvironment
.
GameEnvironment
;
import
java.io.Serializable
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
com.alibaba.fastjson.JSON
;
import
com.qiwu.chatbotbackend.GameEnvironment.bean.Attr
;
import
com.qiwu.chatbotbackend.GameEnvironment.bean.GoodsInstance
;
import
com.qiwu.chatbotbackend.GameEnvironment.bean.SuperClass
;
import
com.qiwu.chatbotbackend.GameEnvironment.bean.NpcInstance
;
import
com.qiwu.chatbotbackend.GameEnvironment.bean.Place
;
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 = "test.json";
// 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
();
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
);
}
}
// npc
// npc class
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
>();
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
.
equals
(
"intro"
)
&&
!
attrKey
.
equals
(
"class"
)
&&
!
attrKey
.
equals
(
""
))
{
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
.
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
);
}
this
.
npcClassIndex
.
put
(
classKey
,
npcClass
);
}
}
// goods
Map
<
String
,
Object
>
goodsClasses
=
(
Map
<
String
,
Object
>)
gameProjectMap
.
get
(
"goods"
);
this
.
goodsClassIndex
=
new
HashMap
<
String
,
SuperClass
>();
this
.
goodsInstanceIndex
=
new
HashMap
<
String
,
GoodsInstance
>();
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
.
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
);
// 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
);
}
}
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
);
}
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
);
}
this
.
goodsClassIndex
.
put
(
classKey
,
goodsClass
);
}
}
}
}
/********************************************地点******************************************/
// 周围有什么
public
List
<
String
>
queryAroundAllBySite
(
String
site
){
List
<
String
>
queryGoods
=
this
.
queryAroundGoodsBySite
(
site
);
List
<
String
>
queryNpc
=
this
.
queryAroundNpcBySite
(
site
);
queryGoods
.
addAll
(
queryNpc
);
return
queryGoods
;
}
// 周围有什么人
public
List
<
String
>
queryAroundNpcBySite
(
String
site
){
Place
place
=
this
.
placeIndex
.
get
(
site
);
List
<
String
>
queryNpc
=
new
ArrayList
<
String
>();
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
;
}
// 周围有什么物品
public
List
<
String
>
queryAroundGoodsBySite
(
String
site
){
Place
place
=
this
.
placeIndex
.
get
(
site
);
List
<
String
>
queryGoods
=
new
ArrayList
<
String
>();
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
;
}
// 我现在能去哪
public
List
<
String
>
queryCanGoBySite
(
String
site
){
List
<
String
>
ableGoString
=
new
ArrayList
<
String
>();
Place
place
=
this
.
placeIndex
.
get
(
site
);
List
<
Place
>
ableGos
=
place
.
getAbleGo
();
for
(
int
i
=
0
;
i
<
ableGos
.
size
();
i
++)
{
ableGoString
.
add
(
ableGos
.
get
(
i
).
getName
());
}
return
ableGoString
;
}
// 两点之间的路径
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
=
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
());
}
}
}
}
return
goodsNames
;
}
// 查询指定物品
public
GoodsInstance
queryGoodsByGoodsName
(
String
name
){
GoodsInstance
goodsInstance
=
this
.
goodsInstanceIndex
.
get
(
name
);
return
goodsInstance
;
}
// 查询指定物品的简介
public
String
queryGoodsIntroByGoodsName
(
String
name
){
GoodsInstance
goodsInstance
=
this
.
queryGoodsByGoodsName
(
name
);
if
(
goodsInstance
!=
null
)
{
return
goodsInstance
.
getIntro
();
}
else
{
return
null
;
}
}
// 查询指定物品的属性值
public
String
queryGoodsAttrByGoodsName
(
String
name
,
String
attrName
){
GoodsInstance
goodsInstance
=
queryGoodsByGoodsName
(
name
);
if
(
goodsInstance
==
null
)
{
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
();
}
}
return
null
;
}
else
{
return
null
;
}
}
// 查询指定物品的所有属性
public
List
<
String
>
queryGoodsAllAttrByGoodsName
(
String
name
){
List
<
String
>
attrnames
=
new
ArrayList
<
String
>();
GoodsInstance
goodsInstance
=
queryGoodsByGoodsName
(
name
);
if
(
goodsInstance
!=
null
)
{
List
<
Attr
>
attrs
=
goodsInstance
.
getAttrs
();
for
(
int
i
=
0
;
i
<
attrs
.
size
();
i
++)
{
attrnames
.
add
(
attrs
.
get
(
i
).
getName
());
}
return
attrnames
;
}
else
{
return
null
;
}
}
/**************************************npc*****************************************/
// 通过地点和类查询所有的npc名陈
public
List
<
String
>
queryNpcByClassAndSite
(
String
className
,
String
site
){
List
<
String
>
npcNames
=
new
ArrayList
<
String
>();
List
<
NpcInstance
>
placeNpcInstances
=
this
.
placeIndex
.
get
(
site
).
getNpcInstances
();
List
<
NpcInstance
>
npcInstances
=
this
.
goodsClassIndex
.
get
(
className
).
getNpcInstances
();
NpcInstance
npcInstance
=
new
NpcInstance
();
for
(
int
i
=
0
;
i
<
placeNpcInstances
.
size
();
i
++)
{
for
(
int
j
=
0
;
j
<
npcInstances
.
size
();
j
++)
{
if
(
placeNpcInstances
.
get
(
i
)
==
npcInstances
.
get
(
j
))
{
npcNames
.
add
(
placeNpcInstances
.
get
(
i
).
getName
());
}
}
}
return
npcNames
;
}
// 查询指定的npc
public
NpcInstance
queryNpcByNpcName
(
String
npcName
){
NpcInstance
npcInstance
=
this
.
npcInstanceIndex
.
get
(
npcName
);
return
npcInstance
;
}
// 查询指定NPC简介
public
String
queryNpcIntroByNpcName
(
String
name
){
NpcInstance
npcInstance
=
queryNpcByNpcName
(
name
);
if
(
npcInstance
!=
null
)
{
return
npcInstance
.
getIntro
();
}
else
{
return
null
;
}
}
// 查询指定npc的属性值
public
String
queryNpcAttrByNpcName
(
String
name
,
String
attrName
){
NpcInstance
npcInstance
=
queryNpcByNpcName
(
name
);
if
(
npcInstance
==
null
)
{
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
++)
{
if
(
attrs
.
get
(
i
).
getName
().
equals
(
attrName
))
{
return
attrs
.
get
(
i
).
getValue
();
}
}
return
null
;
}
else
{
return
null
;
}
}
// 查询指定npc的所有属性
public
List
<
String
>
queryNpcAttrsByNpcName
(
String
name
){
List
<
String
>
attrNames
=
new
ArrayList
<
String
>();
NpcInstance
npcInstance
=
queryNpcByNpcName
(
name
);
if
(
npcInstance
!=
null
)
{
List
<
Attr
>
attrs
=
npcInstance
.
getAttrs
();
for
(
int
i
=
0
;
i
<
attrs
.
size
();
i
++)
{
attrNames
.
add
(
attrs
.
get
(
i
).
getName
());
}
return
attrNames
;
}
else
{
return
null
;
}
}
// 增加
public
boolean
insert
(
String
name
){
String
[]
names
=
name
.
split
(
"_"
);
if
(
names
.
length
==
3
){
if
(
names
[
0
].
equals
(
"goods"
)){
SuperClass
goodsClass
=
this
.
goodsClassIndex
.
get
(
names
[
1
]);
List
<
Attr
>
goodsClassAttrs
=
goodsClass
.
getAttrs
();
GoodsInstance
goodsInstance
=
new
GoodsInstance
();
List
<
Attr
>
goodsInstanceAttr
=
new
ArrayList
<
Attr
>();
goodsInstance
.
setName
(
names
[
2
]);
goodsInstance
.
setIntro
(
goodsClass
.
getIntro
());
for
(
int
i
=
0
;
i
<
goodsClassAttrs
.
size
();
i
++){
Attr
attr
=
new
Attr
();
attr
.
setName
(
goodsClassAttrs
.
get
(
i
).
getName
());
attr
.
setValue
(
goodsClassAttrs
.
get
(
i
).
getValue
());
goodsInstanceAttr
.
add
(
attr
);
}
goodsInstance
.
setAttrs
(
goodsInstanceAttr
);
this
.
goodsInstanceIndex
.
put
(
names
[
2
],
goodsInstance
);
return
true
;
}
else
if
(
names
[
0
].
equals
(
"npc"
))
{
SuperClass
npcClass
=
this
.
npcClassIndex
.
get
(
names
[
1
]);
List
<
Attr
>
npcClassAttrs
=
npcClass
.
getAttrs
();
NpcInstance
npcInstance
=
new
NpcInstance
();
List
<
Attr
>
npcInstanceAttr
=
new
ArrayList
<
Attr
>();
npcInstance
.
setName
(
names
[
2
]);
npcInstance
.
setIntro
(
npcClass
.
getIntro
());
for
(
int
i
=
0
;
i
<
npcClassAttrs
.
size
();
i
++){
Attr
attr
=
new
Attr
();
attr
.
setName
(
npcClassAttrs
.
get
(
i
).
getName
());
attr
.
setValue
(
npcClassAttrs
.
get
(
i
).
getValue
());
npcInstanceAttr
.
add
(
attr
);
}
npcInstance
.
setAttrs
(
npcInstanceAttr
);
this
.
npcInstanceIndex
.
put
(
names
[
2
],
npcInstance
);
return
true
;
}
else
{
return
false
;
}
}
else
{
return
false
;
}
}
// 改变
public
boolean
update
(
String
name
,
String
value
)
{
String
[]
names
=
name
.
split
(
"_"
);
if
(
names
.
length
==
4
){
if
(
names
[
0
].
equals
(
"goods"
)){
List
<
GoodsInstance
>
goodsInstancesByClass
=
this
.
goodsClassIndex
.
get
(
names
[
1
]).
getGoodsInstances
();
boolean
goodsInstanceBoolean
=
false
;
GoodsInstance
goodsInstance
=
this
.
goodsInstanceIndex
.
get
(
names
[
2
]);
for
(
int
i
=
0
;
i
<
goodsInstancesByClass
.
size
();
i
++)
{
if
(
goodsInstance
==
goodsInstancesByClass
.
get
(
i
))
{
goodsInstanceBoolean
=
true
;
}
}
if
(
goodsInstanceBoolean
)
{
List
<
Attr
>
attrs
=
goodsInstance
.
getAttrs
();
for
(
int
j
=
0
;
j
<
attrs
.
size
();
j
++)
{
if
(
names
[
3
].
equals
(
attrs
.
get
(
j
).
getName
()))
{
attrs
.
get
(
j
).
setValue
(
value
);
return
true
;
}
}
return
true
;
}
else
{
return
false
;
}
}
else
if
(
names
[
0
].
equals
(
"npc"
))
{
List
<
NpcInstance
>
npcInstancesByClass
=
this
.
npcClassIndex
.
get
(
names
[
1
]).
getNpcInstances
();
boolean
npcInstanceBoolean
=
false
;
NpcInstance
npcInstance
=
this
.
npcInstanceIndex
.
get
(
names
[
2
]);
for
(
int
i
=
0
;
i
<
npcInstancesByClass
.
size
();
i
++)
{
if
(
npcInstance
==
npcInstancesByClass
.
get
(
i
))
{
npcInstanceBoolean
=
true
;
}
}
if
(
npcInstanceBoolean
)
{
List
<
Attr
>
attrs
=
npcInstance
.
getAttrs
();
for
(
int
j
=
0
;
j
<
attrs
.
size
();
j
++)
{
if
(
names
[
3
].
equals
(
attrs
.
get
(
j
).
getName
()))
{
attrs
.
get
(
j
).
setValue
(
value
);
return
true
;
}
}
return
true
;
}
else
{
return
false
;
}
}
}
return
false
;
}
// 增删改通用
public
boolean
CUD
(
String
name
,
String
operator
,
String
value
){
if
(
operator
.
equals
(
"insert"
))
{
return
this
.
insert
(
name
);
}
else
if
(
operator
.
equals
(
"update"
))
{
return
this
.
update
(
name
,
value
);
}
else
if
(
operator
.
equals
(
"delete"
))
{
return
false
;
}
else
{
return
false
;
}
}
}
src/GameEnvironment/GameEnvironment/Util.java
deleted
100644 → 0
View file @
eaf78424
package
com
.
qiwu
.
chatbotbackend
.
GameEnvironment
.
GameEnvironment
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.io.Reader
;
public
class
Util
{
public
static
String
getJsonString
(
String
fullName
)
{
Reader
reader
=
null
;
String
jsonString
=
""
;
try
{
// System.out.println("以字符为单位读取文件内容,一次读多个字节:");
// 一次读多个字符
char
[]
tempchars
=
new
char
[
256
];
int
charread
=
0
;
reader
=
new
InputStreamReader
(
new
FileInputStream
(
fullName
));
// 读入多个字符到字符数组中,charread为一次读取字符数
while
((
charread
=
reader
.
read
(
tempchars
))
!=
-
1
)
{
// 同样屏蔽掉\r不显示
if
((
charread
==
tempchars
.
length
)
&&
(
tempchars
[
tempchars
.
length
-
1
]
!=
'\r'
))
{
// System.out.println(tempchars);
jsonString
=
jsonString
+
String
.
valueOf
(
tempchars
);
// System.out.print(tempchars);
}
else
{
for
(
int
i
=
0
;
i
<
charread
;
i
++)
{
if
(
tempchars
[
i
]
==
'\r'
)
{
continue
;
}
else
{
jsonString
=
jsonString
+
tempchars
[
i
];
// System.out.print(tempchars[i]);
}
}
}
}
}
catch
(
Exception
e1
)
{
e1
.
printStackTrace
();
}
finally
{
if
(
reader
!=
null
)
{
try
{
reader
.
close
();
}
catch
(
IOException
e1
)
{
}
}
}
return
jsonString
;
}
}
src/GameEnvironment/GameEnvironment/bean/Attr.java
deleted
100644 → 0
View file @
eaf78424
package
com
.
qiwu
.
chatbotbackend
.
GameEnvironment
.
GameEnvironment
.
bean
;
import
java.io.Serializable
;
public
class
Attr
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
name
;
private
String
value
;
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getValue
()
{
return
value
;
}
public
void
setValue
(
String
value
)
{
this
.
value
=
value
;
}
@Override
public
String
toString
()
{
return
"Attr [name="
+
name
+
", value="
+
value
+
"]"
;
}
}
src/GameEnvironment/GameEnvironment/bean/GoodsInstance.java
deleted
100644 → 0
View file @
eaf78424
package
com
.
qiwu
.
chatbotbackend
.
GameEnvironment
.
GameEnvironment
.
bean
;
import
java.io.Serializable
;
import
java.util.List
;
public
class
GoodsInstance
extends
SuperClass
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
Place
place
;
private
NpcInstance
npc
;
public
Place
getPlace
()
{
return
place
;
}
public
void
setPlace
(
Place
place
)
{
this
.
place
=
place
;
}
public
NpcInstance
getNpc
()
{
return
npc
;
}
public
void
setNpc
(
NpcInstance
npc
)
{
this
.
npc
=
npc
;
}
@Override
public
String
toString
()
{
String
placeName
=
""
;
if
(
place
!=
null
)
{
placeName
=
place
.
getName
();
}
String
npcName
=
""
;
if
(
npc
!=
null
)
{
npcName
=
npc
.
getName
();
}
return
super
.
toString
()+
"GoodsInstance [placeName="
+
placeName
+
", npcName="
+
npcName
+
"]"
;
}
}
src/GameEnvironment/GameEnvironment/bean/NpcInstance.java
deleted
100644 → 0
View file @
eaf78424
package
com
.
qiwu
.
chatbotbackend
.
GameEnvironment
.
GameEnvironment
.
bean
;
import
java.io.Serializable
;
import
java.util.List
;
public
class
NpcInstance
extends
SuperClass
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
Place
place
;
private
List
<
GoodsInstance
>
goodsInstances
;
public
Place
getPlace
()
{
return
place
;
}
public
void
setPlace
(
Place
place
)
{
this
.
place
=
place
;
}
public
List
<
GoodsInstance
>
getGoodsInstances
()
{
return
goodsInstances
;
}
public
void
setGoodsInstances
(
List
<
GoodsInstance
>
goodsInstances
)
{
this
.
goodsInstances
=
goodsInstances
;
}
@Override
public
String
toString
()
{
String
placeName
=
""
;
if
(
place
!=
null
)
{
placeName
=
place
.
getName
();
}
int
goodsInstancesSize
=
0
;
if
(
goodsInstances
!=
null
)
{
goodsInstancesSize
=
goodsInstances
.
size
();
}
return
super
.
toString
()+
"NpcInstance [placeName="
+
placeName
+
", goodsInstancesSize="
+
goodsInstancesSize
+
"]"
;
}
}
src/GameEnvironment/GameEnvironment/bean/Place.java
deleted
100644 → 0
View file @
eaf78424
package
com
.
qiwu
.
chatbotbackend
.
GameEnvironment
.
GameEnvironment
.
bean
;
import
java.io.Serializable
;
import
java.util.List
;
public
class
Place
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
name
;
private
String
intro
;
private
List
<
Place
>
ableGo
;
private
List
<
NpcInstance
>
npcInstances
;
private
List
<
GoodsInstance
>
goodsInstances
;
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getIntro
()
{
return
intro
;
}
public
void
setIntro
(
String
intro
)
{
this
.
intro
=
intro
;
}
public
List
<
Place
>
getAbleGo
()
{
return
ableGo
;
}
public
void
setAbleGo
(
List
<
Place
>
ableGo
)
{
this
.
ableGo
=
ableGo
;
}
public
List
<
NpcInstance
>
getNpcInstances
()
{
return
npcInstances
;
}
public
void
setNpcInstances
(
List
<
NpcInstance
>
npcInstances
)
{
this
.
npcInstances
=
npcInstances
;
}
public
List
<
GoodsInstance
>
getGoodsInstances
()
{
return
goodsInstances
;
}
public
void
setGoodsInstances
(
List
<
GoodsInstance
>
goodsInstances
)
{
this
.
goodsInstances
=
goodsInstances
;
}
@Override
public
String
toString
()
{
int
ableGoSize
=
0
;
int
npcInstancesSize
=
0
;
int
goodsInstancesSize
=
0
;
if
(
ableGo
!=
null
)
{
ableGoSize
=
ableGo
.
size
();
}
if
(
npcInstances
!=
null
)
{
npcInstancesSize
=
npcInstances
.
size
();
}
if
(
goodsInstances
!=
null
)
{
goodsInstancesSize
=
goodsInstances
.
size
();
}
return
"Place [name="
+
name
+
", intro="
+
intro
+
", ableGo="
+
ableGoSize
+
", npcInstances="
+
npcInstancesSize
+
", goodsInstances="
+
goodsInstancesSize
+
"]"
;
}
}
src/GameEnvironment/GameEnvironment/bean/SuperClass.java
deleted
100644 → 0
View file @
eaf78424
package
com
.
qiwu
.
chatbotbackend
.
GameEnvironment
.
GameEnvironment
.
bean
;
import
java.io.Serializable
;
import
java.util.List
;
public
class
SuperClass
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
name
;
private
String
intro
;
private
List
<
Attr
>
attrs
;
private
List
<
GoodsInstance
>
goodsInstances
;
private
List
<
NpcInstance
>
npcInstances
;
public
List
<
GoodsInstance
>
getGoodsInstances
()
{
return
goodsInstances
;
}
public
void
setGoodsInstances
(
List
<
GoodsInstance
>
goodsInstances
)
{
this
.
goodsInstances
=
goodsInstances
;
}
public
List
<
NpcInstance
>
getNpcInstances
()
{
return
npcInstances
;
}
public
void
setNpcInstances
(
List
<
NpcInstance
>
npcInstances
)
{
this
.
npcInstances
=
npcInstances
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getIntro
()
{
return
intro
;
}
public
void
setIntro
(
String
intro
)
{
this
.
intro
=
intro
;
}
public
List
<
Attr
>
getAttrs
()
{
return
attrs
;
}
public
void
setAttrs
(
List
<
Attr
>
attrs
)
{
this
.
attrs
=
attrs
;
}
@Override
public
String
toString
()
{
int
goodsInstanceSize
=
0
;
if
(
goodsInstances
!=
null
)
{
goodsInstanceSize
=
goodsInstances
.
size
();
}
return
"SuperClass [name="
+
name
+
", intro="
+
intro
+
"goodsInstancesSize="
+
goodsInstanceSize
+
", attrs="
+
attrs
+
"]"
;
}
}
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