diff --git a/src/main/java/emu/grasscutter/game/home/GameHome.java b/src/main/java/emu/grasscutter/game/home/GameHome.java index dcbe853b9..dcafea6db 100644 --- a/src/main/java/emu/grasscutter/game/home/GameHome.java +++ b/src/main/java/emu/grasscutter/game/home/GameHome.java @@ -11,6 +11,7 @@ import emu.grasscutter.data.excels.HomeWorldLevelData; import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.game.player.Player; import emu.grasscutter.server.packet.send.*; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import lombok.AccessLevel; import lombok.Builder; import lombok.Data; @@ -20,6 +21,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; @Entity(value = "homes", useDiscriminator = false) @Data @@ -57,6 +59,7 @@ public class GameHome { .ownerUid(uid) .level(1) .sceneMap(new ConcurrentHashMap<>()) + .unlockedHomeBgmList(new HashSet<>()) .build(); } @@ -93,7 +96,7 @@ public class GameHome { } public boolean addUnlockedHomeBgm(int homeBgmId) { - if (getUnlockedHomeBgmList().add(homeBgmId)) return false; + if (!getUnlockedHomeBgmList().add(homeBgmId)) return false; var player = this.getPlayer(); player.sendPacket(new PacketUnlockHomeBgmNotify(homeBgmId)); @@ -102,20 +105,22 @@ public class GameHome { return true; } - public Set getUnlockedHomeBgmListInfo() { + public Set getUnlockedHomeBgmList() { if (this.unlockedHomeBgmList == null) { this.unlockedHomeBgmList = new HashSet<>(); - addAllDefaultUnlockedBgmIds(this.unlockedHomeBgmList); + } + + if (this.unlockedHomeBgmList.addAll(getDefaultUnlockedHomeBgmIds())) { save(); } return this.unlockedHomeBgmList; } - private void addAllDefaultUnlockedBgmIds(Set list) { - GameData.getHomeWorldBgmDataMap().forEach((id, data) -> { - if (data.isDefaultUnlock()) - list.add(id); - }); + private Set getDefaultUnlockedHomeBgmIds() { + return GameData.getHomeWorldBgmDataMap().int2ObjectEntrySet().stream() + .filter(e -> e.getValue().isDefaultUnlock()) + .map(Int2ObjectMap.Entry::getIntKey) + .collect(Collectors.toUnmodifiableSet()); } } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeHomeBgmReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeHomeBgmReq.java index ea73264e8..0ce35064e 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeHomeBgmReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeHomeBgmReq.java @@ -17,7 +17,6 @@ public class HandlerChangeHomeBgmReq extends PacketHandler { int homeBgmId = req.getUnk2700BJHAMKKECEI(); var home = session.getPlayer().getHome(); - home.addUnlockedHomeBgm(homeBgmId); // Not sure if this is sane home.getHomeSceneItem(session.getPlayer().getSceneId()).setHomeBgmId(homeBgmId); home.save(); diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockedHomeBgmNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockedHomeBgmNotify.java index 9c7fd43ad..ad8c1e7c7 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockedHomeBgmNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockedHomeBgmNotify.java @@ -13,7 +13,7 @@ public class PacketUnlockedHomeBgmNotify extends BasePacket { return; } - var unlocked = player.getHome().getUnlockedHomeBgmListInfo(); + var unlocked = player.getHome().getUnlockedHomeBgmList(); var notify = Unk2700LOHBMOKOPLHServerNotify.Unk2700_LOHBMOKOPLH_ServerNotify.newBuilder() .addAllUnk2700KMEKMNONMGE(unlocked)