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
15fa3483
Commit
15fa3483
authored
Dec 12, 2018
by
hxw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
routine
parent
1a3a09de
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
519 additions
and
301 deletions
+519
-301
ChatCache.java
src/entity/ChatCache.java
+1
-0
JConfig.java
src/entity/JConfig.java
+3
-3
CharacterConstructor.java
src/gameDesign/CharacterConstructor.java
+55
-34
ElementConstructor.java
src/gameDesign/ElementConstructor.java
+9
-2
GameUtil.java
src/gameDesign/GameUtil.java
+40
-0
GlobalVariableConstructor.java
src/gameDesign/GlobalVariableConstructor.java
+7
-6
ItemConstructor.java
src/gameDesign/ItemConstructor.java
+61
-25
MapConstructor.java
src/gameDesign/MapConstructor.java
+100
-68
PlotConstructor.java
src/gameDesign/PlotConstructor.java
+11
-6
FormsPoster.java
src/processing/FormsPoster.java
+5
-4
MyFunc.java
src/processing/MyFunc.java
+18
-0
QuestionMatcher.java
src/processing/QuestionMatcher.java
+56
-109
ResponseFilter.java
src/processing/ResponseFilter.java
+27
-9
WorldController.java
src/processing/WorldController.java
+75
-24
GameDesignServlet.java
src/servlet/GameDesignServlet.java
+51
-11
No files found.
src/entity/ChatCache.java
View file @
15fa3483
...
@@ -69,6 +69,7 @@ public class ChatCache implements DisposableBean {
...
@@ -69,6 +69,7 @@ public class ChatCache implements DisposableBean {
gameEnv
=
new
GameEnv
(
userInfo
.
botAccount
);
gameEnv
=
new
GameEnv
(
userInfo
.
botAccount
);
}
catch
(
Exception
e
){
}
catch
(
Exception
e
){
System
.
out
.
println
(
"游戏平台初始化失败"
);
System
.
out
.
println
(
"游戏平台初始化失败"
);
e
.
printStackTrace
();
}
}
String
k
;
String
k
;
...
...
src/entity/JConfig.java
View file @
15fa3483
...
@@ -443,7 +443,7 @@ public class JConfig implements Cloneable{
...
@@ -443,7 +443,7 @@ public class JConfig implements Cloneable{
}
}
public
static
void
activateCopy
(
JConfig
jConfig
,
List
<
JConfig
>
jConfigList
){
public
static
void
activateCopy
(
JConfig
jConfig
,
List
<
JConfig
>
jConfigList
,
String
name
){
jConfig
.
setReply
(
jConfig
.
getReply
()
+
"{临时变量reply-2}"
);
jConfig
.
setReply
(
jConfig
.
getReply
()
+
"{临时变量reply-2}"
);
...
@@ -453,13 +453,13 @@ public class JConfig implements Cloneable{
...
@@ -453,13 +453,13 @@ public class JConfig implements Cloneable{
jConfig
.
setHisPremise
(
"临时变量condition::match-Include=+null"
);
jConfig
.
setHisPremise
(
"临时变量condition::match-Include=+null"
);
else
else
jConfig
.
setHisPremise
(
jConfig
.
getjHisPremise
()
+
",临时变量condition::match-Include=+null"
);
jConfig
.
setHisPremise
(
jConfig
.
getjHisPremise
()
+
",临时变量condition::match-Include=+null"
);
jConfig
.
setConfigName
(
"map"
,
true
);
jConfig
.
setConfigName
(
name
,
true
);
if
(
jConfig2
.
getUpdateKnowledge
().
equals
(
""
))
if
(
jConfig2
.
getUpdateKnowledge
().
equals
(
""
))
jConfig2
.
setUpdateKnowledge
(
"process-nextStep:var={临时变量condition-2}"
);
jConfig2
.
setUpdateKnowledge
(
"process-nextStep:var={临时变量condition-2}"
);
else
else
jConfig2
.
setUpdateKnowledge
(
jConfig2
.
getUpdateKnowledge
()
+
"-<-process-nextStep:var={临时变量condition-2}"
);
jConfig2
.
setUpdateKnowledge
(
jConfig2
.
getUpdateKnowledge
()
+
"-<-process-nextStep:var={临时变量condition-2}"
);
jConfig2
.
setConfigName
(
"map"
,
true
);
jConfig2
.
setConfigName
(
name
,
true
);
jConfigList
.
add
(
jConfig
);
jConfigList
.
add
(
jConfig
);
...
...
src/gameDesign/CharacterConstructor.java
View file @
15fa3483
...
@@ -10,13 +10,13 @@ import java.util.*;
...
@@ -10,13 +10,13 @@ import java.util.*;
public
class
CharacterConstructor
extends
ElementConstructor
{
public
class
CharacterConstructor
extends
ElementConstructor
{
public
CharacterConstructor
(
SqlHelper
helper
,
int
botId
,
int
skipCount
,
String
botAccount
,
HashSet
<
String
>
exceptRelation
,
StringBuffer
POS
)
{
public
CharacterConstructor
(
SqlHelper
helper
,
int
botId
,
String
botAccount
,
Map
<
String
,
StringBuffer
>
keywordMap
,
HashSet
<
String
>
exceptRelation
,
StringBuffer
POS
)
{
super
();
super
();
this
.
helper
=
helper
;
this
.
helper
=
helper
;
this
.
botId
=
botId
;
this
.
botId
=
botId
;
this
.
botAccount
=
botAccount
;
this
.
botAccount
=
botAccount
;
this
.
exceptRelation
=
exceptRelation
;
this
.
exceptRelation
=
exceptRelation
;
this
.
skipCount
=
skipCount
;
this
.
keywordMap
=
keywordMap
;
this
.
POS
=
POS
;
this
.
POS
=
POS
;
}
}
...
@@ -24,41 +24,45 @@ public class CharacterConstructor extends ElementConstructor {
...
@@ -24,41 +24,45 @@ public class CharacterConstructor extends ElementConstructor {
String
category
,
name
,
className
,
description
,
attrName
,
attrValue
;
String
category
,
name
,
className
,
description
,
attrName
,
attrValue
;
try
{
try
{
String
pattern1
=
keywordMap
.
get
(
"npc_location_pattern"
).
toString
();
JSONArray
allNPC
=
gameElements
.
getJSONArray
(
"npc"
);
JSONArray
allNPC
=
gameElements
.
getJSONArray
(
"npc"
);
Map
<
String
,
String
>
attribute
=
null
;
Map
<
String
,
String
>
attribute
=
null
;
Iterator
<
String
>
attrIter
=
null
;
Iterator
<
String
>
attrIter
=
null
;
HashSet
<
String
>
classSet
=
new
HashSet
<
String
>();
HashSet
<
String
>
classSet
=
new
HashSet
<
String
>();
//与npc属性相关的所有condition
keywordMap
.
putIfAbsent
(
"npc_wenzainali"
,
new
StringBuffer
());
ArrayList
<
String
>
relateConditions
=
new
ArrayList
<
String
>()
{
keywordMap
.
putIfAbsent
(
"npc_shishenme"
,
new
StringBuffer
());
{
keywordMap
.
putIfAbsent
(
"npc_know_exist_what"
,
new
StringBuffer
());
add
(
"wenzainali"
);
keywordMap
.
putIfAbsent
(
"npc_nums"
,
new
StringBuffer
());
add
(
"shishenme"
);
}
};
//与npc类相关的所有condition
ArrayList
<
String
>
classRelateConditions
=
new
ArrayList
<
String
>()
{
{
add
(
"know_exist_what"
);
}
};
//与物品属性查询相关的所有condition
String
attrRelateConditions
[]
=
{
"nums"
,
"shishenme"
};
//在condition的三元组中添加与NPC相关的关键词
//与物品类查询相关的所有condition
String
classRelateConditions
[]
=
{
"know_exist_what"
};
String
locationRelateConditions
[]
=
{
"wenzainali"
};
String
conditionValue
=
"哪里:人称"
,
repValue
;
StringBuffer
keywords
=
new
StringBuffer
();
//在condition的三元组中添加与NPC相关的关键词
StringBuffer
classKeywords
=
new
StringBuffer
();
StringBuffer
classKeywords
=
new
StringBuffer
();
for
(
JSONObject
character
:
allNPC
.
toJavaList
(
JSONObject
.
class
))
{
for
(
JSONObject
character
:
allNPC
.
toJavaList
(
JSONObject
.
class
))
{
name
=
(
String
)
character
.
get
(
"name"
);
name
=
(
String
)
character
.
get
(
"name"
);
//添加词性
if
(!
name
.
equals
(
""
))
if
(!
name
.
equals
(
""
))
POS
.
append
(
"="
+
name
+
"|人名\r\n"
);
POS
.
append
(
"="
+
name
+
"|人名\r\n"
);
className
=
(
String
)
character
.
get
(
"class"
);
className
=
(
String
)
character
.
get
(
"class"
);
if
(!
className
.
equals
(
""
))
if
(!
className
.
equals
(
""
))
POS
.
append
(
"="
+
className
+
"|人名\r\n"
);
POS
.
append
(
"="
+
className
+
"|人名\r\n"
);
//添加类名称
if
(!
classSet
.
contains
(
className
))
{
if
(!
classSet
.
contains
(
className
))
{
classSet
.
add
(
className
);
classSet
.
add
(
className
);
classKeywords
.
append
(
"+周围:"
+
className
+
"+附近:"
+
className
);
classKeywords
.
append
(
"+周围:"
+
className
+
"+附近:"
+
className
);
...
@@ -67,46 +71,63 @@ public class CharacterConstructor extends ElementConstructor {
...
@@ -67,46 +71,63 @@ public class CharacterConstructor extends ElementConstructor {
attribute
=
gameElements
.
toJavaObject
(
character
.
getJSONObject
(
"attr"
),
Map
.
class
);
attribute
=
gameElements
.
toJavaObject
(
character
.
getJSONObject
(
"attr"
),
Map
.
class
);
attrIter
=
attribute
.
keySet
().
iterator
();
attrIter
=
attribute
.
keySet
().
iterator
();
repValue
=
conditionValue
.
replace
(
"人称"
,
name
);
keywords
.
append
(
"+"
+
repValue
);
keywordMap
.
get
(
"npc_"
+
locationRelateConditions
[
0
]).
append
(
pattern1
.
replace
(
"name"
,
name
));
while
(
attrIter
.
hasNext
())
{
while
(
attrIter
.
hasNext
())
{
attrName
=
attrIter
.
next
();
attrName
=
attrIter
.
next
();
if
(!
attrName
.
equals
(
""
))
if
(!
attrName
.
equals
(
""
))
POS
.
append
(
"="
+
attrName
+
"|名词\r\n"
);
POS
.
append
(
"="
+
attrName
+
"|名词\r\n"
);
attrValue
=
attribute
.
get
(
attrName
);
attrValue
=
attribute
.
get
(
attrName
);
for
(
String
condition:
attrRelateConditions
){
keywordMap
.
get
(
"npc_"
+
condition
).
append
(
"+"
+
attrName
+
":"
+
attrValue
);
}
}
System
.
out
.
println
(
name
);
}
}
}
//根据根据NPC名字和属性查询属性值
for
(
String
conditionName
:
relateConditions
)
{
//根据根据NPC的名字查询地点
for
(
String
conditionName
:
locationRelateConditions
)
{
jConfig
=
new
JConfig
(
jConfig
=
new
JConfig
(
conditionName
+
"::match-Include="
+
keyword
s
,
" "
,
conditionName
+
"::match-Include="
+
keyword
Map
.
get
(
"npc_"
+
conditionName
)
,
" "
,
"match,return-0"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
"{
NPC_query-2}"
,
"yaobuyao"
,
"NPC_query:queryAttrByNPC
Name:"
+
conditionName
"match,return-0"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
"{
npc_query-2}"
,
"yaobuyao"
,
"npc_query:queryLocationByCondition
Name:"
+
conditionName
);
);
jConfig
.
setAuxiliaryPriority
(
"1"
);
JConfig
.
activateCopy
(
jConfig
,
jConfigList
,
"npc"
);
jConfigList
.
add
(
jConfig
);
jConfig
=
new
JConfig
(
conditionName
+
"::match-Include="
+
keywordMap
.
get
(
"npc_"
+
conditionName
)
+
","
+
"zainali::match-Keyword="
+
keywordMap
.
get
(
"map_zainali"
).
toString
(),
" "
,
"match,return-0"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
"{npc_query-2}"
,
"yaobuyao"
,
"npc_query:queryLocationByConditionName:"
+
conditionName
);
JConfig
.
activateCopy
(
jConfig
,
jConfigList
,
"npc"
);
//jConfigList.add(jConfig);
}
//根据根据NPC名字和属性查询属性值
for
(
String
conditionName:
attrRelateConditions
){
jConfig
=
new
JConfig
(
conditionName
+
"::match-Include="
+
keywordMap
.
get
(
"npc_"
+
conditionName
),
" "
,
"match,return-0"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
"{npc_query-2}"
,
"yaobuyao"
,
"npc_query:queryAttrByNPCName:"
+
conditionName
);
JConfig
.
activateCopy
(
jConfig
,
jConfigList
,
"npc"
);
}
}
//根据根据NPC类别和地点属性查询所有NPC实例
//根据根据NPC类别和地点属性查询所有NPC实例
for
(
String
conditionName
:
r
elateConditions
)
{
for
(
String
conditionName
:
classR
elateConditions
)
{
jConfig
=
new
JConfig
(
jConfig
=
new
JConfig
(
conditionName
+
"::match-Include="
+
classKeywords
,
" "
,
conditionName
+
"::match-Include="
+
classKeywords
,
" "
,
"match,return-0"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
"{
NPC_query-2}"
,
"yaobuyao"
,
"NPC
_query:queryAroundNpcByClassName:"
+
conditionName
"match,return-0"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
"{
npc_query-2}"
,
"yaobuyao"
,
"npc
_query:queryAroundNpcByClassName:"
+
conditionName
);
);
jConfig
.
setAuxiliaryPriority
(
"1"
);
JConfig
.
activateCopy
(
jConfig
,
jConfigList
,
"npc"
);
jConfigList
.
add
(
jConfig
);
//jConfigList.add(jConfig);
}
}
}
catch
(
Exception
e
){
}
catch
(
Exception
e
){
operationStatus
=
0
;
operationStatus
=
0
;
message
=
"NPC接口处理出现异常"
;
message
=
"NPC接口处理出现异常"
;
e
.
printStackTrace
();
return
;
return
;
}
}
}
}
...
...
src/gameDesign/ElementConstructor.java
View file @
15fa3483
...
@@ -16,7 +16,7 @@ public class ElementConstructor {
...
@@ -16,7 +16,7 @@ public class ElementConstructor {
int
operationStatus
=
1
;
int
operationStatus
=
1
;
int
skipCount
=
0
;
Map
<
String
,
StringBuffer
>
keywordMap
=
null
;
SqlHelper
helper
=
null
;
SqlHelper
helper
=
null
;
HashSet
<
String
>
exceptRelation
=
null
;
HashSet
<
String
>
exceptRelation
=
null
;
JConfig
jConfig
=
null
;
JConfig
jConfig
=
null
;
...
@@ -97,13 +97,20 @@ public class ElementConstructor {
...
@@ -97,13 +97,20 @@ public class ElementConstructor {
relationKeywords
.
put
(
conditionName
+
"_tail"
,
new
HashSet
<
String
>());
relationKeywords
.
put
(
conditionName
+
"_tail"
,
new
HashSet
<
String
>());
}
}
premise
.
put
(
"keywords"
,
((
String
)
premise
.
get
(
"keywords"
)).
replace
(
"qiwu"
,
"#visitorname"
));
for
(
String
keyword
:
((
String
)
premise
.
get
(
"keywords"
)).
split
(
"\\+"
))
{
for
(
String
keyword
:
((
String
)
premise
.
get
(
"keywords"
)).
split
(
"\\+"
))
{
if
(
keyword
.
equals
(
""
)){
if
(
keyword
.
equals
(
""
)){
continue
;
continue
;
}
else
if
(
keyword
.
contains
(
":"
)){
}
else
if
(
keyword
.
contains
(
":"
)){
pair
=
keyword
.
split
(
":"
);
pair
=
keyword
.
split
(
":"
,
2
);
if
(
pair
[
1
].
equals
(
""
))
continue
;
relationKeywords
.
get
(
conditionName
+
"_head"
).
add
(
pair
[
0
]);
relationKeywords
.
get
(
conditionName
+
"_head"
).
add
(
pair
[
0
]);
relationKeywords
.
get
(
conditionName
+
"_tail"
).
add
(
pair
[
1
]);
relationKeywords
.
get
(
conditionName
+
"_tail"
).
add
(
pair
[
1
]);
...
...
src/gameDesign/GameUtil.java
0 → 100644
View file @
15fa3483
package
com
.
qiwu
.
chatbotbackend
.
gameDesign
;
import
com.qiwu.chatbotbackend.GameEnvironment.GameEnv
;
import
com.qiwu.chatbotbackend.processing.LogWriter
;
import
com.qiwu.chatbotbackend.processing.WorldController
;
import
java.util.Map
;
public
class
GameUtil
{
public
GameEnv
gameEnv
=
null
;
public
Map
<
String
,
String
>
curInfoPoint
=
null
;
public
Map
<
String
,
String
>
historyInfoPoint
=
null
;
public
WorldController
worldController
=
null
;
public
GameUtil
(
GameEnv
gameEnv
,
WorldController
worldController
,
Map
<
String
,
String
>
curInfoPoint
,
Map
<
String
,
String
>
historyInfoPoint
)
{
this
.
gameEnv
=
gameEnv
;
this
.
curInfoPoint
=
curInfoPoint
;
this
.
historyInfoPoint
=
historyInfoPoint
;
this
.
worldController
=
worldController
;
}
public
void
gamePreprocessing
(
LogWriter
logWriter
){
//将要去的地点的别名替换为真名
String
conditionList
[]
=
{
"yaobuyao"
,
"want_know_zenmezuo"
};
for
(
String
conditionName:
conditionList
)
{
if
(!
curInfoPoint
.
get
(
conditionName
).
equals
(
""
)
&&
!
curInfoPoint
.
get
(
conditionName
).
equals
(
"unknown"
))
{
String
info
=
curInfoPoint
.
get
(
conditionName
);
String
destination
=
info
.
split
(
":"
)[
1
];
String
site
=
historyInfoPoint
.
get
(
"site"
);
String
newInfo
=
info
.
replace
(
destination
,
worldController
.
findLocationName
(
gameEnv
,
destination
,
site
));
logWriter
.
record
(
conditionName
+
": 将’"
+
info
+
"‘替换为‘"
+
newInfo
+
"'"
,
1
);
curInfoPoint
.
put
(
conditionName
,
newInfo
);
}
}
}
}
src/gameDesign/GlobalVariableConstructor.java
View file @
15fa3483
...
@@ -12,20 +12,20 @@ import java.util.Map;
...
@@ -12,20 +12,20 @@ import java.util.Map;
public
class
GlobalVariableConstructor
extends
ElementConstructor
{
public
class
GlobalVariableConstructor
extends
ElementConstructor
{
public
GlobalVariableConstructor
(
SqlHelper
helper
,
int
botId
,
int
skipCount
,
String
botAccount
,
HashSet
<
String
>
exceptRelation
,
StringBuffer
POS
)
{
public
GlobalVariableConstructor
(
SqlHelper
helper
,
int
botId
,
String
botAccount
,
Map
<
String
,
StringBuffer
>
keywordMap
,
HashSet
<
String
>
exceptRelation
,
StringBuffer
POS
)
{
super
();
super
();
this
.
helper
=
helper
;
this
.
helper
=
helper
;
this
.
botId
=
botId
;
this
.
botId
=
botId
;
this
.
botAccount
=
botAccount
;
this
.
botAccount
=
botAccount
;
this
.
exceptRelation
=
exceptRelation
;
this
.
exceptRelation
=
exceptRelation
;
this
.
skipCount
=
skipCount
;
this
.
keywordMap
=
keywordMap
;
this
.
POS
=
POS
;
this
.
POS
=
POS
;
}
}
public
void
construct
(
JSONObject
gameElements
,
UserInfo
userinfo
)
{
public
void
construct
(
JSONObject
gameElements
,
UserInfo
userinfo
)
{
try
{
try
{
String
category
,
name
,
description
,
attr
Name
,
attr
Value
;
String
category
,
name
,
description
,
attrValue
;
JSONArray
globalVariable
=
gameElements
.
getJSONArray
(
"globalVariable"
);
JSONArray
globalVariable
=
gameElements
.
getJSONArray
(
"globalVariable"
);
Map
<
String
,
String
>
attribute
=
null
;
Map
<
String
,
String
>
attribute
=
null
;
Iterator
<
String
>
attrIter
=
null
;
Iterator
<
String
>
attrIter
=
null
;
...
@@ -33,9 +33,9 @@ public class GlobalVariableConstructor extends ElementConstructor {
...
@@ -33,9 +33,9 @@ public class GlobalVariableConstructor extends ElementConstructor {
for
(
JSONObject
variableList
:
globalVariable
.
toJavaList
(
JSONObject
.
class
))
{
for
(
JSONObject
variableList
:
globalVariable
.
toJavaList
(
JSONObject
.
class
))
{
category
=
(
String
)
variableList
.
get
(
"category"
);
category
=
(
String
)
variableList
.
get
(
"category"
);
attribute
=
gameElements
.
toJavaObject
(
variableList
.
getJSONObject
(
"variables"
),
Map
.
class
);
attribute
=
gameElements
.
toJavaObject
(
variableList
.
getJSONObject
(
"variables"
),
Map
.
class
);
attrIter
=
attribute
.
keySet
().
iterator
();
while
(
attrIter
.
hasNext
())
{
attrName
=
attrIter
.
next
();
for
(
String
attrName:
attribute
.
keySet
())
{
attrValue
=
attribute
.
get
(
attrName
);
attrValue
=
attribute
.
get
(
attrName
);
varInitialMap
.
put
(
"globalVariable_"
+
category
+
"_"
+
attrName
,
attrValue
);
varInitialMap
.
put
(
"globalVariable_"
+
category
+
"_"
+
attrName
,
attrValue
);
}
}
...
@@ -54,6 +54,7 @@ public class GlobalVariableConstructor extends ElementConstructor {
...
@@ -54,6 +54,7 @@ public class GlobalVariableConstructor extends ElementConstructor {
}
catch
(
Exception
e
){
}
catch
(
Exception
e
){
operationStatus
=
0
;
operationStatus
=
0
;
message
=
"全局变量处理出现异常"
;
message
=
"全局变量处理出现异常"
;
e
.
printStackTrace
();
return
;
return
;
}
}
}
}
...
...
src/gameDesign/ItemConstructor.java
View file @
15fa3483
...
@@ -12,50 +12,63 @@ public class ItemConstructor extends ElementConstructor {
...
@@ -12,50 +12,63 @@ public class ItemConstructor extends ElementConstructor {
public
ItemConstructor
(
SqlHelper
helper
,
int
botId
,
int
skipCount
,
String
botAccount
,
HashSet
<
String
>
exceptRelation
,
StringBuffer
POS
)
{
public
ItemConstructor
(
SqlHelper
helper
,
int
botId
,
String
botAccount
,
Map
<
String
,
StringBuffer
>
keywordMap
,
HashSet
<
String
>
exceptRelation
,
StringBuffer
POS
)
{
super
();
super
();
this
.
helper
=
helper
;
this
.
helper
=
helper
;
this
.
botId
=
botId
;
this
.
botId
=
botId
;
this
.
botAccount
=
botAccount
;
this
.
botAccount
=
botAccount
;
this
.
exceptRelation
=
exceptRelation
;
this
.
exceptRelation
=
exceptRelation
;
this
.
skipCount
=
skipCount
;
this
.
keywordMap
=
keywordMap
;
this
.
POS
=
POS
;
this
.
POS
=
POS
;
}
}
public
void
construct
(
JSONObject
gameElements
,
UserInfo
userinfo
)
{
public
void
construct
(
JSONObject
gameElements
,
UserInfo
userinfo
)
{
try
{
try
{
String
category
,
name
,
className
,
description
,
attrName
,
attrValue
;
String
pattern1
=
keywordMap
.
get
(
"item_location_pattern"
).
toString
();
String
category
,
name
,
className
,
description
,
attrValue
;
JSONArray
goods
=
gameElements
.
getJSONArray
(
"goods"
);
JSONArray
goods
=
gameElements
.
getJSONArray
(
"goods"
);
Map
<
String
,
String
>
attribute
=
null
;
Map
<
String
,
String
>
attribute
=
null
;
Iterator
<
String
>
attrIter
=
null
;
Iterator
<
String
>
attrIter
=
null
;
HashSet
<
String
>
classSet
=
new
HashSet
<
String
>();
HashSet
<
String
>
classSet
=
new
HashSet
<
String
>();
keywordMap
.
putIfAbsent
(
"item_wenzainali"
,
new
StringBuffer
());
keywordMap
.
putIfAbsent
(
"item_shishenme"
,
new
StringBuffer
());
keywordMap
.
putIfAbsent
(
"item_know_exist_what"
,
new
StringBuffer
());
keywordMap
.
putIfAbsent
(
"item_nums"
,
new
StringBuffer
());
//与物品属性查询相关的所有condition
//与物品属性查询相关的所有condition
ArrayList
<
String
>
attrRelateConditions
=
new
ArrayList
<
String
>()
{
String
attrRelateConditions
[]
=
{
"nums"
,
"shishenme"
};
{
add
(
"nums"
);
add
(
"shishenme"
);
}
};
//与物品类查询相关的所有condition
//与物品类查询相关的所有condition
ArrayList
<
String
>
classRelateConditions
=
new
ArrayList
<
String
>()
{
String
classRelateConditions
[]
=
{
"know_exist_what"
};
{
add
(
"know_exist_what"
);
String
locationRelateConditions
[]
=
{
"wenzainali"
};
}
};
//如何找到×××××× ,这样的condition
String
findRelateConditions
[]
=
{
"want_know_zenmezuo"
};
String
findPattern
=
keywordMap
.
get
(
"find_pattern"
).
toString
();
StringBuffer
keywords
=
new
StringBuffer
();
StringBuffer
classKeywords
=
new
StringBuffer
();
StringBuffer
classKeywords
=
new
StringBuffer
();
for
(
JSONObject
good
:
goods
.
toJavaList
(
JSONObject
.
class
))
{
for
(
JSONObject
good
:
goods
.
toJavaList
(
JSONObject
.
class
))
{
name
=
(
String
)
good
.
get
(
"name"
);
name
=
(
String
)
good
.
get
(
"name"
);
//添加词性
if
(!
name
.
equals
(
""
))
if
(!
name
.
equals
(
""
))
POS
.
append
(
"="
+
name
+
"|名词\r\n"
);
POS
.
append
(
"="
+
name
+
"|名词\r\n"
);
className
=
(
String
)
good
.
get
(
"class"
);
className
=
(
String
)
good
.
get
(
"class"
);
if
(!
className
.
equals
(
""
))
if
(!
className
.
equals
(
""
))
POS
.
append
(
"="
+
className
+
"|名词\r\n"
);
POS
.
append
(
"="
+
className
+
"|名词\r\n"
);
keywordMap
.
get
(
"item_"
+
locationRelateConditions
[
0
]).
append
(
pattern1
.
replace
(
"name"
,
name
));
//添加所有物品类别
if
(!
classSet
.
contains
(
className
))
{
if
(!
classSet
.
contains
(
className
))
{
classSet
.
add
(
className
);
classSet
.
add
(
className
);
//添加周围有什么士兵等关于类别的关键词
//添加周围有什么士兵等关于类别的关键词
...
@@ -63,34 +76,58 @@ public class ItemConstructor extends ElementConstructor {
...
@@ -63,34 +76,58 @@ public class ItemConstructor extends ElementConstructor {
}
}
attribute
=
gameElements
.
toJavaObject
(
good
.
getJSONObject
(
"attr"
),
Map
.
class
);
attribute
=
gameElements
.
toJavaObject
(
good
.
getJSONObject
(
"attr"
),
Map
.
class
);
attrIter
=
attribute
.
keySet
().
iterator
();
while
(
attrIter
.
hasNext
())
{
for
(
String
attrName:
attribute
.
keySet
()){
attrName
=
attrIter
.
next
();
if
(!
attrName
.
equals
(
""
))
if
(!
attrName
.
equals
(
""
))
POS
.
append
(
"="
+
attrName
+
"|名词\r\n"
);
POS
.
append
(
"="
+
attrName
+
"|名词\r\n"
);
attrValue
=
attribute
.
get
(
attrName
);
attrValue
=
attribute
.
get
(
attrName
);
keywords
.
append
(
"+"
+
name
+
":"
+
attrName
);
for
(
String
condition:
attrRelateConditions
){
keywordMap
.
get
(
"item_"
+
condition
).
append
(
"+"
+
name
+
":"
+
attrName
);
}
}
}
}
//与地点查询相关的condition
for
(
String
conditionName:
locationRelateConditions
){
jConfig
=
new
JConfig
(
conditionName
+
"::match-Include="
+
keywordMap
.
get
(
"item_"
+
conditionName
).
toString
()
+
","
+
"zainali::match-Keyword="
+
keywordMap
.
get
(
"map_zainali"
).
toString
(),
" "
,
"match,return-0"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
"{goods_query-2}"
,
" "
,
"goods_query:queryLocationByConditionName:"
+
conditionName
);
JConfig
.
activateCopy
(
jConfig
,
jConfigList
,
"item"
);
//jConfigList.add(jConfig);
jConfig
=
new
JConfig
(
conditionName
+
"::match-Include="
+
keywordMap
.
get
(
"item_"
+
conditionName
).
toString
(),
" "
,
"match,return-0"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
"{goods_query-2}"
,
" "
,
"goods_query:queryLocationByConditionName:"
+
conditionName
);
JConfig
.
activateCopy
(
jConfig
,
jConfigList
,
"item"
);
}
}
//根据根据物品名字和属性查询属性值
//根据根据物品名字和属性查询属性值
for
(
String
conditionName
:
attrRelateConditions
)
{
for
(
String
conditionName
:
attrRelateConditions
)
{
jConfig
=
new
JConfig
(
jConfig
=
new
JConfig
(
conditionName
+
"::match-Include="
+
keyword
s
,
" "
,
conditionName
+
"::match-Include="
+
keyword
Map
.
get
(
"item_"
+
conditionName
).
toString
()
,
" "
,
"match,return-0"
,
"match,return-0"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
"{goods_query-2}"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
"{goods_query-2}"
,
" "
,
" "
,
"goods_query:queryAttrByGoodsName:"
+
conditionName
"goods_query:queryAttrByGoodsName:"
+
conditionName
);
);
jConfig
.
setAuxiliaryPriority
(
"1"
);
JConfig
.
activateCopy
(
jConfig
,
jConfigList
,
"item"
);
jConfigList
.
add
(
jConfig
);
}
}
//根据类名和地点查询所有实例
//根据类名查询周围所有实例
for
(
String
conditionName
:
attrRelateConditions
)
{
for
(
String
conditionName
:
attrRelateConditions
)
{
jConfig
=
new
JConfig
(
jConfig
=
new
JConfig
(
conditionName
+
"::match-Include="
+
classKeywords
,
" "
,
conditionName
+
"::match-Include="
+
classKeywords
,
" "
,
...
@@ -99,8 +136,7 @@ public class ItemConstructor extends ElementConstructor {
...
@@ -99,8 +136,7 @@ public class ItemConstructor extends ElementConstructor {
" "
,
" "
,
"goods_query:queryAroundGoodsByClassName:"
+
conditionName
"goods_query:queryAroundGoodsByClassName:"
+
conditionName
);
);
jConfig
.
setAuxiliaryPriority
(
"1"
);
JConfig
.
activateCopy
(
jConfig
,
jConfigList
,
"item"
);
jConfigList
.
add
(
jConfig
);
}
}
}
catch
(
Exception
e
){
}
catch
(
Exception
e
){
operationStatus
=
0
;
operationStatus
=
0
;
...
...
src/gameDesign/MapConstructor.java
View file @
15fa3483
...
@@ -6,10 +6,14 @@ import com.qiwu.chatbotbackend.db.SqlHelper;
...
@@ -6,10 +6,14 @@ import com.qiwu.chatbotbackend.db.SqlHelper;
import
com.qiwu.chatbotbackend.entity.JConfig
;
import
com.qiwu.chatbotbackend.entity.JConfig
;
import
com.qiwu.chatbotbackend.entity.UserInfo
;
import
com.qiwu.chatbotbackend.entity.UserInfo
;
import
java.util.*
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
public
class
MapConstructor
extends
ElementConstructor
{
public
class
MapConstructor
extends
ElementConstructor
{
String
nickname
=
"qiwu"
;
int
[][]
matrix
;
int
[][]
matrix
;
int
locationNum
;
int
locationNum
;
HashMap
<
Integer
,
JSONObject
>
id2j
=
new
HashMap
<
Integer
,
JSONObject
>();
HashMap
<
Integer
,
JSONObject
>
id2j
=
new
HashMap
<
Integer
,
JSONObject
>();
...
@@ -19,13 +23,14 @@ public class MapConstructor extends ElementConstructor {
...
@@ -19,13 +23,14 @@ public class MapConstructor extends ElementConstructor {
Map
<
String
,
String
>
script
=
null
;
//话术模板
Map
<
String
,
String
>
script
=
null
;
//话术模板
public
MapConstructor
(
SqlHelper
helper
,
int
botId
,
int
skipCount
,
String
botAccount
,
HashSet
<
String
>
exceptRelation
,
StringBuffer
POS
)
{
public
MapConstructor
(
SqlHelper
helper
,
int
botId
,
String
botAccount
,
Map
<
String
,
StringBuffer
>
keywordMap
,
HashSet
<
String
>
exceptRelation
,
StringBuffer
POS
)
{
super
();
super
();
this
.
helper
=
helper
;
this
.
helper
=
helper
;
this
.
botId
=
botId
;
this
.
botId
=
botId
;
this
.
botAccount
=
botAccount
;
this
.
botAccount
=
botAccount
;
this
.
exceptRelation
=
exceptRelation
;
this
.
exceptRelation
=
exceptRelation
;
this
.
skipCount
=
skipCount
;
this
.
keywordMap
=
keywordMap
;
this
.
POS
=
POS
;
this
.
POS
=
POS
;
}
}
...
@@ -87,9 +92,6 @@ public class MapConstructor extends ElementConstructor {
...
@@ -87,9 +92,6 @@ public class MapConstructor extends ElementConstructor {
try
{
try
{
conditionDescription
.
put
(
"site"
,
"当前地点"
);
conditionDescription
.
put
(
"site"
,
"当前地点"
);
JSONObject
map
=
gameElements
.
getJSONObject
(
"map"
);
JSONObject
map
=
gameElements
.
getJSONObject
(
"map"
);
...
@@ -97,29 +99,48 @@ public class MapConstructor extends ElementConstructor {
...
@@ -97,29 +99,48 @@ public class MapConstructor extends ElementConstructor {
script
=
JSONObject
.
toJavaObject
(
gameElements
.
getJSONObject
(
"speechcraft"
),
Map
.
class
);
script
=
JSONObject
.
toJavaObject
(
gameElements
.
getJSONObject
(
"speechcraft"
),
Map
.
class
);
if
(!
script
.
containsKey
(
"PATH_AT"
))
if
(!
script
.
containsKey
(
"PATH_AT"
))
script
.
put
(
"PATH_AT"
,
"你已经在
%s
"
);
script
.
put
(
"PATH_AT"
,
"你已经在
[地点名]了
"
);
if
(!
script
.
containsKey
(
"WHERE_I_AM"
))
if
(!
script
.
containsKey
(
"WHERE_I_AM"
))
script
.
put
(
"WHERE_I_AM"
,
"在
%s
"
);
script
.
put
(
"WHERE_I_AM"
,
"在
[地点名]
"
);
if
(!
script
.
containsKey
(
"PATH_ADJOINT"
))
if
(!
script
.
containsKey
(
"PATH_ADJOINT"
))
script
.
put
(
"PATH_ADJOINT"
,
"就在附近哦"
);
script
.
put
(
"PATH_ADJOINT"
,
"就在附近哦"
);
if
(!
script
.
containsKey
(
"PATH_EXIST"
))
if
(!
script
.
containsKey
(
"PATH_EXIST"
))
script
.
put
(
"PATH_EXIST"
,
"通过
%s可以到达目的地
"
);
script
.
put
(
"PATH_EXIST"
,
"通过
[途径]可以到达[目的地]
"
);
if
(!
script
.
containsKey
(
"PATH_NOT_EXIST"
))
if
(!
script
.
containsKey
(
"PATH_NOT_EXIST"
))
script
.
put
(
"PATH_NOT_EXIST"
,
"不可到达"
);
script
.
put
(
"PATH_NOT_EXIST"
,
"不可到达"
);
if
(!
script
.
containsKey
(
"CAN_GO_SITES"
))
if
(!
script
.
containsKey
(
"CAN_GO_SITES"
))
script
.
put
(
"CAN_GO_SITES"
,
"你可以去
%s
"
);
script
.
put
(
"CAN_GO_SITES"
,
"你可以去
[可去列表]
"
);
if
(!
script
.
containsKey
(
"CAN_GO_NOWHERE"
))
if
(!
script
.
containsKey
(
"CAN_GO_NOWHERE"
))
script
.
put
(
"CAN_GO_NOWHERE"
,
"没什么地方可去的,继续玩吧"
);
script
.
put
(
"CAN_GO_NOWHERE"
,
"没什么地方可去的,继续玩吧"
);
if
(!
script
.
containsKey
(
"SITE_NOT_ACTIVE"
))
if
(!
script
.
containsKey
(
"SITE_NOT_ACTIVE"
))
script
.
put
(
"SITE_NOT_ACTIVE"
,
"你来到了
%s\"
"
);
script
.
put
(
"SITE_NOT_ACTIVE"
,
"你来到了
[地点名]
"
);
if
(!
script
.
containsKey
(
"SITE_NOT_ADJOINT"
))
if
(!
script
.
containsKey
(
"SITE_NOT_ADJOINT"
))
script
.
put
(
"SITE_NOT_ADJOINT"
,
"通过
%s可以到达目的地
"
);
script
.
put
(
"SITE_NOT_ADJOINT"
,
"通过
[途径]可以到达[目的地]
"
);
if
(!
script
.
containsKey
(
"AROUND_PEOPLE"
))
if
(!
script
.
containsKey
(
"AROUND_PEOPLE"
))
script
.
put
(
"AROUND_PEOPLE"
,
"周围有
%s
"
);
script
.
put
(
"AROUND_PEOPLE"
,
"周围有
[人物列表]
"
);
if
(!
script
.
containsKey
(
"AROUND_ITEMS"
))
if
(!
script
.
containsKey
(
"AROUND_ITEMS"
))
script
.
put
(
"AROUND_ITEMS"
,
"周围有
%s
"
);
script
.
put
(
"AROUND_ITEMS"
,
"周围有
[物品列表]
"
);
if
(!
script
.
containsKey
(
"AROUND_THINGS"
))
if
(!
script
.
containsKey
(
"AROUND_THINGS"
))
script
.
put
(
"AROUND_THINGS"
,
"周围有%s"
);
script
.
put
(
"AROUND_THINGS"
,
"周围有[人物物品列表]"
);
if
(!
script
.
containsKey
(
"FIND_ITEM_LOCATION"
))
script
.
put
(
"FIND_ITEM_LOCATION"
,
"[物品名]在[地点]"
);
if
(!
script
.
containsKey
(
"FIND_NPC_LOCATION"
))
script
.
put
(
"FIND_NPC_LOCATION"
,
"[人名]在[地点]"
);
if
(!
script
.
containsKey
(
"AROUND_PLACE"
))
script
.
put
(
"AROUND_PLACE"
,
"周围有[地点列表]"
);
if
(!
script
.
containsKey
(
"FIND_ITEM_WAY"
))
script
.
put
(
"FIND_ITEM_WAY"
,
"[人名]在[地点]"
);
if
(!
script
.
containsKey
(
"FIND_NPC_WAY"
))
script
.
put
(
"FIND_NPC_WAY"
,
"[物品名]在[地点]"
);
if
(!
script
.
containsKey
(
"GET_ITEM_ATTR"
))
script
.
put
(
"GET_ITEM_ATTR"
,
"[物品名]的[属性名]是[属性值]"
);
if
(!
script
.
containsKey
(
"WE_HAVE"
))
script
.
put
(
"WE_HAVE"
,
"我们有[物品列表]"
);
if
(!
script
.
containsKey
(
"GET_NPC_ATTR"
))
script
.
put
(
"GET_NPC_ATTR"
,
"[人名]的[属性名]是[属性值]"
);
...
@@ -144,14 +165,14 @@ public class MapConstructor extends ElementConstructor {
...
@@ -144,14 +165,14 @@ public class MapConstructor extends ElementConstructor {
generateSurroundingItem
();
generateSurroundingItem
();
generateSurroundingPeople
();
generateSurroundingPeople
();
generateSurroundThings
();
generateSurroundThings
();
generateSurroundPlace
();
}
catch
(
Exception
e
){
}
catch
(
Exception
e
){
operationStatus
=
0
;
operationStatus
=
0
;
e
.
printStackTrace
();
e
.
printStackTrace
();
message
=
"地图处理出现异常:"
;
message
=
"地图处理出现异常:"
;
e
.
printStackTrace
();
message
+=
e
.
getMessage
();
message
+=
e
.
getMessage
();
return
;
return
;
}
}
...
@@ -162,19 +183,22 @@ public class MapConstructor extends ElementConstructor {
...
@@ -162,19 +183,22 @@ public class MapConstructor extends ElementConstructor {
* 生成‘我在哪里’所需要的配置文件
* 生成‘我在哪里’所需要的配置文件
*/
*/
public
void
generateWhereIam
(
JSONObject
gameElements
,
String
botAccount
)
{
public
void
generateWhereIam
(
JSONObject
gameElements
,
String
botAccount
)
{
String
conditionName
=
"rencheng"
;
String
conditionNameList
[]
=
{
"zainali"
,
"wenzainali"
};
String
conditionKeywords
=
""
;
String
nickname
=
"qiwu"
;
String
conditionKeywords
=
nickname
+
":哪里+"
+
nickname
+
":哪+现在:哪里+现在:哪"
;
for
(
String
condition:
conditionNameList
)
{
conditionKeywords
=
keywordMap
.
get
(
"map_"
+
condition
).
toString
();
jConfig
=
new
JConfig
(
jConfig
=
new
JConfig
(
conditionName
+
"::match-Include="
+
conditionKeywords
,
" "
,
condition
+
"::match-Include="
+
conditionKeywords
,
" "
,
"match"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
String
.
format
(
script
.
get
(
"WHERE_I_AM"
)
,
"{site-2}"
),
"yaobuyao"
,
""
"match"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
script
.
get
(
"WHERE_I_AM"
).
replace
(
"[地点名]"
,
"{site-2}"
),
"yaobuyao"
,
""
);
);
jConfig
.
setNextStepStatus
(
"return-0"
);
jConfig
.
setNextStepStatus
(
"return-0"
);
jConfig
.
setAuxiliaryPriority
(
"1"
);
jConfig
.
setAuxiliaryPriority
(
"1"
);
jConfigList
.
add
(
jConfig
);
JConfig
.
activateCopy
(
jConfig
,
jConfigList
,
"map"
);
}
}
}
...
@@ -188,7 +212,6 @@ public class MapConstructor extends ElementConstructor {
...
@@ -188,7 +212,6 @@ public class MapConstructor extends ElementConstructor {
*/
*/
public
void
generateHowToThere
(
int
[][]
pathMatirx
,
int
[][]
preTable
,
JSONObject
gameElements
)
{
public
void
generateHowToThere
(
int
[][]
pathMatirx
,
int
[][]
preTable
,
JSONObject
gameElements
)
{
String
conditionName
=
"want_know_zenmezuo"
;
String
conditionName
=
"want_know_zenmezuo"
;
String
conditionKeywords
=
"去:地点"
;
StringBuffer
placeKeywords
=
new
StringBuffer
();
StringBuffer
placeKeywords
=
new
StringBuffer
();
String
placeA
,
placeB
,
descriptionB
,
text
,
pathNode
;
String
placeA
,
placeB
,
descriptionB
,
text
,
pathNode
;
...
@@ -197,8 +220,6 @@ public class MapConstructor extends ElementConstructor {
...
@@ -197,8 +220,6 @@ public class MapConstructor extends ElementConstructor {
for
(
int
i
=
0
;
i
<
locationNum
;
i
++)
{
for
(
int
i
=
0
;
i
<
locationNum
;
i
++)
{
placeA
=
(
String
)
locations
.
getJSONObject
(
i
).
get
(
"name"
);
placeA
=
(
String
)
locations
.
getJSONObject
(
i
).
get
(
"name"
);
placeKeywords
.
append
(
"+"
+
placeA
);
placeKeywords
.
append
(
"+"
+
placeA
);
}
}
for
(
int
j
=
0
;
j
<
locationNum
;
j
++)
{
for
(
int
j
=
0
;
j
<
locationNum
;
j
++)
{
...
@@ -211,13 +232,13 @@ public class MapConstructor extends ElementConstructor {
...
@@ -211,13 +232,13 @@ public class MapConstructor extends ElementConstructor {
+
",isNeighbour:"
+
conditionName
+
"::match-Include=0"
,
+
",isNeighbour:"
+
conditionName
+
"::match-Include=0"
,
"site::match-Include="
+
placeB
,
"site::match-Include="
+
placeB
,
"match,return-0"
,
"match,return-0"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
String
.
format
(
script
.
get
(
"PATH_AT"
)
,
"{site-2}"
),
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
script
.
get
(
"PATH_AT"
).
replace
(
"[地点名]"
,
"{site-2}"
),
" "
,
" "
,
""
""
);
);
jConfig
.
setNextStepStatus
(
"return-0"
);
jConfig
.
setNextStepStatus
(
"return-0"
);
jConfig
.
setAuxiliaryPriority
(
"1"
);
jConfig
.
setAuxiliaryPriority
(
"1"
);
jConfigList
.
add
(
jConfig
);
JConfig
.
activateCopy
(
jConfig
,
jConfigList
,
"map"
);
...
@@ -225,16 +246,16 @@ public class MapConstructor extends ElementConstructor {
...
@@ -225,16 +246,16 @@ public class MapConstructor extends ElementConstructor {
jConfig
=
new
JConfig
(
jConfig
=
new
JConfig
(
conditionName
+
"::match-Include="
+
placeKeywords
conditionName
+
"::match-Include="
+
placeKeywords
+
",isNeighbour:"
+
conditionName
+
"::match-Include=1
"
,
+
",isNeighbour:"
+
conditionName
+
"::match-Include=1+3+4
"
,
"site::match-Include="
+
placeB
,
"site::match-Include="
+
placeB
,
"match,return-0"
,
"match,return-0"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
String
.
format
(
script
.
get
(
"PATH_ADJOINT"
),
"{site-2}
"
),
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
script
.
get
(
"PATH_ADJOINT
"
),
" "
,
" "
,
""
""
);
);
jConfig
.
setNextStepStatus
(
"return-0"
);
jConfig
.
setNextStepStatus
(
"return-0"
);
jConfig
.
setAuxiliaryPriority
(
"1"
);
jConfig
.
setAuxiliaryPriority
(
"1"
);
jConfigList
.
add
(
jConfig
);
JConfig
.
activateCopy
(
jConfig
,
jConfigList
,
"map"
);
...
@@ -244,14 +265,13 @@ public class MapConstructor extends ElementConstructor {
...
@@ -244,14 +265,13 @@ public class MapConstructor extends ElementConstructor {
+
",isNeighbour:"
+
conditionName
+
"::match-Include=2"
,
+
",isNeighbour:"
+
conditionName
+
"::match-Include=2"
,
"site::match-Include="
+
placeB
,
"site::match-Include="
+
placeB
,
"match,return-0"
,
"match,return-0"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
"{map_reply-2}"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
"{map_reply-2}"
,
" "
,
" "
,
"map_reply:queryHowToPathBySite:"
+
conditionName
"map_reply:queryHowToPathBySite:"
+
conditionName
);
);
jConfig
.
setNextStepStatus
(
"return-0"
);
jConfig
.
setNextStepStatus
(
"return-0"
);
jConfig
.
setAuxiliaryPriority
(
"1"
);
jConfig
.
setAuxiliaryPriority
(
"1"
);
jConfigList
.
add
(
jConfig
);
JConfig
.
activateCopy
(
jConfig
,
jConfigList
,
"map"
);
}
}
...
@@ -262,29 +282,20 @@ public class MapConstructor extends ElementConstructor {
...
@@ -262,29 +282,20 @@ public class MapConstructor extends ElementConstructor {
* 生成‘我能去哪里’所需要的配置文件
* 生成‘我能去哪里’所需要的配置文件
*/
*/
public
void
generateWhereCanIgo
(
int
[][]
pathMatirx
,
int
[][]
preTable
,
JSONObject
gameElements
)
{
public
void
generateWhereCanIgo
(
int
[][]
pathMatirx
,
int
[][]
preTable
,
JSONObject
gameElements
)
{
String
conditionKeywords
=
"去:哪里+能去:哪+能去:哪里+能去:哪儿"
;
String
conditionName
=
"choose_gowhere"
;
String
conditionName
=
"choose_gowhere"
;
String
conditionKeywords
=
keywordMap
.
get
(
"map_"
+
conditionName
).
toString
();
String
placeA
,
placeB
,
pathNode
;
String
placeA
,
placeB
,
pathNode
;
for
(
int
i
=
0
;
i
<
locationNum
;
i
++)
{
placeA
=
(
String
)
locations
.
getJSONObject
(
i
).
get
(
"name"
);
pathNode
=
""
;
for
(
int
j
=
0
;
j
<
locationNum
;
j
++)
{
if
(
pathMatirx
[
i
][
j
]
==
1
)
{
placeB
=
(
String
)
locations
.
getJSONObject
(
j
).
get
(
"name"
);
pathNode
+=
"、"
+
placeB
;
}
}
jConfig
=
new
JConfig
(
jConfig
=
new
JConfig
(
conditionName
+
"::match-Include="
+
conditionKeywords
,
"site::match-Include="
+
placeA
,
conditionName
+
"::match-Include="
+
conditionKeywords
,
" "
,
"match,return-0"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
"{map_reply-2}"
,
" "
,
"map_reply:queryCanGoBySite:"
"match,return-0"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
"{map_reply-2}"
,
" "
,
"map_reply:queryCanGoBySite:"
);
);
jConfig
.
setNextStepStatus
(
"return-0"
);
jConfig
.
setNextStepStatus
(
"return-0"
);
jConfig
.
setAuxiliaryPriority
(
"1"
);
jConfig
.
setAuxiliaryPriority
(
"1"
);
jConfigList
.
add
(
jConfig
);
JConfig
.
activateCopy
(
jConfig
,
jConfigList
,
"map"
);
}
}
}
...
@@ -308,7 +319,7 @@ public class MapConstructor extends ElementConstructor {
...
@@ -308,7 +319,7 @@ public class MapConstructor extends ElementConstructor {
String
placeAMain
=
placeA
.
split
(
"\\+"
)[
0
];
String
placeAMain
=
placeA
.
split
(
"\\+"
)[
0
];
if
(!
varInitialMap
.
containsKey
(
"任务线"
+
placeAMain
+
"最后一个condition"
))
{
if
(!
varInitialMap
.
containsKey
(
"任务线"
+
placeAMain
+
"最后一个condition"
))
{
varInitialMap
.
put
(
"任务线"
+
placeAMain
+
"最后一个condition"
,
"yaobuyao"
);
varInitialMap
.
put
(
"任务线"
+
placeAMain
+
"最后一个condition"
,
"yaobuyao"
);
varInitialMap
.
put
(
"任务线"
+
placeAMain
+
"最后的回答"
,
"你来到了"
+
placeAMain
+
",现在什么都没有, 请继续之前的剧情,接着往下玩吧!"
);
varInitialMap
.
put
(
"任务线"
+
placeAMain
+
"最后的回答"
,
script
.
get
(
"SITE_NOT_ACTIVE"
).
replace
(
"[地点名]"
,
placeAMain
)
);
conditionDescription
.
put
(
"任务线"
+
placeAMain
+
"最后一个condition"
,
"任务线"
+
placeAMain
+
"最后一个condition"
);
conditionDescription
.
put
(
"任务线"
+
placeAMain
+
"最后一个condition"
,
"任务线"
+
placeAMain
+
"最后一个condition"
);
conditionDescription
.
put
(
"任务线"
+
placeAMain
+
"最后的回答"
,
"任务线"
+
placeAMain
+
"最后的回答"
);
conditionDescription
.
put
(
"任务线"
+
placeAMain
+
"最后的回答"
,
"任务线"
+
placeAMain
+
"最后的回答"
);
}
}
...
@@ -328,22 +339,33 @@ public class MapConstructor extends ElementConstructor {
...
@@ -328,22 +339,33 @@ public class MapConstructor extends ElementConstructor {
+
",isNeighbour:"
+
conditionName
+
"::match-Include=0"
,
+
",isNeighbour:"
+
conditionName
+
"::match-Include=0"
,
"site::match-Include="
+
placeA
,
"site::match-Include="
+
placeA
,
"match,return-0"
,
"match,return-0"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
String
.
format
(
script
.
get
(
"PATH_AT"
),
placeBMain
),
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
script
.
get
(
"PATH_AT"
).
replace
(
"[地点名]"
,
placeBMain
),
" "
,
" "
,
""
""
);
);
jConfig
.
set
AuxiliaryPriority
(
"1"
);
jConfig
.
set
ConfigName
(
"map"
,
true
);
jConfigList
.
add
(
jConfig
);
jConfigList
.
add
(
jConfig
);
jConfig
=
new
JConfig
(
jConfig
=
new
JConfig
(
conditionName
+
"::match-Include="
+
placeKeywords
+
","
+
",isNeighbour:"
+
conditionName
+
"::match-Include=1"
,
conditionName
+
"::match-Include="
+
placeKeywords
+
","
+
",isNeighbour:"
+
conditionName
+
"::match-Include=1
+3+4
"
,
"site::match-Include="
+
placeA
,
"site::match-Include="
+
placeA
,
"match, reutrn-0"
,
"{"
+
lastTaskReply
+
"-2}"
,
"yaobuyao"
,
"site:"
+
placeBMain
+
"-<-process-nextStep:var={"
+
lastTaskCondition
+
"-2}"
"match, reutrn-0,activate"
,
"{"
+
lastTaskReply
+
"-2}"
,
"plot_"
+
placeBMain
+
"_*"
,
""
);
);
jConfig
.
setAuxiliaryPriority
(
"1"
);
jConfig
.
setConfigName
(
"map"
,
true
);
jConfigList
.
add
(
jConfig
);
//上一个配置文件激活时的默认选项
jConfig
=
new
JConfig
(
" "
,
" "
,
""
,
"{"
+
lastTaskReply
+
"-2}"
,
" "
,
"process-nextStep:var={"
+
lastTaskCondition
+
"-2}-<-site:"
+
placeBMain
+
"-<-npc_update:updateFollowerLocation:"
+
placeBMain
);
jConfig
.
setStatus
(
"sleeping"
);
jConfig
.
setConfigName
(
"plot_"
+
placeBMain
+
"_doudi"
,
false
);
jConfig
.
setjStatus
(
1
);
jConfigList
.
add
(
jConfig
);
jConfigList
.
add
(
jConfig
);
...
@@ -353,11 +375,11 @@ public class MapConstructor extends ElementConstructor {
...
@@ -353,11 +375,11 @@ public class MapConstructor extends ElementConstructor {
+
",isNeighbour:"
+
conditionName
+
"::match-Include=2"
,
+
",isNeighbour:"
+
conditionName
+
"::match-Include=2"
,
"site::match-Include="
+
placeA
,
"site::match-Include="
+
placeA
,
"match,return-0"
,
"match,return-0"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
"{map_reply-2}"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
"{map_reply-2}"
,
" "
,
" "
,
"map_reply:queryToDoPathBySite:"
+
conditionName
"map_reply:queryToDoPathBySite:"
+
conditionName
);
);
jConfig
.
set
AuxiliaryPriority
(
"1"
);
jConfig
.
set
ConfigName
(
"map"
,
true
);
jConfigList
.
add
(
jConfig
);
jConfigList
.
add
(
jConfig
);
}
}
...
@@ -367,41 +389,51 @@ public class MapConstructor extends ElementConstructor {
...
@@ -367,41 +389,51 @@ public class MapConstructor extends ElementConstructor {
public
void
generateSurroundingPeople
(){
public
void
generateSurroundingPeople
(){
String
conditionName
=
"know_exist_what"
;
String
conditionName
=
"know_exist_what"
;
String
conditionKeywords
=
"周围:人+附近:人"
;
String
conditionKeywords
=
keywordMap
.
get
(
"people_"
+
conditionName
).
toString
()
;
jConfig
=
new
JConfig
(
jConfig
=
new
JConfig
(
conditionName
+
"::match-Include="
+
conditionKeywords
,
" "
,
conditionName
+
"::match-Include="
+
conditionKeywords
,
" "
,
"match,return-0"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
"{map_query-2}。"
,
"yaobuyao"
,
"map_query:queryAroundNpcBySite:"
"match,return-0"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
"{map_query-2}。"
,
"yaobuyao"
,
"map_query:queryAroundNpcBySite:"
);
);
jConfig
.
setAuxiliaryPriority
(
"1"
);
JConfig
.
activateCopy
(
jConfig
,
jConfigList
,
"map"
);
jConfigList
.
add
(
jConfig
);
}
}
public
void
generateSurroundingItem
(){
public
void
generateSurroundingItem
(){
String
conditionName
=
"know_exist_what"
;
String
conditionName
=
"know_exist_what"
;
String
conditionKeywords
=
"周围:物品+周围:东西+附近:物品+附近:东西"
;
String
conditionKeywords
=
keywordMap
.
get
(
"item_"
+
conditionName
).
toString
()
;
jConfig
=
new
JConfig
(
jConfig
=
new
JConfig
(
conditionName
+
"::match-Include="
+
conditionKeywords
,
" "
,
conditionName
+
"::match-Include="
+
conditionKeywords
,
" "
,
"match,return-0"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
"{map_query-2}。"
,
"yaobuyao"
,
"map_query:queryAroundGoodsBySite:"
"match,return-0"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
"{map_query-2}。"
,
"yaobuyao"
,
"map_query:queryAroundGoodsBySite:"
);
);
jConfig
.
setAuxiliaryPriority
(
"1"
);
JConfig
.
activateCopy
(
jConfig
,
jConfigList
,
"map"
);
jConfigList
.
add
(
jConfig
);
}
}
public
void
generateSurroundThings
(){
public
void
generateSurroundThings
(){
String
conditionName
=
"know_exist_what_mohu"
;
String
conditionName
=
"know_exist_what_mohu"
;
String
conditionKeywords
=
"有什么:周围+有什么:附近"
;
String
conditionKeywords
=
keywordMap
.
get
(
"things_"
+
conditionName
).
toString
()
;
jConfig
=
new
JConfig
(
jConfig
=
new
JConfig
(
conditionName
+
"::match-Include="
+
conditionKeywords
,
" "
,
conditionName
+
"::match-Include="
+
conditionKeywords
,
" "
,
"match,return-0"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
"{map_query-2}。"
,
"yaobuyao"
,
"map_query:queryAroundAllBySite:"
"match,return-0"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
"{map_query-2}。"
,
"yaobuyao"
,
"map_query:queryAroundAllBySite:"
);
);
jConfig
.
setAuxiliaryPriority
(
"1"
);
JConfig
.
activateCopy
(
jConfig
,
jConfigList
,
"map"
);
jConfigList
.
add
(
jConfig
);
}
public
void
generateSurroundPlace
(){
String
conditionName
=
"know_exist_what"
;
String
conditionKeywords
=
keywordMap
.
get
(
"place_"
+
conditionName
).
toString
();
jConfig
=
new
JConfig
(
conditionName
+
"::match-Include="
+
conditionKeywords
,
" "
,
"match,return-0"
,
"【{"
+
PlotConstructor
.
ASSISTANT
+
"-2}】"
+
"{map_reply-2}"
,
" "
,
"map_reply:queryCanGoBySite:"
);
jConfig
.
setNextStepStatus
(
"return-0"
);
JConfig
.
activateCopy
(
jConfig
,
jConfigList
,
"map"
);
}
}
...
...
src/gameDesign/PlotConstructor.java
View file @
15fa3483
...
@@ -27,6 +27,7 @@ public class PlotConstructor extends ElementConstructor {
...
@@ -27,6 +27,7 @@ public class PlotConstructor extends ElementConstructor {
HashMap
<
String
,
Boolean
>
visited
=
new
HashMap
<
String
,
Boolean
>();
HashMap
<
String
,
Boolean
>
visited
=
new
HashMap
<
String
,
Boolean
>();
public
static
String
TASK_LINE
=
"任务线_%s进度"
;
public
static
String
TASK_LINE
=
"任务线_%s进度"
;
public
static
String
TASK_CONDITION
=
"任务线%s最后一个condition"
;
public
static
String
TASK_CONDITION
=
"任务线%s最后一个condition"
;
public
static
String
TASK_REPLY
=
"任务线%s最后的回答"
;
public
static
String
TASK_REPLY
=
"任务线%s最后的回答"
;
...
@@ -35,13 +36,13 @@ public class PlotConstructor extends ElementConstructor {
...
@@ -35,13 +36,13 @@ public class PlotConstructor extends ElementConstructor {
return
id2j
;
return
id2j
;
}
}
public
PlotConstructor
(
SqlHelper
helper
,
int
botId
,
int
skipCount
,
String
botAccount
,
HashSet
<
String
>
exceptRelation
,
StringBuffer
POS
)
{
public
PlotConstructor
(
SqlHelper
helper
,
int
botId
,
String
botAccount
,
Map
<
String
,
StringBuffer
>
keywordMap
,
HashSet
<
String
>
exceptRelation
,
StringBuffer
POS
)
{
super
();
super
();
this
.
helper
=
helper
;
this
.
helper
=
helper
;
this
.
botId
=
botId
;
this
.
botId
=
botId
;
this
.
botAccount
=
botAccount
;
this
.
botAccount
=
botAccount
;
this
.
exceptRelation
=
exceptRelation
;
this
.
exceptRelation
=
exceptRelation
;
this
.
skipCount
=
skipCount
;
this
.
keywordMap
=
keywordMap
;
this
.
POS
=
POS
;
this
.
POS
=
POS
;
}
}
...
@@ -256,7 +257,13 @@ public class PlotConstructor extends ElementConstructor {
...
@@ -256,7 +257,13 @@ public class PlotConstructor extends ElementConstructor {
lastTaskReply
=
"任务线"
+
nextLocation
+
"最后的回答"
;
lastTaskReply
=
"任务线"
+
nextLocation
+
"最后的回答"
;
//额外条件是任务线进度达到当前剧情,额外更新变量是将任务线移动至下一剧情
/**
* 额外条件是任务线进度达到当前剧情,额外更新变量是将任务线移动至下一剧情
* 如果某个地点的剧情已经到结尾啦,那么有两种解决方法:
* 1: 将剧情停留在最后一步剧情
* 2. 设一个专门的剧情表示剧情的结尾
*/
extraHP
=
taskLineName
+
"::match-Include="
+
id
+
",site::match-Include="
+
location
+
","
+
id
+
"::number-BiggerOrEqual="
+
1
;
extraHP
=
taskLineName
+
"::match-Include="
+
id
+
",site::match-Include="
+
location
+
","
+
id
+
"::number-BiggerOrEqual="
+
1
;
if
(!
id
.
equals
(
nextId
)){
if
(!
id
.
equals
(
nextId
)){
extraHP
+=
","
+
nextId
+
"::match-Include=null"
;
extraHP
+=
","
+
nextId
+
"::match-Include=null"
;
...
@@ -342,7 +349,7 @@ public class PlotConstructor extends ElementConstructor {
...
@@ -342,7 +349,7 @@ public class PlotConstructor extends ElementConstructor {
//没有当前条件的限制,
//没有当前条件的限制,
if
(
curPremiseList
.
size
()
==
0
){
if
(
curPremiseList
.
size
()
==
0
){
jConfig
.
setFeature
(
jConfig
.
getFeature
()
+
",activate,post::gameQA("
+
QA_URL
+
")"
);
jConfig
.
setFeature
(
jConfig
.
getFeature
()
+
",activate,post::gameQA("
+
QA_URL
+
")"
);
jConfig
.
setNextStep
(
"queryskip*,map*"
);
jConfig
.
setNextStep
(
"queryskip*,map*
,item*,npc*
"
);
jConfig
.
setUpdateKnowledge
(
jConfig
.
getUpdateKnowledge
()
+
"-<-临时变量condition:"
+
nextCondition
+
"-<-临时变量reply:var={reply-3}"
);
jConfig
.
setUpdateKnowledge
(
jConfig
.
getUpdateKnowledge
()
+
"-<-临时变量condition:"
+
nextCondition
+
"-<-临时变量reply:var={reply-3}"
);
jConfig
.
setNextStepStatus
(
"active"
);
jConfig
.
setNextStepStatus
(
"active"
);
}
}
...
@@ -350,8 +357,6 @@ public class PlotConstructor extends ElementConstructor {
...
@@ -350,8 +357,6 @@ public class PlotConstructor extends ElementConstructor {
jConfigList
.
add
(
jConfig
);
jConfigList
.
add
(
jConfig
);
...
...
src/processing/FormsPoster.java
View file @
15fa3483
...
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
...
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
import
com.qiwu.chatbotbackend.GameEnvironment.GameEnv
;
import
com.qiwu.chatbotbackend.GameEnvironment.GameEnv
;
import
com.qiwu.chatbotbackend.entity.Condition
;
import
com.qiwu.chatbotbackend.entity.Condition
;
import
com.qiwu.chatbotbackend.entity.Solution
;
import
com.qiwu.chatbotbackend.entity.Solution
;
import
com.qiwu.chatbotbackend.entity.UserInfo
;
import
org.apache.http.message.BasicNameValuePair
;
import
org.apache.http.message.BasicNameValuePair
;
import
java.io.UnsupportedEncodingException
;
import
java.io.UnsupportedEncodingException
;
...
@@ -89,8 +90,7 @@ public class FormsPoster {
...
@@ -89,8 +90,7 @@ public class FormsPoster {
}
}
}
}
}
else
{
}
else
{
if
(
URL
.
equals
(
QA_URL
if
(
URL
.
equals
(
QA_URL
))
))
ans
.
setAnswer
(
"qa_threshold, game_step, query_text 看看少了哪个"
);
ans
.
setAnswer
(
"qa_threshold, game_step, query_text 看看少了哪个"
);
else
else
ans
.
setAnswer
(
"提交表单出现异常"
);
ans
.
setAnswer
(
"提交表单出现异常"
);
...
@@ -170,7 +170,7 @@ public class FormsPoster {
...
@@ -170,7 +170,7 @@ public class FormsPoster {
* @param URL
* @param URL
* @throws UnsupportedEncodingException
* @throws UnsupportedEncodingException
*/
*/
public
void
postGameQA
(
Map
<
String
,
String
>
curInfoPoint
,
Map
<
String
,
String
>
historyInfoPoint
,
Solution
ans
,
GameEnv
gameEnv
,
WorldController
worldController
,
String
URL
)
throws
UnsupportedEncodingException
{
public
void
postGameQA
(
Map
<
String
,
String
>
curInfoPoint
,
Map
<
String
,
String
>
historyInfoPoint
,
Solution
ans
,
GameEnv
gameEnv
,
WorldController
worldController
,
String
URL
,
UserInfo
userInfo
)
throws
UnsupportedEncodingException
{
String
key
,
keyName
;
String
key
,
keyName
;
Iterator
<
String
>
k_iter
=
null
;
Iterator
<
String
>
k_iter
=
null
;
List
<
BasicNameValuePair
>
pairList
=
new
ArrayList
<
BasicNameValuePair
>();
List
<
BasicNameValuePair
>
pairList
=
new
ArrayList
<
BasicNameValuePair
>();
...
@@ -206,7 +206,8 @@ public class FormsPoster {
...
@@ -206,7 +206,8 @@ public class FormsPoster {
Matcher
m
=
findTalker
.
matcher
(
textscore
.
get
(
0
));
Matcher
m
=
findTalker
.
matcher
(
textscore
.
get
(
0
));
if
(
m
.
find
())
{
if
(
m
.
find
())
{
npc
=
m
.
group
(
1
);
npc
=
m
.
group
(
1
);
if
(
worldController
.
worldOperation
(
gameEnv
,
"NPC_query"
,
"queryLocationByNPCName:"
+
npc
,
curInfoPoint
,
historyInfoPoint
).
equals
(
site
)){
if
(
worldController
.
worldOperation
(
gameEnv
,
"npc_query"
,
"queryLocationByNPCName:"
+
npc
,
curInfoPoint
,
historyInfoPoint
).
equals
(
userInfo
.
varInitialMap
.
get
(
"FIND_NPC_LOCATION"
).
replace
(
"[人名]"
,
npc
).
replace
(
"[地点]"
,
historyInfoPoint
.
get
(
"site"
)))){
historyInfoPoint
.
put
(
"common_answer"
,
textscore
.
get
(
0
));
historyInfoPoint
.
put
(
"common_answer"
,
textscore
.
get
(
0
));
historyInfoPoint
.
put
(
"qa_score"
,
String
.
valueOf
(
textscore
.
get
(
1
)));
historyInfoPoint
.
put
(
"qa_score"
,
String
.
valueOf
(
textscore
.
get
(
1
)));
break
;
break
;
...
...
src/processing/MyFunc.java
View file @
15fa3483
...
@@ -191,5 +191,22 @@ public class MyFunc {
...
@@ -191,5 +191,22 @@ public class MyFunc {
}
}
public
static
String
randStr
(
String
strList
[]){
String
reply
;
int
randNum
=
(
int
)
(
Math
.
random
()
*
strList
.
length
);
reply
=
strList
[
randNum
];
return
reply
;
}
public
static
String
randStr
(
List
<
String
>
strList
){
String
reply
;
int
randNum
=
(
int
)
(
Math
.
random
()
*
strList
.
size
());
reply
=
strList
.
get
(
randNum
);
return
reply
;
}
}
}
\ No newline at end of file
src/processing/QuestionMatcher.java
View file @
15fa3483
...
@@ -5,6 +5,7 @@ import com.qiwu.chatbotbackend.GameEnvironment.GameEnv;
...
@@ -5,6 +5,7 @@ import com.qiwu.chatbotbackend.GameEnvironment.GameEnv;
import
com.qiwu.chatbotbackend.entity.Solution
;
import
com.qiwu.chatbotbackend.entity.Solution
;
import
com.qiwu.chatbotbackend.entity.Condition
;
import
com.qiwu.chatbotbackend.entity.Condition
;
import
com.qiwu.chatbotbackend.entity.UserInfo
;
import
com.qiwu.chatbotbackend.entity.UserInfo
;
import
com.qiwu.chatbotbackend.gameDesign.GameUtil
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.HttpResponse
;
...
@@ -70,7 +71,7 @@ public class QuestionMatcher {
...
@@ -70,7 +71,7 @@ public class QuestionMatcher {
public
boolean
infoPointPreprocessing
(
Map
<
String
,
String
[]>
receiveParameters
,
Map
<
String
,
String
>
curInfoPoint
,
Map
<
String
,
String
>
historyInfoPoint
,
UserInfo
userinfo
,
ServletContext
context
)
throws
IOException
{
public
boolean
infoPointPreprocessing
(
Map
<
String
,
String
[]>
receiveParameters
,
Map
<
String
,
String
>
curInfoPoint
,
Map
<
String
,
String
>
historyInfoPoint
,
UserInfo
userinfo
,
ServletContext
context
)
throws
IOException
{
String
return_str
=
""
,
k
;
String
return_str
=
""
,
k
,
botType
=
""
;
String
receiveParameterStr
=
""
;
String
receiveParameterStr
=
""
;
boolean
debugFlag
=
false
;
boolean
debugFlag
=
false
;
...
@@ -94,7 +95,7 @@ public class QuestionMatcher {
...
@@ -94,7 +95,7 @@ public class QuestionMatcher {
receiveParameterStr
+=
k
+
": "
;
receiveParameterStr
+=
k
+
": "
;
curInfoPoint
.
put
(
k
,
receiveParameters
.
get
(
k
)[
0
]);
curInfoPoint
.
put
(
k
,
receiveParameters
.
get
(
k
)[
0
]);
if
(
k
.
equals
(
"debug_mode"
))
if
(
k
.
equals
(
"debug_mode"
)
||
k
.
equals
(
"debug_rule"
)
)
debugFlag
=
true
;
debugFlag
=
true
;
String
values
[]
=
receiveParameters
.
get
(
k
);
String
values
[]
=
receiveParameters
.
get
(
k
);
...
@@ -104,11 +105,13 @@ public class QuestionMatcher {
...
@@ -104,11 +105,13 @@ public class QuestionMatcher {
// }
// }
receiveParameterStr
+=
values
[
0
]
+
" "
+
"<br>"
;
receiveParameterStr
+=
values
[
0
]
+
" "
+
"<br>"
;
if
(
values
[
0
].
equals
(
":"
))
{
if
(
values
[
0
].
equals
(
":"
))
{
curInfoPoint
.
put
(
k
,
""
);
curInfoPoint
.
put
(
k
,
""
);
}
}
}
}
logWriter
.
record
(
receiveParameterStr
,
0
);
logWriter
.
record
(
receiveParameterStr
,
0
);
System
.
out
.
println
(
receiveParameterStr
.
toString
());
//如果引擎什么信息都没识别到,那就将上一轮的nextStep(也就是当前轮的actionName)设为unknown
//如果引擎什么信息都没识别到,那就将上一轮的nextStep(也就是当前轮的actionName)设为unknown
iit
=
curInfoPoint
.
keySet
().
iterator
();
iit
=
curInfoPoint
.
keySet
().
iterator
();
...
@@ -146,6 +149,20 @@ public class QuestionMatcher {
...
@@ -146,6 +149,20 @@ public class QuestionMatcher {
logWriter
.
record
(
"historyInfoPoint:"
+
historyInfoPoint
.
toString
(),
1
);
logWriter
.
record
(
"historyInfoPoint:"
+
historyInfoPoint
.
toString
(),
1
);
//根据bot类型做预处理
if
(
userinfo
.
varInitialMap
.
get
(
"botType"
)
!=
null
)
botType
=
userinfo
.
varInitialMap
.
get
(
"botType"
);
switch
(
botType
){
case
"game"
:
GameUtil
util
=
new
GameUtil
(
gameEnv
,
worldController
,
curInfoPoint
,
historyInfoPoint
);
util
.
gamePreprocessing
(
logWriter
);
break
;
}
return
debugFlag
;
return
debugFlag
;
}
}
...
@@ -187,18 +204,17 @@ public class QuestionMatcher {
...
@@ -187,18 +204,17 @@ public class QuestionMatcher {
if
(
conditionSatisfy
(
condition
)){
if
(
conditionSatisfy
(
condition
)){
if
(
condition
.
featureMap
.
get
(
"activate"
)
!=
null
&&
!
condition
.
featureMap
.
containsKey
(
"post"
))
{
if
(
condition
.
featureMap
.
get
(
"activate"
)
!=
null
&&
!
condition
.
featureMap
.
containsKey
(
"post"
))
{
//有post这个feature的配置条目会在最后激活它的待激活列表,这里就不激活了。
//有post这个feature的配置条目会在最后激活它的待激活列表,这里就不激活了。
bestMatch
=
condition
;
logWriter
.
record
(
"匹配更新为:\""
+
userinfo
.
id2config
.
get
(
condition
.
id
)
+
"\""
,
2
);
logWriter
.
writeln
();
activateCondition
(
activatedQueue
,
curInfoPoint
.
get
(
"bot_name"
),
condition
.
priority
,
condition
.
auxiliaryPriority
,
condition
.
nextStep
,
context
);
activateCondition
(
activatedQueue
,
curInfoPoint
.
get
(
"bot_name"
),
condition
.
priority
,
condition
.
auxiliaryPriority
,
condition
.
nextStep
,
context
);
}
else
{
}
bestMatch
=
condition
;
bestMatch
=
condition
;
logWriter
.
record
(
"匹配更新为:\""
+
userinfo
.
id2config
.
get
(
condition
.
id
)
+
"\""
,
2
);
logWriter
.
record
(
"匹配更新为:\""
+
userinfo
.
id2config
.
get
(
condition
.
id
)
+
"\""
,
2
);
logWriter
.
writeln
();
logWriter
.
writeln
();
}
}
}
}
else
{
logWriter
.
record
(
"-----------------------------------优先级不足,跳过"
,
0
);
logWriter
.
record
(
userinfo
.
id2config
.
get
(
condition
.
id
),
1
);
}
}
}
}
/*
/*
...
@@ -252,20 +268,29 @@ public class QuestionMatcher {
...
@@ -252,20 +268,29 @@ public class QuestionMatcher {
condition
=
activatedQueue
.
remove
();
condition
=
activatedQueue
.
remove
();
activatedMap
.
remove
(
condition
.
id
);
activatedMap
.
remove
(
condition
.
id
);
if
(
conditionSatisfy
(
condition
))
{
if
(
condition
.
featureMap
.
containsKey
(
"activate"
)
&&
!
condition
.
featureMap
.
containsKey
(
"post"
))
{
if
((
condition
.
auxiliaryPriority
>
bestMatch
.
auxiliaryPriority
)
||
(
condition
.
auxiliaryPriority
==
bestMatch
.
auxiliaryPriority
&&
condition
.
activePriority
>
bestMatch
.
activePriority
)
logWriter
.
record
(
"匹配更新为:\""
+
userinfo
.
id2config
.
get
(
condition
.
id
)
+
"\""
,
2
);
logWriter
.
writeln
();
||
bestMatch
.
nextStep
.
contains
(
String
.
valueOf
(
condition
.
id
))
||
bestMatch
.
nextStep
.
contains
(
condition
.
configName
.
substring
(
0
,
3
))){
bestMatch
=
condition
;
//激活优先级先比较,但是如果激活的是无条件的就直接判断名字。
if
(
conditionSatisfy
(
condition
)){
if
(
condition
.
featureMap
.
get
(
"activate"
)
!=
null
&&
!
condition
.
featureMap
.
containsKey
(
"post"
))
{
activateCondition
(
activatedQueue
,
curInfoPoint
.
get
(
"bot_name"
),
condition
.
priority
,
condition
.
auxiliaryPriority
,
condition
.
nextStep
,
context
);
activateCondition
(
activatedQueue
,
curInfoPoint
.
get
(
"bot_name"
),
condition
.
priority
,
condition
.
auxiliaryPriority
,
condition
.
nextStep
,
context
);
//} else if ((condition.activePriority > bestMatch.activePriority) || (condition.activePriority == bestMatch.activePriority && condition.auxiliaryPriority > bestMatch.auxiliaryPriority)) {
}
}
else
if
((
condition
.
auxiliaryPriority
>
bestMatch
.
auxiliaryPriority
)
||
(
condition
.
auxiliaryPriority
==
bestMatch
.
auxiliaryPriority
&&
condition
.
activePriority
>
bestMatch
.
activePriority
)
||
bestMatch
.
nextStep
.
contains
(
String
.
valueOf
(
condition
.
id
))
||
bestMatch
.
nextStep
.
contains
(
condition
.
configName
))
{
bestMatch
=
condition
;
bestMatch
=
condition
;
logWriter
.
record
(
"匹配更新为:\""
+
userinfo
.
id2config
.
get
(
condition
.
id
)
+
"\""
,
2
);
logWriter
.
writeln
();
logWriter
.
record
(
"匹配更新为:\""
+
userinfo
.
id2config
.
get
(
condition
.
id
)
+
"\""
,
2
);
logWriter
.
writeln
();
}
}
}
else
{
logWriter
.
record
(
"-----------------------------------优先级不足,跳过"
,
0
);
logWriter
.
record
(
userinfo
.
id2config
.
get
(
condition
.
id
),
1
);
}
}
}
}
return
bestMatch
;
return
bestMatch
;
...
@@ -799,8 +824,7 @@ public class QuestionMatcher {
...
@@ -799,8 +824,7 @@ public class QuestionMatcher {
try
{
try
{
int
randNum
=
(
int
)
(
Math
.
random
()
*
ansCondition
.
answer
.
length
);
reply
=
MyFunc
.
randStr
(
ansCondition
.
answer
);
reply
=
ansCondition
.
answer
[
randNum
];
//用正则表达式将回答中的变量模板{conditionName-2}替换成后台存储的变量值
//用正则表达式将回答中的变量模板{conditionName-2}替换成后台存储的变量值
String
keyword
;
String
keyword
;
Matcher
m
=
replacePattern
.
matcher
(
reply
);
Matcher
m
=
replacePattern
.
matcher
(
reply
);
...
@@ -853,6 +877,8 @@ public class QuestionMatcher {
...
@@ -853,6 +877,8 @@ public class QuestionMatcher {
historyInfoPoint
.
put
(
"currentAction"
,
next
);
historyInfoPoint
.
put
(
"currentAction"
,
next
);
historyInfoPoint
.
put
(
"activeList"
,
historyInfoPoint
.
get
(
"activeList"
)
+
"|"
+
next
);
historyInfoPoint
.
put
(
"activeList"
,
historyInfoPoint
.
get
(
"activeList"
)
+
"|"
+
next
);
logWriter
.
record
(
"处理完成后的信息点:<br>"
+
historyInfoPoint
.
toString
(),
1
);
HashSet
<
String
>
skipSet
=
new
HashSet
<
String
>()
{
HashSet
<
String
>
skipSet
=
new
HashSet
<
String
>()
{
{
{
add
(
"chat_key"
);
add
(
"chat_key"
);
...
@@ -919,6 +945,9 @@ public class QuestionMatcher {
...
@@ -919,6 +945,9 @@ public class QuestionMatcher {
add
(
"bot_name"
);
add
(
"bot_name"
);
add
(
"action_name"
);
add
(
"action_name"
);
add
(
"lastReply"
);
add
(
"lastReply"
);
add
(
"unknownTextList"
);
add
(
"finalUnknownText"
);
add
(
"unknownText"
);
}
}
};
};
...
@@ -937,7 +966,10 @@ public class QuestionMatcher {
...
@@ -937,7 +966,10 @@ public class QuestionMatcher {
}
}
}
}
debugInfo
+=
")(已知:"
;
debugInfo
+=
")"
;
if
(
curInfoPoint
.
containsKey
(
"debug_mode"
))
{
debugInfo
=
debugInfo
.
replace
(
"-)"
,
""
);
debugInfo
+=
"(已知:"
;
it
=
historyInfoPoint
.
keySet
().
iterator
();
it
=
historyInfoPoint
.
keySet
().
iterator
();
while
(
it
.
hasNext
())
{
while
(
it
.
hasNext
())
{
...
@@ -947,6 +979,7 @@ public class QuestionMatcher {
...
@@ -947,6 +979,7 @@ public class QuestionMatcher {
debugInfo
+=
(
" "
+
key
+
":\'"
+
value
+
"\' "
);
debugInfo
+=
(
" "
+
key
+
":\'"
+
value
+
"\' "
);
}
}
}
ans
.
setAnswer
(
debugInfo
+
")</font>"
+
ans
.
getAnswer
());
ans
.
setAnswer
(
debugInfo
+
")</font>"
+
ans
.
getAnswer
());
}
}
...
@@ -978,98 +1011,12 @@ public class QuestionMatcher {
...
@@ -978,98 +1011,12 @@ public class QuestionMatcher {
postType
=
elem
[
1
];
postType
=
elem
[
1
];
// if (postType.equals("all")) {
// k_iter = curInfoPoint.keySet().iterator();
// while (k_iter.hasNext()) {
// key = k_iter.next();
// if (curInfoPoint.get(key) != "")
// //infoMap.put(key + "_cur", curInfoPoint.get(key)[0]);
// pairList.add(new BasicNameValuePair(key, curInfoPoint.get(key)));
// }
//
// k_iter = historyInfoPoint.keySet().iterator();
// while (k_iter.hasNext()) {
// key = k_iter.next();
// if (historyInfoPoint.get(key) != "")
// //infoMap.put(key + "_his", historyInfoPoint.get(key));
// if (key.equals("game_step"))
// pairList.add(new BasicNameValuePair(key, historyInfoPoint.get(key)));
// else if(skipSet.contains(key)){}
// else
// pairList.add(new BasicNameValuePair(key + "_his", historyInfoPoint.get(key)));
// }
//
// } else if (postType.equals("term")) {
// pairList.add(new BasicNameValuePair("chat_key", curInfoPoint.get("chat_key")));
// pairList.add(new BasicNameValuePair("action_name", curInfoPoint.get("action_name")));
// pairList.add(new BasicNameValuePair("bot_name", curInfoPoint.get("bot_name")));
// k_iter = ansCondition.currentPremise.keySet().iterator();
// while (k_iter.hasNext()) {
// key = k_iter.next().split("::")[0];
// if (curInfoPoint.get(key) != "")
// pairList.add(new BasicNameValuePair(key, curInfoPoint.get(key)));
// }
//
// k_iter = ansCondition.historyPremise.keySet().iterator();
// while (k_iter.hasNext()) {
// key = k_iter.next().split("::")[0];
// if (historyInfoPoint.get(key) != "")
// pairList.add(new BasicNameValuePair(key + "_his", historyInfoPoint.get(key)));
// //infoMap.put(key + "_his", historyInfoPoint.get(key));
// }
// }
//
// logWriter.record("提交表单的数据:<br>" + pairList.toString(), 2);
//
// HttpPost httpPost = new HttpPost(url);
// CloseableHttpClient client = HttpClients.createDefault();
// String respContent = null;
// String keyName = null;
//
//
// UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairList, "utf-8");
// entity.setContentType("application/x-www-form-urlencoded");
// httpPost.setEntity(entity);
//
// try {
// HttpResponse resp = client.execute(httpPost);
// if (resp.getStatusLine().getStatusCode() == 200) {
// HttpEntity he = resp.getEntity();
// respContent = EntityUtils.toString(he, "UTF-8");
// logWriter.record("提交表单接收到的数据:<br>" + respContent, 2);
// JSONObject jobj = JSONObject.parseObject(respContent);
// Iterator<String> kit = jobj.keySet().iterator();
//
// while (kit.hasNext()) {
// keyName = kit.next();
// if (keyName.equals("process")) {
// ans.setNext((String) jobj.get(keyName));
// historyInfoPoint.put("process", (String) jobj.get(keyName));
// } else if (keyName.equals("solution")) {
// ans.setAnswer((String) jobj.get(keyName));
// } else if (keyName.equals("status")){
// continue;
// } else{
// historyInfoPoint.put(keyName, jobj.getString(keyName));
// }
// }
// } else {
// ans.setAnswer(API_ERROR);
// }
// } catch (Exception e) {
// e.printStackTrace();
//
// ans.setAnswer(POST_ERROR + url);
// return ans;
// }
if
(
postType
.
equals
(
"all"
)){
if
(
postType
.
equals
(
"all"
)){
poster
.
postAll
(
curInfoPoint
,
historyInfoPoint
,
ans
,
url
);
poster
.
postAll
(
curInfoPoint
,
historyInfoPoint
,
ans
,
url
);
}
else
if
(
postType
.
equals
(
"term"
)){
}
else
if
(
postType
.
equals
(
"term"
)){
poster
.
postTerm
(
curInfoPoint
,
historyInfoPoint
,
ans
,
ansCondition
,
url
);
poster
.
postTerm
(
curInfoPoint
,
historyInfoPoint
,
ans
,
ansCondition
,
url
);
}
else
if
(
postType
.
equals
(
"gameQA"
)){
}
else
if
(
postType
.
equals
(
"gameQA"
)){
poster
.
postGameQA
(
curInfoPoint
,
historyInfoPoint
,
ans
,
gameEnv
,
worldController
,
url
);
poster
.
postGameQA
(
curInfoPoint
,
historyInfoPoint
,
ans
,
gameEnv
,
worldController
,
url
,
userinfo
);
}
}
return
ans
;
return
ans
;
...
@@ -1238,8 +1185,7 @@ public class QuestionMatcher {
...
@@ -1238,8 +1185,7 @@ public class QuestionMatcher {
}
else
if
(
updateValue
.
endsWith
(
"nextStep-3}"
))
{
}
else
if
(
updateValue
.
endsWith
(
"nextStep-3}"
))
{
updateValue
=
condition
.
nextStep
;
updateValue
=
condition
.
nextStep
;
}
else
if
(
updateValue
.
endsWith
(
"reply-3}"
))
{
}
else
if
(
updateValue
.
endsWith
(
"reply-3}"
))
{
int
randNum
=
(
int
)
(
Math
.
random
()
*
condition
.
answer
.
length
);
updateValue
=
MyFunc
.
randStr
(
condition
.
answer
);
updateValue
=
condition
.
answer
[
randNum
];
}
}
if
(
variableName
.
startsWith
(
"process-nextStep"
))
{
if
(
variableName
.
startsWith
(
"process-nextStep"
))
{
condition
.
nextStep
=
updateValue
;
condition
.
nextStep
=
updateValue
;
...
@@ -1276,6 +1222,7 @@ public class QuestionMatcher {
...
@@ -1276,6 +1222,7 @@ public class QuestionMatcher {
List
<
Condition
>
originConditionList
=
new
ArrayList
<
Condition
>();
List
<
Condition
>
originConditionList
=
new
ArrayList
<
Condition
>();
for
(
String
configIdStr
:
activateList
.
split
(
","
))
{
for
(
String
configIdStr
:
activateList
.
split
(
","
))
{
logWriter
.
record
(
"------激活-------"
+
configIdStr
+
"-------<br>"
,
0
);
try
{
try
{
if
(
StringUtils
.
isNumeric
(
configIdStr
))
{
if
(
StringUtils
.
isNumeric
(
configIdStr
))
{
configId
=
Integer
.
parseInt
(
configIdStr
);
configId
=
Integer
.
parseInt
(
configIdStr
);
...
@@ -1312,7 +1259,7 @@ public class QuestionMatcher {
...
@@ -1312,7 +1259,7 @@ public class QuestionMatcher {
newCondition
=
new
Condition
(
originCondition
,
basePriority
,
baseAuxiliaryPriority
);
newCondition
=
new
Condition
(
originCondition
,
basePriority
,
baseAuxiliaryPriority
);
//condition = QuestionMatcher.buildCondition(condition, configStr);
//condition = QuestionMatcher.buildCondition(condition, configStr);
logWriter
.
record
(
"------激活-------"
+
userinfo
.
id2config
.
get
(
configId
)
+
"-------<br>"
,
0
);
if
(
activatedMap
.
containsKey
(
configId
))
{
if
(
activatedMap
.
containsKey
(
configId
))
{
if
(
newCondition
.
auxiliaryPriority
>
activatedMap
.
get
(
configId
).
auxiliaryPriority
)
if
(
newCondition
.
auxiliaryPriority
>
activatedMap
.
get
(
configId
).
auxiliaryPriority
)
...
...
src/processing/ResponseFilter.java
View file @
15fa3483
...
@@ -6,6 +6,8 @@ import com.qiwu.chatbotbackend.entity.Solution;
...
@@ -6,6 +6,8 @@ import com.qiwu.chatbotbackend.entity.Solution;
import
com.qiwu.chatbotbackend.entity.UserInfo
;
import
com.qiwu.chatbotbackend.entity.UserInfo
;
import
com.qiwu.chatbotbackend.gameDesign.PlotConstructor
;
import
com.qiwu.chatbotbackend.gameDesign.PlotConstructor
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
...
@@ -27,10 +29,9 @@ public class ResponseFilter {
...
@@ -27,10 +29,9 @@ public class ResponseFilter {
String
site
=
historyInfoPoint
.
get
(
"site"
);
String
site
=
historyInfoPoint
.
get
(
"site"
);
String
answer
[]
=
reply
.
split
(
"~"
);
reply
=
MyFunc
.
randStr
(
reply
.
split
(
"~"
));
int
randNum
=
(
int
)
(
Math
.
random
()
*
answer
.
length
);
reply
=
answer
[
randNum
];
if
(
reply
.
startsWith
(
"【"
+
historyInfoPoint
.
get
(
PlotConstructor
.
ASSISTANT
)+
"】"
)
){
if
(
reply
.
startsWith
(
"【"
+
historyInfoPoint
.
get
(
PlotConstructor
.
ASSISTANT
))){
return
reply
;
return
reply
;
}
else
if
(
sameLocation
(
reply
,
curInfoPoint
,
historyInfoPoint
,
gameEnv
,
worldController
,
site
,
logWriter
)){
}
else
if
(
sameLocation
(
reply
,
curInfoPoint
,
historyInfoPoint
,
gameEnv
,
worldController
,
site
,
logWriter
)){
return
reply
;
return
reply
;
...
@@ -38,26 +39,43 @@ public class ResponseFilter {
...
@@ -38,26 +39,43 @@ public class ResponseFilter {
}
}
if
(
userInfo
.
varInitialMap
.
get
(
"unknownTextList"
)
!=
null
){
if
(
userInfo
.
varInitialMap
.
get
(
"unknownTextList"
)
!=
null
){
List
<
String
>
unknownList
=
new
ArrayList
<
String
>();
for
(
String
ans:
userInfo
.
varInitialMap
.
get
(
"unknownTextList"
).
split
(
"~"
)){
for
(
String
ans:
userInfo
.
varInitialMap
.
get
(
"unknownTextList"
).
split
(
"~"
)){
if
(
ans
.
equals
(
""
))
if
(
ans
.
equals
(
""
))
continue
;
continue
;
if
(
sameLocation
(
ans
,
curInfoPoint
,
historyInfoPoint
,
gameEnv
,
worldController
,
site
,
logWriter
)){
if
(
sameLocation
(
ans
,
curInfoPoint
,
historyInfoPoint
,
gameEnv
,
worldController
,
site
,
logWriter
)){
return
ans
;
unknownList
.
add
(
ans
);
//return ans;
}
}
}
}
if
(
unknownList
.
size
()
>
0
){
return
MyFunc
.
randStr
(
unknownList
);
}
}
}
if
(
userInfo
.
varInitialMap
.
get
(
"finalUnknownText"
)
!=
null
){
if
(
userInfo
.
varInitialMap
.
get
(
"finalUnknownText"
)
!=
null
){
finalUnknownText
=
userInfo
.
varInitialMap
.
get
(
"finalUnknownText"
);
finalUnknownText
=
userInfo
.
varInitialMap
.
get
(
"finalUnknownText"
);
if
(
sameLocation
(
finalUnknownText
,
curInfoPoint
,
historyInfoPoint
,
gameEnv
,
worldController
,
site
,
logWriter
)){
List
<
String
>
finalUnknownList
=
new
ArrayList
<
String
>();
return
finalUnknownText
;
for
(
String
ans:
finalUnknownText
.
split
(
"~"
)){
if
(
ans
.
equals
(
""
))
continue
;
if
(
sameLocation
(
ans
,
curInfoPoint
,
historyInfoPoint
,
gameEnv
,
worldController
,
site
,
logWriter
)){
finalUnknownList
.
add
(
ans
);
//return ans;
}
}
if
(
finalUnknownList
.
size
()
>
0
){
return
MyFunc
.
randStr
(
finalUnknownList
);
}
}
}
}
}
}
return
""
;
return
"
找不到匹配文本
"
;
}
}
static
Boolean
sameLocation
(
String
reply
,
Map
<
String
,
String
>
curInfoPoint
,
Map
<
String
,
String
>
historyInfoPoint
,
GameEnv
gameEnv
,
WorldController
worldController
,
String
site
,
LogWriter
logWriter
){
static
Boolean
sameLocation
(
String
reply
,
Map
<
String
,
String
>
curInfoPoint
,
Map
<
String
,
String
>
historyInfoPoint
,
GameEnv
gameEnv
,
WorldController
worldController
,
String
site
,
LogWriter
logWriter
){
...
@@ -66,7 +84,7 @@ public class ResponseFilter {
...
@@ -66,7 +84,7 @@ public class ResponseFilter {
Matcher
m
=
findTalker
.
matcher
(
reply
);
Matcher
m
=
findTalker
.
matcher
(
reply
);
if
(
m
.
find
())
{
if
(
m
.
find
())
{
npc
=
m
.
group
(
1
);
npc
=
m
.
group
(
1
);
if
(
worldController
.
worldOperation
(
gameEnv
,
"
NPC
_query"
,
"queryLocationByNPCName:"
+
npc
,
curInfoPoint
,
historyInfoPoint
).
equals
(
site
)){
if
(
worldController
.
worldOperation
(
gameEnv
,
"
npc
_query"
,
"queryLocationByNPCName:"
+
npc
,
curInfoPoint
,
historyInfoPoint
).
equals
(
site
)){
return
true
;
return
true
;
}{
}{
logWriter
.
record
(
npc
+
"不在"
+
site
+
"跳过"
,
1
);
logWriter
.
record
(
npc
+
"不在"
+
site
+
"跳过"
,
1
);
...
...
src/processing/WorldController.java
View file @
15fa3483
...
@@ -26,7 +26,7 @@ public class WorldController {
...
@@ -26,7 +26,7 @@ public class WorldController {
logWriter
.
record
(
String
.
format
(
"---------------------key:%s, value:%s"
,
varName
,
varValue
),
0
);
logWriter
.
record
(
String
.
format
(
"---------------------key:%s, value:%s"
,
varName
,
varValue
),
0
);
String
location
=
""
,
value
=
""
;
if
(
valuePair
[
0
].
startsWith
(
"query"
)){
//查询专用
if
(
valuePair
[
0
].
startsWith
(
"query"
)){
//查询专用
if
(
varName
.
startsWith
(
"goods_"
))
{
if
(
varName
.
startsWith
(
"goods_"
))
{
...
@@ -40,10 +40,14 @@ public class WorldController {
...
@@ -40,10 +40,14 @@ public class WorldController {
case
"queryAttrByGoodsName"
:
case
"queryAttrByGoodsName"
:
subValuePair
=
currentInfoPoint
.
get
(
valuePair
[
1
]).
split
(
":"
,
2
);
subValuePair
=
currentInfoPoint
.
get
(
valuePair
[
1
]).
split
(
":"
,
2
);
subValuePair
[
0
]
=
subValuePair
[
0
].
replace
(
"哪里"
,
"location"
);
value
=
gameEnv
.
queryGoodsAttrByGoodsName
(
subValuePair
[
0
],
subValuePair
[
1
]);
returnStr
=
gameEnv
.
queryGoodsAttrByGoodsName
(
subValuePair
[
0
],
subValuePair
[
1
]);
if
(
returnStr
==
null
)
if
(
returnStr
==
null
)
{
returnStr
=
"无"
;
returnStr
=
"没找到"
;
}
else
{
returnStr
=
userInfo
.
varInitialMap
.
get
(
"GET_ITEM_ATTR"
).
replace
(
"[物品名]"
,
subValuePair
[
0
]).
replace
(
"[属性名]"
,
subValuePair
[
1
]).
replace
(
"[属性值]"
,
value
);
}
break
;
break
;
case
"queryAllAttrByGoodsName"
:
case
"queryAllAttrByGoodsName"
:
textList
=
gameEnv
.
queryGoodsAllAttrByGoodsName
(
varName
);
textList
=
gameEnv
.
queryGoodsAllAttrByGoodsName
(
varName
);
...
@@ -65,9 +69,25 @@ public class WorldController {
...
@@ -65,9 +69,25 @@ public class WorldController {
returnStr
=
returnStr
.
substring
(
1
);
returnStr
=
returnStr
.
substring
(
1
);
}
}
break
;
break
;
case
"queryLocationByConditionName"
:
//
String
NPCName
=
currentInfoPoint
.
get
(
valuePair
[
1
]).
split
(
":"
)[
1
];
returnStr
=
gameEnv
.
queryGoodsAttrByGoodsName
(
NPCName
,
"可被询问"
);
if
(
returnStr
==
null
||
returnStr
.
equals
(
"否"
)){
returnStr
=
"没找到"
;
}
else
if
(
returnStr
.
equals
(
"是"
)){
location
=
gameEnv
.
queryGoodsAttrByGoodsName
(
NPCName
,
"location"
);
if
(
location
==
null
){
returnStr
=
"没找到"
;
}
else
{
returnStr
=
userInfo
.
varInitialMap
.
get
(
"FIND_ITEM_LOCATION"
).
replace
(
"[物品名]"
,
NPCName
).
replace
(
"[地点]"
,
location
);
}
}
break
;
default
:
default
:
}
}
}
else
if
(
varName
.
startsWith
(
"
NPC
_"
))
{
}
else
if
(
varName
.
startsWith
(
"
npc
_"
))
{
switch
(
valuePair
[
0
]){
switch
(
valuePair
[
0
]){
case
"queryNpcIntro"
:
case
"queryNpcIntro"
:
//operationFlag = gameEnv.queryNpcIntro(valuePair[1], namePair[2]);
//operationFlag = gameEnv.queryNpcIntro(valuePair[1], namePair[2]);
...
@@ -81,16 +101,42 @@ public class WorldController {
...
@@ -81,16 +101,42 @@ public class WorldController {
//根据condition的名字,从当前信息点中获取npc的名字
//根据condition的名字,从当前信息点中获取npc的名字
subValuePair
=
currentInfoPoint
.
get
(
valuePair
[
1
]).
split
(
":"
,
2
);
subValuePair
=
currentInfoPoint
.
get
(
valuePair
[
1
]).
split
(
":"
,
2
);
subValuePair
[
0
]
=
subValuePair
[
0
].
replace
(
"哪里"
,
"location"
);
subValuePair
[
0
]
=
subValuePair
[
0
].
replace
(
"哪里"
,
"location"
);
returnStr
=
gameEnv
.
queryNpcAttrByNpcName
(
subValuePair
[
0
],
subValuePair
[
1
]);
value
=
gameEnv
.
queryNpcAttrByNpcName
(
subValuePair
[
0
],
subValuePair
[
1
]);
if
(
returnStr
==
null
)
if
(
returnStr
==
null
)
{
returnStr
=
"无"
;
returnStr
=
"没找到"
;
}
else
{
returnStr
=
userInfo
.
varInitialMap
.
get
(
"GET_NPC_ATTR"
).
replace
(
"[人名]"
,
subValuePair
[
0
]).
replace
(
"[属性名]"
,
subValuePair
[
1
]).
replace
(
"[属性值]"
,
value
);
}
break
;
break
;
case
"queryLocationByNPCName"
:
case
"queryLocationByNPCName"
:
//
//
returnStr
=
gameEnv
.
queryNpcAttrByNpcName
(
valuePair
[
1
],
"location"
);
location
=
gameEnv
.
queryNpcAttrByNpcName
(
valuePair
[
1
],
"location"
);
if
(
returnStr
==
null
)
if
(
location
==
null
){
returnStr
=
"无"
;
returnStr
=
"没找到"
;
}
else
{
returnStr
=
location
;
}
break
;
break
;
case
"queryLocationByConditionName"
:
//
String
NPCName
=
currentInfoPoint
.
get
(
valuePair
[
1
]).
split
(
":"
)[
1
];
returnStr
=
gameEnv
.
queryNpcAttrByNpcName
(
NPCName
,
"可被询问"
);
if
(
returnStr
==
null
||
returnStr
.
equals
(
"否"
)){
returnStr
=
"没找到"
;
}
else
if
(
returnStr
.
equals
(
"是"
)){
location
=
gameEnv
.
queryNpcAttrByNpcName
(
NPCName
,
"location"
);
if
(
location
==
null
){
returnStr
=
"没找到"
;
}
else
{
returnStr
=
userInfo
.
varInitialMap
.
get
(
"FIND_NPC_LOCATION"
).
replace
(
"[人名]"
,
NPCName
).
replace
(
"[地点]"
,
location
);
}
}
break
;
default
:
default
:
}
}
}
else
if
(
varName
.
startsWith
(
"map_"
))
{
}
else
if
(
varName
.
startsWith
(
"map_"
))
{
...
@@ -102,7 +148,7 @@ public class WorldController {
...
@@ -102,7 +148,7 @@ public class WorldController {
if
(
userInfo
.
varInitialMap
.
containsKey
(
"AROUND_THINGS"
))
{
if
(
userInfo
.
varInitialMap
.
containsKey
(
"AROUND_THINGS"
))
{
format
=
userInfo
.
varInitialMap
.
get
(
"AROUND_THINGS"
);
format
=
userInfo
.
varInitialMap
.
get
(
"AROUND_THINGS"
);
}
else
{
}
else
{
format
=
"
有%s
"
;
format
=
"
周围有[人物物品列表]
"
;
}
}
...
@@ -117,14 +163,14 @@ public class WorldController {
...
@@ -117,14 +163,14 @@ public class WorldController {
text
.
append
(
"、"
+
site
);
text
.
append
(
"、"
+
site
);
}
}
returnStr
=
String
.
format
(
format
,
text
.
substring
(
1
));
returnStr
=
format
.
replace
(
"[人物物品列表]"
,
text
.
substring
(
1
));
}
}
break
;
break
;
case
"queryAroundNpcBySite"
:
case
"queryAroundNpcBySite"
:
if
(
userInfo
.
varInitialMap
.
containsKey
(
"AROUND_PEOPLE"
))
{
if
(
userInfo
.
varInitialMap
.
containsKey
(
"AROUND_PEOPLE"
))
{
format
=
userInfo
.
varInitialMap
.
get
(
"AROUND_PEOPLE"
);
format
=
userInfo
.
varInitialMap
.
get
(
"AROUND_PEOPLE"
);
}
else
{
}
else
{
format
=
"
有%s
"
;
format
=
"
周围有[人物列表]
"
;
}
}
...
@@ -139,7 +185,7 @@ public class WorldController {
...
@@ -139,7 +185,7 @@ public class WorldController {
text
.
append
(
"、"
+
site
);
text
.
append
(
"、"
+
site
);
}
}
returnStr
=
String
.
format
(
format
,
text
.
substring
(
1
));
returnStr
=
format
.
replace
(
"[人物列表]"
,
text
.
substring
(
1
));
}
}
break
;
break
;
case
"queryAroundGoodsBySite"
:
case
"queryAroundGoodsBySite"
:
...
@@ -147,7 +193,7 @@ public class WorldController {
...
@@ -147,7 +193,7 @@ public class WorldController {
if
(
userInfo
.
varInitialMap
.
containsKey
(
"AROUND_ITEMS"
))
{
if
(
userInfo
.
varInitialMap
.
containsKey
(
"AROUND_ITEMS"
))
{
format
=
userInfo
.
varInitialMap
.
get
(
"AROUND_ITEMS"
);
format
=
userInfo
.
varInitialMap
.
get
(
"AROUND_ITEMS"
);
}
else
{
}
else
{
format
=
"
有%s
"
;
format
=
"
周围有[物品列表]
"
;
}
}
sites
=
gameEnv
.
queryAroundGoodsBySite
(
historyInfoPoint
.
get
(
"site"
));
sites
=
gameEnv
.
queryAroundGoodsBySite
(
historyInfoPoint
.
get
(
"site"
));
...
@@ -160,7 +206,7 @@ public class WorldController {
...
@@ -160,7 +206,7 @@ public class WorldController {
for
(
String
site:
sites
){
for
(
String
site:
sites
){
text
.
append
(
"、"
+
site
);
text
.
append
(
"、"
+
site
);
}
}
returnStr
=
String
.
format
(
format
,
text
.
substring
(
1
));
returnStr
=
format
.
replace
(
"[物品列表]"
,
text
.
substring
(
1
));
}
}
}
}
break
;
break
;
...
@@ -169,7 +215,7 @@ public class WorldController {
...
@@ -169,7 +215,7 @@ public class WorldController {
if
(
userInfo
.
varInitialMap
.
containsKey
(
"CAN_GO_SITES"
))
{
if
(
userInfo
.
varInitialMap
.
containsKey
(
"CAN_GO_SITES"
))
{
format
=
userInfo
.
varInitialMap
.
get
(
"CAN_GO_SITES"
);
format
=
userInfo
.
varInitialMap
.
get
(
"CAN_GO_SITES"
);
}
else
{
}
else
{
format
=
"
可以去%s
"
;
format
=
"
你可以去[可去列表]
"
;
}
}
sites
=
gameEnv
.
queryCanGoBySite
(
historyInfoPoint
.
get
(
"site"
));
sites
=
gameEnv
.
queryCanGoBySite
(
historyInfoPoint
.
get
(
"site"
));
...
@@ -185,7 +231,7 @@ public class WorldController {
...
@@ -185,7 +231,7 @@ public class WorldController {
for
(
String
site:
sites
){
for
(
String
site:
sites
){
text
.
append
(
"、"
+
site
);
text
.
append
(
"、"
+
site
);
}
}
returnStr
=
String
.
format
(
format
,
text
.
substring
(
1
));
returnStr
=
format
.
replace
(
"[可去列表]"
,
text
.
substring
(
1
));
}
}
}
}
break
;
break
;
...
@@ -194,7 +240,7 @@ public class WorldController {
...
@@ -194,7 +240,7 @@ public class WorldController {
if
(
userInfo
.
varInitialMap
.
containsKey
(
"PATH_EXIST"
))
{
if
(
userInfo
.
varInitialMap
.
containsKey
(
"PATH_EXIST"
))
{
format
=
userInfo
.
varInitialMap
.
get
(
"PATH_EXIST"
);
format
=
userInfo
.
varInitialMap
.
get
(
"PATH_EXIST"
);
}
else
{
}
else
{
format
=
"通过
%s可以到达
"
;
format
=
"通过
[途径]可以到达[目的地]
"
;
}
}
if
(!
currentInfoPoint
.
containsKey
(
valuePair
[
1
]))
{
if
(!
currentInfoPoint
.
containsKey
(
valuePair
[
1
]))
{
...
@@ -213,7 +259,7 @@ public class WorldController {
...
@@ -213,7 +259,7 @@ public class WorldController {
for
(
String
site:
sites
){
for
(
String
site:
sites
){
text
.
append
(
"、"
+
site
);
text
.
append
(
"、"
+
site
);
}
}
returnStr
=
String
.
format
(
format
,
text
.
substring
(
1
)
);
returnStr
=
format
.
replace
(
"[途径]"
,
text
.
substring
(
1
)).
replace
(
"[目的地]"
,
currentInfoPoint
.
get
(
valuePair
[
1
]).
split
(
":"
)[
1
]
);
}
}
}
}
break
;
break
;
...
@@ -222,7 +268,7 @@ public class WorldController {
...
@@ -222,7 +268,7 @@ public class WorldController {
if
(
userInfo
.
varInitialMap
.
containsKey
(
"SITE_NOT_ADJOINT"
))
{
if
(
userInfo
.
varInitialMap
.
containsKey
(
"SITE_NOT_ADJOINT"
))
{
format
=
userInfo
.
varInitialMap
.
get
(
"SITE_NOT_ADJOINT"
);
format
=
userInfo
.
varInitialMap
.
get
(
"SITE_NOT_ADJOINT"
);
}
else
{
}
else
{
format
=
"通过
%s可以到达
"
;
format
=
"通过
[途径]可以到达[目的地]
"
;
}
}
if
(!
currentInfoPoint
.
containsKey
(
valuePair
[
1
]))
{
if
(!
currentInfoPoint
.
containsKey
(
valuePair
[
1
]))
{
...
@@ -240,7 +286,7 @@ public class WorldController {
...
@@ -240,7 +286,7 @@ public class WorldController {
for
(
String
site:
sites
){
for
(
String
site:
sites
){
text
.
append
(
"、"
+
site
);
text
.
append
(
"、"
+
site
);
}
}
returnStr
=
String
.
format
(
format
,
text
.
substring
(
1
)
);
returnStr
=
format
.
replace
(
"[途径]"
,
text
.
substring
(
1
)).
replace
(
"[目的地]"
,
currentInfoPoint
.
get
(
valuePair
[
1
]).
split
(
":"
)[
1
]
);
}
}
}
}
break
;
break
;
...
@@ -269,4 +315,9 @@ public class WorldController {
...
@@ -269,4 +315,9 @@ public class WorldController {
return
returnStr
;
return
returnStr
;
}
}
public
static
String
findLocationName
(
GameEnv
gameEnv
,
String
locationName
,
String
site
){
return
gameEnv
.
getPlaceNameByNickname
(
site
,
locationName
);
}
}
}
src/servlet/GameDesignServlet.java
View file @
15fa3483
...
@@ -24,6 +24,7 @@ import java.util.*;
...
@@ -24,6 +24,7 @@ import java.util.*;
public
class
GameDesignServlet
extends
HttpServlet
{
public
class
GameDesignServlet
extends
HttpServlet
{
String
POST_URL
=
"http://localhost:1111/conditionProcess"
;
String
POST_URL
=
"http://localhost:1111/conditionProcess"
;
String
KEYWORD_DIR
=
"keywords.txt"
;
//分组及其相应的id,id初始化为0, 新建分组成功后id会更新。
//分组及其相应的id,id初始化为0, 新建分组成功后id会更新。
HashMap
<
String
,
Integer
>
categoryMap
=
new
HashMap
<
String
,
Integer
>(){
HashMap
<
String
,
Integer
>
categoryMap
=
new
HashMap
<
String
,
Integer
>(){
{
{
...
@@ -42,8 +43,11 @@ public class GameDesignServlet extends HttpServlet {
...
@@ -42,8 +43,11 @@ public class GameDesignServlet extends HttpServlet {
//所有需要修改的词性
//所有需要修改的词性
StringBuffer
POS
=
new
StringBuffer
();
StringBuffer
POS
=
new
StringBuffer
();
//每个condition的三元组两端需要补充的关键词,比如npc名字、npc属性等
//每个condition的三元组两端需要补充的关键词,比如npc名字、npc属性等,格式为: "conditionName_tail/head":"keywords"
HashMap
<
String
,
HashSet
<
String
>>
relationKeywords
=
new
HashMap
<
String
,
HashSet
<
String
>>();
HashMap
<
String
,
HashSet
<
String
>>
additionalKeywords
=
new
HashMap
<
String
,
HashSet
<
String
>>();
//预先定义好的所有condition相关的关键词,格式为 "conditionName_标签":"keywords"
Map
<
String
,
StringBuffer
>
keywordMap
=
new
HashMap
<
String
,
StringBuffer
>();
//特定的relation的三元组不会被添加到relationKeywords
//特定的relation的三元组不会被添加到relationKeywords
HashSet
<
String
>
exceptRelation
=
new
HashSet
<
String
>();
HashSet
<
String
>
exceptRelation
=
new
HashSet
<
String
>();
...
@@ -105,35 +109,40 @@ public class GameDesignServlet extends HttpServlet {
...
@@ -105,35 +109,40 @@ public class GameDesignServlet extends HttpServlet {
StringBuffer
mergedConfigText
=
new
StringBuffer
();
StringBuffer
mergedConfigText
=
new
StringBuffer
();
int
skipCount
=
0
;
int
skipCount
=
0
;
//从文件中读取condition相关的关键词
System
.
out
.
println
(
"----------------------read-------------------------/r------------------------------------------------------"
);
readKeywords
(
keywordMap
,
KEYWORD_DIR
);
String
moduleList
[]
=
{
"map"
,
"goods"
,
"globalVariable"
,
"npc"
,
"plots"
};
String
moduleList
[]
=
{
"map"
,
"goods"
,
"globalVariable"
,
"npc"
,
"plots"
};
for
(
String
moduleName:
moduleList
){
for
(
String
moduleName:
moduleList
){
switch
(
moduleName
)
{
switch
(
moduleName
)
{
case
"map"
:
case
"map"
:
moduleName2
=
"地图"
;
moduleName2
=
"地图"
;
constructor
=
new
MapConstructor
2
(
helper
,
botId
,
skipCount
,
botAccount
,
exceptRelation
,
POS
);
constructor
=
new
MapConstructor
(
helper
,
botId
,
botAccount
,
keywordMap
,
exceptRelation
,
POS
);
constructor
.
construct
(
gameElements
,
userinfo
);
constructor
.
construct
(
gameElements
,
userinfo
);
break
;
break
;
case
"plots"
:
case
"plots"
:
moduleName2
=
"剧情"
;
moduleName2
=
"剧情"
;
constructor
=
new
PlotConstructor
(
helper
,
botId
,
skipCount
,
botAccount
,
exceptRelation
,
POS
);
constructor
=
new
PlotConstructor
(
helper
,
botId
,
botAccount
,
keywordMap
,
exceptRelation
,
POS
);
constructor
.
construct
(
gameElements
,
userinfo
);
constructor
.
construct
(
gameElements
,
userinfo
);
root
=
((
PlotConstructor
)
constructor
).
getId2j
().
get
((
String
)
gameElements
.
get
(
"start"
));
root
=
((
PlotConstructor
)
constructor
).
getId2j
().
get
((
String
)
gameElements
.
get
(
"start"
));
break
;
break
;
case
"goods"
:
case
"goods"
:
moduleName2
=
"物品"
;
moduleName2
=
"物品"
;
constructor
=
new
ItemConstructor
(
helper
,
botId
,
skipCount
,
botAccount
,
exceptRelation
,
POS
);
constructor
=
new
ItemConstructor
(
helper
,
botId
,
botAccount
,
keywordMap
,
exceptRelation
,
POS
);
constructor
.
construct
(
gameElements
,
userinfo
);
constructor
.
construct
(
gameElements
,
userinfo
);
break
;
break
;
case
"globalVariable"
:
case
"globalVariable"
:
moduleName2
=
"全局变量"
;
moduleName2
=
"全局变量"
;
constructor
=
new
GlobalVariableConstructor
(
helper
,
botId
,
skipCount
,
botAccount
,
exceptRelation
,
POS
);
constructor
=
new
GlobalVariableConstructor
(
helper
,
botId
,
botAccount
,
keywordMap
,
exceptRelation
,
POS
);
constructor
.
construct
(
gameElements
,
userinfo
);
constructor
.
construct
(
gameElements
,
userinfo
);
break
;
break
;
case
"npc"
:
case
"npc"
:
moduleName2
=
"NPC"
;
moduleName2
=
"NPC"
;
constructor
=
new
CharacterConstructor
(
helper
,
botId
,
skipCount
,
botAccount
,
exceptRelation
,
POS
);
constructor
=
new
CharacterConstructor
(
helper
,
botId
,
botAccount
,
keywordMap
,
exceptRelation
,
POS
);
constructor
.
construct
(
gameElements
,
userinfo
);
constructor
.
construct
(
gameElements
,
userinfo
);
break
;
break
;
default
:
default
:
...
@@ -150,7 +159,7 @@ public class GameDesignServlet extends HttpServlet {
...
@@ -150,7 +159,7 @@ public class GameDesignServlet extends HttpServlet {
List
<
JSONObject
>
jsonList
=
new
ArrayList
<
JSONObject
>();
List
<
JSONObject
>
jsonList
=
new
ArrayList
<
JSONObject
>();
for
(
JConfig
jConfig:
constructor
.
getjConfigList
()){
for
(
JConfig
jConfig:
constructor
.
getjConfigList
()){
json
=
jConfig
.
toJson
(
constructor
.
getConditionDescription
());
json
=
jConfig
.
toJson
(
constructor
.
getConditionDescription
());
constructor
.
parseKeyword
(
json
,
relation
Keywords
,
exceptRelation
);
constructor
.
parseKeyword
(
json
,
additional
Keywords
,
exceptRelation
);
jsonList
.
add
(
json
);
jsonList
.
add
(
json
);
}
}
...
@@ -174,7 +183,7 @@ public class GameDesignServlet extends HttpServlet {
...
@@ -174,7 +183,7 @@ public class GameDesignServlet extends HttpServlet {
UserInfoController
.
buildUserInfo
(
br
,
userinfo
,
true
);
UserInfoController
.
buildUserInfo
(
br
,
userinfo
,
true
);
context
.
setAttribute
(
botAccount
,
userinfo
);
context
.
setAttribute
(
botAccount
,
userinfo
);
ConditionTableController
.
writeConfigText
(
botAccount
,
userinfo
);
ConditionTableController
.
writeConfigText
(
botAccount
,
userinfo
);
String
postResult
=
actionRegenerate
(
root
,
gameElements
,
userinfo
,
relation
Keywords
,
exceptRelation
,
POS
);
String
postResult
=
actionRegenerate
(
root
,
gameElements
,
userinfo
,
additional
Keywords
,
exceptRelation
,
POS
);
if
(!
postResult
.
equals
(
"success"
)){
if
(!
postResult
.
equals
(
"success"
)){
returnStatus
=
0
;
returnStatus
=
0
;
...
@@ -229,7 +238,7 @@ public class GameDesignServlet extends HttpServlet {
...
@@ -229,7 +238,7 @@ public class GameDesignServlet extends HttpServlet {
return
deleteConfigFlag
&&
deleteVariableFlag
;
return
deleteConfigFlag
&&
deleteVariableFlag
;
}
}
public
String
actionRegenerate
(
JSONObject
root
,
JSONObject
gameElements
,
UserInfo
userInfo
,
HashMap
<
String
,
HashSet
<
String
>>
relation
Keywords
,
HashSet
<
String
>
exceptRelation
,
StringBuffer
POS
){
public
String
actionRegenerate
(
JSONObject
root
,
JSONObject
gameElements
,
UserInfo
userInfo
,
HashMap
<
String
,
HashSet
<
String
>>
additional
Keywords
,
HashSet
<
String
>
exceptRelation
,
StringBuffer
POS
){
String
startCondition
,
POS2
=
""
;
String
startCondition
,
POS2
=
""
;
String
botName
=
(
String
)
gameElements
.
get
(
"botName"
);
String
botName
=
(
String
)
gameElements
.
get
(
"botName"
);
JSONObject
returnMessage
=
null
;
JSONObject
returnMessage
=
null
;
...
@@ -243,7 +252,7 @@ public class GameDesignServlet extends HttpServlet {
...
@@ -243,7 +252,7 @@ public class GameDesignServlet extends HttpServlet {
actionPostData
.
put
(
"botId"
,
(
Integer
)
gameElements
.
get
(
"botId"
));
actionPostData
.
put
(
"botId"
,
(
Integer
)
gameElements
.
get
(
"botId"
));
actionPostData
.
put
(
"type"
,
"game_plot_init"
);
actionPostData
.
put
(
"type"
,
"game_plot_init"
);
actionPostData
.
put
(
"welcome"
,
"欢迎来到"
+
(
String
)
gameElements
.
get
(
"botName"
)
+
",请说开始剧情或者重新开始"
);
actionPostData
.
put
(
"welcome"
,
"欢迎来到"
+
(
String
)
gameElements
.
get
(
"botName"
)
+
",请说开始剧情或者重新开始"
);
actionPostData
.
put
(
"relationKeywords"
,
relation
Keywords
);
actionPostData
.
put
(
"relationKeywords"
,
additional
Keywords
);
actionPostData
.
put
(
"auth"
,
gameElements
.
get
(
"auth"
));
actionPostData
.
put
(
"auth"
,
gameElements
.
get
(
"auth"
));
...
@@ -271,4 +280,35 @@ public class GameDesignServlet extends HttpServlet {
...
@@ -271,4 +280,35 @@ public class GameDesignServlet extends HttpServlet {
}
}
}
}
public
void
readKeywords
(
Map
<
String
,
StringBuffer
>
keywordsMap
,
String
path
){
File
file
=
new
File
(
path
);
String
line
,
pair
[];
System
.
out
.
println
(
file
.
getAbsolutePath
());
if
(
file
.
exists
()){
FileReader
reader
=
null
;
try
{
reader
=
new
FileReader
(
file
);
BufferedReader
br
=
new
BufferedReader
(
reader
);
while
((
line
=
br
.
readLine
())
!=
null
)
{
if
(!
line
.
equals
(
""
)
&&
!
line
.
startsWith
(
"#"
)){
pair
=
line
.
split
(
"\\|"
,
2
);
keywordsMap
.
put
(
pair
[
0
],
new
StringBuffer
(
pair
[
1
]));
}
}
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
}
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