Commit 12146ff0 authored by Akka's avatar Akka Committed by Melledy
Browse files

implement the music game

parent 977f1ca2
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.game.activity.musicgame.MusicGameBeatmap;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.MusicGameGetBeatmapReqOuterClass;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketMusicGameGetBeatmapRsp;
@Opcodes(PacketOpcodes.MusicGameGetBeatmapReq)
public class HandlerMusicGameGetBeatmapReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
var req = MusicGameGetBeatmapReqOuterClass.MusicGameGetBeatmapReq.parseFrom(payload);
var musicGameBeatmap = MusicGameBeatmap.getByShareId(req.getMusicShareId());
if(musicGameBeatmap == null){
return;
}
session.send(new PacketMusicGameGetBeatmapRsp(
musicGameBeatmap.toBriefProto().build(),
musicGameBeatmap.toProto(),
req
));
}
}
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.game.activity.musicgame.MusicGameBeatmap;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.MusicGameSearchBeatmapReqOuterClass;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketMusicGameSearchBeatmapRsp;
@Opcodes(PacketOpcodes.MusicGameSearchBeatmapReq)
public class HandlerMusicGameSearchBeatmapReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
var req = MusicGameSearchBeatmapReqOuterClass.MusicGameSearchBeatmapReq.parseFrom(payload);
var musicGameBeatmap = MusicGameBeatmap.getByShareId(req.getMusicShareId());
if(musicGameBeatmap == null){
session.send(new PacketMusicGameSearchBeatmapRsp(11153, req.getUnknownEnum1()));
return;
}
session.send(new PacketMusicGameSearchBeatmapRsp(musicGameBeatmap.toBriefProto().build(), req.getUnknownEnum1()));
}
}
package emu.grasscutter.server.packet.recv; package emu.grasscutter.server.packet.recv;
import emu.grasscutter.game.activity.musicgame.MusicGameActivityHandler;
import emu.grasscutter.game.activity.musicgame.MusicGamePlayerData;
import emu.grasscutter.game.props.ActivityType;
import emu.grasscutter.game.props.WatcherTriggerType; import emu.grasscutter.game.props.WatcherTriggerType;
import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler; import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.MusicGameSettleReqOuterClass; import emu.grasscutter.net.proto.MusicGameSettleReqOuterClass;
import emu.grasscutter.server.game.GameSession; import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketActivityInfoNotify;
import emu.grasscutter.server.packet.send.PacketMusicGameSettleRsp; import emu.grasscutter.server.packet.send.PacketMusicGameSettleRsp;
@Opcodes(PacketOpcodes.MusicGameSettleReq) @Opcodes(PacketOpcodes.MusicGameSettleReq)
...@@ -15,15 +19,40 @@ public class HandlerMusicGameSettleReq extends PacketHandler { ...@@ -15,15 +19,40 @@ public class HandlerMusicGameSettleReq extends PacketHandler {
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
var req = MusicGameSettleReqOuterClass.MusicGameSettleReq.parseFrom(payload); var req = MusicGameSettleReqOuterClass.MusicGameSettleReq.parseFrom(payload);
session.getPlayer().getActivityManager().triggerWatcher( var playerData = session.getPlayer().getActivityManager().getPlayerActivityDataByActivityType(ActivityType.NEW_ACTIVITY_MUSIC_GAME);
WatcherTriggerType.TRIGGER_FLEUR_FAIR_MUSIC_GAME_REACH_SCORE, if(playerData.isEmpty()){
String.valueOf(req.getMusicBasicId()), return;
String.valueOf(req.getScore()) }
var handler = (MusicGameActivityHandler) playerData.get().getActivityHandler();
boolean isNewRecord = false;
// check if custom beatmap
if(req.getMusicShareId() == 0){
session.getPlayer().getActivityManager().triggerWatcher(
WatcherTriggerType.TRIGGER_FLEUR_FAIR_MUSIC_GAME_REACH_SCORE,
String.valueOf(req.getMusicBasicId()),
String.valueOf(req.getScore())
); );
isNewRecord = handler.setMusicGameRecord(playerData.get(),
MusicGamePlayerData.MusicGameRecord.of()
.musicId(req.getMusicBasicId())
.maxCombo(req.getMaxCombo())
.maxScore(req.getScore())
.build());
//session.send(new PacketMusicGameSettleRsp(req.getMusicBasicId())); // update activity info
session.send(new PacketMusicGameSettleRsp(req.getMusicBasicId())); session.send(new PacketActivityInfoNotify(handler.toProto(playerData.get())));
}else{
handler.setMusicGameCustomBeatmapRecord(playerData.get(),
MusicGamePlayerData.CustomBeatmapRecord.of()
.musicShareId(req.getMusicShareId())
.score(req.getMaxCombo())
.settle(req.getSuccess())
.build());
}
session.send(new PacketMusicGameSettleRsp(req.getMusicBasicId(), req.getMusicShareId(), isNewRecord));
} }
} }
...@@ -9,12 +9,12 @@ import emu.grasscutter.server.packet.send.PacketMusicGameStartRsp; ...@@ -9,12 +9,12 @@ import emu.grasscutter.server.packet.send.PacketMusicGameStartRsp;
@Opcodes(PacketOpcodes.MusicGameStartReq) @Opcodes(PacketOpcodes.MusicGameStartReq)
public class HandlerMusicGameStartReq extends PacketHandler { public class HandlerMusicGameStartReq extends PacketHandler {
@Override @Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
var req = MusicGameStartReqOuterClass.MusicGameStartReq.parseFrom(payload); var req = MusicGameStartReqOuterClass.MusicGameStartReq.parseFrom(payload);
session.send(new PacketMusicGameStartRsp(req.getMusicBasicId())); session.send(new PacketMusicGameStartRsp(req.getMusicBasicId(), req.getMusicShareId()));
} }
} }
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.ActivityTakeWatcherRewardRspOuterClass;
public class PacketActivityTakeWatcherRewardRsp extends BasePacket {
public PacketActivityTakeWatcherRewardRsp(int activityId, int watcherId) {
super(PacketOpcodes.ActivityTakeWatcherRewardRsp);
var proto = ActivityTakeWatcherRewardRspOuterClass.ActivityTakeWatcherRewardRsp.newBuilder();
proto.setActivityId(activityId)
.setWatcherId(watcherId);
this.setData(proto);
}
}
...@@ -14,7 +14,7 @@ public class PacketGetActivityInfoRsp extends BasePacket { ...@@ -14,7 +14,7 @@ public class PacketGetActivityInfoRsp extends BasePacket {
var proto = GetActivityInfoRsp.newBuilder(); var proto = GetActivityInfoRsp.newBuilder();
activityIdList.stream() activityIdList.stream()
.map(activityManager::getInfoProto) .map(activityManager::getInfoProtoByActivityId)
.forEach(proto::addActivityInfoList); .forEach(proto::addActivityInfoList);
this.setData(proto); this.setData(proto);
......
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.MusicGameCreateBeatmapRspOuterClass;
import emu.grasscutter.net.proto.MusicGameUnknown1EnumOuterClass;
public class PacketMusicGameCreateBeatmapRsp extends BasePacket {
public PacketMusicGameCreateBeatmapRsp(long musicShareId, MusicGameUnknown1EnumOuterClass.MusicGameUnknown1Enum unknownEnum1) {
super(PacketOpcodes.MusicGameCreateBeatmapRsp);
var proto = MusicGameCreateBeatmapRspOuterClass.MusicGameCreateBeatmapRsp.newBuilder();
proto.setMusicShareId(musicShareId)
.setUnknownEnum1(unknownEnum1);
this.setData(proto);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.MusicBeatmapOuterClass;
import emu.grasscutter.net.proto.MusicBriefInfoOuterClass;
import emu.grasscutter.net.proto.MusicGameGetBeatmapReqOuterClass;
import emu.grasscutter.net.proto.MusicGameGetBeatmapRspOuterClass;
public class PacketMusicGameGetBeatmapRsp extends BasePacket {
public PacketMusicGameGetBeatmapRsp(MusicBriefInfoOuterClass.MusicBriefInfo briefInfo, MusicBeatmapOuterClass.MusicBeatmap musicRecord, MusicGameGetBeatmapReqOuterClass.MusicGameGetBeatmapReq req) {
super(PacketOpcodes.MusicGameGetBeatmapRsp);
var proto = MusicGameGetBeatmapRspOuterClass.MusicGameGetBeatmapRsp.newBuilder();
proto.setMusicBriefInfo(briefInfo)
.setMusicShareId(briefInfo.getMusicShareId())
.setMusicRecord(musicRecord)
.setUnknownEnum1(req.getUnknownEnum1())
.setReqType(req.getReqType())
;
this.setData(proto);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.MusicBriefInfoOuterClass;
import emu.grasscutter.net.proto.MusicGameSearchBeatmapRspOuterClass;
import emu.grasscutter.net.proto.MusicGameUnknown1EnumOuterClass;
public class PacketMusicGameSearchBeatmapRsp extends BasePacket {
public PacketMusicGameSearchBeatmapRsp(int ret, MusicGameUnknown1EnumOuterClass.MusicGameUnknown1Enum unknownEnum1) {
super(PacketOpcodes.MusicGameSearchBeatmapRsp);
var proto = MusicGameSearchBeatmapRspOuterClass.MusicGameSearchBeatmapRsp.newBuilder();
proto.setRetcode(ret)
.setUnknownEnum1(unknownEnum1);
this.setData(proto);
}
public PacketMusicGameSearchBeatmapRsp(MusicBriefInfoOuterClass.MusicBriefInfo briefInfo, MusicGameUnknown1EnumOuterClass.MusicGameUnknown1Enum unknownEnum1) {
super(PacketOpcodes.MusicGameSearchBeatmapRsp);
var proto = MusicGameSearchBeatmapRspOuterClass.MusicGameSearchBeatmapRsp.newBuilder();
proto.setMusicBriefInfo(briefInfo)
.setUnknownEnum1(unknownEnum1);
this.setData(proto);
}
}
...@@ -6,14 +6,15 @@ import emu.grasscutter.net.proto.MusicGameSettleRspOuterClass; ...@@ -6,14 +6,15 @@ import emu.grasscutter.net.proto.MusicGameSettleRspOuterClass;
public class PacketMusicGameSettleRsp extends BasePacket { public class PacketMusicGameSettleRsp extends BasePacket {
public PacketMusicGameSettleRsp(int musicBasicId) { public PacketMusicGameSettleRsp(int musicBasicId, long musicShareId, boolean isNewRecord) {
super(PacketOpcodes.MusicGameSettleRsp); super(PacketOpcodes.MusicGameSettleRsp);
var proto = MusicGameSettleRspOuterClass.MusicGameSettleRsp.newBuilder(); var proto = MusicGameSettleRspOuterClass.MusicGameSettleRsp.newBuilder();
proto.setMusicBasicId(musicBasicId) proto.setMusicBasicId(musicBasicId)
.setIsNewRecord(true); .setMusicShareId(musicShareId)
.setIsNewRecord(isNewRecord);
this.setData(proto); this.setData(proto);
} }
} }
...@@ -6,12 +6,13 @@ import emu.grasscutter.net.proto.MusicGameStartRspOuterClass; ...@@ -6,12 +6,13 @@ import emu.grasscutter.net.proto.MusicGameStartRspOuterClass;
public class PacketMusicGameStartRsp extends BasePacket { public class PacketMusicGameStartRsp extends BasePacket {
public PacketMusicGameStartRsp(int musicBasicId) { public PacketMusicGameStartRsp(int musicBasicId, long musicShareId) {
super(PacketOpcodes.MusicGameStartRsp); super(PacketOpcodes.MusicGameStartRsp);
var proto = MusicGameStartRspOuterClass.MusicGameStartRsp.newBuilder(); var proto = MusicGameStartRspOuterClass.MusicGameStartRsp.newBuilder();
proto.setMusicBasicId(musicBasicId); proto.setMusicBasicId(musicBasicId)
.setMusicShareId(musicShareId);
this.setData(proto); this.setData(proto);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
{ {
"activityId" : 5072, "activityId" : 5072,
"activityType" : 2202, "activityType" : 2202,
"scheduleId": 5072001,
"meetCondList" : [ "meetCondList" : [
5072001, 5072001,
5072002, 5072002,
...@@ -9,7 +10,10 @@ ...@@ -9,7 +10,10 @@
5072004, 5072004,
5072005, 5072005,
5072006, 5072006,
5072007 5072007,
5072008,
5072009,
5072013
], ],
"beginTime" : "2022-05-01T00:00:00+08:00", "beginTime" : "2022-05-01T00:00:00+08:00",
"endTime" : "2023-05-01T00:00:00+08:00" "endTime" : "2023-05-01T00:00:00+08:00"
......
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