Commit a8690ef7 authored by Akka's avatar Akka Committed by Melledy
Browse files

fix bug

parent 12146ff0
...@@ -23,7 +23,7 @@ public class MusicGameActivityHandler extends ActivityHandler { ...@@ -23,7 +23,7 @@ public class MusicGameActivityHandler extends ActivityHandler {
@Override @Override
public void onProtoBuild(PlayerActivityData playerActivityData, ActivityInfoOuterClass.ActivityInfo.Builder activityInfo) { public void onProtoBuild(PlayerActivityData playerActivityData, ActivityInfoOuterClass.ActivityInfo.Builder activityInfo) {
MusicGamePlayerData musicGamePlayerData = getMusicGameRecord(playerActivityData); MusicGamePlayerData musicGamePlayerData = getMusicGamePlayerData(playerActivityData);
activityInfo.setMusicGameInfo(MusicGameActivityDetailInfoOuterClass.MusicGameActivityDetailInfo.newBuilder() activityInfo.setMusicGameInfo(MusicGameActivityDetailInfoOuterClass.MusicGameActivityDetailInfo.newBuilder()
.putAllMusicGameRecordMap( .putAllMusicGameRecordMap(
...@@ -31,18 +31,18 @@ public class MusicGameActivityHandler extends ActivityHandler { ...@@ -31,18 +31,18 @@ public class MusicGameActivityHandler extends ActivityHandler {
.collect(Collectors.toMap(MusicGamePlayerData.MusicGameRecord::getMusicId, MusicGamePlayerData.MusicGameRecord::toProto))) .collect(Collectors.toMap(MusicGamePlayerData.MusicGameRecord::getMusicId, MusicGamePlayerData.MusicGameRecord::toProto)))
.addAllPersonCustomBeatmap(musicGamePlayerData.getPersonalCustomBeatmapRecord().values().stream() .addAllPersonCustomBeatmap(musicGamePlayerData.getPersonalCustomBeatmapRecord().values().stream()
.map(MusicGamePlayerData.CustomBeatmapRecord::toProto) .map(MusicGamePlayerData.CustomBeatmapRecord::toPersonalBriefProto)
.map(MusicBriefInfoOuterClass.MusicBriefInfo.Builder::build) .map(MusicBriefInfoOuterClass.MusicBriefInfo.Builder::build)
.toList()) .toList())
.addAllPersonCustomBeatmap(musicGamePlayerData.getOthersCustomBeatmapRecord().values().stream() .addAllPersonCustomBeatmap(musicGamePlayerData.getOthersCustomBeatmapRecord().values().stream()
.map(MusicGamePlayerData.CustomBeatmapRecord::toProto) .map(MusicGamePlayerData.CustomBeatmapRecord::toOthersBriefProto)
.map(MusicBriefInfoOuterClass.MusicBriefInfo.Builder::build) .map(MusicBriefInfoOuterClass.MusicBriefInfo.Builder::build)
.toList()) .toList())
.build()); .build());
} }
public MusicGamePlayerData getMusicGameRecord(PlayerActivityData playerActivityData){ public MusicGamePlayerData getMusicGamePlayerData(PlayerActivityData playerActivityData){
if(playerActivityData.getDetail() == null || playerActivityData.getDetail().isBlank()){ if(playerActivityData.getDetail() == null || playerActivityData.getDetail().isBlank()){
onInitPlayerActivityData(playerActivityData); onInitPlayerActivityData(playerActivityData);
playerActivityData.save(); playerActivityData.save();
...@@ -53,7 +53,7 @@ public class MusicGameActivityHandler extends ActivityHandler { ...@@ -53,7 +53,7 @@ public class MusicGameActivityHandler extends ActivityHandler {
} }
public boolean setMusicGameRecord(PlayerActivityData playerActivityData, MusicGamePlayerData.MusicGameRecord newRecord){ public boolean setMusicGameRecord(PlayerActivityData playerActivityData, MusicGamePlayerData.MusicGameRecord newRecord){
var musicGamePlayerData = getMusicGameRecord(playerActivityData); var musicGamePlayerData = getMusicGamePlayerData(playerActivityData);
var saveRecord = musicGamePlayerData.getMusicGameRecord().get(newRecord.getMusicId()); var saveRecord = musicGamePlayerData.getMusicGameRecord().get(newRecord.getMusicId());
saveRecord.setMaxCombo(Math.max(newRecord.getMaxCombo(), saveRecord.getMaxCombo())); saveRecord.setMaxCombo(Math.max(newRecord.getMaxCombo(), saveRecord.getMaxCombo()));
...@@ -65,7 +65,7 @@ public class MusicGameActivityHandler extends ActivityHandler { ...@@ -65,7 +65,7 @@ public class MusicGameActivityHandler extends ActivityHandler {
return newRecord.getMaxScore() > saveRecord.getMaxScore(); return newRecord.getMaxScore() > saveRecord.getMaxScore();
} }
public void setMusicGameCustomBeatmapRecord(PlayerActivityData playerActivityData, MusicGamePlayerData.CustomBeatmapRecord newRecord){ public void setMusicGameCustomBeatmapRecord(PlayerActivityData playerActivityData, MusicGamePlayerData.CustomBeatmapRecord newRecord){
var musicGamePlayerData = getMusicGameRecord(playerActivityData); var musicGamePlayerData = getMusicGamePlayerData(playerActivityData);
musicGamePlayerData.getOthersCustomBeatmapRecord().put(newRecord.getMusicShareId(), newRecord); musicGamePlayerData.getOthersCustomBeatmapRecord().put(newRecord.getMusicShareId(), newRecord);
playerActivityData.setDetail(musicGamePlayerData); playerActivityData.setDetail(musicGamePlayerData);
...@@ -73,7 +73,7 @@ public class MusicGameActivityHandler extends ActivityHandler { ...@@ -73,7 +73,7 @@ public class MusicGameActivityHandler extends ActivityHandler {
} }
public void addPersonalBeatmap(PlayerActivityData playerActivityData, MusicGameBeatmap musicGameBeatmap) { public void addPersonalBeatmap(PlayerActivityData playerActivityData, MusicGameBeatmap musicGameBeatmap) {
var musicGamePlayerData = getMusicGameRecord(playerActivityData); var musicGamePlayerData = getMusicGamePlayerData(playerActivityData);
musicGamePlayerData.getPersonalCustomBeatmapRecord().put(musicGameBeatmap.getMusicShareId(), musicGamePlayerData.getPersonalCustomBeatmapRecord().put(musicGameBeatmap.getMusicShareId(),
MusicGamePlayerData.CustomBeatmapRecord.of() MusicGamePlayerData.CustomBeatmapRecord.of()
.musicShareId(musicGameBeatmap.getMusicShareId()) .musicShareId(musicGameBeatmap.getMusicShareId())
...@@ -82,4 +82,12 @@ public class MusicGameActivityHandler extends ActivityHandler { ...@@ -82,4 +82,12 @@ public class MusicGameActivityHandler extends ActivityHandler {
playerActivityData.setDetail(musicGamePlayerData); playerActivityData.setDetail(musicGamePlayerData);
playerActivityData.save(); playerActivityData.save();
} }
public void removePersonalBeatmap(PlayerActivityData playerActivityData, MusicGameBeatmap musicGameBeatmap) {
var musicGamePlayerData = getMusicGamePlayerData(playerActivityData);
musicGamePlayerData.getPersonalCustomBeatmapRecord().remove(musicGameBeatmap.getMusicShareId());
playerActivityData.setDetail(musicGamePlayerData);
playerActivityData.save();
}
} }
...@@ -64,12 +64,10 @@ public class MusicGameBeatmap { ...@@ -64,12 +64,10 @@ public class MusicGameBeatmap {
var player = DatabaseHelper.getPlayerByUid(authorUid); var player = DatabaseHelper.getPlayerByUid(authorUid);
return MusicBriefInfoOuterClass.MusicBriefInfo.newBuilder() return MusicBriefInfoOuterClass.MusicBriefInfo.newBuilder()
.setCanShare(true)
.setMusicId(musicId) .setMusicId(musicId)
.setMusicNoteCount(musicNoteCount) .setMusicNoteCount(musicNoteCount)
.setMusicShareId(musicShareId) .setMusicShareId(musicShareId)
.setMaxScore(maxScore) .setMaxScore(maxScore)
.setCreateTime(createTime)
.setShareTime(createTime) .setShareTime(createTime)
.setAuthorNickname(player.getNickname()) .setAuthorNickname(player.getNickname())
.setVersion(1) .setVersion(1)
......
...@@ -61,7 +61,21 @@ public class MusicGamePlayerData { ...@@ -61,7 +61,21 @@ public class MusicGamePlayerData {
int score; int score;
boolean settle; 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); var musicGameBeatmap = MusicGameBeatmap.getByShareId(musicShareId);
return musicGameBeatmap.toBriefProto() return musicGameBeatmap.toBriefProto()
......
...@@ -909,6 +909,8 @@ public class PacketOpcodes { ...@@ -909,6 +909,8 @@ public class PacketOpcodes {
public static final int MusicGameSettleRsp = 8288; public static final int MusicGameSettleRsp = 8288;
public static final int MusicGameStartReq = 8927; public static final int MusicGameStartReq = 8927;
public static final int MusicGameStartRsp = 8101; 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 NavMeshStatsNotify = 2387;
public static final int NormalUidOpNotify = 5718; public static final int NormalUidOpNotify = 5718;
public static final int NpcTalkReq = 509; public static final int NpcTalkReq = 509;
......
package emu.grasscutter.server.packet.recv; package emu.grasscutter.server.packet.recv;
import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.activity.musicgame.MusicGameActivityHandler; import emu.grasscutter.game.activity.musicgame.MusicGameActivityHandler;
import emu.grasscutter.game.activity.musicgame.MusicGameBeatmap; import emu.grasscutter.game.activity.musicgame.MusicGameBeatmap;
import emu.grasscutter.game.activity.musicgame.MusicGamePlayerData;
import emu.grasscutter.game.props.ActivityType; import emu.grasscutter.game.props.ActivityType;
import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler; import emu.grasscutter.net.packet.PacketHandler;
...@@ -12,6 +14,8 @@ import emu.grasscutter.server.packet.send.PacketActivityInfoNotify; ...@@ -12,6 +14,8 @@ import emu.grasscutter.server.packet.send.PacketActivityInfoNotify;
import emu.grasscutter.server.packet.send.PacketMusicGameCreateBeatmapRsp; import emu.grasscutter.server.packet.send.PacketMusicGameCreateBeatmapRsp;
import emu.grasscutter.utils.Utils; import emu.grasscutter.utils.Utils;
import java.util.Objects;
@Opcodes(PacketOpcodes.MusicGameCreateBeatmapReq) @Opcodes(PacketOpcodes.MusicGameCreateBeatmapReq)
public class HandlerMusicGameCreateBeatmapReq extends PacketHandler { public class HandlerMusicGameCreateBeatmapReq extends PacketHandler {
...@@ -22,14 +26,13 @@ public class HandlerMusicGameCreateBeatmapReq extends PacketHandler { ...@@ -22,14 +26,13 @@ public class HandlerMusicGameCreateBeatmapReq extends PacketHandler {
var musicGameBeatmap = MusicGameBeatmap.of() var musicGameBeatmap = MusicGameBeatmap.of()
.musicId(req.getMusicBriefInfo().getMusicId()) .musicId(req.getMusicBriefInfo().getMusicId())
.musicNoteCount(req.getMusicBriefInfo().getMusicNoteCount()) .musicNoteCount(req.getMusicBriefInfo().getMusicNoteCount())
.savePosition(req.getMusicBriefInfo().getSavePosition()) .savePosition(req.getMusicBriefInfo().getPosition())
.maxScore(req.getMusicBriefInfo().getMaxScore()) .maxScore(req.getMusicBriefInfo().getMaxScore())
.authorUid(session.getPlayer().getUid()) .authorUid(session.getPlayer().getUid())
.beatmap(MusicGameBeatmap.parse(req.getMusicRecord().getBeatmapItemListList())) .beatmap(MusicGameBeatmap.parse(req.getMusicRecord().getBeatmapItemListList()))
.createTime(Utils.getCurrentSeconds()) .createTime(Utils.getCurrentSeconds())
.build(); .build();
// TODO avoid player save too much to make server down
musicGameBeatmap.save(); musicGameBeatmap.save();
var playerData = session.getPlayer().getActivityManager().getPlayerActivityDataByActivityType(ActivityType.NEW_ACTIVITY_MUSIC_GAME); var playerData = session.getPlayer().getActivityManager().getPlayerActivityDataByActivityType(ActivityType.NEW_ACTIVITY_MUSIC_GAME);
...@@ -38,6 +41,22 @@ public class HandlerMusicGameCreateBeatmapReq extends PacketHandler { ...@@ -38,6 +41,22 @@ public class HandlerMusicGameCreateBeatmapReq extends PacketHandler {
} }
var handler = (MusicGameActivityHandler) playerData.get().getActivityHandler(); 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); handler.addPersonalBeatmap(playerData.get(), musicGameBeatmap);
session.send(new PacketActivityInfoNotify(handler.toProto(playerData.get()))); session.send(new PacketActivityInfoNotify(handler.toProto(playerData.get())));
......
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()));
}
}
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);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment