Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
797afd4c
Commit
797afd4c
authored
Jul 26, 2022
by
Melledy
Committed by
GitHub
Jul 26, 2022
Browse files
Merge pull request #1553 from akatatsu27/questing
Major quest framework improvements
parents
1c5c3633
8bdcfb89
Changes
63
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/game/quest/exec/ExecIncQuestGlobalVar.java
0 → 100644
View file @
797afd4c
package
emu.grasscutter.game.quest.exec
;
import
emu.grasscutter.data.excels.QuestData
;
import
emu.grasscutter.game.quest.GameQuest
;
import
emu.grasscutter.game.quest.QuestValue
;
import
emu.grasscutter.game.quest.enums.QuestTrigger
;
import
emu.grasscutter.game.quest.handlers.QuestExecHandler
;
@QuestValue
(
QuestTrigger
.
QUEST_EXEC_INC_QUEST_GLOBAL_VAR
)
public
class
ExecIncQuestGlobalVar
extends
QuestExecHandler
{
@Override
public
boolean
execute
(
GameQuest
quest
,
QuestData
.
QuestExecParam
condition
,
String
...
paramStr
)
{
quest
.
getOwner
().
getQuestManager
().
incQuestGlobalVarValue
(
Integer
.
valueOf
(
paramStr
[
0
]),
Integer
.
valueOf
(
paramStr
[
1
]));
return
true
;
}
}
\ No newline at end of file
src/main/java/emu/grasscutter/game/quest/exec/ExecIncQuestVar.java
0 → 100644
View file @
797afd4c
package
emu.grasscutter.game.quest.exec
;
import
emu.grasscutter.data.excels.QuestData
;
import
emu.grasscutter.game.quest.GameQuest
;
import
emu.grasscutter.game.quest.QuestValue
;
import
emu.grasscutter.game.quest.enums.QuestTrigger
;
import
emu.grasscutter.game.quest.handlers.QuestExecHandler
;
@QuestValue
(
QuestTrigger
.
QUEST_EXEC_INC_QUEST_VAR
)
public
class
ExecIncQuestVar
extends
QuestExecHandler
{
@Override
public
boolean
execute
(
GameQuest
quest
,
QuestData
.
QuestExecParam
condition
,
String
...
paramStr
)
{
quest
.
getMainQuest
().
incQuestVar
(
Integer
.
parseInt
(
paramStr
[
0
]),
Integer
.
parseInt
(
paramStr
[
1
]));
return
true
;
}
}
src/main/java/emu/grasscutter/game/quest/exec/ExecSetQuestGlobalVar.java
0 → 100644
View file @
797afd4c
package
emu.grasscutter.game.quest.exec
;
import
emu.grasscutter.data.excels.QuestData
;
import
emu.grasscutter.game.quest.GameQuest
;
import
emu.grasscutter.game.quest.QuestValue
;
import
emu.grasscutter.game.quest.enums.QuestTrigger
;
import
emu.grasscutter.game.quest.handlers.QuestExecHandler
;
@QuestValue
(
QuestTrigger
.
QUEST_EXEC_SET_QUEST_GLOBAL_VAR
)
public
class
ExecSetQuestGlobalVar
extends
QuestExecHandler
{
@Override
public
boolean
execute
(
GameQuest
quest
,
QuestData
.
QuestExecParam
condition
,
String
...
paramStr
)
{
quest
.
getOwner
().
getQuestManager
().
setQuestGlobalVarValue
(
Integer
.
valueOf
(
paramStr
[
0
]),
Integer
.
valueOf
(
paramStr
[
1
]));
return
true
;
}
}
src/main/java/emu/grasscutter/game/quest/exec/ExecSetQuestVar.java
0 → 100644
View file @
797afd4c
package
emu.grasscutter.game.quest.exec
;
import
emu.grasscutter.data.excels.QuestData
;
import
emu.grasscutter.game.quest.GameQuest
;
import
emu.grasscutter.game.quest.QuestValue
;
import
emu.grasscutter.game.quest.enums.QuestTrigger
;
import
emu.grasscutter.game.quest.handlers.QuestExecHandler
;
@QuestValue
(
QuestTrigger
.
QUEST_EXEC_SET_QUEST_VAR
)
public
class
ExecSetQuestVar
extends
QuestExecHandler
{
@Override
public
boolean
execute
(
GameQuest
quest
,
QuestData
.
QuestExecParam
condition
,
String
...
paramStr
)
{
quest
.
getMainQuest
().
setQuestVar
(
Integer
.
parseInt
(
paramStr
[
0
]),
Integer
.
parseInt
(
paramStr
[
1
]));
return
true
;
}
}
src/main/java/emu/grasscutter/game/world/Scene.java
View file @
797afd4c
...
...
@@ -627,8 +627,14 @@ public class Scene {
.
flatMap
(
Collection:
:
stream
)
.
toList
();
onLoadGroup
(
groups
);
Grasscutter
.
getLogger
().
info
(
"Scene {} Block {} loaded."
,
this
.
getId
(),
block
.
id
);
onLoadGroup
(
groups
);
Grasscutter
.
getLogger
().
info
(
"Scene {} Block {} loaded."
,
this
.
getId
(),
block
.
id
);
}
public
void
loadTriggerFromGroup
(
SceneGroup
group
,
String
triggerName
)
{
//Load triggers and regions
getScriptManager
().
registerTrigger
(
group
.
triggers
.
values
().
stream
().
filter
(
p
->
p
.
name
.
contains
(
triggerName
)).
toList
());
group
.
regions
.
values
().
stream
().
filter
(
q
->
q
.
config_id
==
Integer
.
parseInt
(
triggerName
.
substring
(
13
))).
map
(
region
->
new
EntityRegion
(
this
,
region
))
.
forEach
(
getScriptManager
()::
registerRegion
);
}
public
void
onLoadGroup
(
List
<
SceneGroup
>
groups
)
{
...
...
src/main/java/emu/grasscutter/scripts/SceneScriptManager.java
View file @
797afd4c
...
...
@@ -92,6 +92,7 @@ public class SceneScriptManager {
}
public
void
registerTrigger
(
SceneTrigger
trigger
)
{
getTriggersByEvent
(
trigger
.
event
).
add
(
trigger
);
Grasscutter
.
getLogger
().
debug
(
"Registered trigger {}"
,
trigger
.
name
);
}
public
void
deregisterTrigger
(
List
<
SceneTrigger
>
triggers
)
{
triggers
.
forEach
(
this
::
deregisterTrigger
);
...
...
@@ -122,6 +123,7 @@ public class SceneScriptManager {
public
void
registerRegion
(
EntityRegion
region
)
{
regions
.
put
(
region
.
getId
(),
region
);
Grasscutter
.
getLogger
().
debug
(
"Registered region {} from group {}"
,
region
.
getMetaRegion
().
config_id
,
region
.
getGroupId
());
}
public
void
registerRegionInGroupSuite
(
SceneGroup
group
,
SceneSuite
suite
){
suite
.
sceneRegions
.
stream
().
map
(
region
->
new
EntityRegion
(
this
.
getScene
(),
region
))
...
...
@@ -195,9 +197,30 @@ public class SceneScriptManager {
.
filter
(
e
->
e
.
getEntityType
()
==
EntityType
.
Avatar
.
getValue
()
&&
region
.
getMetaRegion
().
contains
(
e
.
getPosition
()))
.
forEach
(
region:
:
addEntity
);
var
players
=
region
.
getScene
().
getPlayers
();
int
targetID
=
0
;
if
(
players
.
size
()
>
0
)
targetID
=
players
.
get
(
0
).
getUid
();
if
(
region
.
hasNewEntities
())
{
Grasscutter
.
getLogger
().
trace
(
"Call EVENT_ENTER_REGION_{}"
,
region
.
getMetaRegion
().
config_id
);
callEvent
(
EventType
.
EVENT_ENTER_REGION
,
new
ScriptArgs
(
region
.
getConfigId
())
.
setSourceEntityId
(
region
.
getId
())
.
setTargetEntityId
(
targetID
)
);
region
.
resetNewEntities
();
}
for
(
int
entityId
:
region
.
getEntities
())
{
if
(!
region
.
getMetaRegion
().
contains
(
getScene
().
getEntityById
(
entityId
).
getPosition
()))
{
region
.
removeEntity
(
entityId
);
}
}
if
(
region
.
entityLeave
())
{
callEvent
(
EventType
.
EVENT_LEAVE_REGION
,
new
ScriptArgs
(
region
.
getConfigId
())
.
setSourceEntityId
(
region
.
getId
())
.
setTargetEntityId
(
region
.
getFirstEntityId
())
);
...
...
@@ -286,27 +309,41 @@ public class SceneScriptManager {
}
private
void
realCallEvent
(
int
eventType
,
ScriptArgs
params
)
{
try
{
ScriptLoader
.
getScriptLib
().
setSceneScriptManager
(
this
);
for
(
SceneTrigger
trigger
:
this
.
getTriggersByEvent
(
eventType
))
{
try
{
ScriptLoader
.
getScriptLib
().
setCurrentGroup
(
trigger
.
currentGroup
);
LuaValue
ret
=
callScriptFunc
(
trigger
.
condition
,
trigger
.
currentGroup
,
params
);
Grasscutter
.
getLogger
().
trace
(
"Call Condition Trigger {}"
,
trigger
.
condition
);
if
(
ret
.
isboolean
()
&&
ret
.
checkboolean
())
{
// the SetGroupVariableValueByGroup in tower need the param to record the first stage time
callScriptFunc
(
trigger
.
action
,
trigger
.
currentGroup
,
params
);
Grasscutter
.
getLogger
().
trace
(
"Call Action Trigger {}"
,
trigger
.
action
);
}
//TODO some ret may not bool
}
finally
{
ScriptLoader
.
getScriptLib
().
removeCurrentGroup
();
}
}
}
finally
{
try
{
Set
<
SceneTrigger
>
relevantTriggers
=
new
HashSet
<>();
if
(
eventType
==
EventType
.
EVENT_ENTER_REGION
||
eventType
==
EventType
.
EVENT_LEAVE_REGION
)
{
List
<
SceneTrigger
>
relevantTriggersList
=
this
.
getTriggersByEvent
(
eventType
).
stream
()
.
filter
(
p
->
p
.
condition
.
contains
(
String
.
valueOf
(
params
.
param1
))).
toList
();
relevantTriggers
=
new
HashSet
<>(
relevantTriggersList
);
}
else
{
relevantTriggers
=
this
.
getTriggersByEvent
(
eventType
);}
for
(
SceneTrigger
trigger
:
relevantTriggers
)
{
try
{
ScriptLoader
.
getScriptLib
().
setCurrentGroup
(
trigger
.
currentGroup
);
LuaValue
ret
=
this
.
callScriptFunc
(
trigger
.
condition
,
trigger
.
currentGroup
,
params
);
Grasscutter
.
getLogger
().
trace
(
"Call Condition Trigger {}, [{},{},{}]"
,
trigger
.
condition
,
params
.
param1
,
params
.
source_eid
,
params
.
target_eid
);
if
(
ret
.
isboolean
()
&&
ret
.
checkboolean
())
{
// the SetGroupVariableValueByGroup in tower need the param to record the first stage time
this
.
callScriptFunc
(
trigger
.
action
,
trigger
.
currentGroup
,
params
);
Grasscutter
.
getLogger
().
trace
(
"Call Action Trigger {}"
,
trigger
.
action
);
if
(
trigger
.
event
==
EventType
.
EVENT_ENTER_REGION
)
{
EntityRegion
region
=
this
.
regions
.
values
().
stream
().
filter
(
p
->
p
.
getConfigId
()
==
params
.
param1
).
toList
().
get
(
0
);
getScene
().
getPlayers
().
forEach
(
p
->
p
.
onEnterRegion
(
region
.
getMetaRegion
()));
deregisterRegion
(
region
.
getMetaRegion
());
}
else
if
(
trigger
.
event
==
EventType
.
EVENT_LEAVE_REGION
)
{
EntityRegion
region
=
this
.
regions
.
values
().
stream
().
filter
(
p
->
p
.
getConfigId
()
==
params
.
param1
).
toList
().
get
(
0
);
getScene
().
getPlayers
().
forEach
(
p
->
p
.
onLeaveRegion
(
region
.
getMetaRegion
()));
deregisterRegion
(
region
.
getMetaRegion
());
}
deregisterTrigger
(
trigger
);
}
else
{
Grasscutter
.
getLogger
().
debug
(
"Condition Trigger {} returned {}"
,
trigger
.
condition
,
ret
);
}
//TODO some ret do not bool
}
finally
{
ScriptLoader
.
getScriptLib
().
removeCurrentGroup
();
}
}
}
finally
{
// make sure it is removed
ScriptLoader
.
getScriptLib
().
removeSceneScriptManager
();
}
...
...
src/main/java/emu/grasscutter/scripts/data/SceneRegion.java
View file @
797afd4c
...
...
@@ -26,7 +26,8 @@ public class SceneRegion {
var
x
=
Math
.
pow
(
pos
.
getX
()
-
position
.
getX
(),
2
);
var
y
=
Math
.
pow
(
pos
.
getY
()
-
position
.
getY
(),
2
);
var
z
=
Math
.
pow
(
pos
.
getZ
()
-
position
.
getZ
(),
2
);
return
x
+
y
+
z
<=
(
radius
^
2
);
// ^ means XOR in java!
return
x
+
y
+
z
<=
(
radius
*
radius
);
}
return
false
;
}
...
...
src/main/java/emu/grasscutter/scripts/serializer/LuaSerializer.java
View file @
797afd4c
...
...
@@ -29,22 +29,70 @@ public class LuaSerializer implements Serializer {
public
<
T
>
T
toObject
(
Class
<
T
>
type
,
Object
obj
)
{
return
serialize
(
type
,
(
LuaTable
)
obj
);
}
public
<
T
>
List
<
T
>
serializeList
(
Class
<
T
>
type
,
LuaTable
table
)
{
@Override
public
<
T
>
Map
<
String
,
T
>
toMap
(
Class
<
T
>
type
,
Object
obj
)
{
return
serializeMap
(
type
,
(
LuaTable
)
obj
);
}
private
<
T
>
Map
<
String
,
T
>
serializeMap
(
Class
<
T
>
type
,
LuaTable
table
)
{
Map
<
String
,
T
>
map
=
new
HashMap
<>();
if
(
table
==
null
)
{
return
map
;
}
try
{
LuaValue
[]
keys
=
table
.
keys
();
for
(
LuaValue
k
:
keys
)
{
try
{
LuaValue
keyValue
=
table
.
get
(
k
);
T
object
=
null
;
if
(
keyValue
.
istable
())
{
object
=
serialize
(
type
,
keyValue
.
checktable
());
}
else
if
(
keyValue
.
isint
())
{
object
=
(
T
)
(
Integer
)
keyValue
.
toint
();
}
else
if
(
keyValue
.
isnumber
())
{
object
=
(
T
)
(
Float
)
keyValue
.
tofloat
();
// terrible...
}
else
if
(
keyValue
.
isstring
())
{
object
=
(
T
)
keyValue
.
tojstring
();
}
else
if
(
keyValue
.
isboolean
())
{
object
=
(
T
)
(
Boolean
)
keyValue
.
toboolean
();
}
else
{
object
=
(
T
)
keyValue
;
}
if
(
object
!=
null
)
{
map
.
put
(
String
.
valueOf
(
k
),
object
);
}
}
catch
(
Exception
ex
)
{
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
map
;
}
public
<
T
>
List
<
T
>
serializeList
(
Class
<
T
>
type
,
LuaTable
table
)
{
List
<
T
>
list
=
new
ArrayList
<>();
if
(
table
==
null
)
{
return
list
;
}
try
{
LuaValue
[]
keys
=
table
.
keys
();
for
(
LuaValue
k
:
keys
)
{
try
{
LuaValue
keyValue
=
table
.
get
(
k
);
T
object
=
null
;
if
(
keyValue
.
istable
())
{
object
=
serialize
(
type
,
keyValue
.
checktable
());
}
else
if
(
keyValue
.
isint
())
{
...
...
@@ -75,7 +123,7 @@ public class LuaSerializer implements Serializer {
public
<
T
>
T
serialize
(
Class
<
T
>
type
,
LuaTable
table
)
{
T
object
=
null
;
if
(
type
==
List
.
class
)
{
try
{
Class
<
T
>
listType
=
(
Class
<
T
>)
type
.
getTypeParameters
()[
0
].
getClass
();
...
...
@@ -85,7 +133,7 @@ public class LuaSerializer implements Serializer {
return
null
;
}
}
try
{
if
(!
methodAccessCache
.
containsKey
(
type
))
{
cacheType
(
type
);
...
...
@@ -98,7 +146,7 @@ public class LuaSerializer implements Serializer {
if
(
table
==
null
)
{
return
object
;
}
LuaValue
[]
keys
=
table
.
keys
();
for
(
LuaValue
k
:
keys
)
{
try
{
...
...
@@ -131,7 +179,7 @@ public class LuaSerializer implements Serializer {
Grasscutter
.
getLogger
().
info
(
ScriptUtils
.
toMap
(
table
).
toString
());
e
.
printStackTrace
();
}
return
object
;
}
...
...
src/main/java/emu/grasscutter/scripts/serializer/Serializer.java
View file @
797afd4c
package
emu.grasscutter.scripts.serializer
;
import
java.util.List
;
import
java.util.Map
;
import
org.luaj.vm2.LuaTable
;
public
interface
Serializer
{
public
<
T
>
List
<
T
>
toList
(
Class
<
T
>
type
,
Object
obj
);
public
<
T
>
T
toObject
(
Class
<
T
>
type
,
Object
obj
);
public
<
T
>
Map
<
String
,
T
>
toMap
(
Class
<
T
>
type
,
Object
obj
);
}
src/main/java/emu/grasscutter/server/packet/recv/HandlerAddQuestContentProgressReq.java
View file @
797afd4c
package
emu.grasscutter.server.packet.recv
;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.data.excels.QuestData
;
import
emu.grasscutter.game.quest.GameQuest
;
import
emu.grasscutter.game.quest.enums.QuestTrigger
;
import
emu.grasscutter.net.packet.Opcodes
;
import
emu.grasscutter.net.packet.PacketHandler
;
...
...
@@ -7,6 +10,9 @@ import emu.grasscutter.net.packet.PacketOpcodes;
import
emu.grasscutter.net.proto.AddQuestContentProgressReqOuterClass
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.packet.send.PacketAddQuestContentProgressRsp
;
import
emu.grasscutter.data.excels.QuestData.QuestCondition
;
import
java.util.List
;
import
java.util.stream.Stream
;
@Opcodes
(
PacketOpcodes
.
AddQuestContentProgressReq
)
public
class
HandlerAddQuestContentProgressReq
extends
PacketHandler
{
...
...
@@ -14,9 +20,14 @@ public class HandlerAddQuestContentProgressReq extends PacketHandler {
@Override
public
void
handle
(
GameSession
session
,
byte
[]
header
,
byte
[]
payload
)
throws
Exception
{
var
req
=
AddQuestContentProgressReqOuterClass
.
AddQuestContentProgressReq
.
parseFrom
(
payload
);
session
.
getPlayer
().
getQuestManager
().
triggerEvent
(
QuestTrigger
.
getContentTriggerByValue
(
req
.
getContentType
()),
req
.
getParam
());
//Find all conditions in quest that are the same as the given one
Stream
<
QuestCondition
>
finishCond
=
GameData
.
getQuestDataMap
().
get
(
req
.
getParam
()).
getFinishCond
().
stream
();
Stream
<
QuestCondition
>
acceptCond
=
GameData
.
getQuestDataMap
().
get
(
req
.
getParam
()).
getAcceptCond
().
stream
();
Stream
<
QuestCondition
>
failCond
=
GameData
.
getQuestDataMap
().
get
(
req
.
getParam
()).
getFailCond
().
stream
();
List
<
QuestCondition
>
allCondMatch
=
Stream
.
concat
(
Stream
.
concat
(
acceptCond
,
failCond
),
finishCond
).
filter
(
p
->
p
.
getType
().
getValue
()
==
req
.
getContentType
()).
toList
();
for
(
QuestCondition
cond
:
allCondMatch
)
{
session
.
getPlayer
().
getQuestManager
().
triggerEvent
(
QuestTrigger
.
getContentTriggerByValue
(
req
.
getContentType
()),
cond
.
getParam
());
}
session
.
send
(
new
PacketAddQuestContentProgressRsp
(
req
.
getContentType
()));
}
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterSceneDoneReq.java
View file @
797afd4c
package
emu.grasscutter.server.packet.recv
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.game.player.Player.SceneLoadState
;
import
emu.grasscutter.game.quest.QuestGroupSuite
;
import
emu.grasscutter.net.packet.Opcodes
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.packet.PacketHandler
;
...
...
@@ -16,7 +18,7 @@ public class HandlerEnterSceneDoneReq extends PacketHandler {
session
.
getPlayer
().
setSceneLoadState
(
SceneLoadState
.
LOADED
);
// Done
session
.
send
(
new
PacketEnterSceneDoneRsp
(
session
.
getPlayer
()));
session
.
send
(
new
PacketPlayerTimeNotify
(
session
.
getPlayer
()));
// Probably not the right place
// Spawn player in world
...
...
@@ -35,11 +37,15 @@ public class HandlerEnterSceneDoneReq extends PacketHandler {
// notify client to load the npc for quest
var
questGroupSuites
=
session
.
getPlayer
().
getQuestManager
().
getSceneGroupSuite
(
session
.
getPlayer
().
getSceneId
());
session
.
getPlayer
().
getScene
().
loadGroupForQuest
(
questGroupSuites
);
Grasscutter
.
getLogger
().
debug
(
"Loaded Scene {} Quest(s) Groupsuite(s): {}"
,
session
.
getPlayer
().
getSceneId
(),
questGroupSuites
);
session
.
send
(
new
PacketGroupSuiteNotify
(
questGroupSuites
));
// Reset timer for sending player locations
session
.
getPlayer
().
resetSendPlayerLocTime
();
//Rsp
session
.
send
(
new
PacketEnterSceneDoneRsp
(
session
.
getPlayer
()));
}
}
src/main/java/emu/grasscutter/server/packet/recv/HandlerNpcTalkReq.java
View file @
797afd4c
package
emu.grasscutter.server.packet.recv
;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.data.binout.MainQuestData
;
import
emu.grasscutter.game.inventory.GameItem
;
import
emu.grasscutter.game.quest.GameMainQuest
;
import
emu.grasscutter.game.quest.enums.ParentQuestState
;
import
emu.grasscutter.game.quest.enums.QuestTrigger
;
import
emu.grasscutter.net.packet.Opcodes
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
...
...
@@ -11,16 +15,28 @@ import emu.grasscutter.server.packet.send.PacketNpcTalkRsp;
@Opcodes
(
PacketOpcodes
.
NpcTalkReq
)
public
class
HandlerNpcTalkReq
extends
PacketHandler
{
@Override
public
void
handle
(
GameSession
session
,
byte
[]
header
,
byte
[]
payload
)
throws
Exception
{
NpcTalkReq
req
=
NpcTalkReq
.
parseFrom
(
payload
);
// Why are there 2 quest triggers that do the same thing...
session
.
getPlayer
().
getQuestManager
().
triggerEvent
(
QuestTrigger
.
QUEST_CONTENT_COMPLETE_TALK
,
req
.
getTalkId
());
session
.
getPlayer
().
getQuestManager
().
triggerEvent
(
QuestTrigger
.
QUEST_CONTENT_FINISH_PLOT
,
req
.
getTalkId
());
//Check if mainQuest exists
int
talkId
=
req
.
getTalkId
();
//remove last 2 digits to get a mainQuestId
int
mainQuestId
=
talkId
/
100
;
MainQuestData
mainQuestData
=
GameData
.
getMainQuestDataMap
().
get
(
mainQuestId
);
if
(
mainQuestData
!=
null
)
{
MainQuestData
.
TalkData
talk
=
mainQuestData
.
getTalks
().
stream
().
filter
(
p
->
p
.
getId
()
==
talkId
).
toList
().
get
(
0
);
if
(
talk
!=
null
)
{
//talk is finished
session
.
getPlayer
().
getQuestManager
().
getMainQuestById
(
mainQuestId
).
getTalks
().
put
(
Integer
.
valueOf
(
talkId
),
talk
);
session
.
getPlayer
().
getQuestManager
().
triggerEvent
(
QuestTrigger
.
QUEST_CONTENT_COMPLETE_ANY_TALK
,
String
.
valueOf
(
req
.
getTalkId
()),
0
,
0
);
// Why are there 2 quest triggers that do the same thing...
session
.
getPlayer
().
getQuestManager
().
triggerEvent
(
QuestTrigger
.
QUEST_CONTENT_COMPLETE_TALK
,
req
.
getTalkId
(),
0
);
session
.
getPlayer
().
getQuestManager
().
triggerEvent
(
QuestTrigger
.
QUEST_CONTENT_FINISH_PLOT
,
req
.
getTalkId
(),
0
);
}
}
session
.
send
(
new
PacketNpcTalkRsp
(
req
.
getNpcEntityId
(),
req
.
getTalkId
(),
req
.
getEntityId
()));
}
}
}
\ No newline at end of file
src/main/java/emu/grasscutter/server/packet/recv/HandlerPersonalLineAllDataReq.java
View file @
797afd4c
...
...
@@ -11,7 +11,7 @@ public class HandlerPersonalLineAllDataReq extends PacketHandler {
@Override
public
void
handle
(
GameSession
session
,
byte
[]
header
,
byte
[]
payload
)
throws
Exception
{
session
.
send
(
new
PacketPersonalLineAllDataRsp
(
session
.
getPlayer
().
getQuestManager
().
getQuests
().
values
()));
session
.
send
(
new
PacketPersonalLineAllDataRsp
(
session
.
getPlayer
().
getQuestManager
().
get
Main
Quests
().
values
()));
}
}
src/main/java/emu/grasscutter/server/packet/recv/HandlerPostEnterSceneReq.java
View file @
797afd4c
...
...
@@ -14,7 +14,7 @@ public class HandlerPostEnterSceneReq extends PacketHandler {
@Override
public
void
handle
(
GameSession
session
,
byte
[]
header
,
byte
[]
payload
)
throws
Exception
{
if
(
session
.
getPlayer
().
getScene
().
getSceneType
()
==
SceneType
.
SCENE_ROOM
){
session
.
getPlayer
().
getQuestManager
().
triggerEvent
(
QuestTrigger
.
QUEST_CONTENT_ENTER_ROOM
,
session
.
getPlayer
().
getSceneId
());
session
.
getPlayer
().
getQuestManager
().
triggerEvent
(
QuestTrigger
.
QUEST_CONTENT_ENTER_ROOM
,
session
.
getPlayer
().
getSceneId
()
,
0
);
}
session
.
send
(
new
PacketPostEnterSceneRsp
(
session
.
getPlayer
()));
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestUpdateQuestVarReq.java
0 → 100644
View file @
797afd4c
package
emu.grasscutter.server.packet.recv
;
import
emu.grasscutter.game.quest.GameMainQuest
;
import
emu.grasscutter.net.packet.Opcodes
;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.PacketHeadOuterClass
;
import
emu.grasscutter.net.proto.PlayerSetPauseReqOuterClass
;
import
emu.grasscutter.net.proto.QuestUpdateQuestVarReqOuterClass
;
import
emu.grasscutter.net.proto.QuestVarOpOuterClass
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.packet.send.PacketPlayerSetPauseRsp
;
import
emu.grasscutter.server.packet.send.PacketQuestUpdateQuestVarRsp
;
import
java.util.List
;
@Opcodes
(
PacketOpcodes
.
QuestUpdateQuestVarReq
)
public
class
HandlerQuestUpdateQuestVarReq
extends
PacketHandler
{
@Override
public
void
handle
(
GameSession
session
,
byte
[]
header
,
byte
[]
payload
)
throws
Exception
{
//Client sends packets. One with the value, and one with the index and the new value to set/inc/dec
var
req
=
QuestUpdateQuestVarReqOuterClass
.
QuestUpdateQuestVarReq
.
parseFrom
(
payload
);
GameMainQuest
mainQuest
=
session
.
getPlayer
().
getQuestManager
().
getMainQuestById
(
req
.
getQuestId
()/
100
);
List
<
QuestVarOpOuterClass
.
QuestVarOp
>
questVars
=
req
.
getQuestVarOpListList
();
if
(
mainQuest
.
getQuestVarsUpdate
().
size
()
==
0
)
{
for
(
QuestVarOpOuterClass
.
QuestVarOp
questVar
:
questVars
)
{
mainQuest
.
getQuestVarsUpdate
().
add
(
questVar
.
getValue
());
}
}
else
{
for
(
QuestVarOpOuterClass
.
QuestVarOp
questVar
:
questVars
)
{
if
(
questVar
.
getIsAdd
())
{
if
(
questVar
.
getValue
()
>=
0
)
{
mainQuest
.
incQuestVar
(
questVar
.
getIndex
(),
questVar
.
getValue
());
}
else
{
mainQuest
.
decQuestVar
(
questVar
.
getIndex
(),
questVar
.
getValue
());
}
}
else
{
mainQuest
.
setQuestVar
(
questVar
.
getIndex
(),
mainQuest
.
getQuestVarsUpdate
().
get
(
0
));
}
//remove the first element from the update list
mainQuest
.
getQuestVarsUpdate
().
remove
(
0
);
}
}
session
.
send
(
new
PacketQuestUpdateQuestVarRsp
(
req
.
getQuestId
()));
}
}
src/main/java/emu/grasscutter/server/packet/send/PacketFinishedParentQuestNotify.java
View file @
797afd4c
...
...
@@ -2,21 +2,25 @@ package emu.grasscutter.server.packet.send;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.quest.GameMainQuest
;
import
emu.grasscutter.game.quest.enums.ParentQuestState
;
import
emu.grasscutter.net.packet.BasePacket
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.FinishedParentQuestNotifyOuterClass.FinishedParentQuestNotify
;
public
class
PacketFinishedParentQuestNotify
extends
BasePacket
{
public
PacketFinishedParentQuestNotify
(
Player
player
)
{
super
(
PacketOpcodes
.
FinishedParentQuestNotify
,
true
);
FinishedParentQuestNotify
.
Builder
proto
=
FinishedParentQuestNotify
.
newBuilder
();
for
(
GameMainQuest
mainQuest
:
player
.
getQuestManager
().
getQuests
().
values
())
{
proto
.
addParentQuestList
(
mainQuest
.
toProto
());
for
(
GameMainQuest
mainQuest
:
player
.
getQuestManager
().
getMainQuests
().
values
())
{
//Canceled Quests do not appear in this packet
if
(
mainQuest
.
getState
()
!=
ParentQuestState
.
PARENT_QUEST_STATE_CANCELED
)
{
proto
.
addParentQuestList
(
mainQuest
.
toProto
());
}
}
this
.
setData
(
proto
);
}
}
src/main/java/emu/grasscutter/server/packet/send/PacketFinishedParentQuestUpdateNotify.java
View file @
797afd4c
...
...
@@ -5,15 +5,29 @@ import emu.grasscutter.net.packet.BasePacket;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.FinishedParentQuestUpdateNotifyOuterClass.FinishedParentQuestUpdateNotify
;
import
java.util.List
;
public
class
PacketFinishedParentQuestUpdateNotify
extends
BasePacket
{
public
PacketFinishedParentQuestUpdateNotify
(
GameMainQuest
quest
)
{
super
(
PacketOpcodes
.
FinishedParentQuestUpdateNotify
);
FinishedParentQuestUpdateNotify
proto
=
FinishedParentQuestUpdateNotify
.
newBuilder
()
.
addParentQuestList
(
quest
.
toProto
())
.
build
();
this
.
setData
(
proto
);
}
public
PacketFinishedParentQuestUpdateNotify
(
List
<
GameMainQuest
>
quests
)
{
super
(
PacketOpcodes
.
FinishedParentQuestUpdateNotify
);
var
proto
=
FinishedParentQuestUpdateNotify
.
newBuilder
();
for
(
GameMainQuest
mainQuest
:
quests
)
{
proto
.
addParentQuestList
(
mainQuest
.
toProto
());
}
proto
.
build
();
this
.
setData
(
proto
);
}
}
src/main/java/emu/grasscutter/server/packet/send/PacketPersonalLineAllDataRsp.java
View file @
797afd4c
...
...
@@ -23,7 +23,7 @@ public class PacketPersonalLineAllDataRsp extends BasePacket {
.
map
(
GameMainQuest:
:
getChildQuests
)
.
map
(
Map:
:
values
)
.
flatMap
(
Collection:
:
stream
)
.
map
(
GameQuest:
:
getQuestId
)
.
map
(
GameQuest:
:
get
Sub
QuestId
)
.
collect
(
Collectors
.
toSet
());
GameData
.
getPersonalLineDataMap
().
values
().
stream
()
...
...
src/main/java/emu/grasscutter/server/packet/send/PacketQuestListNotify.java
View file @
797afd4c
...
...
@@ -3,21 +3,24 @@ package emu.grasscutter.server.packet.send;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.quest.GameMainQuest
;
import
emu.grasscutter.game.quest.QuestManager
;
import
emu.grasscutter.game.quest.enums.QuestState
;
import
emu.grasscutter.net.packet.BasePacket
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.QuestListNotifyOuterClass.QuestListNotify
;
public
class
PacketQuestListNotify
extends
BasePacket
{
public
PacketQuestListNotify
(
Player
player
)
{
super
(
PacketOpcodes
.
QuestListNotify
,
true
);
QuestListNotify
.
Builder
proto
=
QuestListNotify
.
newBuilder
();
player
.
getQuestManager
().
forEachQuest
(
quest
->
{
proto
.
addQuestList
(
quest
.
toProto
());
if
(
quest
.
getState
()
!=
QuestState
.
QUEST_STATE_UNSTARTED
)
{
proto
.
addQuestList
(
quest
.
toProto
());
}
});
this
.
setData
(
proto
);
}
}
src/main/java/emu/grasscutter/server/packet/send/PacketQuestListUpdateNotify.java
View file @
797afd4c
...
...
@@ -6,15 +6,28 @@ import emu.grasscutter.net.packet.BasePacket;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.QuestListUpdateNotifyOuterClass.QuestListUpdateNotify
;
import
java.util.List
;
public
class
PacketQuestListUpdateNotify
extends
BasePacket
{
public
PacketQuestListUpdateNotify
(
GameQuest
quest
)
{
super
(
PacketOpcodes
.
QuestListUpdateNotify
);
QuestListUpdateNotify
proto
=
QuestListUpdateNotify
.
newBuilder
()
.
addQuestList
(
quest
.
toProto
())
.
build
();
this
.
setData
(
proto
);
}
public
PacketQuestListUpdateNotify
(
List
<
GameQuest
>
quests
)
{
super
(
PacketOpcodes
.
QuestListUpdateNotify
);
var
proto
=
QuestListUpdateNotify
.
newBuilder
();
for
(
GameQuest
quest
:
quests
)
{
proto
.
addQuestList
(
quest
.
toProto
());
}
proto
.
build
();
this
.
setData
(
proto
);
}
}
Prev
1
2
3
4
Next
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