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
a8690ef7
Commit
a8690ef7
authored
Jun 27, 2022
by
Akka
Committed by
Melledy
Jun 29, 2022
Browse files
fix bug
parent
12146ff0
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/game/activity/musicgame/MusicGameActivityHandler.java
View file @
a8690ef7
...
...
@@ -23,7 +23,7 @@ public class MusicGameActivityHandler extends ActivityHandler {
@Override
public
void
onProtoBuild
(
PlayerActivityData
playerActivityData
,
ActivityInfoOuterClass
.
ActivityInfo
.
Builder
activityInfo
)
{
MusicGamePlayerData
musicGamePlayerData
=
getMusicGame
Record
(
playerActivityData
);
MusicGamePlayerData
musicGamePlayerData
=
getMusicGame
PlayerData
(
playerActivityData
);
activityInfo
.
setMusicGameInfo
(
MusicGameActivityDetailInfoOuterClass
.
MusicGameActivityDetailInfo
.
newBuilder
()
.
putAllMusicGameRecordMap
(
...
...
@@ -31,18 +31,18 @@ public class MusicGameActivityHandler extends ActivityHandler {
.
collect
(
Collectors
.
toMap
(
MusicGamePlayerData
.
MusicGameRecord
::
getMusicId
,
MusicGamePlayerData
.
MusicGameRecord
::
toProto
)))
.
addAllPersonCustomBeatmap
(
musicGamePlayerData
.
getPersonalCustomBeatmapRecord
().
values
().
stream
()
.
map
(
MusicGamePlayerData
.
CustomBeatmapRecord
::
toProto
)
.
map
(
MusicGamePlayerData
.
CustomBeatmapRecord
::
toP
ersonalBriefP
roto
)
.
map
(
MusicBriefInfoOuterClass
.
MusicBriefInfo
.
Builder
::
build
)
.
toList
())
.
addAllPersonCustomBeatmap
(
musicGamePlayerData
.
getOthersCustomBeatmapRecord
().
values
().
stream
()
.
map
(
MusicGamePlayerData
.
CustomBeatmapRecord
::
toProto
)
.
map
(
MusicGamePlayerData
.
CustomBeatmapRecord
::
to
OthersBrief
Proto
)
.
map
(
MusicBriefInfoOuterClass
.
MusicBriefInfo
.
Builder
::
build
)
.
toList
())
.
build
());
}
public
MusicGamePlayerData
getMusicGame
Record
(
PlayerActivityData
playerActivityData
){
public
MusicGamePlayerData
getMusicGame
PlayerData
(
PlayerActivityData
playerActivityData
){
if
(
playerActivityData
.
getDetail
()
==
null
||
playerActivityData
.
getDetail
().
isBlank
()){
onInitPlayerActivityData
(
playerActivityData
);
playerActivityData
.
save
();
...
...
@@ -53,7 +53,7 @@ public class MusicGameActivityHandler extends ActivityHandler {
}
public
boolean
setMusicGameRecord
(
PlayerActivityData
playerActivityData
,
MusicGamePlayerData
.
MusicGameRecord
newRecord
){
var
musicGamePlayerData
=
getMusicGame
Record
(
playerActivityData
);
var
musicGamePlayerData
=
getMusicGame
PlayerData
(
playerActivityData
);
var
saveRecord
=
musicGamePlayerData
.
getMusicGameRecord
().
get
(
newRecord
.
getMusicId
());
saveRecord
.
setMaxCombo
(
Math
.
max
(
newRecord
.
getMaxCombo
(),
saveRecord
.
getMaxCombo
()));
...
...
@@ -65,7 +65,7 @@ public class MusicGameActivityHandler extends ActivityHandler {
return
newRecord
.
getMaxScore
()
>
saveRecord
.
getMaxScore
();
}
public
void
setMusicGameCustomBeatmapRecord
(
PlayerActivityData
playerActivityData
,
MusicGamePlayerData
.
CustomBeatmapRecord
newRecord
){
var
musicGamePlayerData
=
getMusicGame
Record
(
playerActivityData
);
var
musicGamePlayerData
=
getMusicGame
PlayerData
(
playerActivityData
);
musicGamePlayerData
.
getOthersCustomBeatmapRecord
().
put
(
newRecord
.
getMusicShareId
(),
newRecord
);
playerActivityData
.
setDetail
(
musicGamePlayerData
);
...
...
@@ -73,7 +73,7 @@ public class MusicGameActivityHandler extends ActivityHandler {
}
public
void
addPersonalBeatmap
(
PlayerActivityData
playerActivityData
,
MusicGameBeatmap
musicGameBeatmap
)
{
var
musicGamePlayerData
=
getMusicGame
Record
(
playerActivityData
);
var
musicGamePlayerData
=
getMusicGame
PlayerData
(
playerActivityData
);
musicGamePlayerData
.
getPersonalCustomBeatmapRecord
().
put
(
musicGameBeatmap
.
getMusicShareId
(),
MusicGamePlayerData
.
CustomBeatmapRecord
.
of
()
.
musicShareId
(
musicGameBeatmap
.
getMusicShareId
())
...
...
@@ -82,4 +82,12 @@ public class MusicGameActivityHandler extends ActivityHandler {
playerActivityData
.
setDetail
(
musicGamePlayerData
);
playerActivityData
.
save
();
}
public
void
removePersonalBeatmap
(
PlayerActivityData
playerActivityData
,
MusicGameBeatmap
musicGameBeatmap
)
{
var
musicGamePlayerData
=
getMusicGamePlayerData
(
playerActivityData
);
musicGamePlayerData
.
getPersonalCustomBeatmapRecord
().
remove
(
musicGameBeatmap
.
getMusicShareId
());
playerActivityData
.
setDetail
(
musicGamePlayerData
);
playerActivityData
.
save
();
}
}
src/main/java/emu/grasscutter/game/activity/musicgame/MusicGameBeatmap.java
View file @
a8690ef7
...
...
@@ -64,12 +64,10 @@ public class MusicGameBeatmap {
var
player
=
DatabaseHelper
.
getPlayerByUid
(
authorUid
);
return
MusicBriefInfoOuterClass
.
MusicBriefInfo
.
newBuilder
()
.
setCanShare
(
true
)
.
setMusicId
(
musicId
)
.
setMusicNoteCount
(
musicNoteCount
)
.
setMusicShareId
(
musicShareId
)
.
setMaxScore
(
maxScore
)
.
setCreateTime
(
createTime
)
.
setShareTime
(
createTime
)
.
setAuthorNickname
(
player
.
getNickname
())
.
setVersion
(
1
)
...
...
src/main/java/emu/grasscutter/game/activity/musicgame/MusicGamePlayerData.java
View file @
a8690ef7
...
...
@@ -61,7 +61,21 @@ public class MusicGamePlayerData {
int
score
;
boolean
settle
;
public
MusicBriefInfoOuterClass
.
MusicBriefInfo
.
Builder
toProto
(){
public
MusicBriefInfoOuterClass
.
MusicBriefInfo
.
Builder
toPersonalBriefProto
(){
var
musicGameBeatmap
=
MusicGameBeatmap
.
getByShareId
(
musicShareId
);
return
MusicBriefInfoOuterClass
.
MusicBriefInfo
.
newBuilder
()
.
setCanShare
(
true
)
.
setCreateTime
(
musicGameBeatmap
.
getCreateTime
())
.
setMusicId
(
musicGameBeatmap
.
getMusicId
())
.
setMaxScore
(
musicGameBeatmap
.
getMaxScore
())
.
setPosition
(
musicGameBeatmap
.
getSavePosition
())
.
setMusicNoteCount
(
musicGameBeatmap
.
getMusicNoteCount
())
.
setMusicShareId
(
musicShareId
)
;
}
public
MusicBriefInfoOuterClass
.
MusicBriefInfo
.
Builder
toOthersBriefProto
(){
var
musicGameBeatmap
=
MusicGameBeatmap
.
getByShareId
(
musicShareId
);
return
musicGameBeatmap
.
toBriefProto
()
...
...
src/main/java/emu/grasscutter/net/packet/PacketOpcodes.java
View file @
a8690ef7
...
...
@@ -909,6 +909,8 @@ public class PacketOpcodes {
public
static
final
int
MusicGameSettleRsp
=
8288
;
public
static
final
int
MusicGameStartReq
=
8927
;
public
static
final
int
MusicGameStartRsp
=
8101
;
public
static
final
int
MusicGameStartToPlayOthersBeatmapReq
=
6302
;
public
static
final
int
MusicGameStartToPlayOthersBeatmapRsp
=
6313
;
public
static
final
int
NavMeshStatsNotify
=
2387
;
public
static
final
int
NormalUidOpNotify
=
5718
;
public
static
final
int
NpcTalkReq
=
509
;
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerMusicGameCreateBeatmapReq.java
View file @
a8690ef7
package
emu.grasscutter.server.packet.recv
;
import
emu.grasscutter.database.DatabaseHelper
;
import
emu.grasscutter.game.activity.musicgame.MusicGameActivityHandler
;
import
emu.grasscutter.game.activity.musicgame.MusicGameBeatmap
;
import
emu.grasscutter.game.activity.musicgame.MusicGamePlayerData
;
import
emu.grasscutter.game.props.ActivityType
;
import
emu.grasscutter.net.packet.Opcodes
;
import
emu.grasscutter.net.packet.PacketHandler
;
...
...
@@ -12,6 +14,8 @@ import emu.grasscutter.server.packet.send.PacketActivityInfoNotify;
import
emu.grasscutter.server.packet.send.PacketMusicGameCreateBeatmapRsp
;
import
emu.grasscutter.utils.Utils
;
import
java.util.Objects
;
@Opcodes
(
PacketOpcodes
.
MusicGameCreateBeatmapReq
)
public
class
HandlerMusicGameCreateBeatmapReq
extends
PacketHandler
{
...
...
@@ -22,14 +26,13 @@ public class HandlerMusicGameCreateBeatmapReq extends PacketHandler {
var
musicGameBeatmap
=
MusicGameBeatmap
.
of
()
.
musicId
(
req
.
getMusicBriefInfo
().
getMusicId
())
.
musicNoteCount
(
req
.
getMusicBriefInfo
().
getMusicNoteCount
())
.
savePosition
(
req
.
getMusicBriefInfo
().
get
Save
Position
())
.
savePosition
(
req
.
getMusicBriefInfo
().
getPosition
())
.
maxScore
(
req
.
getMusicBriefInfo
().
getMaxScore
())
.
authorUid
(
session
.
getPlayer
().
getUid
())
.
beatmap
(
MusicGameBeatmap
.
parse
(
req
.
getMusicRecord
().
getBeatmapItemListList
()))
.
createTime
(
Utils
.
getCurrentSeconds
())
.
build
();
// TODO avoid player save too much to make server down
musicGameBeatmap
.
save
();
var
playerData
=
session
.
getPlayer
().
getActivityManager
().
getPlayerActivityDataByActivityType
(
ActivityType
.
NEW_ACTIVITY_MUSIC_GAME
);
...
...
@@ -38,6 +41,22 @@ public class HandlerMusicGameCreateBeatmapReq extends PacketHandler {
}
var
handler
=
(
MusicGameActivityHandler
)
playerData
.
get
().
getActivityHandler
();
var
musicGamePlayerData
=
handler
.
getMusicGamePlayerData
(
playerData
.
get
());
var
oldBeatmap
=
musicGamePlayerData
.
getPersonalCustomBeatmapRecord
().
values
().
stream
()
.
map
(
MusicGamePlayerData
.
CustomBeatmapRecord
::
getMusicShareId
)
.
map
(
DatabaseHelper:
:
getMusicGameBeatmap
)
.
filter
(
Objects:
:
nonNull
)
.
filter
(
item
->
item
.
getAuthorUid
()
==
session
.
getPlayer
().
getUid
())
.
filter
(
item
->
item
.
getMusicId
()
==
req
.
getMusicBriefInfo
().
getMusicId
())
.
filter
(
item
->
item
.
getSavePosition
()
==
req
.
getMusicBriefInfo
().
getPosition
())
.
findFirst
();
// delete old beatmap for player
// the old beatmap is still in database so that others can still play.
oldBeatmap
.
ifPresent
(
i
->
handler
.
removePersonalBeatmap
(
playerData
.
get
(),
i
));
// link this beatmap to player's personal data
handler
.
addPersonalBeatmap
(
playerData
.
get
(),
musicGameBeatmap
);
session
.
send
(
new
PacketActivityInfoNotify
(
handler
.
toProto
(
playerData
.
get
())));
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerMusicGameStartToPlayOthersBeatmapReq.java
0 → 100644
View file @
a8690ef7
package
emu.grasscutter.server.packet.recv
;
import
emu.grasscutter.net.packet.Opcodes
;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.MusicGameStartToPlayOthersBeatmapReqOuterClass
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.packet.send.PacketMusicGameStartToPlayOthersBeatmapRsp
;
@Opcodes
(
PacketOpcodes
.
MusicGameStartToPlayOthersBeatmapReq
)
public
class
HandlerMusicGameStartToPlayOthersBeatmapReq
extends
PacketHandler
{
@Override
public
void
handle
(
GameSession
session
,
byte
[]
header
,
byte
[]
payload
)
throws
Exception
{
var
req
=
MusicGameStartToPlayOthersBeatmapReqOuterClass
.
MusicGameStartToPlayOthersBeatmapReq
.
parseFrom
(
payload
);
session
.
send
(
new
PacketMusicGameStartToPlayOthersBeatmapRsp
(
req
.
getUnknownEnum1
()));
}
}
src/main/java/emu/grasscutter/server/packet/send/PacketMusicGameStartToPlayOthersBeatmapRsp.java
0 → 100644
View file @
a8690ef7
package
emu.grasscutter.server.packet.send
;
import
emu.grasscutter.net.packet.BasePacket
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.MusicGameStartToPlayOthersBeatmapRspOuterClass
;
import
emu.grasscutter.net.proto.MusicGameUnknown1EnumOuterClass
;
public
class
PacketMusicGameStartToPlayOthersBeatmapRsp
extends
BasePacket
{
public
PacketMusicGameStartToPlayOthersBeatmapRsp
(
MusicGameUnknown1EnumOuterClass
.
MusicGameUnknown1Enum
unknownEnum1
)
{
super
(
PacketOpcodes
.
MusicGameStartToPlayOthersBeatmapRsp
);
var
proto
=
MusicGameStartToPlayOthersBeatmapRspOuterClass
.
MusicGameStartToPlayOthersBeatmapRsp
.
newBuilder
();
proto
.
setUnknownEnum1
(
unknownEnum1
);
this
.
setData
(
proto
);
}
}
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