Unverified Commit 8b520b38 authored by hamusuke's avatar hamusuke Committed by GitHub
Browse files

fix: unlocking home bgm doesn't work. (#1886)



* fix: unlocking home bgm doesn't work.

* Update src/main/java/emu/grasscutter/game/home/GameHome.java
Co-authored-by: default avatarLuke H-W <Birdulon@users.noreply.github.com>
Co-authored-by: default avatarLuke H-W <Birdulon@users.noreply.github.com>
parent 54ad108a
...@@ -11,6 +11,7 @@ import emu.grasscutter.data.excels.HomeWorldLevelData; ...@@ -11,6 +11,7 @@ import emu.grasscutter.data.excels.HomeWorldLevelData;
import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.packet.send.*; import emu.grasscutter.server.packet.send.*;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
...@@ -20,6 +21,7 @@ import java.util.HashSet; ...@@ -20,6 +21,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@Entity(value = "homes", useDiscriminator = false) @Entity(value = "homes", useDiscriminator = false)
@Data @Data
...@@ -57,6 +59,7 @@ public class GameHome { ...@@ -57,6 +59,7 @@ public class GameHome {
.ownerUid(uid) .ownerUid(uid)
.level(1) .level(1)
.sceneMap(new ConcurrentHashMap<>()) .sceneMap(new ConcurrentHashMap<>())
.unlockedHomeBgmList(new HashSet<>())
.build(); .build();
} }
...@@ -93,7 +96,7 @@ public class GameHome { ...@@ -93,7 +96,7 @@ public class GameHome {
} }
public boolean addUnlockedHomeBgm(int homeBgmId) { public boolean addUnlockedHomeBgm(int homeBgmId) {
if (getUnlockedHomeBgmList().add(homeBgmId)) return false; if (!getUnlockedHomeBgmList().add(homeBgmId)) return false;
var player = this.getPlayer(); var player = this.getPlayer();
player.sendPacket(new PacketUnlockHomeBgmNotify(homeBgmId)); player.sendPacket(new PacketUnlockHomeBgmNotify(homeBgmId));
...@@ -102,20 +105,22 @@ public class GameHome { ...@@ -102,20 +105,22 @@ public class GameHome {
return true; return true;
} }
public Set<Integer> getUnlockedHomeBgmListInfo() { public Set<Integer> getUnlockedHomeBgmList() {
if (this.unlockedHomeBgmList == null) { if (this.unlockedHomeBgmList == null) {
this.unlockedHomeBgmList = new HashSet<>(); this.unlockedHomeBgmList = new HashSet<>();
addAllDefaultUnlockedBgmIds(this.unlockedHomeBgmList); }
if (this.unlockedHomeBgmList.addAll(getDefaultUnlockedHomeBgmIds())) {
save(); save();
} }
return this.unlockedHomeBgmList; return this.unlockedHomeBgmList;
} }
private void addAllDefaultUnlockedBgmIds(Set<Integer> list) { private Set<Integer> getDefaultUnlockedHomeBgmIds() {
GameData.getHomeWorldBgmDataMap().forEach((id, data) -> { return GameData.getHomeWorldBgmDataMap().int2ObjectEntrySet().stream()
if (data.isDefaultUnlock()) .filter(e -> e.getValue().isDefaultUnlock())
list.add(id); .map(Int2ObjectMap.Entry::getIntKey)
}); .collect(Collectors.toUnmodifiableSet());
} }
} }
...@@ -17,7 +17,6 @@ public class HandlerChangeHomeBgmReq extends PacketHandler { ...@@ -17,7 +17,6 @@ public class HandlerChangeHomeBgmReq extends PacketHandler {
int homeBgmId = req.getUnk2700BJHAMKKECEI(); int homeBgmId = req.getUnk2700BJHAMKKECEI();
var home = session.getPlayer().getHome(); var home = session.getPlayer().getHome();
home.addUnlockedHomeBgm(homeBgmId); // Not sure if this is sane
home.getHomeSceneItem(session.getPlayer().getSceneId()).setHomeBgmId(homeBgmId); home.getHomeSceneItem(session.getPlayer().getSceneId()).setHomeBgmId(homeBgmId);
home.save(); home.save();
......
...@@ -13,7 +13,7 @@ public class PacketUnlockedHomeBgmNotify extends BasePacket { ...@@ -13,7 +13,7 @@ public class PacketUnlockedHomeBgmNotify extends BasePacket {
return; return;
} }
var unlocked = player.getHome().getUnlockedHomeBgmListInfo(); var unlocked = player.getHome().getUnlockedHomeBgmList();
var notify = Unk2700LOHBMOKOPLHServerNotify.Unk2700_LOHBMOKOPLH_ServerNotify.newBuilder() var notify = Unk2700LOHBMOKOPLHServerNotify.Unk2700_LOHBMOKOPLH_ServerNotify.newBuilder()
.addAllUnk2700KMEKMNONMGE(unlocked) .addAllUnk2700KMEKMNONMGE(unlocked)
......
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