mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-23 10:44:36 +01:00
implement background music
This commit is contained in:
@@ -34,6 +34,7 @@ public class GameData {
|
||||
@Getter private static Int2ObjectMap<PlayerIconExcel> playerIconExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
@Getter private static Int2ObjectMap<ItemComposeExcel> itemComposeExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
@Getter private static Int2ObjectMap<ActivityPanelExcel> activityPanelExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
@Getter private static Int2ObjectMap<BackGroundMusicExcel> backGroundMusicExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
@Getter private static Int2ObjectMap<ChallengeGroupExcel> challengeGroupExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
@Getter private static Int2ObjectMap<ChallengeExcel> challengeExcelMap = new Int2ObjectOpenHashMap<>();
|
||||
@@ -97,6 +98,22 @@ public class GameData {
|
||||
return allIds;
|
||||
}
|
||||
|
||||
public static List<Integer> getAllMusicIds() {
|
||||
List<Integer> allIds = new ArrayList<>();
|
||||
|
||||
for (Int2ObjectMap.Entry<BackGroundMusicExcel> entry : backGroundMusicExcelMap.int2ObjectEntrySet()) {
|
||||
BackGroundMusicExcel backGroundMusicExcel = entry.getValue();
|
||||
allIds.add(backGroundMusicExcel.getId());
|
||||
}
|
||||
|
||||
return allIds;
|
||||
}
|
||||
|
||||
public static int getMusicGroupId(int musicId) {
|
||||
var excel = backGroundMusicExcelMap.get(musicId);
|
||||
return excel != null ? excel.getGroupId() : 0;
|
||||
}
|
||||
|
||||
public static List<Integer> getAllPhoneThemes() {
|
||||
List<Integer> allIds = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package emu.lunarcore.data.excel;
|
||||
|
||||
import emu.lunarcore.data.GameResource;
|
||||
import emu.lunarcore.data.ResourceType;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@ResourceType(name = {"BackGroundMusic.json"})
|
||||
public class BackGroundMusicExcel extends GameResource {
|
||||
private int ID;
|
||||
private int GroupID;
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return ID;
|
||||
}
|
||||
public int getGroupId() {
|
||||
return GroupID;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -100,6 +100,8 @@ public class Player {
|
||||
private int planeId;
|
||||
private int floorId;
|
||||
private int entryId;
|
||||
|
||||
private int currentBgm;
|
||||
|
||||
private IntSet unlockedHeadIcons;
|
||||
private long lastActiveTime;
|
||||
@@ -161,6 +163,8 @@ public class Player {
|
||||
this.level = 1;
|
||||
this.stamina = GameConstants.MAX_STAMINA;
|
||||
this.nextStaminaRecover = System.currentTimeMillis();
|
||||
|
||||
this.currentBgm = 210000;
|
||||
|
||||
this.unlockedHeadIcons = new IntOpenHashSet();
|
||||
this.lineupManager = new LineupManager(this);
|
||||
@@ -254,6 +258,19 @@ public class Player {
|
||||
public int getChatBubble() {
|
||||
return this.chatBubble;
|
||||
}
|
||||
|
||||
public int getCurrentBgm() {
|
||||
if (this.currentBgm == 0) {
|
||||
this.currentBgm = 210000;
|
||||
this.save();
|
||||
}
|
||||
return this.currentBgm;
|
||||
}
|
||||
|
||||
public void setCurrentBgm(int musicId) {
|
||||
this.currentBgm = musicId;
|
||||
this.save();
|
||||
}
|
||||
|
||||
public Set<Integer> getUnlockedHeadIcons() {
|
||||
if (this.unlockedHeadIcons == null) {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package emu.lunarcore.server.packet.recv;
|
||||
|
||||
import emu.lunarcore.server.game.GameSession;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
import emu.lunarcore.server.packet.Opcodes;
|
||||
import emu.lunarcore.server.packet.PacketHandler;
|
||||
import emu.lunarcore.proto.GetJukeboxDataCsReqOuterClass.GetJukeboxDataCsReq;
|
||||
import emu.lunarcore.server.packet.send.PacketGetJukeboxDataScRsp;
|
||||
|
||||
@Opcodes(CmdId.GetJukeboxDataCsReq)
|
||||
public class HandlerGetJukeboxDataCsReq extends PacketHandler {
|
||||
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] data) throws Exception {
|
||||
// var req = GetJukeboxDataCsReq.parseFrom(data);
|
||||
session.send(new PacketGetJukeboxDataScRsp(session.getPlayer()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package emu.lunarcore.server.packet.recv;
|
||||
|
||||
import emu.lunarcore.proto.PlayBackGroundMusicCsReqOuterClass.PlayBackGroundMusicCsReq;
|
||||
import emu.lunarcore.server.packet.send.PacketPlayBackGroundMusicScRsp;
|
||||
import emu.lunarcore.server.game.GameSession;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
import emu.lunarcore.server.packet.Opcodes;
|
||||
import emu.lunarcore.server.packet.PacketHandler;
|
||||
|
||||
@Opcodes(CmdId.PlayBackGroundMusicCsReq)
|
||||
public class HandlerPlayBackGroundMusicCsReq extends PacketHandler {
|
||||
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] data) throws Exception {
|
||||
var req = PlayBackGroundMusicCsReq.parseFrom(data);
|
||||
|
||||
session.getPlayer().setCurrentBgm(req.getPlayMusicId());
|
||||
session.send(new PacketPlayBackGroundMusicScRsp(req.getPlayMusicId()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package emu.lunarcore.server.packet.recv;
|
||||
|
||||
import emu.lunarcore.proto.UnlockBackGroundMusicCsReqOuterClass.UnlockBackGroundMusicCsReq;
|
||||
import emu.lunarcore.server.game.GameSession;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import emu.lunarcore.server.packet.Opcodes;
|
||||
import emu.lunarcore.server.packet.PacketHandler;
|
||||
import emu.lunarcore.server.packet.send.PacketUnlockBackGroundMusicScRsp;
|
||||
|
||||
@Opcodes(CmdId.UnlockBackGroundMusicCsReq)
|
||||
public class HandlerUnlockBackGroundMusicCsReq extends PacketHandler {
|
||||
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] data) throws Exception {
|
||||
var req = UnlockBackGroundMusicCsReq.parseFrom(data);
|
||||
|
||||
var unlockIds = req.getUnlockIds();
|
||||
List<Integer> unlockIdsList = new ArrayList<>();
|
||||
for (int unlockId : unlockIds) {
|
||||
unlockIdsList.add(unlockId);
|
||||
}
|
||||
if (unlockIdsList.isEmpty()) {
|
||||
session.send(new PacketUnlockBackGroundMusicScRsp());
|
||||
}
|
||||
else {
|
||||
session.send(new PacketUnlockBackGroundMusicScRsp(unlockIdsList));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package emu.lunarcore.server.packet.send;
|
||||
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.data.GameData;
|
||||
import emu.lunarcore.proto.GetJukeboxDataScRspOuterClass.GetJukeboxDataScRsp;
|
||||
import emu.lunarcore.proto.GetJukeboxDataScRspOuterClass.GetJukeboxDataScRsp.UnlockedMusic;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
|
||||
public class PacketGetJukeboxDataScRsp extends BasePacket {
|
||||
|
||||
public PacketGetJukeboxDataScRsp(Player player) {
|
||||
super(CmdId.GetJukeboxDataScRsp);
|
||||
|
||||
var allmusicids = GameData.getAllMusicIds();
|
||||
|
||||
var data = GetJukeboxDataScRsp.newInstance()
|
||||
.setPlayingId(player.getCurrentBgm());
|
||||
|
||||
for (int musicId : allmusicids) {
|
||||
UnlockedMusic musicListEntry = UnlockedMusic.newInstance()
|
||||
.setId(musicId)
|
||||
.setUnkbool(true)
|
||||
.setGroupId(GameData.getMusicGroupId(musicId));
|
||||
|
||||
data.addMusicList(musicListEntry);
|
||||
}
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package emu.lunarcore.server.packet.send;
|
||||
|
||||
import emu.lunarcore.proto.PlayBackGroundMusicScRspOuterClass.PlayBackGroundMusicScRsp;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
|
||||
public class PacketPlayBackGroundMusicScRsp extends BasePacket {
|
||||
|
||||
public PacketPlayBackGroundMusicScRsp(int musicId) {
|
||||
super(CmdId.PlayBackGroundMusicScRsp);
|
||||
|
||||
var data = PlayBackGroundMusicScRsp.newInstance()
|
||||
.setPlayingId(musicId)
|
||||
.setPlayMusicId(musicId);
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package emu.lunarcore.server.packet.send;
|
||||
|
||||
import java.util.List;
|
||||
import emu.lunarcore.proto.UnlockBackGroundMusicScRspOuterClass.UnlockBackGroundMusicScRsp.UnlockedMusic;
|
||||
import emu.lunarcore.proto.UnlockBackGroundMusicScRspOuterClass.UnlockBackGroundMusicScRsp;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
import emu.lunarcore.data.GameData;
|
||||
|
||||
public class PacketUnlockBackGroundMusicScRsp extends BasePacket {
|
||||
|
||||
public PacketUnlockBackGroundMusicScRsp(List<Integer> unlockIds) {
|
||||
super(CmdId.UnlockBackGroundMusicScRsp);
|
||||
|
||||
var data = UnlockBackGroundMusicScRsp.newInstance();
|
||||
|
||||
for (int unlockId : unlockIds) {
|
||||
UnlockedMusic music = UnlockedMusic.newInstance()
|
||||
.setGroupId(GameData.getMusicGroupId(unlockId))
|
||||
.setId(unlockId);
|
||||
data.addMusicList(music);
|
||||
}
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
|
||||
public PacketUnlockBackGroundMusicScRsp() {
|
||||
super(CmdId.UnlockBackGroundMusicScRsp);
|
||||
this.setData(UnlockBackGroundMusicScRsp.newInstance());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user